From a9bacd14e6b73104302cbd74e9a6c3df921a836a Mon Sep 17 00:00:00 2001 From: v-saha Date: Thu, 23 Sep 2021 17:05:44 +0530 Subject: [PATCH] Add support of run time flags for enable Castanets This change adds runtime flag to enable castanets. Runtime flags --enable-forking, --server-address has been removed. Castanets can be verified as below, Standalone mode: chrome Castanets mode: Browser: chrome --enable-castanets Renderer: chrome --type=renderer --enable-castanets= Signed-off-by: v-saha --- base/BUILD.gn | 8 + base/base_switches.cc | 6 +- base/base_switches.h | 3 +- base/distributed_chromium_util.cc | 30 +++ base/distributed_chromium_util.h | 22 ++ .../platform_shared_memory_region_posix.cc | 4 +- base/memory/shared_memory_tracker.cc | 25 +- base/process/kill_posix.cc | 8 +- base/process/process_posix.cc | 15 +- cc/raster/one_copy_raster_buffer_provider.cc | 6 +- cc/raster/staging_buffer_pool.cc | 31 ++- cc/tiles/tile_manager.cc | 6 +- cc/trees/layer_tree_host_impl.cc | 9 +- chrome/app/chrome_main_delegate.cc | 90 ++++--- ...lient_discardable_shared_memory_manager.cc | 79 +++--- .../font/public/cpp/font_service_thread.cc | 74 ++--- .../renderer/unverified_ruleset_dealer.cc | 10 +- .../server_shared_bitmap_manager.cc | 4 +- content/app/content_main_runner_impl.cc | 44 +-- .../browser/android/content_startup_flags.cc | 33 +-- .../browser_child_process_host_impl.cc | 11 +- .../browser/child_process_launcher_helper.cc | 13 +- .../child_process_launcher_helper_linux.cc | 32 ++- content/browser/frame_host/frame_tree_node.cc | 5 +- .../frame_host/render_frame_host_manager.cc | 6 +- .../renderer_host/render_process_host_impl.cc | 14 +- ...hild_process_sandbox_support_impl_linux.cc | 70 ++--- content/child/child_thread_impl.cc | 27 +- .../public/browser/content_browser_client.cc | 10 +- .../public/common/use_zoom_for_dsf_policy.cc | 7 +- content/test/test_render_frame.cc | 2 +- .../client/cmd_buffer_helper.cc | 7 +- .../client/implementation_base.cc | 29 +- gpu/command_buffer/client/mapped_memory.h | 6 +- gpu/command_buffer/client/transfer_buffer.cc | 6 +- .../service/command_buffer_service.cc | 3 +- gpu/command_buffer/service/common_decoder.cc | 19 +- ipc/ipc_message_utils.cc | 6 +- media/renderers/video_resource_updater.cc | 11 +- .../gpu_memory_buffer_video_frame_pool.cc | 9 +- mojo/core/broker_host.cc | 18 +- mojo/core/broker_posix.cc | 2 +- mojo/core/channel_posix.cc | 48 ++-- mojo/core/core.cc | 43 +-- mojo/core/data_pipe_consumer_dispatcher.cc | 75 +++--- mojo/core/data_pipe_producer_dispatcher.cc | 7 +- mojo/core/node_controller.cc | 253 ++++++++++-------- mojo/core/node_controller.h | 4 +- mojo/core/shared_buffer_dispatcher.cc | 35 ++- .../platform/named_platform_channel_posix.cc | 6 +- .../platform/fonts/skia/font_cache_skia.cc | 12 +- 51 files changed, 782 insertions(+), 521 deletions(-) create mode 100644 base/distributed_chromium_util.cc create mode 100644 base/distributed_chromium_util.h diff --git a/base/BUILD.gn b/base/BUILD.gn index 297cd619eae..4131fc437f5 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -2084,6 +2084,14 @@ jumbo_component("base") { sources += [ "time/time_android.cc" ] } + # Distributed chromium + if (enable_castanets) { + sources += [ + "distributed_chromium_util.cc", + "distributed_chromium_util.h", + ] + } + if (!use_glib) { sources -= [ "message_loop/message_pump_glib.cc", diff --git a/base/base_switches.cc b/base/base_switches.cc index ffd61f60df1..92c742a7294 100644 --- a/base/base_switches.cc +++ b/base/base_switches.cc @@ -151,10 +151,8 @@ const char kEnableThreadInstructionCount[] = "enable-thread-instruction-count"; #endif #if defined(CASTANETS) -const char kEnableForking[] = "enable-forking"; - -// Specify distributed chrome server address. -const char kServerAddress[] = "server-address"; +// Enable features for distributed chromium. +const char kEnableCastanets[] = "enable-castanets"; const char kTcpLaunchTimeout[] = "tcp-launch-timeout"; diff --git a/base/base_switches.h b/base/base_switches.h index 43ae5ab99a8..849318884a4 100644 --- a/base/base_switches.h +++ b/base/base_switches.h @@ -57,8 +57,7 @@ extern const char kEnableThreadInstructionCount[]; #endif #if defined(CASTANETS) -extern const char kEnableForking[]; -extern const char kServerAddress[]; +extern const char kEnableCastanets[]; extern const char kTcpLaunchTimeout[]; extern const char kSecureConnection[]; #endif diff --git a/base/distributed_chromium_util.cc b/base/distributed_chromium_util.cc new file mode 100644 index 00000000000..3271bdba805 --- /dev/null +++ b/base/distributed_chromium_util.cc @@ -0,0 +1,30 @@ +// Copyright 2020 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/distributed_chromium_util.h" + +#include "base/base_switches.h" +#include "base/command_line.h" + +namespace base { + +bool Castanets::IsEnabled() { + return (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableCastanets)) + ? true + : false; +} + +std::string Castanets::ServerAddress() { + std::string server_address; + base::CommandLine* command_line = CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kEnableCastanets)) { + server_address = + command_line->GetSwitchValueASCII(switches::kEnableCastanets); + } + + return server_address; +} + +} // namespace base diff --git a/base/distributed_chromium_util.h b/base/distributed_chromium_util.h new file mode 100644 index 00000000000..86eae12fb51 --- /dev/null +++ b/base/distributed_chromium_util.h @@ -0,0 +1,22 @@ +// Copyright 2020 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_DISTRIBUTED_CHROMIUM_H_ +#define BASE_DISTRIBUTED_CHROMIUM_H_ + +#include +#include + +#include "base/base_export.h" + +namespace base { +class BASE_EXPORT Castanets { + public: + static bool IsEnabled(); + static std::string ServerAddress(); +}; + +} // namespace base + +#endif // BASE_DISTRIBUTED_CHROMIUM_H_ diff --git a/base/memory/platform_shared_memory_region_posix.cc b/base/memory/platform_shared_memory_region_posix.cc index 254277f6dad..87be5f87903 100644 --- a/base/memory/platform_shared_memory_region_posix.cc +++ b/base/memory/platform_shared_memory_region_posix.cc @@ -17,6 +17,7 @@ #if defined(CASTANETS) #include "base/base_switches.h" #include "base/command_line.h" +#include "base/distributed_chromium_util.h" #endif #if defined(OS_ANDROID) && defined(CASTANETS) @@ -173,8 +174,7 @@ PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Duplicate() const { bool PlatformSharedMemoryRegion::ConvertToReadOnly() { #if defined(CASTANETS) - if (!base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableForking)) { + if (base::Castanets::IsEnabled()) { mode_ = Mode::kReadOnly; return true; } diff --git a/base/memory/shared_memory_tracker.cc b/base/memory/shared_memory_tracker.cc index 8ff26e44219..7cc3a7a22ac 100644 --- a/base/memory/shared_memory_tracker.cc +++ b/base/memory/shared_memory_tracker.cc @@ -16,6 +16,7 @@ #endif // BUILDFLAG(ENABLE_BASE_TRACING) #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "base/logging.h" #include "base/memory/castanets_memory_mapping.h" #include "base/memory/castanets_memory_syncer.h" @@ -105,11 +106,13 @@ void SharedMemoryTracker::IncrementMemoryUsage( UsageInfo(mapping.mapped_size(), mapping.guid())); #if defined(CASTANETS) - AutoGuidLock guid_lock(mapping.guid()); - AddMapping(mapping.guid(), mapping.mapped_size(), mapping.raw_memory_ptr()); - // The shared memory corresponding to the guid began to be used somewhere. - // Therefore delete the holder if it exists. - RemoveHolder(mapping.guid()); + if (base::Castanets::IsEnabled()) { + AutoGuidLock guid_lock(mapping.guid()); + AddMapping(mapping.guid(), mapping.mapped_size(), mapping.raw_memory_ptr()); + // The shared memory corresponding to the guid began to be used somewhere. + // Therefore delete the holder if it exists. + RemoveHolder(mapping.guid()); + } #endif } @@ -119,14 +122,19 @@ void SharedMemoryTracker::DecrementMemoryUsage( DCHECK(usages_.find(mapping.raw_memory_ptr()) != usages_.end()); usages_.erase(mapping.raw_memory_ptr()); #if defined(CASTANETS) - AutoGuidLock guid_lock(mapping.guid()); - RemoveMapping(mapping.guid(), mapping.raw_memory_ptr()); + if (base::Castanets::IsEnabled()) { + AutoGuidLock guid_lock(mapping.guid()); + RemoveMapping(mapping.guid(), mapping.raw_memory_ptr()); + } #endif } #if defined(CASTANETS) void SharedMemoryTracker::AddMapping(const UnguessableToken &guid, size_t size, void *ptr) { + if (!base::Castanets::IsEnabled()) + return; + AutoLock hold(mapping_lock_); auto it = mappings_.find(guid); if (it == mappings_.end()) { @@ -149,6 +157,9 @@ void SharedMemoryTracker::AddMapping(const UnguessableToken &guid, size_t size, void SharedMemoryTracker::RemoveMapping(const UnguessableToken &guid, void *ptr) { + if (!base::Castanets::IsEnabled()) + return; + AutoLock hold(mapping_lock_); auto it = mappings_.find(guid); CHECK(it != mappings_.end()); diff --git a/base/process/kill_posix.cc b/base/process/kill_posix.cc index 00721ba754a..3a49806498d 100644 --- a/base/process/kill_posix.cc +++ b/base/process/kill_posix.cc @@ -20,6 +20,10 @@ #include "base/threading/platform_thread.h" #include "build/build_config.h" +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + namespace base { namespace { @@ -30,7 +34,7 @@ TerminationStatus GetTerminationStatusImpl(ProcessHandle handle, DCHECK(exit_code); #if defined(CASTANETS) - if (handle == kCastanetsProcessHandle) { + if (base::Castanets::IsEnabled() && (handle == kCastanetsProcessHandle)) { *exit_code = 0; return TERMINATION_STATUS_NORMAL_TERMINATION; } @@ -99,7 +103,7 @@ TerminationStatus GetTerminationStatus(ProcessHandle handle, int* exit_code) { TerminationStatus GetKnownDeadTerminationStatus(ProcessHandle handle, int* exit_code) { #if defined(CASTANETS) - if (handle == kCastanetsProcessHandle) + if (base::Castanets::IsEnabled() && (handle == kCastanetsProcessHandle)) return GetTerminationStatusImpl(handle, true /* can_block */, exit_code); #endif bool result = kill(handle, SIGKILL) == 0; diff --git a/base/process/process_posix.cc b/base/process/process_posix.cc index 92e31c86564..c8298a6a913 100644 --- a/base/process/process_posix.cc +++ b/base/process/process_posix.cc @@ -27,6 +27,10 @@ #include "base/test/clang_profiling.h" #endif +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + namespace { #if !defined(OS_NACL_NONSFI) @@ -188,7 +192,8 @@ bool WaitForExitWithTimeoutImpl(base::ProcessHandle handle, base::TimeDelta timeout) { #if defined(CASTANETS) - if (handle < base::kCastanetsProcessHandle) { + if (base::Castanets::IsEnabled() && + (handle < base::kCastanetsProcessHandle)) { *exit_code = -1; return true; } @@ -292,7 +297,7 @@ void Process::TerminateCurrentProcessImmediately(int exit_code) { bool Process::IsValid() const { #if defined(CASTANETS) - if (process_ < kCastanetsProcessHandle) + if (base::Castanets::IsEnabled() && (process_ < kCastanetsProcessHandle)) return true; #endif return process_ != kNullProcessHandle; @@ -311,7 +316,7 @@ Process Process::Duplicate() const { ProcessId Process::Pid() const { #if defined(CASTANETS) - if (process_ < kCastanetsProcessHandle) + if (base::Castanets::IsEnabled() && (process_ < kCastanetsProcessHandle)) return kCastanetsProcessId; #endif DCHECK(IsValid()); @@ -332,7 +337,7 @@ void Process::Close() { #if !defined(OS_NACL_NONSFI) bool Process::Terminate(int exit_code, bool wait) const { #if defined(CASTANETS) - if (process_ < kCastanetsProcessHandle) { + if (base::Castanets::IsEnabled() && (process_ < kCastanetsProcessHandle)) { // TODO(hw1008.kim): We have to send exit_code to the remote child process? return true; } @@ -403,7 +408,7 @@ bool Process::SetProcessBackgrounded(bool value) { int Process::GetPriority() const { #if defined(CASTANETS) - if (process_ < kCastanetsProcessHandle) + if (base::Castanets::IsEnabled() && (process_ < kCastanetsProcessHandle)) return 0; // The default priority is 0 #endif DCHECK(IsValid()); diff --git a/cc/raster/one_copy_raster_buffer_provider.cc b/cc/raster/one_copy_raster_buffer_provider.cc index 0e2d8301ab1..5bdda214c7f 100644 --- a/cc/raster/one_copy_raster_buffer_provider.cc +++ b/cc/raster/one_copy_raster_buffer_provider.cc @@ -34,6 +34,7 @@ #if defined(CASTANETS) #include "base/command_line.h" +#include "base/distributed_chromium_util.h" #include "mojo/public/cpp/system/sync.h" #endif @@ -341,8 +342,9 @@ void OneCopyRasterBufferProvider::PlaybackToStagingBuffer( raster_source, raster_full_rect, playback_rect, transform, dst_color_space, /*gpu_compositing=*/true, playback_settings); #if defined(CASTANETS) - if (std::string("renderer") == - base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type")) { + if (base::Castanets::IsEnabled() && + (std::string("renderer") == + base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type"))) { mojo::SyncSharedMemory2d( buffer->CloneHandle().region.GetGUID(), staging_buffer->size.width(), staging_buffer->size.height(), diff --git a/cc/raster/staging_buffer_pool.cc b/cc/raster/staging_buffer_pool.cc index ff41d57d428..7bbddc50b0b 100644 --- a/cc/raster/staging_buffer_pool.cc +++ b/cc/raster/staging_buffer_pool.cc @@ -20,6 +20,10 @@ #include "third_party/khronos/GLES2/gl2ext.h" #include "ui/gfx/gpu_memory_buffer.h" +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + using base::trace_event::MemoryAllocatorDump; using base::trace_event::MemoryAllocatorDumpGuid; using base::trace_event::MemoryDumpLevelOfDetail; @@ -27,26 +31,22 @@ using base::trace_event::MemoryDumpLevelOfDetail; namespace cc { namespace { -#if !defined(CASTANETS) // Delay between checking for query result to be available. const int kCheckForQueryResultAvailableTickRateMs = 1; // Number of attempts to allow before we perform a check that will wait for // query to complete. const int kMaxCheckForQueryResultAvailableAttempts = 256; -#endif // Delay before a staging buffer might be released. const int kStagingBufferExpirationDelayMs = 1000; -#if !defined(CASTANETS) bool CheckForQueryResult(gpu::raster::RasterInterface* ri, GLuint query_id) { DCHECK(query_id); GLuint complete = 1; ri->GetQueryObjectuivEXT(query_id, GL_QUERY_RESULT_AVAILABLE_EXT, &complete); return !!complete; } -#endif void WaitForQueryResult(gpu::raster::RasterInterface* ri, GLuint query_id) { TRACE_EVENT0("cc", "WaitForQueryResult"); @@ -55,8 +55,9 @@ void WaitForQueryResult(gpu::raster::RasterInterface* ri, GLuint query_id) { #if defined(CASTANETS) // FIXME: Skip this region because shared memory of query result // is not being syncronized. - return; -#else + if (base::Castanets::IsEnabled()) + return; +#endif int attempts_left = kMaxCheckForQueryResultAvailableAttempts; while (attempts_left--) { @@ -73,7 +74,6 @@ void WaitForQueryResult(gpu::raster::RasterInterface* ri, GLuint query_id) { GLuint result = 0; ri->GetQueryObjectuivEXT(query_id, GL_QUERY_RESULT_EXT, &result); -#endif } } // namespace @@ -265,14 +265,17 @@ std::unique_ptr StagingBufferPool::AcquireStagingBuffer( while (!busy_buffers_.empty()) { #if defined(CASTANETS) // FIXME: Fall-back to glFinish because QueryResult isnt handled. - ri->Finish(); -#else - // Early out if query isn't used, or if query isn't complete yet. Query is - // created in OneCopyRasterBufferProvider::CopyOnWorkerThread(). - if (!busy_buffers_.front()->query_id || - !CheckForQueryResult(ri, busy_buffers_.front()->query_id)) - break; + if (base::Castanets::IsEnabled()) { + ri->Finish(); + } else #endif + { + // Early out if query isn't used, or if query isn't complete yet. Query + // is created in OneCopyRasterBufferProvider::CopyOnWorkerThread(). + if (!busy_buffers_.front()->query_id || + !CheckForQueryResult(ri, busy_buffers_.front()->query_id)) + break; + } MarkStagingBufferAsFree(busy_buffers_.front().get()); free_buffers_.push_back(PopFront(&busy_buffers_)); } diff --git a/cc/tiles/tile_manager.cc b/cc/tiles/tile_manager.cc index 73bb3b54f89..1bc079a4d58 100644 --- a/cc/tiles/tile_manager.cc +++ b/cc/tiles/tile_manager.cc @@ -35,6 +35,7 @@ #if defined(CASTANETS) #include "base/command_line.h" +#include "base/distributed_chromium_util.h" #include "mojo/public/cpp/system/sync.h" #endif // defined(CASTANETS) @@ -133,8 +134,9 @@ class RasterTaskImpl : public TileTask { raster_transform_, playback_settings_, url_); #if defined(CASTANETS) - if (std::string("renderer") == - base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type")) { + if (base::Castanets::IsEnabled() && + (std::string("renderer") == + base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type"))) { ResourcePool::SoftwareBacking* sw_backing = resource_.software_backing(); if (sw_backing) { int bytes_per_pixel = BitsPerPixel(resource_.format()) / 8; diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index e00a572808f..4f19aed1c7f 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -131,6 +131,7 @@ #include "ui/gfx/skia_util.h" #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "mojo/public/cpp/system/sync.h" #endif @@ -5988,9 +5989,11 @@ void LayerTreeHostImpl::CreateUIResource(UIResourceId uid, transferable.format = format; } else { #if defined(CASTANETS) - mojo::SyncSharedMemory( - shm.region.GetGUID(), 0, - upload_size.width() * upload_size.height() * BitsPerPixel(format) / 8); + if (base::Castanets::IsEnabled()) { + mojo::SyncSharedMemory(shm.region.GetGUID(), 0, + upload_size.width() * upload_size.height() * + BitsPerPixel(format) / 8); + } #endif layer_tree_frame_sink_->DidAllocateSharedBitmap(std::move(shm.region), shared_bitmap_id); diff --git a/chrome/app/chrome_main_delegate.cc b/chrome/app/chrome_main_delegate.cc index 103f0168f96..6828fb6c3e8 100644 --- a/chrome/app/chrome_main_delegate.cc +++ b/chrome/app/chrome_main_delegate.cc @@ -172,6 +172,10 @@ #include "components/gwp_asan/client/gwp_asan.h" // nogncheck #endif +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + base::LazyInstance::DestructorAtExit g_chrome_content_gpu_client = LAZY_INSTANCE_INITIALIZER; base::LazyInstance::DestructorAtExit @@ -991,51 +995,55 @@ void ChromeMainDelegate::PreSandboxStartup() { } #endif #if defined(OS_ANDROID) + std::string loaded_locale; #if defined(CASTANETS) - const std::string loaded_locale = - ui::ResourceBundle::InitSharedInstanceWithLocale( - locale, NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES); - ui::ResourceBundle::GetSharedInstance().AddDataPackFromAsset( - "assets/resources.pak"); -#else - // The renderer sandbox prevents us from accessing our .pak files directly. - // Therefore file descriptors to the .pak files that we need are passed in - // at process creation time. - auto* global_descriptors = base::GlobalDescriptors::GetInstance(); - int pak_fd = global_descriptors->Get(kAndroidLocalePakDescriptor); - base::MemoryMappedFile::Region pak_region = - global_descriptors->GetRegion(kAndroidLocalePakDescriptor); - ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(base::File(pak_fd), - pak_region); - - // Load secondary locale .pak file if it exists. - pak_fd = global_descriptors->MaybeGet(kAndroidSecondaryLocalePakDescriptor); - if (pak_fd != -1) { - pak_region = global_descriptors->GetRegion( - kAndroidSecondaryLocalePakDescriptor); - ui::ResourceBundle::GetSharedInstance() - .LoadSecondaryLocaleDataWithPakFileRegion(base::File(pak_fd), - pak_region); - } + if (base::Castanets::IsEnabled()) { + loaded_locale = ui::ResourceBundle::InitSharedInstanceWithLocale( + locale, NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES); + ui::ResourceBundle::GetSharedInstance().AddDataPackFromAsset( + "assets/resources.pak"); + } else +#endif + { + // The renderer sandbox prevents us from accessing our .pak files + // directly. Therefore file descriptors to the .pak files that we need are + // passed in at process creation time. + auto* global_descriptors = base::GlobalDescriptors::GetInstance(); + int pak_fd = global_descriptors->Get(kAndroidLocalePakDescriptor); + base::MemoryMappedFile::Region pak_region = + global_descriptors->GetRegion(kAndroidLocalePakDescriptor); + ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( + base::File(pak_fd), pak_region); + + // Load secondary locale .pak file if it exists. + pak_fd = + global_descriptors->MaybeGet(kAndroidSecondaryLocalePakDescriptor); + if (pak_fd != -1) { + pak_region = + global_descriptors->GetRegion(kAndroidSecondaryLocalePakDescriptor); + ui::ResourceBundle::GetSharedInstance() + .LoadSecondaryLocaleDataWithPakFileRegion(base::File(pak_fd), + pak_region); + } - int extra_pak_keys[] = { - kAndroidChrome100PercentPakDescriptor, - kAndroidUIResourcesPakDescriptor, - }; - for (int extra_pak_key : extra_pak_keys) { - pak_fd = global_descriptors->Get(extra_pak_key); - pak_region = global_descriptors->GetRegion(extra_pak_key); - ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion( - base::File(pak_fd), pak_region, ui::SCALE_FACTOR_100P); - } + int extra_pak_keys[] = { + kAndroidChrome100PercentPakDescriptor, + kAndroidUIResourcesPakDescriptor, + }; + for (int extra_pak_key : extra_pak_keys) { + pak_fd = global_descriptors->Get(extra_pak_key); + pak_region = global_descriptors->GetRegion(extra_pak_key); + ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion( + base::File(pak_fd), pak_region, ui::SCALE_FACTOR_100P); + } - // For Android: Native resources for DFMs should only be used by the browser - // process. Their file descriptors and memory mapped file region are not - // passed to child processes, and are therefore not loaded here. + // For Android: Native resources for DFMs should only be used by the + // browser process. Their file descriptors and memory mapped file region + // are not passed to child processes, and are therefore not loaded here. - base::i18n::SetICUDefaultLocale(locale); - const std::string loaded_locale = locale; -#endif + base::i18n::SetICUDefaultLocale(locale); + loaded_locale = locale; + } #else const std::string loaded_locale = ui::ResourceBundle::InitSharedInstanceWithLocale( diff --git a/components/discardable_memory/client/client_discardable_shared_memory_manager.cc b/components/discardable_memory/client/client_discardable_shared_memory_manager.cc index 94338d4debd..2f67fc414d6 100644 --- a/components/discardable_memory/client/client_discardable_shared_memory_manager.cc +++ b/components/discardable_memory/client/client_discardable_shared_memory_manager.cc @@ -27,6 +27,10 @@ #include "build/build_config.h" #include "components/crash/core/common/crash_key.h" +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + namespace discardable_memory { namespace { @@ -102,13 +106,11 @@ void InitManagerMojoOnIO( manager_mojo->Bind(std::move(remote)); } -#if !defined(CASTANETS) void DeletedDiscardableSharedMemoryOnIO( mojo::Remote* manager_mojo, int32_t id) { (*manager_mojo)->DeletedDiscardableSharedMemory(id); } -#endif } // namespace @@ -378,40 +380,40 @@ ClientDiscardableSharedMemoryManager::AllocateLockedDiscardableSharedMemory( "size", size, "id", id); base::UnsafeSharedMemoryRegion region; #if defined(CASTANETS) - std::unique_ptr memory( - new base::DiscardableSharedMemory); - if (!memory->CreateAndMap(size)) { - region = base::UnsafeSharedMemoryRegion(); - return nullptr; - } - //*shared_memory_region = memory->DuplicateRegion(); - // Close file descriptor to avoid running out. - // memory->Close(); needed ? -#else - base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, - base::WaitableEvent::InitialState::NOT_SIGNALED); - base::ScopedClosureRunner event_signal_runner( - base::BindOnce(&base::WaitableEvent::Signal, base::Unretained(&event))); - io_task_runner_->PostTask( - FROM_HERE, - base::BindOnce(&ClientDiscardableSharedMemoryManager::AllocateOnIO, - base::Unretained(this), size, id, ®ion, - std::move(event_signal_runner))); - // Waiting until IPC has finished on the IO thread. - event.Wait(); - - // This is likely address space exhaustion in the the browser process. We - // don't want to crash the browser process for that, which is why the check is - // here, and not there. - if (!region.IsValid()) - return nullptr; - - auto memory = - std::make_unique(std::move(region)); - if (!memory->Map(size)) - return nullptr; + if (base::Castanets::IsEnabled()) { + std::unique_ptr memory( + new base::DiscardableSharedMemory); + if (!memory->CreateAndMap(size)) { + region = base::UnsafeSharedMemoryRegion(); + return nullptr; + } + return memory; + } else #endif - return memory; + { + base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, + base::WaitableEvent::InitialState::NOT_SIGNALED); + base::ScopedClosureRunner event_signal_runner( + base::BindOnce(&base::WaitableEvent::Signal, base::Unretained(&event))); + io_task_runner_->PostTask( + FROM_HERE, + base::BindOnce(&ClientDiscardableSharedMemoryManager::AllocateOnIO, + base::Unretained(this), size, id, ®ion, + std::move(event_signal_runner))); + // Waiting until IPC has finished on the IO thread. + event.Wait(); + // This is likely address space exhaustion in the the browser process. We + // don't want to crash the browser process for that, which is why the check + // is here, and not there. + if (!region.IsValid()) + return nullptr; + + auto memory = + std::make_unique(std::move(region)); + if (!memory->Map(size)) + return nullptr; + return memory; + } } void ClientDiscardableSharedMemoryManager::AllocateOnIO( @@ -436,7 +438,12 @@ void ClientDiscardableSharedMemoryManager::AllocateCompletedOnIO( void ClientDiscardableSharedMemoryManager::DeletedDiscardableSharedMemory( int32_t id) { -#if !defined(CASTANETS) +#if defined(CASTANETS) + if (!base::Castanets::IsEnabled()) + io_task_runner_->PostTask( + FROM_HERE, base::BindOnce(&DeletedDiscardableSharedMemoryOnIO, + manager_mojo_.get(), id)); +#else io_task_runner_->PostTask(FROM_HERE, base::BindOnce(&DeletedDiscardableSharedMemoryOnIO, manager_mojo_.get(), id)); diff --git a/components/services/font/public/cpp/font_service_thread.cc b/components/services/font/public/cpp/font_service_thread.cc index 9f38e740ba2..92480be6471 100644 --- a/components/services/font/public/cpp/font_service_thread.cc +++ b/components/services/font/public/cpp/font_service_thread.cc @@ -12,6 +12,7 @@ #include #include #include +#include "base/distributed_chromium_util.h" #endif #include "base/bind.h" @@ -51,25 +52,25 @@ bool FontServiceThread::MatchFamilyName( DCHECK(!task_runner_->RunsTasksInCurrentSequence()); bool out_valid = false; #if defined(CASTANETS) - SkFontConfigInterface* fc = - SkFontConfigInterface::GetSingletonDirectInterface(); - out_valid = - fc->matchFamilyName(family_name, - requested_style, - out_font_identity, - out_family_name, - out_style); -#else - // This proxies to the other thread, which proxies to mojo. Only on the reply - // from mojo do we return from this. - base::WaitableEvent done_event; - task_runner_->PostTask( - FROM_HERE, - base::BindOnce(&FontServiceThread::MatchFamilyNameImpl, this, &done_event, - family_name, requested_style, &out_valid, - out_font_identity, out_family_name, out_style)); - done_event.Wait(); + if (base::Castanets::IsEnabled()) { + SkFontConfigInterface* fc = + SkFontConfigInterface::GetSingletonDirectInterface(); + out_valid = + fc->matchFamilyName(family_name, requested_style, out_font_identity, + out_family_name, out_style); + } else #endif + { + // This proxies to the other thread, which proxies to mojo. Only on the + // reply from mojo do we return from this. + base::WaitableEvent done_event; + task_runner_->PostTask( + FROM_HERE, + base::BindOnce(&FontServiceThread::MatchFamilyNameImpl, this, + &done_event, family_name, requested_style, &out_valid, + out_font_identity, out_family_name, out_style)); + done_event.Wait(); + } return out_valid; } @@ -150,25 +151,28 @@ scoped_refptr FontServiceThread::OpenStream( const SkFontConfigInterface::FontIdentity& identity) { DCHECK(!task_runner_->RunsTasksInCurrentSequence()); - -#if defined(CASTANETS) - int result_fd = open(identity.fString.c_str(), O_RDONLY); - base::File stream_file(result_fd); -#else base::File stream_file; - // This proxies to the other thread, which proxies to mojo. Only on the - // reply from mojo do we return from this. - base::WaitableEvent done_event; - task_runner_->PostTask( - FROM_HERE, base::BindOnce(&FontServiceThread::OpenStreamImpl, this, - &done_event, &stream_file, identity.fID)); - done_event.Wait(); - - if (!stream_file.IsValid()) { - // The font-service may have been killed. - return nullptr; - } +#if defined(CASTANETS) + if (base::Castanets::IsEnabled()) { + int result_fd = open(identity.fString.c_str(), O_RDONLY); + base::File local_file(result_fd); + stream_file = std::move(local_file); + } else #endif + { + // This proxies to the other thread, which proxies to mojo. Only on the + // reply from mojo do we return from this. + base::WaitableEvent done_event; + task_runner_->PostTask( + FROM_HERE, base::BindOnce(&FontServiceThread::OpenStreamImpl, this, + &done_event, &stream_file, identity.fID)); + done_event.Wait(); + + if (!stream_file.IsValid()) { + // The font-service may have been killed. + return nullptr; + } + } // Converts the file to out internal type. scoped_refptr mapped_font_file = diff --git a/components/subresource_filter/content/renderer/unverified_ruleset_dealer.cc b/components/subresource_filter/content/renderer/unverified_ruleset_dealer.cc index 6df79753960..9589e298a75 100644 --- a/components/subresource_filter/content/renderer/unverified_ruleset_dealer.cc +++ b/components/subresource_filter/content/renderer/unverified_ruleset_dealer.cc @@ -7,6 +7,10 @@ #include "components/subresource_filter/content/common/subresource_filter_messages.h" #include "ipc/ipc_message_macros.h" +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + namespace subresource_filter { UnverifiedRulesetDealer::UnverifiedRulesetDealer() = default; @@ -26,8 +30,10 @@ bool UnverifiedRulesetDealer::OnControlMessageReceived( void UnverifiedRulesetDealer::OnSetRulesetForProcess( const IPC::PlatformFileForTransit& platform_file) { #if defined(CASTANETS) - LOG(INFO) << "SKIP!!!!! UnverifiedRulesetDealer::OnSetRulesetForProcess"; - return; + if (base::Castanets::IsEnabled()) { + LOG(INFO) << "SKIP!!!!! UnverifiedRulesetDealer::OnSetRulesetForProcess"; + return; + } #else SetRulesetFile(IPC::PlatformFileForTransitToFile(platform_file)); #endif diff --git a/components/viz/service/display_embedder/server_shared_bitmap_manager.cc b/components/viz/service/display_embedder/server_shared_bitmap_manager.cc index dcfa12ec285..2ca35ea668d 100644 --- a/components/viz/service/display_embedder/server_shared_bitmap_manager.cc +++ b/components/viz/service/display_embedder/server_shared_bitmap_manager.cc @@ -23,6 +23,7 @@ #include "ui/gfx/geometry/size.h" #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "mojo/public/cpp/system/sync.h" #endif @@ -95,7 +96,8 @@ std::unique_ptr ServerSharedBitmapManager::GetSharedBitmapFromId( return nullptr; } #if defined(CASTANETS) - mojo::WaitSyncSharedMemory(data->mapped_id()); + if (base::Castanets::IsEnabled()) + mojo::WaitSyncSharedMemory(data->mapped_id()); #endif if (!data->memory()) { return nullptr; diff --git a/content/app/content_main_runner_impl.cc b/content/app/content_main_runner_impl.cc index 4249ff1e1ac..ccd18a82878 100644 --- a/content/app/content_main_runner_impl.cc +++ b/content/app/content_main_runner_impl.cc @@ -103,6 +103,7 @@ #include "ui/gfx/switches.h" #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "components/viz/common/switches.h" #include "gpu/config/gpu_switches.h" #include "ui/gl/gl_switches.h" @@ -659,26 +660,28 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) { command_line.GetSwitchValueASCII(switches::kProcessType); #if defined(CASTANETS) - base::CommandLine::ForCurrentProcess()->AppendSwitch(service_manager::switches::kNoSandbox); - base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kNoZygote); - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kInProcessGPU); - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kDisableAcceleratedVideoDecode); - - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kProcessPerTab); - - base::CommandLine::ForCurrentProcess()->AppendSwitch("no-first-run"); - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kLang, - "en-US"); - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kNumRasterThreads, "4"); - - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kDisallowNonExactResourceReuse); - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kIgnoreGpuBlacklist); + if (base::Castanets::IsEnabled()) { + base::CommandLine::ForCurrentProcess()->AppendSwitch( + service_manager::switches::kNoSandbox); + base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kNoZygote); + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kInProcessGPU); + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kDisableAcceleratedVideoDecode); + + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kProcessPerTab); + + base::CommandLine::ForCurrentProcess()->AppendSwitch("no-first-run"); + base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kLang, + "en-US"); + base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kNumRasterThreads, "4"); + + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kDisallowNonExactResourceReuse); + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kIgnoreGpuBlacklist); #if defined(OS_LINUX) base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( switches::kEnableLogging, "stderr"); @@ -687,6 +690,7 @@ int ContentMainRunnerImpl::Initialize(const ContentMainParams& params) { switches::kDisableGpuDriverBugWorkarounds); base::CommandLine::ForCurrentProcess()->AppendSwitch( switches::kDisableFrameRateLimit); + } #endif // CASTANETS #if defined(OS_WIN) diff --git a/content/browser/android/content_startup_flags.cc b/content/browser/android/content_startup_flags.cc index 6cf6e8d7475..adb2e057b12 100644 --- a/content/browser/android/content_startup_flags.cc +++ b/content/browser/android/content_startup_flags.cc @@ -15,6 +15,7 @@ #include "ui/base/ui_base_switches.h" #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "components/viz/common/switches.h" #include "services/service_manager/sandbox/switches.h" #include "ui/gl/gl_switches.h" @@ -33,21 +34,23 @@ void SetContentCommandLineFlags(bool single_process) { base::CommandLine::ForCurrentProcess(); #if defined(CASTANETS) - base::CommandLine::ForCurrentProcess()->AppendSwitch( - service_manager::switches::kNoSandbox); - base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kNoZygote); - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kNumRasterThreads, "4"); - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kLang, - "en-US"); - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kIgnoreGpuBlacklist); - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kDisableGpuDriverBugWorkarounds); - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kDisableFrameRateLimit); - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kDisallowNonExactResourceReuse); + if (base::Castanets::IsEnabled()) { + base::CommandLine::ForCurrentProcess()->AppendSwitch( + service_manager::switches::kNoSandbox); + base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kNoZygote); + base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kNumRasterThreads, "4"); + base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kLang, + "en-US"); + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kIgnoreGpuBlacklist); + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kDisableGpuDriverBugWorkarounds); + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kDisableFrameRateLimit); + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kDisallowNonExactResourceReuse); + } #endif if (single_process) { // Need to ensure the command line flag is consistent as a lot of chrome diff --git a/content/browser/browser_child_process_host_impl.cc b/content/browser/browser_child_process_host_impl.cc index 935cb3d0856..b3f28aa02ea 100644 --- a/content/browser/browser_child_process_host_impl.cc +++ b/content/browser/browser_child_process_host_impl.cc @@ -67,6 +67,10 @@ #include "content/public/common/font_cache_win.mojom.h" #endif +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + namespace content { namespace { @@ -603,8 +607,11 @@ void BrowserChildProcessHostImpl::CreateMetricsAllocator() { void BrowserChildProcessHostImpl::ShareMetricsAllocatorToProcess() { #if defined(CASTANETS) - LOG(INFO) << "SKIP!!!!! BrowserChildProcessHostImpl::ShareMetricsAllocatorToProcess"; - return; + if (base::Castanets::IsEnabled()) { + LOG(INFO) << "SKIP!!!!! " + "BrowserChildProcessHostImpl::ShareMetricsAllocatorToProcess"; + return; + } #else if (metrics_allocator_) { HistogramController::GetInstance()->SetHistogramMemory( diff --git a/content/browser/child_process_launcher_helper.cc b/content/browser/child_process_launcher_helper.cc index 34d952b4928..72916e2f235 100644 --- a/content/browser/child_process_launcher_helper.cc +++ b/content/browser/child_process_launcher_helper.cc @@ -27,6 +27,7 @@ #if defined(CASTANETS) #include "base/base_switches.h" +#include "base/distributed_chromium_util.h" #include "base/strings/string_number_conversions.h" #include "content/browser/renderer_host/input/timeout_monitor.h" @@ -106,8 +107,7 @@ ChildProcessLauncherHelper::ChildProcessLauncherHelper( tcp_success_callback_ = base::BindRepeating( &ChildProcessLauncherHelper::OnCastanetsRendererLaunchedViaTcp, base::Unretained(this)); - remote_process_ = !base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableForking); + remote_process_ = base::Castanets::IsEnabled(); if (base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kTcpLaunchTimeout)) { relaunch_renderer_process_monitor_timeout_.reset(new TimeoutMonitor( @@ -252,12 +252,6 @@ void ChildProcessLauncherHelper::PostLaunchOnLauncherThread( #if defined(CASTANETS) if (remote_process_ && GetProcessType() == switches::kRendererProcess) { uint16_t port = mojo::kCastanetsRendererPort; - std::string address = - base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kServerAddress) - ? base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( - switches::kServerAddress) - : std::string(); // Reset IPC socket mojo_channel_->TakeLocalEndpoint().reset(); @@ -265,7 +259,8 @@ void ChildProcessLauncherHelper::PostLaunchOnLauncherThread( mojo::OutgoingInvitation::SendTcpSocket( std::move(invitation), process.process.Handle(), mojo::CreateTCPSocketHandle(), process_error_callback_, - tcp_success_callback_, false, address, port); + tcp_success_callback_, false, base::Castanets::ServerAddress(), + port); } else { // Send OutgoingInvitation to IPC socket diff --git a/content/browser/child_process_launcher_helper_linux.cc b/content/browser/child_process_launcher_helper_linux.cc index ad9d4a9a870..568f9045d01 100644 --- a/content/browser/child_process_launcher_helper_linux.cc +++ b/content/browser/child_process_launcher_helper_linux.cc @@ -23,6 +23,7 @@ #include "services/service_manager/sandbox/linux/sandbox_linux.h" #if defined(CASTANETS) #include "base/base_switches.h" +#include "base/distributed_chromium_util.h" #include "dbus/bus.h" #include "dbus/message.h" #include "dbus/object_path.h" @@ -34,26 +35,23 @@ namespace internal { base::Optional ChildProcessLauncherHelper::CreateNamedPlatformChannelOnClientThread() { #if defined(CASTANETS) - - if (!remote_process_) + if (base::Castanets::IsEnabled()) { + if (!remote_process_) + return base::nullopt; + + if (base::Castanets::ServerAddress().empty()) { + mojo::NamedPlatformChannel::Options options; + options.port = mojo::kCastanetsRendererPort; + + // This socket pair is not used, however it is added + // to avoid failure of validation check of codes afterwards. + mojo_channel_.emplace(); + return mojo::NamedPlatformChannel(options); + } return base::nullopt; - - if (GetProcessType() != switches::kRendererProcess) + } else { return base::nullopt; - - base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); - if (!command_line->HasSwitch(switches::kServerAddress) || - command_line->GetSwitchValueASCII(switches::kServerAddress).empty()) { - mojo::NamedPlatformChannel::Options options; - options.port = mojo::kCastanetsRendererPort; - - // This socket pair is not used, however it is added - // to avoid failure of validation check of codes afterwards. - mojo_channel_.emplace(); - return mojo::NamedPlatformChannel(options); } - - return base::nullopt; #else DCHECK(client_task_runner_->RunsTasksInCurrentSequence()); return base::nullopt; diff --git a/content/browser/frame_host/frame_tree_node.cc b/content/browser/frame_host/frame_tree_node.cc index 6152ab1a61e..2e9505d177b 100644 --- a/content/browser/frame_host/frame_tree_node.cc +++ b/content/browser/frame_host/frame_tree_node.cc @@ -34,6 +34,9 @@ #include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom.h" #include "third_party/blink/public/mojom/security_context/insecure_request_policy.mojom.h" +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif namespace content { namespace { @@ -446,7 +449,7 @@ bool FrameTreeNode::CommitFramePolicy( void FrameTreeNode::TransferNavigationRequestOwnership( RenderFrameHostImpl* render_frame_host) { #if defined(CASTANETS) - if (!navigation_request_) { + if (base::Castanets::IsEnabled() && !navigation_request_) { LOG(WARNING) << "NavigationRequest is null"; return; } diff --git a/content/browser/frame_host/render_frame_host_manager.cc b/content/browser/frame_host/render_frame_host_manager.cc index 7a44c8c1aa8..07f6ea35476 100644 --- a/content/browser/frame_host/render_frame_host_manager.cc +++ b/content/browser/frame_host/render_frame_host_manager.cc @@ -70,6 +70,10 @@ #include "ui/gfx/mac/scoped_cocoa_disable_screen_updates.h" #endif // defined(OS_MACOSX) +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + namespace content { namespace { @@ -702,7 +706,7 @@ RenderFrameHostImpl* RenderFrameHostManager::GetFrameHostForNavigation( #if defined(CASTANETS) // FIXME: Currently once use_current_rfh is false, browser seem to be creating // new channel for renderer ignoring the already connected renderer. - if (1/* || use_current_rfh*/) { + if (1 /*|| base::Castanets::IsEnabled() || use_current_rfh*/) { // GetFrameHostForNavigation will be called more than once during a // navigation (currently twice, on request and when it's about to commit in // the renderer). In the follow up calls an existing pending WebUI should diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index c7249e57992..89cfa1b95da 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -296,6 +296,10 @@ #include "content/public/common/profiling_utils.h" #endif +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + namespace content { namespace { @@ -3460,7 +3464,7 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer( switches::kIpcFuzzerTestcase, #endif #if defined(CASTANETS) - switches::kServerAddress, + switches::kEnableCastanets, #endif }; renderer_cmd->CopySwitchesFrom(browser_cmd, kSwitchNames, @@ -4513,8 +4517,12 @@ RenderProcessHost* RenderProcessHostImpl::GetProcessHostForSiteInstance( void RenderProcessHostImpl::CreateSharedRendererHistogramAllocator() { #if defined(CASTANETS) - LOG(INFO) << "SKIP!!!!! RenderProcessHostImpl::CreateSharedRendererHistogramAllocator"; - return; + if (base::Castanets::IsEnabled()) { + LOG(INFO) + << "SKIP!!!!! " + "RenderProcessHostImpl::CreateSharedRendererHistogramAllocator"; + return; + } #else // Create a persistent memory segment for renderer histograms only if // they're active in the browser. diff --git a/content/child/child_process_sandbox_support_impl_linux.cc b/content/child/child_process_sandbox_support_impl_linux.cc index 11904f305ee..8301aba53cf 100644 --- a/content/child/child_process_sandbox_support_impl_linux.cc +++ b/content/child/child_process_sandbox_support_impl_linux.cc @@ -20,6 +20,7 @@ #include "ui/gfx/font_fallback_linux.h" #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "ui/gfx/font_fallback_linux.h" #include "ui/gfx/font_render_params.h" #endif @@ -48,39 +49,44 @@ bool WebSandboxSupportLinux::GetFallbackFontForCharacter( } #if defined(CASTANETS) - gfx::FallbackFontData fallback_font_; - gfx::GetFallbackFontForChar(character, preferred_locale, &fallback_font_); - - font_service::mojom::FontIdentityPtr identity(font_service::mojom::FontIdentity::New()); - identity->id = 0; - identity->ttc_index = fallback_font_.ttc_index; - - std::string family_name = fallback_font_.name; - fallback_font->name = family_name; - fallback_font->fontconfig_interface_id = 0; - fallback_font->filepath = fallback_font_.filepath; - fallback_font->ttc_index = fallback_font_.ttc_index; - fallback_font->is_bold = fallback_font_.is_bold; - fallback_font->is_italic = fallback_font_.is_italic; -#else - font_service::mojom::FontIdentityPtr font_identity; - bool is_bold = false; - bool is_italic = false; - std::string family_name; - if (!font_loader_->FallbackFontForCharacter(character, preferred_locale, - &font_identity, &family_name, - &is_bold, &is_italic)) - return false; - - // mojom::FontIdentityPtr cannot be exposed on the blink/public interface. - // Use gfx::FallbackFontData as the container to pass this to blink. - fallback_font->name = family_name; - fallback_font->fontconfig_interface_id = font_identity->id; - fallback_font->filepath = font_identity->filepath; - fallback_font->ttc_index = font_identity->ttc_index; - fallback_font->is_bold = is_bold; - fallback_font->is_italic = is_italic; + if (base::Castanets::IsEnabled()) { + gfx::FallbackFontData fallback_font_; + gfx::GetFallbackFontForChar(character, preferred_locale, &fallback_font_); + + font_service::mojom::FontIdentityPtr identity( + font_service::mojom::FontIdentity::New()); + identity->id = 0; + identity->ttc_index = fallback_font_.ttc_index; + + std::string family_name = fallback_font_.name; + fallback_font->name = family_name; + fallback_font->fontconfig_interface_id = 0; + fallback_font->filepath = fallback_font_.filepath; + fallback_font->ttc_index = fallback_font_.ttc_index; + fallback_font->is_bold = fallback_font_.is_bold; + fallback_font->is_italic = fallback_font_.is_italic; + } else #endif + { + font_service::mojom::FontIdentityPtr font_identity; + bool is_bold = false; + bool is_italic = false; + std::string family_name; + if (!font_loader_->FallbackFontForCharacter(character, preferred_locale, + &font_identity, &family_name, + &is_bold, &is_italic)) + return false; + + // mojom::FontIdentityPtr cannot be exposed on the blink/public interface. + // Use gfx::FallbackFontData as the container to pass this to blink. + fallback_font->name = family_name; + fallback_font->fontconfig_interface_id = font_identity->id; + fallback_font->filepath = font_identity->filepath; + fallback_font->ttc_index = font_identity->ttc_index; + fallback_font->is_bold = is_bold; + fallback_font->is_italic = is_italic; + } + base::AutoLock lock(lock_); unicode_font_families_.emplace(character, *fallback_font); return true; diff --git a/content/child/child_thread_impl.cc b/content/child/child_thread_impl.cc index 1999731bfea..357e9a69361 100644 --- a/content/child/child_thread_impl.cc +++ b/content/child/child_thread_impl.cc @@ -98,6 +98,7 @@ extern "C" void __llvm_profile_set_file_object(FILE* File, int EnableMerge); #endif #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "mojo/public/cpp/platform/tcp_platform_handle_utils.h" #endif @@ -243,16 +244,12 @@ mojo::IncomingInvitation InitializeMojoIPCChannelTCP() { TRACE_EVENT0("startup", "InitializeMojoIPCChannelTCP"); mojo::PlatformHandle handle; base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); - std::string server_address = - command_line->HasSwitch(switches::kServerAddress) - ? command_line->GetSwitchValueASCII(switches::kServerAddress) - : std::string(); std::string process_type( base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( switches::kProcessType)); uint16_t port = mojo::kCastanetsRendererPort; bool secure_connection = false; - if (server_address.empty()) { + if (base::Castanets::ServerAddress().empty()) { LOG(INFO) << "Listen on port:" << port; handle = mojo::CreateTCPServerHandle(port); secure_connection = command_line->HasSwitch(switches::kSecureConnection); @@ -270,7 +267,8 @@ mojo::IncomingInvitation InitializeMojoIPCChannelTCP() { } return mojo::IncomingInvitation::AcceptTcpSocket( - (std::move(handle)), server_address, port, secure_connection); + (std::move(handle)), base::Castanets::ServerAddress(), port, + secure_connection); } #endif @@ -628,13 +626,16 @@ void ChildThreadImpl::Init(const Options& options) { } #if defined(CASTANETS) mojo::IncomingInvitation invitation; - if (!base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kRendererClientId) && - base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( - +switches::kProcessType) == switches::kRendererProcess) { - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kRendererClientId, std::to_string(1)); // workaround - invitation = InitializeMojoIPCChannelTCP(); + if (base::Castanets::IsEnabled()) { + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kRendererClientId) && + base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + +switches::kProcessType) == switches::kRendererProcess) { + base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kRendererClientId, std::to_string(1)); // workaround + invitation = InitializeMojoIPCChannelTCP(); + } else + invitation = InitializeMojoIPCChannel(); } else invitation = InitializeMojoIPCChannel(); #else diff --git a/content/public/browser/content_browser_client.cc b/content/public/browser/content_browser_client.cc index a1f0a00aeaf..8a2253e987c 100644 --- a/content/public/browser/content_browser_client.cc +++ b/content/public/browser/content_browser_client.cc @@ -57,6 +57,10 @@ #include "url/gurl.h" #include "url/origin.h" +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + namespace content { std::unique_ptr ContentBrowserClient::CreateBrowserMainParts( @@ -262,9 +266,13 @@ ContentBrowserClient::GetOriginsRequiringDedicatedProcess() { } bool ContentBrowserClient::ShouldEnableStrictSiteIsolation() { -#if defined(OS_ANDROID) || defined(CASTANETS) +#if defined(OS_ANDROID) return false; #else +#if defined(CASTANETS) + if (base::Castanets::IsEnabled()) + return false; +#endif return true; #endif } diff --git a/content/public/common/use_zoom_for_dsf_policy.cc b/content/public/common/use_zoom_for_dsf_policy.cc index 564dbd18ce0..7bb02c3e8ca 100644 --- a/content/public/common/use_zoom_for_dsf_policy.cc +++ b/content/public/common/use_zoom_for_dsf_policy.cc @@ -12,6 +12,10 @@ #include "base/feature_list.h" #endif +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + namespace { #if defined(OS_WIN) @@ -26,7 +30,8 @@ const base::Feature kUseZoomForDsfEnabledByDefault{ bool IsUseZoomForDSFEnabledByDefault() { #if defined(CASTANETS) - return false; + if (base::Castanets::IsEnabled()) + return false; #endif #if defined(OS_LINUX) || defined(OS_FUCHSIA) return true; diff --git a/content/test/test_render_frame.cc b/content/test/test_render_frame.cc index 16564fee19c..d9ffb858a5a 100644 --- a/content/test/test_render_frame.cc +++ b/content/test/test_render_frame.cc @@ -234,7 +234,7 @@ class MockFrameHost : public mojom::FrameHost { } } -#if defined(OS_ANDROID) +#if defined(OS_ANDROID) || defined(CASTANETS) void UpdateUserGestureCarryoverInfo() override {} #endif diff --git a/gpu/command_buffer/client/cmd_buffer_helper.cc b/gpu/command_buffer/client/cmd_buffer_helper.cc index 742273d9bf5..7298ba3b377 100644 --- a/gpu/command_buffer/client/cmd_buffer_helper.cc +++ b/gpu/command_buffer/client/cmd_buffer_helper.cc @@ -23,6 +23,7 @@ #if defined(CASTANETS) #include "base/command_line.h" +#include "base/distributed_chromium_util.h" #include "mojo/public/cpp/system/sync.h" #endif @@ -206,7 +207,8 @@ void CommandBufferHelper::Flush() { if (HaveRingBuffer()) { #if defined(CASTANETS) - SyncSharedMemoryForCommands(); + if (base::Castanets::IsEnabled()) + SyncSharedMemoryForCommands(); #endif last_flush_time_ = base::TimeTicks::Now(); last_flush_put_ = put_; @@ -230,7 +232,8 @@ void CommandBufferHelper::OrderingBarrier() { if (HaveRingBuffer()) { #if defined(CASTANETS) - SyncSharedMemoryForCommands(); + if (base::Castanets::IsEnabled()) + SyncSharedMemoryForCommands(); #endif last_ordering_barrier_put_ = put_; command_buffer_->OrderingBarrier(put_); diff --git a/gpu/command_buffer/client/implementation_base.cc b/gpu/command_buffer/client/implementation_base.cc index 65361aa9057..384e14667fa 100644 --- a/gpu/command_buffer/client/implementation_base.cc +++ b/gpu/command_buffer/client/implementation_base.cc @@ -18,6 +18,10 @@ #include "gpu/command_buffer/client/shared_memory_limits.h" #include "gpu/command_buffer/common/sync_token.h" +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + namespace gpu { #if !defined(_MSC_VER) @@ -261,19 +265,20 @@ gpu::ContextResult ImplementationBase::Initialize( void ImplementationBase::WaitForCmd() { TRACE_EVENT0("gpu", "ImplementationBase::WaitForCmd"); #if defined(CASTANETS) - // Synchronize the result because some commands require initialization. - mojo::SyncSharedMemory(transfer_buffer_->shared_memory_guid(), - GetResultShmOffset(), kMaxSizeOfSimpleResult); - // Call this api to synchronize the result shared memory. - helper_->SyncResultData(GetResultShmId(), GetResultShmOffset(), - kMaxSizeOfSimpleResult); - helper_->Finish(); - - // Wait for command execution result. - mojo::WaitSyncSharedMemory(transfer_buffer_->shared_memory_guid()); -#else - helper_->Finish(); + if (base::Castanets::IsEnabled()) { + // Synchronize the result because some commands require initialization. + mojo::SyncSharedMemory(transfer_buffer_->shared_memory_guid(), + GetResultShmOffset(), kMaxSizeOfSimpleResult); + // Call this api to synchronize the result shared memory. + helper_->SyncResultData(GetResultShmId(), GetResultShmOffset(), + kMaxSizeOfSimpleResult); + helper_->Finish(); + + // Wait for command execution result. + mojo::WaitSyncSharedMemory(transfer_buffer_->shared_memory_guid()); + } else #endif + helper_->Finish(); } int32_t ImplementationBase::GetResultShmId() { diff --git a/gpu/command_buffer/client/mapped_memory.h b/gpu/command_buffer/client/mapped_memory.h index 58336113e1c..1c1223faaf1 100644 --- a/gpu/command_buffer/client/mapped_memory.h +++ b/gpu/command_buffer/client/mapped_memory.h @@ -20,6 +20,7 @@ #if defined(CASTANETS) #include "base/command_line.h" +#include "base/distributed_chromium_util.h" #include "mojo/public/cpp/system/sync.h" #endif @@ -87,8 +88,9 @@ class GPU_EXPORT MemoryChunk { void FreePendingToken(void* pointer, uint32_t token) { allocator_.FreePendingToken(pointer, token); #if defined(CASTANETS) - if (std::string("renderer") == - base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type")) { + if (base::Castanets::IsEnabled() && + (std::string("renderer") == + base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type"))) { mojo::SyncSharedMemory(shm_->backing()->GetGUID(), GetOffset(pointer), allocator_.GetBlockSize(pointer)); } diff --git a/gpu/command_buffer/client/transfer_buffer.cc b/gpu/command_buffer/client/transfer_buffer.cc index 28bb08b42bb..2f2c012142c 100644 --- a/gpu/command_buffer/client/transfer_buffer.cc +++ b/gpu/command_buffer/client/transfer_buffer.cc @@ -17,6 +17,7 @@ #if defined(CASTANETS) #include "base/command_line.h" +#include "base/distributed_chromium_util.h" #include "mojo/public/cpp/system/sync.h" #endif @@ -94,8 +95,9 @@ void TransferBuffer::DiscardBlock(void* p) { void TransferBuffer::FreePendingToken(void* p, unsigned int token) { ring_buffer_->FreePendingToken(p, token); #if defined(CASTANETS) - if (std::string("renderer") == - base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type")) { + if (base::Castanets::IsEnabled() && + (std::string("renderer") == + base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type"))) { mojo::SyncSharedMemory(shared_memory_guid(), GetOffset(p), ring_buffer_->GetBlockSize(p)); } diff --git a/gpu/command_buffer/service/command_buffer_service.cc b/gpu/command_buffer/service/command_buffer_service.cc index cce541da539..fbd565be86e 100644 --- a/gpu/command_buffer/service/command_buffer_service.cc +++ b/gpu/command_buffer/service/command_buffer_service.cc @@ -17,6 +17,7 @@ #include "gpu/command_buffer/service/transfer_buffer_manager.h" #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "mojo/public/cpp/system/sync.h" #endif @@ -65,7 +66,7 @@ void CommandBufferService::Flush(int32_t put_offset, } #if defined(CASTANETS) - if (ring_buffer_ && ring_buffer_->backing()) + if (base::Castanets::IsEnabled() && ring_buffer_ && ring_buffer_->backing()) mojo::WaitSyncSharedMemory(ring_buffer_->backing()->GetGUID()); #endif diff --git a/gpu/command_buffer/service/common_decoder.cc b/gpu/command_buffer/service/common_decoder.cc index 88d0bdb52d0..dc1b7125c63 100644 --- a/gpu/command_buffer/service/common_decoder.cc +++ b/gpu/command_buffer/service/common_decoder.cc @@ -16,6 +16,7 @@ #include "ui/gfx/ipc/color/gfx_param_traits.h" #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "mojo/public/cpp/system/sync.h" #endif @@ -345,10 +346,12 @@ error::Error CommonDecoder::HandleGetBucketStart( memcpy(data, bucket->GetData(0, size), size); } #if defined(CASTANETS) - scoped_refptr buffer = - command_buffer_service_->GetTransferBuffer(data_memory_id); - mojo::SyncSharedMemory(buffer->backing()->GetGUID(), data_memory_offset, - data_memory_size); + if (base::Castanets::IsEnabled()) { + scoped_refptr buffer = + command_buffer_service_->GetTransferBuffer(data_memory_id); + mojo::SyncSharedMemory(buffer->backing()->GetGUID(), data_memory_offset, + data_memory_size); + } #endif return error::kNoError; } @@ -375,9 +378,11 @@ error::Error CommonDecoder::HandleGetBucketData(uint32_t immediate_data_size, } memcpy(data, src, size); #if defined(CASTANETS) - scoped_refptr buffer = - command_buffer_service_->GetTransferBuffer(args.shared_memory_id); - mojo::SyncSharedMemory(buffer->backing()->GetGUID(), offset, size); + if (base::Castanets::IsEnabled()) { + scoped_refptr buffer = + command_buffer_service_->GetTransferBuffer(args.shared_memory_id); + mojo::SyncSharedMemory(buffer->backing()->GetGUID(), offset, size); + } #endif return error::kNoError; } diff --git a/ipc/ipc_message_utils.cc b/ipc/ipc_message_utils.cc index f64862d2384..b3a1af56ae1 100644 --- a/ipc/ipc_message_utils.cc +++ b/ipc/ipc_message_utils.cc @@ -49,6 +49,7 @@ #endif #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "base/memory/shared_memory_helper.h" #endif @@ -1023,8 +1024,9 @@ bool ParamTraits::Read( } } #if defined(CASTANETS) - if (static_cast(attachment.get())->file() - == -1) { + if (base::Castanets::IsEnabled() && + (static_cast(attachment.get()) + ->file() == -1)) { base::SharedMemoryCreateOptions options; options.size = size; options.share_read_only = diff --git a/media/renderers/video_resource_updater.cc b/media/renderers/video_resource_updater.cc index 15bdb4a13d8..81e8d9adc1f 100644 --- a/media/renderers/video_resource_updater.cc +++ b/media/renderers/video_resource_updater.cc @@ -54,6 +54,7 @@ #include "ui/gl/trace_util.h" #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "mojo/public/cpp/system/sync.h" #endif @@ -1013,10 +1014,12 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( media::kNoTransformation, nullptr); #if defined(CASTANETS) // Compute the memory size with a RGBA_8888 format. - size_t memory_bytes = software_resource->resource_size().width() * - software_resource->resource_size().height() * 4; - mojo::SyncSharedMemory(software_resource->GetSharedMemoryGuid(), 0, - memory_bytes); + if (base::Castanets::IsEnabled()) { + size_t memory_bytes = software_resource->resource_size().width() * + software_resource->resource_size().height() * 4; + mojo::SyncSharedMemory(software_resource->GetSharedMemoryGuid(), 0, + memory_bytes); + } #endif } else { diff --git a/media/video/gpu_memory_buffer_video_frame_pool.cc b/media/video/gpu_memory_buffer_video_frame_pool.cc index 37d0f304113..2ff3728a6f6 100644 --- a/media/video/gpu_memory_buffer_video_frame_pool.cc +++ b/media/video/gpu_memory_buffer_video_frame_pool.cc @@ -40,6 +40,7 @@ #include "ui/gl/trace_util.h" #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "mojo/public/cpp/system/sync.h" #endif @@ -695,9 +696,11 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::OnCopiesDone( for (const auto& plane_resource : frame_resources->plane_resources) { if (plane_resource.gpu_memory_buffer) { #if defined(CASTANETS) - gfx::GpuMemoryBuffer *buffer = plane_resource.gpu_memory_buffer.get(); - mojo::SyncSharedMemory(buffer->CloneHandle().region.GetGUID(), 0, - buffer->CloneHandle().region.GetSize()); + if (base::Castanets::IsEnabled()) { + gfx::GpuMemoryBuffer* buffer = plane_resource.gpu_memory_buffer.get(); + mojo::SyncSharedMemory(buffer->CloneHandle().region.GetGUID(), 0, + buffer->CloneHandle().region.GetSize()); + } #endif plane_resource.gpu_memory_buffer->Unmap(); plane_resource.gpu_memory_buffer->SetColorSpace( diff --git a/mojo/core/broker_host.cc b/mojo/core/broker_host.cc index d685cc0490d..9d20bcd84a8 100644 --- a/mojo/core/broker_host.cc +++ b/mojo/core/broker_host.cc @@ -18,6 +18,10 @@ #include #endif +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + namespace mojo { namespace core { @@ -73,15 +77,15 @@ bool BrokerHost::SendChannel(PlatformHandle handle) { CreateBrokerMessage(BrokerMessageType::INIT, 1, 0, &data); data->pipe_name_length = 0; #else + Channel::MessagePtr message; #if defined(CASTANETS) - InitData* data; - Channel::MessagePtr message = - CreateBrokerMessage(BrokerMessageType::INIT, 1, 0, &data); - data->port = -1; -#else - Channel::MessagePtr message = - CreateBrokerMessage(BrokerMessageType::INIT, 1, nullptr); + if (base::Castanets::IsEnabled()) { + InitData* data; + message = CreateBrokerMessage(BrokerMessageType::INIT, 1, 0, &data); + data->port = -1; + } else #endif + message = CreateBrokerMessage(BrokerMessageType::INIT, 1, nullptr); #endif std::vector handles(1); handles[0] = PlatformHandleInTransit(std::move(handle)); diff --git a/mojo/core/broker_posix.cc b/mojo/core/broker_posix.cc index 83925412d1b..64fff727ef9 100644 --- a/mojo/core/broker_posix.cc +++ b/mojo/core/broker_posix.cc @@ -115,7 +115,7 @@ base::WritableSharedMemoryRegion Broker::GetWritableSharedMemoryRegion( return base::WritableSharedMemoryRegion(); } -#if !defined(OS_POSIX) || defined(OS_ANDROID) || \ +#if !defined(OS_POSIX) || (defined(OS_ANDROID) && !defined(CASTANETS)) || \ (defined(OS_MACOSX) && !defined(OS_IOS)) // Non-POSIX systems, as well as Android, and non-iOS Mac, only use a single // handle to represent a writable region. diff --git a/mojo/core/channel_posix.cc b/mojo/core/channel_posix.cc index f6f76679603..8968023d295 100644 --- a/mojo/core/channel_posix.cc +++ b/mojo/core/channel_posix.cc @@ -26,6 +26,7 @@ #include "mojo/public/cpp/platform/socket_utils_posix.h" #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "base/memory/castanets_memory_syncer.h" #include "base/memory/shared_memory_tracker.h" #include "base/task/post_task.h" @@ -219,7 +220,8 @@ class ChannelPosix : public Channel, if (num_handles > std::numeric_limits::max()) return false; #if defined(CASTANETS) - if (num_handles && incoming_fds_.size() < num_handles) { + if (base::Castanets::IsEnabled() && num_handles && + incoming_fds_.size() < num_handles) { handles->clear(); handles->resize(num_handles); for (size_t i = 0; i < num_handles; ++i) @@ -327,17 +329,19 @@ class ChannelPosix : public Channel, base::MessageLoopCurrent::Get()->RemoveDestructionObserver(this); #if defined(CASTANETS) - TCPServerAcceptConnection(server_.platform_handle().GetFD().get(), - &socket_); - if (secure_connection_) { - ssl_.reset(AcceptSSLConnection(socket_.get())); - CHECK(ssl_); - LOG(INFO) << "SSL Server Connection Success - socket: " - << socket_.get(); - } -#else - AcceptSocketConnection(server_.platform_handle().GetFD().get(), &socket_); + if (base::Castanets::IsEnabled()) { + TCPServerAcceptConnection(server_.platform_handle().GetFD().get(), + &socket_); + if (secure_connection_) { + ssl_.reset(AcceptSSLConnection(socket_.get())); + CHECK(ssl_); + LOG(INFO) << "SSL Server Connection Success - socket: " + << socket_.get(); + } + } else #endif + AcceptSocketConnection(server_.platform_handle().GetFD().get(), + &socket_); ignore_result(server_.TakePlatformHandle()); if (!socket_.is_valid()) { OnError(Error::kConnectionFailed); @@ -446,16 +450,18 @@ class ChannelPosix : public Channel, for (size_t i = 0; i < num_handles_to_send; ++i) fds[i] = handles[i + handles_written].TakeHandle().TakeFD(); #if defined(CASTANETS) - scoped_refptr delegate = - Core::Get()->GetNodeController()->GetSyncDelegate( - remote_process().get()); - for (size_t i = 0; i < fds.size(); ++i) { - if (delegate) - base::SharedMemoryTracker::GetInstance()->MapExternalMemory( - fds[i].get(), delegate); - else - base::SharedMemoryTracker::GetInstance()->MapInternalMemory( - fds[i].get()); + if (base::Castanets::IsEnabled()) { + scoped_refptr delegate = + Core::Get()->GetNodeController()->GetSyncDelegate( + remote_process().get()); + for (size_t i = 0; i < fds.size(); ++i) { + if (delegate) + base::SharedMemoryTracker::GetInstance()->MapExternalMemory( + fds[i].get(), delegate); + else + base::SharedMemoryTracker::GetInstance()->MapInternalMemory( + fds[i].get()); + } } if (secure_connection_) result = SecureSocketWrite(ssl_.get(), message_view.data(), diff --git a/mojo/core/core.cc b/mojo/core/core.cc index 5e73a0b9ce9..4b92645d07c 100644 --- a/mojo/core/core.cc +++ b/mojo/core/core.cc @@ -43,6 +43,7 @@ #include "mojo/core/watcher_dispatcher.h" #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "base/memory/shared_memory_tracker.h" #endif // defined(CASTANETS) @@ -1409,15 +1410,17 @@ MojoResult Core::SendInvitation( connection_name); } else { #if defined(CASTANETS) - if (transport_endpoint->type == - MOJO_INVITATION_TRANSPORT_TYPE_CHANNEL_TCP_CLIENT) { - connection_params.SetTcpClient( - std::string(options->tcp_address, options->tcp_address_length), - options->tcp_port); - } else if (transport_endpoint->type == - MOJO_INVITATION_TRANSPORT_TYPE_CHANNEL_SERVER) { - if (transport_endpoint->secure_connection) - connection_params.SetSecure(); + if (base::Castanets::IsEnabled()) { + if (transport_endpoint->type == + MOJO_INVITATION_TRANSPORT_TYPE_CHANNEL_TCP_CLIENT) { + connection_params.SetTcpClient( + std::string(options->tcp_address, options->tcp_address_length), + options->tcp_port); + } else if (transport_endpoint->type == + MOJO_INVITATION_TRANSPORT_TYPE_CHANNEL_SERVER) { + if (transport_endpoint->secure_connection) + connection_params.SetSecure(); + } } #endif if (transport_endpoint->type == @@ -1495,16 +1498,18 @@ MojoResult Core::AcceptInvitation( connection_params.set_leak_endpoint(true); } #if defined(CASTANETS) - if (transport_endpoint->type == - MOJO_INVITATION_TRANSPORT_TYPE_CHANNEL_TCP_CLIENT) { - connection_params.SetTcpClient( - std::string(transport_endpoint->tcp_address, - transport_endpoint->tcp_address_length), - transport_endpoint->tcp_port); - } else if (transport_endpoint->type == - MOJO_INVITATION_TRANSPORT_TYPE_CHANNEL_SERVER) { - if (transport_endpoint->secure_connection) - connection_params.SetSecure(); + if (base::Castanets::IsEnabled()) { + if (transport_endpoint->type == + MOJO_INVITATION_TRANSPORT_TYPE_CHANNEL_TCP_CLIENT) { + connection_params.SetTcpClient( + std::string(transport_endpoint->tcp_address, + transport_endpoint->tcp_address_length), + transport_endpoint->tcp_port); + } else if (transport_endpoint->type == + MOJO_INVITATION_TRANSPORT_TYPE_CHANNEL_SERVER) { + if (transport_endpoint->secure_connection) + connection_params.SetSecure(); + } } #endif bool is_isolated = diff --git a/mojo/core/data_pipe_consumer_dispatcher.cc b/mojo/core/data_pipe_consumer_dispatcher.cc index 5201baf4abd..ae3fb6cb5e5 100644 --- a/mojo/core/data_pipe_consumer_dispatcher.cc +++ b/mojo/core/data_pipe_consumer_dispatcher.cc @@ -23,6 +23,7 @@ #include "mojo/public/c/system/data_pipe.h" #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "base/memory/castanets_memory_mapping.h" #include "base/memory/shared_memory_helper.h" #include "base/memory/shared_memory_tracker.h" @@ -107,7 +108,8 @@ MojoResult DataPipeConsumerDispatcher::ReadData( void* elements, uint32_t* num_bytes) { #if defined(CASTANETS) - node_controller_->WaitSyncSharedBuffer(ring_buffer_mapping_.guid()); + if (base::Castanets::IsEnabled()) + node_controller_->WaitSyncSharedBuffer(ring_buffer_mapping_.guid()); #endif base::AutoLock lock(lock_); @@ -187,7 +189,8 @@ MojoResult DataPipeConsumerDispatcher::ReadData( if (discard || !peek) { read_offset_ = (read_offset_ + bytes_to_read) % options_.capacity_num_bytes; #if defined(CASTANETS) - unrolled_read_offset_ += bytes_to_read; + if (base::Castanets::IsEnabled()) + unrolled_read_offset_ += bytes_to_read; #endif bytes_available_ -= bytes_to_read; @@ -206,7 +209,8 @@ MojoResult DataPipeConsumerDispatcher::BeginReadData( const void** buffer, uint32_t* buffer_num_bytes) { #if defined(CASTANETS) - node_controller_->WaitSyncSharedBuffer(ring_buffer_mapping_.guid()); + if (base::Castanets::IsEnabled()) + node_controller_->WaitSyncSharedBuffer(ring_buffer_mapping_.guid()); #endif base::AutoLock lock(lock_); if (!shared_ring_buffer_.IsValid() || in_transit_) @@ -230,17 +234,19 @@ MojoResult DataPipeConsumerDispatcher::BeginReadData( std::min(bytes_available_, options_.capacity_num_bytes - read_offset_); #if defined(CASTANETS) - scoped_refptr mapping = - base::SharedMemoryTracker::GetInstance()->FindMappedMemory( - ring_buffer_mapping_.guid()); - if (mapping && mapping->current_size() && - mapping->current_size() < (unrolled_read_offset_ + bytes_to_read)) { - VLOG(2) << ring_buffer_mapping_.guid() - << " is not fully received, received size: " - << mapping->current_size() - << ", but trying to read: " << bytes_to_read - << " bytes from offset: " << unrolled_read_offset_; - return MOJO_RESULT_SHOULD_WAIT; + if (base::Castanets::IsEnabled()) { + scoped_refptr mapping = + base::SharedMemoryTracker::GetInstance()->FindMappedMemory( + ring_buffer_mapping_.guid()); + if (mapping && mapping->current_size() && + mapping->current_size() < (unrolled_read_offset_ + bytes_to_read)) { + VLOG(2) << ring_buffer_mapping_.guid() + << " is not fully received, received size: " + << mapping->current_size() + << ", but trying to read: " << bytes_to_read + << " bytes from offset: " << unrolled_read_offset_; + return MOJO_RESULT_SHOULD_WAIT; + } } #endif @@ -278,7 +284,8 @@ MojoResult DataPipeConsumerDispatcher::EndReadData(uint32_t num_bytes_read) { read_offset_ = (read_offset_ + num_bytes_read) % options_.capacity_num_bytes; #if defined(CASTANETS) - unrolled_read_offset_ += num_bytes_read; + if (base::Castanets::IsEnabled()) + unrolled_read_offset_ += num_bytes_read; #endif DCHECK_GE(bytes_available_, num_bytes_read); @@ -364,8 +371,10 @@ bool DataPipeConsumerDispatcher::EndSerialize( #if defined(CASTANETS) #if DISABLE_MULTI_CONNECTION_CHANGES - base::SharedMemoryTracker::GetInstance()->AddFDInTransit( - guid, platform_handles[0].GetFD().get()); + if (base::Castanets::IsEnabled()) { + base::SharedMemoryTracker::GetInstance()->AddFDInTransit( + guid, platform_handles[0].GetFD().get()); + } #endif #endif return true; @@ -422,28 +431,29 @@ DataPipeConsumerDispatcher::Deserialize(const void* data, if (node_controller->node()->GetPort(ports[0], &port) != ports::OK) return nullptr; -#if defined(CASTANETS) base::subtle::PlatformSharedMemoryRegion::ScopedPlatformHandle region_handle; - if (handles[0].GetFD().get() < 0) { - base::SharedMemoryCreateOptions options; - options.size = static_cast(state->options.capacity_num_bytes); - auto new_region = base::CreateAnonymousSharedMemoryIfNeeded( - base::UnguessableToken::Deserialize(state->buffer_guid_high, - state->buffer_guid_low), - options); - region_handle = new_region.PassPlatformHandle(); - } else { +#if defined(CASTANETS) + if (base::Castanets::IsEnabled()) { + if (handles[0].GetFD().get() < 0) { + base::SharedMemoryCreateOptions options; + options.size = static_cast(state->options.capacity_num_bytes); + auto new_region = base::CreateAnonymousSharedMemoryIfNeeded( + base::UnguessableToken::Deserialize(state->buffer_guid_high, + state->buffer_guid_low), + options); + region_handle = new_region.PassPlatformHandle(); + } else { #if DISABLE_MULTI_CONNECTION_CHANGES base::SharedMemoryTracker::GetInstance()->MapInternalMemory( handles[0].GetFD().get()); #endif region_handle = CreateSharedMemoryRegionHandleFromPlatformHandles( std::move(handles[0]), PlatformHandle()); - } -#else - auto region_handle = CreateSharedMemoryRegionHandleFromPlatformHandles( - std::move(handles[0]), PlatformHandle()); + } + } else #endif + region_handle = CreateSharedMemoryRegionHandleFromPlatformHandles( + std::move(handles[0]), PlatformHandle()); auto region = base::subtle::PlatformSharedMemoryRegion::Take( std::move(region_handle), base::subtle::PlatformSharedMemoryRegion::Mode::kUnsafe, @@ -466,7 +476,8 @@ DataPipeConsumerDispatcher::Deserialize(const void* data, base::AutoLock lock(dispatcher->lock_); dispatcher->read_offset_ = state->read_offset; #if defined(CASTANETS) - dispatcher->unrolled_read_offset_ = state->read_offset; + if (base::Castanets::IsEnabled()) + dispatcher->unrolled_read_offset_ = state->read_offset; #endif dispatcher->bytes_available_ = state->bytes_available; dispatcher->new_data_available_ = state->bytes_available > 0; diff --git a/mojo/core/data_pipe_producer_dispatcher.cc b/mojo/core/data_pipe_producer_dispatcher.cc index dbd35a55952..4cbfa99b987 100644 --- a/mojo/core/data_pipe_producer_dispatcher.cc +++ b/mojo/core/data_pipe_producer_dispatcher.cc @@ -21,6 +21,10 @@ #include "mojo/core/user_message_impl.h" #include "mojo/public/c/system/data_pipe.h" +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + namespace mojo { namespace core { @@ -241,7 +245,8 @@ MojoResult DataPipeProducerDispatcher::EndWriteData( base::AutoUnlock unlock(lock_); NotifyWrite(num_bytes_written); #if defined(CASTANETS) - SyncData(num_bytes_written); + if (base::Castanets::IsEnabled()) + SyncData(num_bytes_written); #endif } diff --git a/mojo/core/node_controller.cc b/mojo/core/node_controller.cc index b4dec681cbb..6eae7cc522d 100644 --- a/mojo/core/node_controller.cc +++ b/mojo/core/node_controller.cc @@ -37,6 +37,7 @@ #if defined(CASTANETS) #include "base/base_switches.h" +#include "base/distributed_chromium_util.h" #include "base/memory/castanets_memory_mapping.h" #include "base/memory/castanets_memory_syncer.h" #include "base/memory/shared_memory_tracker.h" @@ -163,7 +164,8 @@ NodeController::NodeController(Core* core) node_(new ports::Node(name_, this)) { DVLOG(1) << "Initializing node " << name_; #if defined(CASTANETS) - fence_manager_ = std::make_unique(); + if (base::Castanets::IsEnabled()) + fence_manager_ = std::make_unique(); #endif } @@ -200,7 +202,8 @@ void NodeController::SendBrokerClientInvitation( } #if defined(CASTANETS) - tcp_success_callback_ = std::move(tcp_success_callback); + if (base::Castanets::IsEnabled()) + tcp_success_callback_ = std::move(tcp_success_callback); #endif ScopedProcessHandle scoped_target_process = @@ -239,34 +242,37 @@ void NodeController::AcceptBrokerClientInvitation( DCHECK(connection_params.endpoint().is_valid()); base::ElapsedTimer timer; #if defined(CASTANETS) - broker_ = BrokerCastanets::CreateInChildProcess( - std::move(connection_params), io_task_runner_, fence_manager_.get()); - connection_params = broker_->GetInviterConnectionParams(); - if (!connection_params.endpoint().is_valid() && - !connection_params.server_endpoint().is_valid()) { - // Most likely the inviter's side of the channel has already been closed - // and the broker was unable to negotiate a NodeChannel pipe. In this case - // we can cancel our connection to our inviter. - DVLOG(1) << "Cannot connect to invalid inviter channel."; - CancelPendingPortMerges(); - return; - } -#else - broker_ = std::make_unique( - connection_params.TakeEndpoint().TakePlatformHandle(), - /*wait_for_channel_handle=*/true); - PlatformChannelEndpoint endpoint = broker_->GetInviterEndpoint(); - if (!endpoint.is_valid()) { - // Most likely the inviter's side of the channel has already been closed - // and the broker was unable to negotiate a NodeChannel pipe. In this case - // we can cancel our connection to our inviter. - DVLOG(1) << "Cannot connect to invalid inviter channel."; - CancelPendingPortMerges(); - return; + if (base::Castanets::IsEnabled()) { + broker_castanets_ = BrokerCastanets::CreateInChildProcess( + std::move(connection_params), io_task_runner_, fence_manager_.get()); + connection_params = broker_castanets_->GetInviterConnectionParams(); + if (!connection_params.endpoint().is_valid() && + !connection_params.server_endpoint().is_valid()) { + // Most likely the inviter's side of the channel has already been closed + // and the broker was unable to negotiate a NodeChannel pipe. In this + // case we can cancel our connection to our inviter. + DVLOG(1) << "Cannot connect to invalid inviter channel."; + CancelPendingPortMerges(); + return; + } + } else +#endif + { + broker_ = std::make_unique( + connection_params.TakeEndpoint().TakePlatformHandle(), + /*wait_for_channel_handle=*/true); + PlatformChannelEndpoint endpoint = broker_->GetInviterEndpoint(); + if (!endpoint.is_valid()) { + // Most likely the inviter's side of the channel has already been closed + // and the broker was unable to negotiate a NodeChannel pipe. In this + // case we can cancel our connection to our inviter. + DVLOG(1) << "Cannot connect to invalid inviter channel."; + CancelPendingPortMerges(); + return; + } + connection_params = ConnectionParams(std::move(endpoint)); } - const bool leak_endpoint = connection_params.leak_endpoint(); - connection_params = ConnectionParams(std::move(endpoint)); connection_params.set_leak_endpoint(leak_endpoint); #endif } else { @@ -282,7 +288,7 @@ void NodeController::AcceptBrokerClientInvitation( broker_host_handle = channel.TakeRemoteEndpoint().TakePlatformHandle(); #endif } -#endif + //#endif // Re-enable port merge operations, which may have been disabled if this isn't // the first invitation accepted by this process. base::AutoLock lock(pending_port_merges_lock_); @@ -360,8 +366,19 @@ base::WritableSharedMemoryRegion NodeController::CreateSharedBuffer( #if !defined(OS_MACOSX) && !defined(OS_NACL_SFI) && !defined(OS_FUCHSIA) // Shared buffer creation failure is fatal, so always use the broker when we // have one; unless of course the embedder forces us not to. +#if defined(CASTANETS) + if (base::Castanets::IsEnabled()) { + if (!GetConfiguration().force_direct_shared_memory_allocation && + broker_castanets_) + return broker_castanets_->GetWritableSharedMemoryRegion(num_bytes); + } else { + if (!GetConfiguration().force_direct_shared_memory_allocation && broker_) + return broker_->GetWritableSharedMemoryRegion(num_bytes); + } +#else if (!GetConfiguration().force_direct_shared_memory_allocation && broker_) return broker_->GetWritableSharedMemoryRegion(num_bytes); +#endif #endif return base::WritableSharedMemoryRegion::Create(num_bytes); } @@ -371,8 +388,9 @@ bool NodeController::SyncSharedBuffer(const base::UnguessableToken& guid, size_t offset, size_t sync_size, BrokerCompressionMode compression_mode) { - if (broker_) - return broker_->SyncSharedBuffer(guid, offset, sync_size, compression_mode); + if (broker_castanets_) + return broker_castanets_->SyncSharedBuffer(guid, offset, sync_size, + compression_mode); #if !DISABLE_MULTI_CONNECTION_CHANGES // TODO(hw1008.kim): Assume there is only one connected node. In multiple @@ -396,8 +414,8 @@ bool NodeController::SyncSharedBuffer( base::WritableSharedMemoryMapping& mapping, size_t offset, size_t sync_size) { - if (broker_) - return broker_->SyncSharedBuffer(mapping, offset, sync_size); + if (broker_castanets_) + return broker_castanets_->SyncSharedBuffer(mapping, offset, sync_size); #if !DISABLE_MULTI_CONNECTION_CHANGES // TODO(hw1008.kim): Assume there is only one connected node. In multiple @@ -427,15 +445,15 @@ bool NodeController::SyncSharedBuffer2d( BrokerCompressionMode compression_mode) { // If broker_ is null, it means the current process is a browser process. // The browser process isn't likely to send tile data. - CHECK(broker_); - return broker_->SyncSharedBuffer2d(guid, width, height, bytes_per_pixel, - offset, stride, compression_mode); + CHECK(broker_castanets_); + return broker_castanets_->SyncSharedBuffer2d( + guid, width, height, bytes_per_pixel, offset, stride, compression_mode); } scoped_refptr NodeController::GetSyncDelegate( base::ProcessHandle process) { - if (broker_) - return broker_.get(); + if (broker_castanets_) + return broker_castanets_.get(); base::AutoLock lock(broker_hosts_lock_); auto it = broker_hosts_.find(process); @@ -448,8 +466,8 @@ scoped_refptr NodeController::GetSyncDelegate( void NodeController::OnAddSyncFence(base::ProcessHandle process_handle, base::UnguessableToken guid, uint32_t fence_id) { - if (broker_) { - broker_->AddSyncFence(guid, fence_id); + if (broker_castanets_) { + broker_castanets_->AddSyncFence(guid, fence_id); return; } @@ -527,37 +545,43 @@ void NodeController::SendBrokerClientInvitationOnIOThread( DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); #if !defined(OS_MACOSX) && !defined(OS_NACL) && !defined(OS_FUCHSIA) -#if defined(CASTANETS) bool channel_ok = false; ConnectionParams node_connection_params; - scoped_refptr broker_host = - BrokerCastanets::CreateInBrowserProcess( - target_process.get(), std::move(connection_params), - process_error_callback, fence_manager_.get()); - node_connection_params = broker_host->GetInviterConnectionParams(); - channel_ok = node_connection_params.endpoint().is_valid() || - node_connection_params.server_endpoint().is_valid(); - if (!channel_ok && !broker_host->is_tcp_connection()) { - // IPC Unix Domain Socket - PlatformChannel node_channel; - node_connection_params = ConnectionParams(node_channel.TakeLocalEndpoint()); - channel_ok = broker_host->SendChannel( - node_channel.TakeRemoteEndpoint().TakePlatformHandle()); - } -#else - ConnectionParams node_connection_params; - if (!connection_params.is_async()) { - // Sync connections usurp the passed endpoint and use it for the sync broker - // channel. A new channel is created here for the NodeChannel and sent over - // a sync broker message to the client. - PlatformChannel node_channel; - node_connection_params = ConnectionParams(node_channel.TakeLocalEndpoint()); - // BrokerHost owns itself. - BrokerHost* broker_host = - new BrokerHost(target_process.get(), std::move(connection_params), - process_error_callback); - bool channel_ok = broker_host->SendChannel( - node_channel.TakeRemoteEndpoint().TakePlatformHandle()); +#if defined(CASTANETS) + scoped_refptr broker_host_castanets; + if (base::Castanets::IsEnabled()) { + broker_host_castanets = BrokerCastanets::CreateInBrowserProcess( + target_process.get(), std::move(connection_params), + process_error_callback, fence_manager_.get()); + node_connection_params = + broker_host_castanets->GetInviterConnectionParams(); + channel_ok = node_connection_params.endpoint().is_valid() || + node_connection_params.server_endpoint().is_valid(); + if (!channel_ok && !broker_host_castanets->is_tcp_connection()) { + // IPC Unix Domain Socket + PlatformChannel node_channel; + node_connection_params = + ConnectionParams(node_channel.TakeLocalEndpoint()); + channel_ok = broker_host_castanets->SendChannel( + node_channel.TakeRemoteEndpoint().TakePlatformHandle()); + } + } else +#endif + { + // ConnectionParams node_connection_params; + if (!connection_params.is_async()) { + // Sync connections usurp the passed endpoint and use it for the sync + // broker channel. A new channel is created here for the NodeChannel and + // sent over a sync broker message to the client. + PlatformChannel node_channel; + node_connection_params = + ConnectionParams(node_channel.TakeLocalEndpoint()); + // BrokerHost owns itself. + BrokerHost* broker_host = + new BrokerHost(target_process.get(), std::move(connection_params), + process_error_callback); + channel_ok = broker_host->SendChannel( + node_channel.TakeRemoteEndpoint().TakePlatformHandle()); #if defined(OS_WIN) if (!channel_ok) { @@ -572,13 +596,13 @@ void NodeController::SendBrokerClientInvitationOnIOThread( #else CHECK(channel_ok); #endif // defined(OS_WIN) - } else { - // For async connections, the passed endpoint really is the NodeChannel - // endpoint. The broker channel will be established asynchronously by a - // |BIND_SYNC_BROKER| message from the invited client. - node_connection_params = std::move(connection_params); + } else { + // For async connections, the passed endpoint really is the NodeChannel + // endpoint. The broker channel will be established asynchronously by a + // |BIND_SYNC_BROKER| message from the invited client. + node_connection_params = std::move(connection_params); + } } -#endif scoped_refptr channel = NodeChannel::Create(this, std::move(node_connection_params), @@ -586,9 +610,12 @@ void NodeController::SendBrokerClientInvitationOnIOThread( io_task_runner_, process_error_callback); #if defined(CASTANETS) { - base::AutoLock broker_lock(broker_hosts_lock_); - broker_host->SetNodeChannel(channel); - broker_hosts_.emplace(target_process.get(), std::move(broker_host)); + if (base::Castanets::IsEnabled()) { + base::AutoLock broker_lock(broker_hosts_lock_); + broker_host_castanets->SetNodeChannel(channel); + broker_hosts_.emplace(target_process.get(), + std::move(broker_host_castanets)); + } } #endif @@ -685,7 +712,8 @@ void NodeController::AcceptBrokerClientInvitationOnIOThread( bootstrap_inviter_channel_->LeakHandleOnShutdown(); } #if defined(CASTANETS) - broker_->SetNodeChannel(bootstrap_inviter_channel_); + if (broker_castanets_) + broker_castanets_->SetNodeChannel(bootstrap_inviter_channel_); #endif } bootstrap_inviter_channel_->Start(); @@ -820,11 +848,13 @@ void NodeController::DropPeer(const ports::NodeName& name, ports::NodeName peer = it->first; #if defined(CASTANETS) { - base::AutoLock broker_lock(broker_hosts_lock_); - ScopedProcessHandle process = it->second->CloneRemoteProcessHandle(); - auto host = broker_hosts_.find(process.get()); - if (host != broker_hosts_.end()) - broker_hosts_.erase(host); + if (base::Castanets::IsEnabled()) { + base::AutoLock broker_lock(broker_hosts_lock_); + ScopedProcessHandle process = it->second->CloneRemoteProcessHandle(); + auto host = broker_hosts_.find(process.get()); + if (host != broker_hosts_.end()) + broker_hosts_.erase(host); + } } #endif peers_.erase(it); @@ -968,8 +998,10 @@ void NodeController::DropAllPeers() { #if defined(CASTANETS) { - base::AutoLock broker_lock(broker_hosts_lock_); - broker_hosts_.clear(); + if (base::Castanets::IsEnabled()) { + base::AutoLock broker_lock(broker_hosts_lock_); + broker_hosts_.clear(); + } } #endif @@ -1367,35 +1399,38 @@ void NodeController::OnIntroduce(const ports::NodeName& from_node, #endif #if defined(CASTANETS) - std::string process_type_str = - base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type"); - if (process_type_str == "utility") { - scoped_refptr channel = NodeChannel::Create( - this, - ConnectionParams(mojo::PlatformChannelServerEndpoint( - mojo::CreateTCPServerHandle(mojo::kCastanetsNonBrokerPort))), - kPeerHandlePolicy, io_task_runner_, ProcessErrorCallback()); - DVLOG(1) << "Adding new peer " << name << " via broker introduction."; - AddPeer(name, channel, true /* start_channel */); - } - else { + if (base::Castanets::IsEnabled()) { + std::string process_type_str = + base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type"); + if (process_type_str == "utility") { + scoped_refptr channel = NodeChannel::Create( + this, + ConnectionParams(mojo::PlatformChannelServerEndpoint( + mojo::CreateTCPServerHandle(mojo::kCastanetsNonBrokerPort))), + kPeerHandlePolicy, io_task_runner_, ProcessErrorCallback()); + DVLOG(1) << "Adding new peer " << name << " via broker introduction."; + AddPeer(name, channel, true /* start_channel */); + } else { + scoped_refptr channel = NodeChannel::Create( + this, + ConnectionParams(PlatformChannelEndpoint( + mojo::CreateTCPClientHandle(mojo::kCastanetsNonBrokerPort))), + kPeerHandlePolicy, io_task_runner_, ProcessErrorCallback()); + DVLOG(1) << "Adding new peer " << name << " via broker introduction."; + AddPeer(name, channel, true /* start_channel */); + } + } else +#endif + { scoped_refptr channel = NodeChannel::Create( this, - ConnectionParams(PlatformChannelEndpoint( - mojo::CreateTCPClientHandle(mojo::kCastanetsNonBrokerPort))), + ConnectionParams(PlatformChannelEndpoint(std::move(channel_handle))), kPeerHandlePolicy, io_task_runner_, ProcessErrorCallback()); + DVLOG(1) << "Adding new peer " << name << " via broker introduction."; AddPeer(name, channel, true /* start_channel */); } -#else - scoped_refptr channel = NodeChannel::Create( - this, - ConnectionParams(PlatformChannelEndpoint(std::move(channel_handle))), - kPeerHandlePolicy, io_task_runner_, ProcessErrorCallback()); - - DVLOG(1) << "Adding new peer " << name << " via broker introduction."; - AddPeer(name, channel, true /* start_channel */); -#endif + //#endif } void NodeController::OnBroadcast(const ports::NodeName& from_node, diff --git a/mojo/core/node_controller.h b/mojo/core/node_controller.h index da2f6230ae0..f4ae7dc7ca1 100644 --- a/mojo/core/node_controller.h +++ b/mojo/core/node_controller.h @@ -393,8 +393,8 @@ class MOJO_SYSTEM_IMPL_EXPORT NodeController : public ports::NodeDelegate, #if !defined(OS_MACOSX) && !defined(OS_NACL_SFI) && !defined(OS_FUCHSIA) // Broker for sync shared buffer creation on behalf of broker clients. #if defined(CASTANETS) - scoped_refptr broker_; - + scoped_refptr broker_castanets_; + std::unique_ptr broker_; base::Lock broker_hosts_lock_; std::unordered_map> broker_hosts_; diff --git a/mojo/core/shared_buffer_dispatcher.cc b/mojo/core/shared_buffer_dispatcher.cc index 7f0f7c98e94..051bcc7ed9c 100644 --- a/mojo/core/shared_buffer_dispatcher.cc +++ b/mojo/core/shared_buffer_dispatcher.cc @@ -22,6 +22,7 @@ #include "mojo/public/c/system/platform_handle.h" #if defined(CASTANETS) +#include "base/distributed_chromium_util.h" #include "base/memory/shared_memory_helper.h" #include "base/memory/shared_memory_tracker.h" #endif // defined(CASTANETS) @@ -188,21 +189,15 @@ scoped_refptr SharedBufferDispatcher::Deserialize( mode, static_cast(serialized_state->num_bytes), guid); #if defined(CASTANETS) - if (!region.IsValid()) { - base::SharedMemoryCreateOptions options; - options.size = static_cast(serialized_state->num_bytes); - // TODO: Check why read only mode crashes -#if 0 - if (mode == base::subtle::PlatformSharedMemoryRegion::Mode::kReadOnly) { - options.share_read_only = true; + if (base::Castanets::IsEnabled()) { + if (!region.IsValid()) { + base::SharedMemoryCreateOptions options; + options.size = static_cast(serialized_state->num_bytes); + region = base::CreateAnonymousSharedMemoryIfNeeded(guid, options); + } else { + base::SharedMemoryTracker::GetInstance()->MapInternalMemory( + region.GetPlatformHandle().fd); } -#endif - region = base::CreateAnonymousSharedMemoryIfNeeded(guid, options); -#if DISABLE_MULTI_CONNECTION_CHANGES - } else { - base::SharedMemoryTracker::GetInstance()->MapInternalMemory( - region.GetPlatformHandle().fd); -#endif } #endif @@ -389,8 +384,10 @@ bool SharedBufferDispatcher::EndSerialize(void* destination, handles[1] = std::move(platform_handles[1]); #if defined(CASTANETS) #if DISABLE_MULTI_CONNECTION_CHANGES - base::SharedMemoryTracker::GetInstance()->AddFDInTransit( - guid, handles[0].GetFD().get()); + if (base::Castanets::IsEnabled()) { + base::SharedMemoryTracker::GetInstance()->AddFDInTransit( + guid, handles[0].GetFD().get()); + } #endif #endif return true; @@ -405,8 +402,10 @@ bool SharedBufferDispatcher::EndSerialize(void* destination, #if defined(CASTANETS) #if DISABLE_MULTI_CONNECTION_CHANGES - base::SharedMemoryTracker::GetInstance()->AddFDInTransit( - guid, handles[0].GetFD().get()); + if (base::Castanets::IsEnabled()) { + base::SharedMemoryTracker::GetInstance()->AddFDInTransit( + guid, handles[0].GetFD().get()); + } #endif #endif return true; diff --git a/mojo/public/cpp/platform/named_platform_channel_posix.cc b/mojo/public/cpp/platform/named_platform_channel_posix.cc index 0ae1c45271b..34140433ce5 100644 --- a/mojo/public/cpp/platform/named_platform_channel_posix.cc +++ b/mojo/public/cpp/platform/named_platform_channel_posix.cc @@ -16,6 +16,10 @@ #include "base/rand_util.h" #include "base/strings/string_number_conversions.h" +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + namespace mojo { namespace { @@ -82,7 +86,7 @@ PlatformChannelServerEndpoint NamedPlatformChannel::CreateServerEndpoint( const Options& options, ServerName* server_name) { #if defined(CASTANETS) - if (options.port > -1) { + if (base::Castanets::IsEnabled() && (options.port > -1)) { uint16_t port = options.port; return PlatformChannelServerEndpoint(CreateTCPServerHandle(port, &port)); } diff --git a/third_party/blink/renderer/platform/fonts/skia/font_cache_skia.cc b/third_party/blink/renderer/platform/fonts/skia/font_cache_skia.cc index 89026e4c02e..11a7ebe5767 100644 --- a/third_party/blink/renderer/platform/fonts/skia/font_cache_skia.cc +++ b/third_party/blink/renderer/platform/fonts/skia/font_cache_skia.cc @@ -55,6 +55,10 @@ #include "third_party/skia/include/core/SkStream.h" #include "third_party/skia/include/core/SkTypeface.h" +#if defined(CASTANETS) +#include "base/distributed_chromium_util.h" +#endif + namespace blink { AtomicString ToAtomicString(const SkString& str) { @@ -199,9 +203,15 @@ sk_sp FontCache::CreateTypeface( // TODO(fuchsia): Revisit this and other font code for Fuchsia. if (creation_params.CreationType() == kCreateFontByFciIdAndTtcIndex) { -#if !defined(CASTANETS) +#if defined(CASTANETS) // fontconfigInterfaceId() of browser will not be known by renderer in // distributed chromium scenario. So lets go by filename. + if (!base::Castanets::IsEnabled() && + Platform::Current()->GetSandboxSupport()) { + return SkTypeface_Factory::FromFontConfigInterfaceIdAndTtcIndex( + creation_params.FontconfigInterfaceId(), creation_params.TtcIndex()); + } +#else if (Platform::Current()->GetSandboxSupport()) { return SkTypeface_Factory::FromFontConfigInterfaceIdAndTtcIndex( creation_params.FontconfigInterfaceId(), creation_params.TtcIndex());