Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/files/file_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ BASE_EXPORT FILE* CreateAndOpenTemporaryFile(FilePath* path);

// Similar to CreateAndOpenTemporaryFile, but the file is created in |dir|.
BASE_EXPORT FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir,
#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
FilePath* path,
int* id = NULL);
#else
Expand Down
10 changes: 5 additions & 5 deletions base/files/file_util_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#include <grp.h>
#endif

#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
#include "base/base_switches.h"
#include "base/command_line.h"
#endif
Expand Down Expand Up @@ -143,7 +143,7 @@ std::string TempFileName() {
#endif
}

#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
// Creates and opens a temporary file in |directory|, returning the
// file descriptor. |path| is set to the temporary file path.
// This function does NOT unlink() the file.
Expand Down Expand Up @@ -689,7 +689,7 @@ bool CreateTemporaryFile(FilePath* path) {
return true;
}

#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, FilePath* path, int* id) {
int fd = CreateAndOpenFdForTemporaryFile(dir, path, id);
#else
Expand All @@ -713,7 +713,7 @@ bool CreateTemporaryFileInDir(const FilePath& dir, FilePath* temp_file) {

static bool CreateTemporaryDirInDirImpl(const FilePath& base_dir,
const FilePath::StringType& name_tmpl,
#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
FilePath* new_dir,
int *id = NULL) {
#else
Expand Down Expand Up @@ -1041,7 +1041,7 @@ bool GetShmemTempDir(bool executable, FilePath* path) {
if (use_dev_shm) {
// Use mountpoint for browser process and actual folder for renderer process
// assuming NFS server is renderer and browser is its client.
#if !defined(NETWORK_SHARED_MEMORY)
#if !defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
*path = FilePath("/dev/shm");
#else
std::string shared_memory_file_path;
Expand Down
8 changes: 4 additions & 4 deletions base/memory/shared_memory_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class BASE_EXPORT SharedMemoryHandle {
// when trying to map the SharedMemoryHandle at a later point in time.
SharedMemoryHandle(const base::FileDescriptor& file_descriptor,
size_t size,
#if !defined(NETWORK_SHARED_MEMORY)
#if !defined(NETWORK_SHARED_MEMORY) && !defined(LOCAL_SHARED_MEMORY)
const base::UnguessableToken& guid);
#else
const base::UnguessableToken& guid, int shared_memory_file_id = 0);
Expand All @@ -169,7 +169,7 @@ class BASE_EXPORT SharedMemoryHandle {
// service.
// Passing the wrong |size| has no immediate consequence, but may cause errors
// when trying to map the SharedMemoryHandle at a later point in time.
#if !defined(NETWORK_SHARED_MEMORY)
#if !defined(NETWORK_SHARED_MEMORY)&& !defined(LOCAL_SHARED_MEMORY)
static SharedMemoryHandle ImportHandle(int fd, size_t size);
#else
static SharedMemoryHandle ImportHandle(int fd, size_t size, int shared_memory_file_id = 0);
Expand All @@ -182,7 +182,7 @@ class BASE_EXPORT SharedMemoryHandle {
// unless the caller is careful.
int Release();
#endif
#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
int GetMemoryFileId() const { return shared_memory_file_id_; }
void SetMemoryFileId(int id) { shared_memory_file_id_ = id; }
#endif
Expand Down Expand Up @@ -228,7 +228,7 @@ class BASE_EXPORT SharedMemoryHandle {

// The size of the region referenced by the SharedMemoryHandle.
size_t size_ = 0;
#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
int shared_memory_file_id_;
#endif
};
Expand Down
12 changes: 6 additions & 6 deletions base/memory/shared_memory_handle_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ SharedMemoryHandle::SharedMemoryHandle() = default;
SharedMemoryHandle::SharedMemoryHandle(
const base::FileDescriptor& file_descriptor,
size_t size,
#if !defined(NETWORK_SHARED_MEMORY)
#if !defined(NETWORK_SHARED_MEMORY) && !defined(LOCAL_SHARED_MEMORY)
const base::UnguessableToken& guid)
#else
const base::UnguessableToken& guid, int shared_memory_file_id)
#endif
: file_descriptor_(file_descriptor), guid_(guid), size_(size) {
#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
shared_memory_file_id_ = shared_memory_file_id;
#endif
}

// static
#if !defined(NETWORK_SHARED_MEMORY)
#if !defined(NETWORK_SHARED_MEMORY) && !defined(LOCAL_SHARED_MEMORY)
SharedMemoryHandle SharedMemoryHandle::ImportHandle(int fd, size_t size) {
#else
SharedMemoryHandle SharedMemoryHandle::ImportHandle(int fd, size_t size, int shared_memory_file_id) {
Expand All @@ -43,7 +43,7 @@ SharedMemoryHandle SharedMemoryHandle::ImportHandle(int fd, size_t size, int sha
handle.file_descriptor_.auto_close = false;
handle.guid_ = UnguessableToken::Create();
handle.size_ = size;
#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
handle.shared_memory_file_id_ = shared_memory_file_id;
#endif
return handle;
Expand Down Expand Up @@ -82,7 +82,7 @@ SharedMemoryHandle SharedMemoryHandle::Duplicate() const {
#if defined(CASTANETS)
if (base::Castanets::IsEnabled() &&
file_descriptor_.fd == 0) {
#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
return SharedMemoryHandle(FileDescriptor(0, true), GetSize(), GetGUID(), GetMemoryFileId());
#else
return SharedMemoryHandle(FileDescriptor(0, true), GetSize(), GetGUID());
Expand All @@ -94,7 +94,7 @@ SharedMemoryHandle SharedMemoryHandle::Duplicate() const {
if (duped_handle < 0)
return SharedMemoryHandle();
return SharedMemoryHandle(FileDescriptor(duped_handle, true), GetSize(),
#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
GetGUID(), GetMemoryFileId());
#else
GetGUID());
Expand Down
6 changes: 3 additions & 3 deletions base/memory/shared_memory_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ using ScopedPathUnlinker =
bool CreateAnonymousSharedMemory(const SharedMemoryCreateOptions& options,
ScopedFILE* fp,
ScopedFD* readonly_fd,
#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
FilePath* path,
int *id) {
#else
Expand All @@ -49,7 +49,7 @@ bool CreateAnonymousSharedMemory(const SharedMemoryCreateOptions& options,
if (!GetShmemTempDir(options.executable, &directory))
return false;

#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
fp->reset(base::CreateAndOpenTemporaryFileInDir(directory, path, id));
#else
fp->reset(base::CreateAndOpenTemporaryFileInDir(directory, path));
Expand All @@ -61,7 +61,7 @@ bool CreateAnonymousSharedMemory(const SharedMemoryCreateOptions& options,
// Deleting the file prevents anyone else from mapping it in (making it
// private), and prevents the need for cleanup (once the last fd is
// closed, it is truly freed).
#if !defined(NETWORK_SHARED_MEMORY)
#if !defined(NETWORK_SHARED_MEMORY) && !defined(LOCAL_SHARED_MEMORY)
path_unlinker.reset(path);
#endif

Expand Down
2 changes: 1 addition & 1 deletion base/memory/shared_memory_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace base {
bool CreateAnonymousSharedMemory(const SharedMemoryCreateOptions& options,
ScopedFILE* fp,
ScopedFD* readonly_fd,
#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
FilePath* path,
int* id = NULL);
#else
Expand Down
37 changes: 28 additions & 9 deletions base/memory/shared_memory_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <sys/stat.h>
#include <unistd.h>

#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/logging.h"
Expand All @@ -25,6 +27,7 @@
#include "base/trace_event/trace_event.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
#include "content/public/common/content_switches.h"

#if defined(OS_ANDROID)
#include "base/os_compat_android.h"
Expand Down Expand Up @@ -105,11 +108,11 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options, int sid) {
ScopedFD readonly_fd;

FilePath path;
#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
int shared_memory_file_id = sid;
#endif
if (options.name_deprecated == NULL || options.name_deprecated->empty()) {
#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
bool result =
CreateAnonymousSharedMemory(options, &fp, &readonly_fd, &path, &shared_memory_file_id);
#else
Expand All @@ -125,7 +128,7 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options, int sid) {

// Make sure that the file is opened without any permission
// to other users on the system.
#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) && !defined(LOCAL_SHARED_MEMORY)
const mode_t kOwnerOnly = S_IRUSR | S_IWUSR | S_IRWXU| S_IRWXO;
#else
const mode_t kOwnerOnly = S_IRUSR | S_IWUSR;
Expand Down Expand Up @@ -153,7 +156,7 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options, int sid) {
// Check that the current user owns the file.
// If uid != euid, then a more complex permission model is used and this
// API is not appropriate.
#if !defined(NETWORK_SHARED_MEMORY)
#if !defined(NETWORK_SHARED_MEMORY) && !defined(LOCAL_SHARED_MEMORY)
const uid_t real_uid = getuid();
const uid_t effective_uid = geteuid();
struct stat sb;
Expand Down Expand Up @@ -215,7 +218,7 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options, int sid) {
int readonly_mapped_file = -1;
bool result = PrepareMapFile(std::move(fp), std::move(readonly_fd),
&mapped_file, &readonly_mapped_file);
#if !defined(NETWORK_SHARED_MEMORY)
#if !defined(NETWORK_SHARED_MEMORY) && !defined(LOCAL_SHARED_MEMORY)
shm_ = SharedMemoryHandle(base::FileDescriptor(mapped_file, false),
options.size, UnguessableToken::Create());
readonly_shm_ =
Expand Down Expand Up @@ -305,8 +308,14 @@ bool SharedMemory::MapAt(off_t offset, size_t bytes) {
#endif

#if defined(CASTANETS)
std::string process_type_str =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type");
if (Castanets::IsEnabled())
memory_ = new uint8_t[bytes];
if (process_type_str == "renderer" || process_type_str == "utility")
memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE),
MAP_SHARED, shm_.GetHandle(), offset);
else
memory_ = new uint8_t[bytes];
else {
memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE),
MAP_SHARED, shm_.GetHandle(), offset);
Expand Down Expand Up @@ -343,8 +352,13 @@ bool SharedMemory::Unmap() {

SharedMemoryTracker::GetInstance()->DecrementMemoryUsage(*this);
#if defined(CASTANETS)
std::string process_type_str =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type");
if (Castanets::IsEnabled())
delete [] memory_;
if (process_type_str == "renderer" || process_type_str == "utility")
munmap(memory_, mapped_size_);
else
delete [] memory_;
#else
munmap(memory_, mapped_size_);
#endif
Expand All @@ -363,8 +377,13 @@ SharedMemoryHandle SharedMemory::TakeHandle() {
handle_copy.SetOwnershipPassesToIPC(true);
shm_ = SharedMemoryHandle();
#if defined(CASTANETS)
std::string process_type_str =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type");
if (Castanets::IsEnabled())
delete [] memory_;
if (process_type_str == "renderer" || process_type_str == "utility")
munmap(memory_, mapped_size_);
else
delete [] memory_;
#endif
memory_ = nullptr;
mapped_size_ = 0;
Expand Down Expand Up @@ -399,7 +418,7 @@ bool SharedMemory::FilePathForMemoryName(const std::string& mem_name,

#if defined(GOOGLE_CHROME_BUILD)
std::string name_base = std::string("com.google.Chrome");
#elif defined(NETWORK_SHARED_MEMORY)
#elif defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
std::string name_base = std::string(".org.chromium.Chromium");
#else
std::string name_base = std::string("org.chromium.Chromium");
Expand Down
3 changes: 3 additions & 0 deletions build/config/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ config("feature_flags") {
if (enable_network_shared_memory) {
defines += [ "NETWORK_SHARED_MEMORY" ]
}
if (enable_local_shared_memory) {
defines += [ "LOCAL_SHARED_MEMORY" ]
}
if (dcheck_always_on) {
defines += [ "DCHECK_ALWAYS_ON=1" ]
}
Expand Down
1 change: 1 addition & 0 deletions build/config/features.gni
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ declare_args() {
# Enables CASTANETS.
enable_castanets = false
enable_network_shared_memory = false
enable_local_shared_memory = false

# Enables proprietary codecs and demuxers; e.g. H264, AAC, MP3, and MP4.
# We always build Google Chrome and Chromecast with proprietary codecs.
Expand Down
7 changes: 0 additions & 7 deletions content/browser/loader/mojo_async_resource_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,8 @@ void MojoAsyncResourceHandler::OnReadCompleted(

if (response_body_consumer_handle_.is_valid()) {
// Send the data pipe on the first OnReadCompleted call.
#if defined(CASTANETS)
if (!base::Castanets::IsEnabled()) {
url_loader_client_->OnStartLoadingResponseBody(
std::move(response_body_consumer_handle_));
}
#else
url_loader_client_->OnStartLoadingResponseBody(
std::move(response_body_consumer_handle_));
#endif
response_body_consumer_handle_.reset();
}

Expand Down
25 changes: 18 additions & 7 deletions content/child/child_thread_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,13 @@ InitializeMojoIPCChannel() {
if (!platform_channel.is_valid())
return nullptr;

std::string type =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessType);

return mojo::edk::IncomingBrokerClientInvitation::Accept(
mojo::edk::ConnectionParams(mojo::edk::TransportProtocol::kLegacy,
std::move(platform_channel)));
std::move(platform_channel)), type);
}

class ChannelBootstrapFilter : public ConnectionFilter {
Expand Down Expand Up @@ -503,12 +507,19 @@ void ChildThreadImpl::Init(const Options& options) {
#if defined(CASTANETS)
std::string service_request_token;
if (base::Castanets::IsEnabled()) {
service_request_token = "castanets_service_request";
// workaround
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kRendererClientId, std::to_string(1));
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kNumRasterThreads, std::to_string(4));
std::string process_type_str =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessType);
if (process_type_str == switches::kUtilityProcess)
service_request_token = "castanets_service_utility_request";
else {
service_request_token = "castanets_service_renderer_request";
// workaround
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kRendererClientId, std::to_string(1));
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kNumRasterThreads, std::to_string(4));
}
} else {
service_request_token =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
Expand Down
5 changes: 1 addition & 4 deletions content/child/resource_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void ResourceDispatcher::OnSetDataBuffer(int request_id,
CHECK((shm_valid && shm_size > 0) || (!shm_valid && !shm_size));
}
#endif
#if defined(NETWORK_SHARED_MEMORY)
#if defined(NETWORK_SHARED_MEMORY) || defined(LOCAL_SHARED_MEMORY)
request_info->buffer.reset(
new base::SharedMemory(shm_handle, true)); // read only
if(request_info->buffer->handle().GetHandle() == 0)
Expand Down Expand Up @@ -298,9 +298,6 @@ void ResourceDispatcher::OnReceivedData(int request_id,
CHECK(data_start);
CHECK(data_start + data_offset);
const char* data_ptr = data_start + data_offset;
const uint8_t* start_ptr = static_cast<uint8_t*>(request_info->buffer->memory()) + data_offset;
std::vector<uint8_t> bytes(start_ptr, start_ptr + data_length);
DVLOG(1) << " Renderer received data :" << reinterpret_cast<const char*>(&bytes.front());
#if defined(CASTANETS) && !defined(NETWORK_SHARED_MEMORY)
if (base::Castanets::IsEnabled()) {
uint8_t* cpy_ptr = static_cast<uint8_t*>(request_info->buffer->memory()) + data_offset;
Expand Down
Loading