diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-01-04 14:17:57 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-01-05 10:05:06 +0000 |
commit | 39d357e3248f80abea0159765ff39554affb40db (patch) | |
tree | aba0e6bfb76de0244bba0f5fdbd64b830dd6e621 /chromium/content/browser/browser_main_loop.cc | |
parent | 87778abf5a1f89266f37d1321b92a21851d8244d (diff) | |
download | qtwebengine-chromium-39d357e3248f80abea0159765ff39554affb40db.tar.gz |
BASELINE: Update Chromium to 55.0.2883.105
And updates ninja to 1.7.2
Change-Id: I20d43c737f82764d857ada9a55586901b18b9243
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/content/browser/browser_main_loop.cc')
-rw-r--r-- | chromium/content/browser/browser_main_loop.cc | 255 |
1 files changed, 154 insertions, 101 deletions
diff --git a/chromium/content/browser/browser_main_loop.cc b/chromium/content/browser/browser_main_loop.cc index db8ea8df063..325b85d3ec2 100644 --- a/chromium/content/browser/browser_main_loop.cc +++ b/chromium/content/browser/browser_main_loop.cc @@ -19,7 +19,7 @@ #include "base/memory/memory_pressure_monitor.h" #include "base/memory/ptr_util.h" #include "base/metrics/field_trial.h" -#include "base/metrics/histogram.h" +#include "base/metrics/histogram_macros.h" #include "base/metrics/user_metrics.h" #include "base/pending_task.h" #include "base/power_monitor/power_monitor.h" @@ -41,8 +41,9 @@ #include "components/tracing/common/trace_to_console.h" #include "components/tracing/common/tracing_switches.h" #include "content/browser/browser_thread_impl.h" -#include "content/browser/device_sensors/device_inertial_sensor_service.h" +#include "content/browser/device_sensors/device_sensor_service.h" #include "content/browser/dom_storage/dom_storage_area.h" +#include "content/browser/download/download_resource_handler.h" #include "content/browser/download/save_file_manager.h" #include "content/browser/gamepad/gamepad_service.h" #include "content/browser/gpu/browser_gpu_channel_host_factory.h" @@ -55,22 +56,22 @@ #include "content/browser/loader/resource_dispatcher_host_impl.h" #include "content/browser/loader_delegate_impl.h" #include "content/browser/media/media_internals.h" -#include "content/browser/mojo/mojo_shell_context.h" #include "content/browser/net/browser_online_state_observer.h" #include "content/browser/renderer_host/media/media_stream_manager.h" #include "content/browser/renderer_host/render_process_host_impl.h" +#include "content/browser/service_manager/service_manager_context.h" #include "content/browser/speech/speech_recognition_manager_impl.h" #include "content/browser/startup_task_runner.h" -#include "content/browser/time_zone_monitor.h" #include "content/browser/utility_process_host_impl.h" #include "content/browser/webui/content_web_ui_controller_factory.h" #include "content/browser/webui/url_data_manager.h" #include "content/common/content_switches_internal.h" #include "content/common/host_discardable_shared_memory_manager.h" #include "content/common/host_shared_bitmap_manager.h" -#include "content/common/mojo/mojo_shell_connection_impl.h" +#include "content/common/service_manager/service_manager_connection_impl.h" #include "content/public/browser/browser_main_parts.h" #include "content/public/browser/content_browser_client.h" +#include "content/public/browser/gpu_data_manager_observer.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/tracing_controller.h" #include "content/public/common/content_client.h" @@ -78,6 +79,7 @@ #include "content/public/common/main_function_params.h" #include "content/public/common/result_codes.h" #include "device/battery/battery_status_service.h" +#include "device/time_zone_monitor/time_zone_monitor.h" #include "media/base/media.h" #include "media/base/user_input_monitor.h" #include "media/midi/midi_manager.h" @@ -106,8 +108,10 @@ #include "components/tracing/common/graphics_memory_dump_provider_android.h" #include "content/browser/android/browser_startup_controller.h" #include "content/browser/android/browser_surface_texture_manager.h" +#include "content/browser/android/scoped_surface_request_manager.h" #include "content/browser/android/tracing_controller_android.h" #include "content/browser/media/android/browser_media_player_manager.h" +#include "content/browser/renderer_host/context_provider_factory_impl_android.h" #include "content/browser/screen_orientation/screen_orientation_delegate_android.h" #include "content/public/browser/screen_orientation_provider.h" #include "gpu/ipc/client/android/in_process_surface_texture_manager.h" @@ -152,11 +156,11 @@ #endif #if defined(OS_WIN) -#include "media/capture/system_message_window_win.h" +#include "media/device_monitors/system_message_window_win.h" #elif defined(OS_LINUX) && defined(USE_UDEV) -#include "media/capture/device_monitor_udev.h" +#include "media/device_monitors/device_monitor_udev.h" #elif defined(OS_MACOSX) -#include "media/capture/device_monitor_mac.h" +#include "media/device_monitors/device_monitor_mac.h" #endif #if defined(OS_POSIX) && !defined(OS_MACOSX) @@ -178,9 +182,9 @@ #endif #if defined(USE_X11) +#include "gpu/config/gpu_driver_bug_workaround_type.h" #include "ui/base/x/x11_util_internal.h" // nogncheck #include "ui/gfx/x/x11_connection.h" // nogncheck -#include "ui/gfx/x/x11_switches.h" // nogncheck #include "ui/gfx/x/x11_types.h" // nogncheck #endif @@ -192,11 +196,6 @@ #include "gpu/vulkan/vulkan_implementation.h" #endif -#if defined(MOJO_SHELL_CLIENT) && defined(USE_AURA) -#include "components/mus/common/gpu_service.h" // nogncheck -#endif - - // One of the linux specific headers defines this as a macro. #ifdef DestroyAll #undef DestroyAll @@ -208,6 +207,11 @@ namespace { #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) void SetupSandbox(const base::CommandLine& parsed_command_line) { TRACE_EVENT0("startup", "SetupSandbox"); + if (parsed_command_line.HasSwitch(switches::kNoZygote)) { + CHECK(parsed_command_line.HasSwitch(switches::kNoSandbox)) + << "--no-sandbox should be used together with --no--zygote"; + return; + } // Tickle the sandbox host and zygote host so they fork now. RenderSandboxHostLinux::GetInstance()->Init(); @@ -279,16 +283,6 @@ static void SetUpGLibLogHandler() { } #endif // defined(USE_GLIB) -#if defined(MOJO_SHELL_CLIENT) && defined(USE_AURA) -void WaitForMojoShellInitialize() { - // TODO(rockot): Remove this. http://crbug.com/594852. - base::RunLoop wait_loop; - MojoShellConnection::GetForProcess()->GetShellConnection()-> - set_initialize_handler(wait_loop.QuitClosure()); - wait_loop.Run(); -} -#endif // defined(MOJO_SHELL_CLIENT) && defined(USE_AURA) - void OnStoppedStartupTracing(const base::FilePath& trace_file) { VLOG(0) << "Completed startup tracing to " << trace_file.value(); } @@ -376,6 +370,44 @@ base::win::MemoryPressureMonitor* CreateWinMemoryPressureMonitor( } // namespace +#if defined(USE_X11) && !defined(OS_CHROMEOS) +namespace internal { + +// Forwards GPUInfo updates to ui::XVisualManager +class GpuDataManagerVisualProxy : public GpuDataManagerObserver { + public: + explicit GpuDataManagerVisualProxy(GpuDataManagerImpl* gpu_data_manager) + : gpu_data_manager_(gpu_data_manager) { + gpu_data_manager_->AddObserver(this); + } + + ~GpuDataManagerVisualProxy() override { + gpu_data_manager_->RemoveObserver(this); + } + + void OnGpuInfoUpdate() override { + gpu::GPUInfo gpu_info = gpu_data_manager_->GetGPUInfo(); + if (!ui::XVisualManager::GetInstance()->OnGPUInfoChanged( + gpu_info.software_rendering || + !gpu_data_manager_->GpuAccessAllowed(nullptr), + gpu_info.system_visual, gpu_info.rgba_visual)) { + // The GPU process sent back bad visuals, which should never happen. + auto* gpu_process_host = GpuProcessHost::Get( + GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, false); + if (gpu_process_host) + gpu_process_host->ForceShutdown(); + } + } + + private: + GpuDataManagerImpl* gpu_data_manager_; + + DISALLOW_COPY_AND_ASSIGN(GpuDataManagerVisualProxy); +}; + +} // namespace internal +#endif + // The currently-running BrowserMainLoop. There can be one or zero. BrowserMainLoop* g_current_browser_main_loop = NULL; @@ -479,17 +511,16 @@ void BrowserMainLoop::EarlyInitialization() { if (parts_) parts_->PreEarlyInitialization(); -#if defined(OS_MACOSX) - // We use quite a few file descriptors for our IPC, and the default limit on - // the Mac is low (256), so bump it up. - base::SetFdLimit(1024); -#elif defined(OS_LINUX) +#if defined(OS_MACOSX) || defined(OS_LINUX) + // We use quite a few file descriptors for our IPC as well as disk the disk + // cache,and the default limit on the Mac is low (256), so bump it up. + // Same for Linux. The default various per distro, but it is 1024 on Fedora. // Low soft limits combined with liberal use of file descriptors means power // users can easily hit this limit with many open tabs. Bump up the limit to // an arbitrarily high number. See https://crbug.com/539567 base::SetFdLimit(8192); -#endif // default(OS_MACOSX) +#endif // defined(OS_MACOSX) || defined(OS_LINUX) #if defined(OS_WIN) net::EnsureWinsockInit(); @@ -587,7 +618,7 @@ void BrowserMainLoop::PostMainMessageLoopStart() { { base::SetRecordActionTaskRunner( - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)); + BrowserThread::GetTaskRunnerForThread(BrowserThread::UI)); } #if defined(OS_WIN) @@ -640,6 +671,8 @@ void BrowserMainLoop::PostMainMessageLoopStart() { if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) { gpu::SurfaceTextureManager::SetInstance( gpu::InProcessSurfaceTextureManager::GetInstance()); + gpu::ScopedSurfaceRequestConduit::SetInstance( + ScopedSurfaceRequestManager::GetInstance()); } else { gpu::SurfaceTextureManager::SetInstance( BrowserSurfaceTextureManager::GetInstance()); @@ -755,7 +788,13 @@ int BrowserMainLoop::PreCreateThreads() { // It's unsafe to append the gpu command line switches to the global // CommandLine::ForCurrentProcess object after threads are created. // 2) Must be after parts_->PreCreateThreads to pick up chrome://flags. - GpuDataManagerImpl::GetInstance()->Initialize(); + GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance(); + gpu_data_manager->Initialize(); + +#if defined(USE_X11) && !defined(OS_CHROMEOS) + gpu_data_manager_visual_proxy_.reset( + new internal::GpuDataManagerVisualProxy(gpu_data_manager)); +#endif #if !defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID) // Single-process is an unsupported and not fully tested mode, so @@ -773,12 +812,12 @@ void BrowserMainLoop::CreateStartupTasks() { // First time through, we really want to create all the tasks if (!startup_task_runner_.get()) { #if defined(OS_ANDROID) - startup_task_runner_ = base::WrapUnique( - new StartupTaskRunner(base::Bind(&BrowserStartupComplete), - base::ThreadTaskRunnerHandle::Get())); + startup_task_runner_ = base::MakeUnique<StartupTaskRunner>( + base::Bind(&BrowserStartupComplete), + base::ThreadTaskRunnerHandle::Get()); #else - startup_task_runner_ = base::WrapUnique(new StartupTaskRunner( - base::Callback<void(int)>(), base::ThreadTaskRunnerHandle::Get())); + startup_task_runner_ = base::MakeUnique<StartupTaskRunner>( + base::Callback<void(int)>(), base::ThreadTaskRunnerHandle::Get()); #endif StartupTask pre_create_threads = base::Bind(&BrowserMainLoop::PreCreateThreads, base::Unretained(this)); @@ -817,7 +856,7 @@ void BrowserMainLoop::CreateStartupTasks() { } int BrowserMainLoop::CreateThreads() { - TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads"); + TRACE_EVENT0("startup,rail", "BrowserMainLoop::CreateThreads"); base::Thread::Options io_message_loop_options; io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; @@ -1027,7 +1066,7 @@ void BrowserMainLoop::ShutdownThreadsAndCleanUp() { #endif // Shutdown Mojo shell and IPC. - mojo_shell_context_.reset(); + service_manager_context_.reset(); mojo_ipc_support_.reset(); // Must be size_t so we can subtract from it. @@ -1061,8 +1100,7 @@ void BrowserMainLoop::ShutdownThreadsAndCleanUp() { TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:FileThread"); // Clean up state that lives on or uses the file_thread_ before // it goes away. - if (resource_dispatcher_host_) - resource_dispatcher_host_.get()->save_file_manager()->Shutdown(); + save_file_manager_->Shutdown(); ResetThread_FILE(std::move(file_thread_)); break; } @@ -1113,8 +1151,14 @@ void BrowserMainLoop::ShutdownThreadsAndCleanUp() { // it. { TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:GPUChannelFactory"); - if (BrowserGpuChannelHostFactory::instance()) + if (BrowserGpuChannelHostFactory::instance()) { +#if defined(OS_ANDROID) + // Clean up the references to the factory before terminating it. + ui::ContextProviderFactory::SetInstance(nullptr); + ContextProviderFactoryImpl::Terminate(); +#endif BrowserGpuChannelHostFactory::Terminate(); + } } // Must happen after the I/O thread is shutdown since this class lives on the @@ -1125,7 +1169,7 @@ void BrowserMainLoop::ShutdownThreadsAndCleanUp() { } { TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:SensorService"); - DeviceInertialSensorService::GetInstance()->Shutdown(); + DeviceSensorService::GetInstance()->Shutdown(); } #if !defined(OS_ANDROID) { @@ -1160,34 +1204,17 @@ void BrowserMainLoop::InitializeMainThread() { int BrowserMainLoop::BrowserThreadsStarted() { TRACE_EVENT0("startup", "BrowserMainLoop::BrowserThreadsStarted"); - // Bring up Mojo IPC and shell as early as possible. - - // Disallow mojo sync call in the browser process. - bool sync_call_allowed = false; - MojoResult result = mojo::edk::SetProperty( - MOJO_PROPERTY_TYPE_SYNC_CALL_ALLOWED, &sync_call_allowed); - DCHECK_EQ(MOJO_RESULT_OK, result); + // Bring up Mojo IPC and shell as early as possible. Initializaing mojo + // requires the IO thread to have been initialized first. So this cannot + // happen any earlier than this. + InitializeMojo(); - mojo_ipc_support_.reset(new mojo::edk::ScopedIPCSupport( - BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) - ->task_runner())); - - mojo_shell_context_.reset(new MojoShellContext); +#if defined(USE_AURA) if (shell::ShellIsRemote()) { -#if defined(MOJO_SHELL_CLIENT) && defined(USE_AURA) - // TODO(rockot): Remove the blocking wait for init. - // http://crbug.com/594852. - auto connection = MojoShellConnection::GetForProcess(); - if (connection) { - WaitForMojoShellInitialize(); - mus::GpuService::Initialize(connection->GetConnector()); - } -#endif + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kIsRunningInMash); } - -#if defined(OS_MACOSX) - mojo::edk::SetMachPortProvider(MachBroker::GetInstance()); -#endif // defined(OS_MACOSX) +#endif indexed_db_thread_.reset(new base::Thread("IndexedDB")); indexed_db_thread_->Start(); @@ -1212,20 +1239,29 @@ int BrowserMainLoop::BrowserThreadsStarted() { established_gpu_channel = false; always_uses_gpu = ShouldStartGpuProcessOnBrowserStartup(); BrowserGpuChannelHostFactory::Initialize(established_gpu_channel); + ContextProviderFactoryImpl::Initialize( + BrowserGpuChannelHostFactory::instance()); + ui::ContextProviderFactory::SetInstance( + ContextProviderFactoryImpl::GetInstance()); #elif defined(USE_AURA) || defined(OS_MACOSX) established_gpu_channel = true; if (!GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor() || - parsed_command_line_.HasSwitch(switches::kDisableGpuEarlyInit)) { + parsed_command_line_.HasSwitch(switches::kDisableGpuEarlyInit) || + shell::ShellIsRemote()) { established_gpu_channel = always_uses_gpu = false; } - BrowserGpuChannelHostFactory::Initialize(established_gpu_channel); + gpu::GpuChannelEstablishFactory* factory = + GetContentClient()->browser()->GetGpuChannelEstablishFactory(); + if (!factory) { + BrowserGpuChannelHostFactory::Initialize(established_gpu_channel); + factory = BrowserGpuChannelHostFactory::instance(); + } + DCHECK(factory); ImageTransportFactory::Initialize(); + ImageTransportFactory::GetInstance()->SetGpuChannelEstablishFactory(factory); #if defined(USE_AURA) - bool use_mus_in_renderer = false; -#if defined (MOJO_SHELL_CLIENT) - use_mus_in_renderer = base::CommandLine::ForCurrentProcess()->HasSwitch( + bool use_mus_in_renderer = base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kUseMusInRenderer); -#endif // defined(MOJO_SHELL_CLIENT); if (aura::Env::GetInstance() && !use_mus_in_renderer) { aura::Env::GetInstance()->set_context_factory(GetContextFactory()); } @@ -1272,7 +1308,14 @@ int BrowserMainLoop::BrowserThreadsStarted() { { TRACE_EVENT0("startup", "BrowserMainLoop::BrowserThreadsStarted:InitResourceDispatcherHost"); - resource_dispatcher_host_.reset(new ResourceDispatcherHostImpl()); + // TODO(ananta) + // We register an interceptor on the ResourceDispatcherHostImpl instance to + // intercept requests to create handlers for download requests. We need to + // find a better way to achieve this. Ideally we don't want knowledge of + // downloads in ResourceDispatcherHostImpl. + resource_dispatcher_host_.reset(new ResourceDispatcherHostImpl( + base::Bind(&DownloadResourceHandler::Create))); + GetContentClient()->browser()->ResourceDispatcherHostCreated(); loader_delegate_.reset(new LoaderDelegateImpl()); resource_dispatcher_host_->SetLoaderDelegate(loader_delegate_.get()); @@ -1303,7 +1346,14 @@ int BrowserMainLoop::BrowserThreadsStarted() { { TRACE_EVENT0("startup", "BrowserMainLoop::BrowserThreadsStarted::TimeZoneMonitor"); - time_zone_monitor_ = TimeZoneMonitor::Create(); + time_zone_monitor_ = + device::TimeZoneMonitor::Create(file_thread_->task_runner()); + } + + { + TRACE_EVENT0("startup", + "BrowserMainLoop::BrowserThreadsStarted::SaveFileManager"); + save_file_manager_ = new SaveFileManager(); } // Alert the clipboard class to which threads are allowed to access the @@ -1322,16 +1372,15 @@ int BrowserMainLoop::BrowserThreadsStarted() { // since creating the GPU thread races against creation of the one-and-only // ChildProcess instance which is created by the renderer thread. if (GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL) && - !established_gpu_channel && - always_uses_gpu && - !UsingInProcessGpu()) { + !established_gpu_channel && always_uses_gpu && !UsingInProcessGpu() && + !shell::ShellIsRemote()) { TRACE_EVENT_INSTANT0("gpu", "Post task to launch GPU process", TRACE_EVENT_SCOPE_THREAD); BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, base::Bind(base::IgnoreResult(&GpuProcessHost::Get), GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, - CAUSE_FOR_GPU_LAUNCH_BROWSER_STARTUP)); + true /* force_create */)); } #if defined(OS_MACOSX) @@ -1377,20 +1426,6 @@ bool BrowserMainLoop::InitializeToolkit() { LOG(ERROR) << "Unable to open X display."; return false; } - -#if !defined(OS_CHROMEOS) - // InitializeToolkit is called before CreateStartupTasks which one starts the - // gpu process. - Visual* visual = NULL; - int depth = 0; - ui::ChooseVisualForWindow(&visual, &depth); - DCHECK(depth > 0); - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kWindowDepth, base::IntToString(depth)); - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kX11VisualID, base::UintToString(visual->visualid)); -#endif - #endif // Env creates the compositor. Aura widgets need the compositor to be created @@ -1420,6 +1455,31 @@ void BrowserMainLoop::MainMessageLoopRun() { #endif } +void BrowserMainLoop::InitializeMojo() { + if (!parsed_command_line_.HasSwitch(switches::kSingleProcess)) { + // Disallow mojo sync calls in the browser process. Note that we allow sync + // calls in single-process mode since renderer IPCs are made from a browser + // thread. + bool sync_call_allowed = false; + MojoResult result = mojo::edk::SetProperty( + MOJO_PROPERTY_TYPE_SYNC_CALL_ALLOWED, &sync_call_allowed); + DCHECK_EQ(MOJO_RESULT_OK, result); + } + + mojo_ipc_support_.reset(new mojo::edk::ScopedIPCSupport( + BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) + ->task_runner())); + + service_manager_context_.reset(new ServiceManagerContext); +#if defined(OS_MACOSX) + mojo::edk::SetMachPortProvider(MachBroker::GetInstance()); +#endif // defined(OS_MACOSX) + if (parts_) { + parts_->ServiceManagerConnectionStarted( + ServiceManagerConnection::GetForProcess()); + } +} + base::FilePath BrowserMainLoop::GetStartupTraceFileName( const base::CommandLine& command_line) const { base::FilePath trace_file; @@ -1490,7 +1550,6 @@ void BrowserMainLoop::CreateAudioManager() { DCHECK(!audio_thread_); DCHECK(!audio_manager_); - bool use_hang_monitor = true; audio_manager_ = GetContentClient()->browser()->CreateAudioManager( MediaInternals::GetInstance()); if (!audio_manager_) { @@ -1502,9 +1561,6 @@ void BrowserMainLoop::CreateAudioManager() { #if defined(OS_MACOSX) // On Mac audio task runner must belong to the main thread. // See http://crbug.com/158170. - // Since the audio thread is the UI thread, a hang monitor is not - // necessary or recommended. - use_hang_monitor = false; scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner = base::ThreadTaskRunnerHandle::Get(); #else @@ -1518,9 +1574,6 @@ void BrowserMainLoop::CreateAudioManager() { MediaInternals::GetInstance()); } CHECK(audio_manager_); - - if (use_hang_monitor) - media::AudioManager::StartHangMonitor(io_thread_->task_runner()); } } // namespace content |