| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/utility_process_host_impl.h" | 5 #include "content/browser/utility_process_host_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 18 #include "base/process/process_handle.h" | 18 #include "base/process/process_handle.h" |
| 19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
| 20 #include "base/sequenced_task_runner.h" | 20 #include "base/sequenced_task_runner.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
| 23 #include "base/synchronization/waitable_event.h" | 23 #include "base/synchronization/waitable_event.h" |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "components/discardable_memory/service/discardable_shared_memory_manage
r.h" |
| 25 #include "content/browser/browser_child_process_host_impl.h" | 26 #include "content/browser/browser_child_process_host_impl.h" |
| 27 #include "content/browser/browser_main_loop.h" |
| 26 #include "content/browser/renderer_host/render_process_host_impl.h" | 28 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 27 #include "content/browser/service_manager/service_manager_context.h" | 29 #include "content/browser/service_manager/service_manager_context.h" |
| 28 #include "content/common/child_process_host_impl.h" | 30 #include "content/common/child_process_host_impl.h" |
| 29 #include "content/common/in_process_child_thread_params.h" | 31 #include "content/common/in_process_child_thread_params.h" |
| 30 #include "content/common/service_manager/child_connection.h" | 32 #include "content/common/service_manager/child_connection.h" |
| 31 #include "content/common/utility_messages.h" | 33 #include "content/common/utility_messages.h" |
| 32 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/content_browser_client.h" | 35 #include "content/public/browser/content_browser_client.h" |
| 34 #include "content/public/browser/utility_process_host_client.h" | 36 #include "content/public/browser/utility_process_host_client.h" |
| 37 #include "content/public/common/connection_filter.h" |
| 35 #include "content/public/common/content_switches.h" | 38 #include "content/public/common/content_switches.h" |
| 36 #include "content/public/common/mojo_channel_switches.h" | 39 #include "content/public/common/mojo_channel_switches.h" |
| 37 #include "content/public/common/process_type.h" | 40 #include "content/public/common/process_type.h" |
| 38 #include "content/public/common/sandbox_type.h" | 41 #include "content/public/common/sandbox_type.h" |
| 39 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 42 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| 40 #include "content/public/common/service_manager_connection.h" | 43 #include "content/public/common/service_manager_connection.h" |
| 41 #include "content/public/common/service_names.mojom.h" | 44 #include "content/public/common/service_names.mojom.h" |
| 42 #include "mojo/edk/embedder/embedder.h" | 45 #include "mojo/edk/embedder/embedder.h" |
| 43 #include "services/service_manager/public/cpp/connection.h" | 46 #include "services/service_manager/public/cpp/connection.h" |
| 44 #include "services/service_manager/public/cpp/interface_provider.h" | 47 #include "services/service_manager/public/cpp/interface_provider.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 #elif defined(OS_POSIX) | 131 #elif defined(OS_POSIX) |
| 129 base::EnvironmentMap env_; | 132 base::EnvironmentMap env_; |
| 130 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 133 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 131 bool no_sandbox_; | 134 bool no_sandbox_; |
| 132 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID) | 135 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 133 #endif // OS_WIN | 136 #endif // OS_WIN |
| 134 }; | 137 }; |
| 135 | 138 |
| 136 UtilityMainThreadFactoryFunction g_utility_main_thread_factory = NULL; | 139 UtilityMainThreadFactoryFunction g_utility_main_thread_factory = NULL; |
| 137 | 140 |
| 141 class UtilityProcessHost::ConnectionFilterImpl : public ConnectionFilter { |
| 142 public: |
| 143 ConnectionFilterImpl() {} |
| 144 |
| 145 private: |
| 146 // ConnectionFilter: |
| 147 bool OnConnect(const service_manager::Identity& remote_identity, |
| 148 service_manager::InterfaceRegistry* registry, |
| 149 service_manager::Connector* connector) override { |
| 150 if (BrowserMainLoop::GetInstance()) { |
| 151 discardable_memory::DiscardableSharedMemoryManager* manager = |
| 152 BrowserMainLoop::GetInstance()->discardable_shared_memory_manager(); |
| 153 registry->AddInterface( |
| 154 base::Bind(&discardable_memory::DiscardableSharedMemoryManager::Bind, |
| 155 base::Unretained(manager))); |
| 156 } |
| 157 return true; |
| 158 } |
| 159 |
| 160 DISALLOW_COPY_AND_ASSIGN(ConnectionFilterImpl); |
| 161 }; |
| 162 |
| 138 UtilityProcessHost* UtilityProcessHost::Create( | 163 UtilityProcessHost* UtilityProcessHost::Create( |
| 139 const scoped_refptr<UtilityProcessHostClient>& client, | 164 const scoped_refptr<UtilityProcessHostClient>& client, |
| 140 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner) { | 165 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner) { |
| 141 return new UtilityProcessHostImpl(client, client_task_runner); | 166 return new UtilityProcessHostImpl(client, client_task_runner); |
| 142 } | 167 } |
| 143 | 168 |
| 144 void UtilityProcessHostImpl::RegisterUtilityMainThreadFactory( | 169 void UtilityProcessHostImpl::RegisterUtilityMainThreadFactory( |
| 145 UtilityMainThreadFactoryFunction create) { | 170 UtilityMainThreadFactoryFunction create) { |
| 146 g_utility_main_thread_factory = create; | 171 g_utility_main_thread_factory = create; |
| 147 } | 172 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 | 250 |
| 226 bool UtilityProcessHostImpl::Start() { | 251 bool UtilityProcessHostImpl::Start() { |
| 227 return StartProcess(); | 252 return StartProcess(); |
| 228 } | 253 } |
| 229 | 254 |
| 230 service_manager::InterfaceProvider* | 255 service_manager::InterfaceProvider* |
| 231 UtilityProcessHostImpl::GetRemoteInterfaces() { | 256 UtilityProcessHostImpl::GetRemoteInterfaces() { |
| 232 return process_->child_connection()->GetRemoteInterfaces(); | 257 return process_->child_connection()->GetRemoteInterfaces(); |
| 233 } | 258 } |
| 234 | 259 |
| 260 void UtilityProcessHostImpl::RegisterMojoServices() { |
| 261 // May be null during test execution. |
| 262 if (ServiceManagerConnection::GetForProcess()) { |
| 263 ServiceManagerConnection::GetForProcess()->AddConnectionFilter( |
| 264 base::MakeUnique<ConnectionFilterImpl>()); |
| 265 } |
| 266 } |
| 267 |
| 235 void UtilityProcessHostImpl::SetName(const base::string16& name) { | 268 void UtilityProcessHostImpl::SetName(const base::string16& name) { |
| 236 name_ = name; | 269 name_ = name; |
| 237 } | 270 } |
| 238 | 271 |
| 239 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) | 272 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) |
| 240 // static | 273 // static |
| 241 void UtilityProcessHostImpl::EarlyZygoteLaunch() { | 274 void UtilityProcessHostImpl::EarlyZygoteLaunch() { |
| 242 DCHECK(!g_utility_zygote); | 275 DCHECK(!g_utility_zygote); |
| 243 g_utility_zygote = CreateZygote(); | 276 g_utility_zygote = CreateZygote(); |
| 244 } | 277 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 base::WeakPtr<UtilityProcessHostImpl> host, | 428 base::WeakPtr<UtilityProcessHostImpl> host, |
| 396 int error_code) { | 429 int error_code) { |
| 397 if (!host) | 430 if (!host) |
| 398 return; | 431 return; |
| 399 | 432 |
| 400 host->OnProcessLaunchFailed(error_code); | 433 host->OnProcessLaunchFailed(error_code); |
| 401 delete host.get(); | 434 delete host.get(); |
| 402 } | 435 } |
| 403 | 436 |
| 404 } // namespace content | 437 } // namespace content |
| OLD | NEW |