| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/service_manager/service_manager_context.h" | 5 #include "content/browser/service_manager/service_manager_context.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "services/service_manager/public/cpp/service.h" | 36 #include "services/service_manager/public/cpp/service.h" |
| 37 #include "services/service_manager/public/interfaces/service.mojom.h" | 37 #include "services/service_manager/public/interfaces/service.mojom.h" |
| 38 #include "services/service_manager/runner/common/client_util.h" | 38 #include "services/service_manager/runner/common/client_util.h" |
| 39 #include "services/service_manager/runner/host/in_process_native_runner.h" | 39 #include "services/service_manager/runner/host/in_process_native_runner.h" |
| 40 #include "services/service_manager/service_manager.h" | 40 #include "services/service_manager/service_manager.h" |
| 41 | 41 |
| 42 namespace content { | 42 namespace content { |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 base::LazyInstance<std::unique_ptr<shell::Connector>>::Leaky | 46 base::LazyInstance<std::unique_ptr<service_manager::Connector>>::Leaky |
| 47 g_io_thread_connector = LAZY_INSTANCE_INITIALIZER; | 47 g_io_thread_connector = LAZY_INSTANCE_INITIALIZER; |
| 48 | 48 |
| 49 void DestroyConnectorOnIOThread() { g_io_thread_connector.Get().reset(); } | 49 void DestroyConnectorOnIOThread() { g_io_thread_connector.Get().reset(); } |
| 50 | 50 |
| 51 void StartUtilityProcessOnIOThread(shell::mojom::ServiceFactoryRequest request, | 51 void StartUtilityProcessOnIOThread( |
| 52 const base::string16& process_name, | 52 service_manager::mojom::ServiceFactoryRequest request, |
| 53 bool use_sandbox) { | 53 const base::string16& process_name, |
| 54 bool use_sandbox) { |
| 54 UtilityProcessHost* process_host = | 55 UtilityProcessHost* process_host = |
| 55 UtilityProcessHost::Create(nullptr, nullptr); | 56 UtilityProcessHost::Create(nullptr, nullptr); |
| 56 process_host->SetName(process_name); | 57 process_host->SetName(process_name); |
| 57 if (!use_sandbox) | 58 if (!use_sandbox) |
| 58 process_host->DisableSandbox(); | 59 process_host->DisableSandbox(); |
| 59 process_host->Start(); | 60 process_host->Start(); |
| 60 process_host->GetRemoteInterfaces()->GetInterface(std::move(request)); | 61 process_host->GetRemoteInterfaces()->GetInterface(std::move(request)); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void StartServiceInUtilityProcess(const std::string& service_name, | 64 void StartServiceInUtilityProcess( |
| 64 const base::string16& process_name, | 65 const std::string& service_name, |
| 65 bool use_sandbox, | 66 const base::string16& process_name, |
| 66 shell::mojom::ServiceRequest request) { | 67 bool use_sandbox, |
| 67 shell::mojom::ServiceFactoryPtr service_factory; | 68 service_manager::mojom::ServiceRequest request) { |
| 69 service_manager::mojom::ServiceFactoryPtr service_factory; |
| 68 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 70 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 69 base::Bind(&StartUtilityProcessOnIOThread, | 71 base::Bind(&StartUtilityProcessOnIOThread, |
| 70 base::Passed(GetProxy(&service_factory)), | 72 base::Passed(GetProxy(&service_factory)), |
| 71 process_name, use_sandbox)); | 73 process_name, use_sandbox)); |
| 72 service_factory->CreateService(std::move(request), service_name); | 74 service_factory->CreateService(std::move(request), service_name); |
| 73 } | 75 } |
| 74 | 76 |
| 75 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 77 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 76 | 78 |
| 77 // Request shell::mojom::ServiceFactory from GPU process host. Must be called on | 79 // Request service_manager::mojom::ServiceFactory from GPU process host. Must be |
| 80 // called on |
| 78 // IO thread. | 81 // IO thread. |
| 79 void RequestGpuServiceFactory(shell::mojom::ServiceFactoryRequest request) { | 82 void RequestGpuServiceFactory( |
| 83 service_manager::mojom::ServiceFactoryRequest request) { |
| 80 GpuProcessHost* process_host = | 84 GpuProcessHost* process_host = |
| 81 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED); | 85 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED); |
| 82 if (!process_host) { | 86 if (!process_host) { |
| 83 DLOG(ERROR) << "GPU process host not available."; | 87 DLOG(ERROR) << "GPU process host not available."; |
| 84 return; | 88 return; |
| 85 } | 89 } |
| 86 | 90 |
| 87 // TODO(xhwang): It's possible that |process_host| is non-null, but the actual | 91 // TODO(xhwang): It's possible that |process_host| is non-null, but the actual |
| 88 // process is dead. In that case, |request| will be dropped and application | 92 // process is dead. In that case, |request| will be dropped and application |
| 89 // load requests through ServiceFactory will also fail. Make sure we handle | 93 // load requests through ServiceFactory will also fail. Make sure we handle |
| 90 // these cases correctly. | 94 // these cases correctly. |
| 91 process_host->GetRemoteInterfaces()->GetInterface(std::move(request)); | 95 process_host->GetRemoteInterfaces()->GetInterface(std::move(request)); |
| 92 } | 96 } |
| 93 | 97 |
| 94 void StartServiceInGpuProcess(const std::string& service_name, | 98 void StartServiceInGpuProcess(const std::string& service_name, |
| 95 shell::mojom::ServiceRequest request) { | 99 service_manager::mojom::ServiceRequest request) { |
| 96 shell::mojom::ServiceFactoryPtr service_factory; | 100 service_manager::mojom::ServiceFactoryPtr service_factory; |
| 97 BrowserThread::PostTask( | 101 BrowserThread::PostTask( |
| 98 BrowserThread::IO, FROM_HERE, | 102 BrowserThread::IO, FROM_HERE, |
| 99 base::Bind(&RequestGpuServiceFactory, | 103 base::Bind(&RequestGpuServiceFactory, |
| 100 base::Passed(GetProxy(&service_factory)))); | 104 base::Passed(GetProxy(&service_factory)))); |
| 101 service_factory->CreateService(std::move(request), service_name); | 105 service_factory->CreateService(std::move(request), service_name); |
| 102 } | 106 } |
| 103 | 107 |
| 104 #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS | 108 #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS |
| 105 | 109 |
| 106 // A ManifestProvider which resolves application names to builtin manifest | 110 // A ManifestProvider which resolves application names to builtin manifest |
| (...skipping 23 matching lines...) Expand all Loading... |
| 130 }; | 134 }; |
| 131 | 135 |
| 132 } // namespace | 136 } // namespace |
| 133 | 137 |
| 134 // State which lives on the IO thread and drives the ServiceManager. | 138 // State which lives on the IO thread and drives the ServiceManager. |
| 135 class ServiceManagerContext::InProcessServiceManagerContext | 139 class ServiceManagerContext::InProcessServiceManagerContext |
| 136 : public base::RefCountedThreadSafe<InProcessServiceManagerContext> { | 140 : public base::RefCountedThreadSafe<InProcessServiceManagerContext> { |
| 137 public: | 141 public: |
| 138 InProcessServiceManagerContext() {} | 142 InProcessServiceManagerContext() {} |
| 139 | 143 |
| 140 shell::mojom::ServiceRequest Start( | 144 service_manager::mojom::ServiceRequest Start( |
| 141 std::unique_ptr<BuiltinManifestProvider> manifest_provider) { | 145 std::unique_ptr<BuiltinManifestProvider> manifest_provider) { |
| 142 shell::mojom::ServicePtr embedder_service_proxy; | 146 service_manager::mojom::ServicePtr embedder_service_proxy; |
| 143 shell::mojom::ServiceRequest embedder_service_request = | 147 service_manager::mojom::ServiceRequest embedder_service_request = |
| 144 mojo::GetProxy(&embedder_service_proxy); | 148 mojo::GetProxy(&embedder_service_proxy); |
| 145 shell::mojom::ServicePtrInfo embedder_service_proxy_info = | 149 service_manager::mojom::ServicePtrInfo embedder_service_proxy_info = |
| 146 embedder_service_proxy.PassInterface(); | 150 embedder_service_proxy.PassInterface(); |
| 147 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)->PostTask( | 151 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)->PostTask( |
| 148 FROM_HERE, | 152 FROM_HERE, |
| 149 base::Bind(&InProcessServiceManagerContext::StartOnIOThread, this, | 153 base::Bind(&InProcessServiceManagerContext::StartOnIOThread, this, |
| 150 base::Passed(&manifest_provider), | 154 base::Passed(&manifest_provider), |
| 151 base::Passed(&embedder_service_proxy_info))); | 155 base::Passed(&embedder_service_proxy_info))); |
| 152 return embedder_service_request; | 156 return embedder_service_request; |
| 153 } | 157 } |
| 154 | 158 |
| 155 void ShutDown() { | 159 void ShutDown() { |
| 156 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)->PostTask( | 160 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)->PostTask( |
| 157 FROM_HERE, | 161 FROM_HERE, |
| 158 base::Bind(&InProcessServiceManagerContext::ShutDownOnIOThread, this)); | 162 base::Bind(&InProcessServiceManagerContext::ShutDownOnIOThread, this)); |
| 159 } | 163 } |
| 160 | 164 |
| 161 private: | 165 private: |
| 162 friend class base::RefCountedThreadSafe<InProcessServiceManagerContext>; | 166 friend class base::RefCountedThreadSafe<InProcessServiceManagerContext>; |
| 163 | 167 |
| 164 ~InProcessServiceManagerContext() {} | 168 ~InProcessServiceManagerContext() {} |
| 165 | 169 |
| 166 void StartOnIOThread( | 170 void StartOnIOThread( |
| 167 std::unique_ptr<BuiltinManifestProvider> manifest_provider, | 171 std::unique_ptr<BuiltinManifestProvider> manifest_provider, |
| 168 shell::mojom::ServicePtrInfo embedder_service_proxy_info) { | 172 service_manager::mojom::ServicePtrInfo embedder_service_proxy_info) { |
| 169 manifest_provider_ = std::move(manifest_provider); | 173 manifest_provider_ = std::move(manifest_provider); |
| 170 | 174 |
| 171 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); | 175 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); |
| 172 std::unique_ptr<shell::NativeRunnerFactory> native_runner_factory( | 176 std::unique_ptr<service_manager::NativeRunnerFactory> native_runner_factory( |
| 173 new shell::InProcessNativeRunnerFactory(blocking_pool)); | 177 new service_manager::InProcessNativeRunnerFactory(blocking_pool)); |
| 174 catalog_.reset( | 178 catalog_.reset( |
| 175 new catalog::Catalog(blocking_pool, nullptr, manifest_provider_.get())); | 179 new catalog::Catalog(blocking_pool, nullptr, manifest_provider_.get())); |
| 176 service_manager_.reset(new shell::ServiceManager( | 180 service_manager_.reset(new service_manager::ServiceManager( |
| 177 std::move(native_runner_factory), catalog_->TakeService())); | 181 std::move(native_runner_factory), catalog_->TakeService())); |
| 178 | 182 |
| 179 shell::mojom::ServiceRequest request = | 183 service_manager::mojom::ServiceRequest request = |
| 180 service_manager_->StartEmbedderService(kBrowserServiceName); | 184 service_manager_->StartEmbedderService(kBrowserServiceName); |
| 181 mojo::FuseInterface( | 185 mojo::FuseInterface( |
| 182 std::move(request), std::move(embedder_service_proxy_info)); | 186 std::move(request), std::move(embedder_service_proxy_info)); |
| 183 } | 187 } |
| 184 | 188 |
| 185 void ShutDownOnIOThread() { | 189 void ShutDownOnIOThread() { |
| 186 service_manager_.reset(); | 190 service_manager_.reset(); |
| 187 catalog_.reset(); | 191 catalog_.reset(); |
| 188 manifest_provider_.reset(); | 192 manifest_provider_.reset(); |
| 189 } | 193 } |
| 190 | 194 |
| 191 std::unique_ptr<BuiltinManifestProvider> manifest_provider_; | 195 std::unique_ptr<BuiltinManifestProvider> manifest_provider_; |
| 192 std::unique_ptr<catalog::Catalog> catalog_; | 196 std::unique_ptr<catalog::Catalog> catalog_; |
| 193 std::unique_ptr<shell::ServiceManager> service_manager_; | 197 std::unique_ptr<service_manager::ServiceManager> service_manager_; |
| 194 | 198 |
| 195 DISALLOW_COPY_AND_ASSIGN(InProcessServiceManagerContext); | 199 DISALLOW_COPY_AND_ASSIGN(InProcessServiceManagerContext); |
| 196 }; | 200 }; |
| 197 | 201 |
| 198 ServiceManagerContext::ServiceManagerContext() { | 202 ServiceManagerContext::ServiceManagerContext() { |
| 199 shell::mojom::ServiceRequest request; | 203 service_manager::mojom::ServiceRequest request; |
| 200 if (shell::ShellIsRemote()) { | 204 if (service_manager::ServiceManagerIsRemote()) { |
| 201 mojo::edk::SetParentPipeHandleFromCommandLine(); | 205 mojo::edk::SetParentPipeHandleFromCommandLine(); |
| 202 request = shell::GetServiceRequestFromCommandLine(); | 206 request = service_manager::GetServiceRequestFromCommandLine(); |
| 203 } else { | 207 } else { |
| 204 std::unique_ptr<BuiltinManifestProvider> manifest_provider = | 208 std::unique_ptr<BuiltinManifestProvider> manifest_provider = |
| 205 base::MakeUnique<BuiltinManifestProvider>(); | 209 base::MakeUnique<BuiltinManifestProvider>(); |
| 206 | 210 |
| 207 static const struct ManifestInfo { | 211 static const struct ManifestInfo { |
| 208 const char* name; | 212 const char* name; |
| 209 int resource_id; | 213 int resource_id; |
| 210 } kManifests[] = { | 214 } kManifests[] = { |
| 211 { kBrowserServiceName, IDR_MOJO_CONTENT_BROWSER_MANIFEST }, | 215 { kBrowserServiceName, IDR_MOJO_CONTENT_BROWSER_MANIFEST }, |
| 212 { kGpuServiceName, IDR_MOJO_CONTENT_GPU_MANIFEST }, | 216 { kGpuServiceName, IDR_MOJO_CONTENT_GPU_MANIFEST }, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 // which it may attempt to service by launching a new instance of the browser. | 298 // which it may attempt to service by launching a new instance of the browser. |
| 295 if (in_process_context_) | 299 if (in_process_context_) |
| 296 in_process_context_->ShutDown(); | 300 in_process_context_->ShutDown(); |
| 297 if (ServiceManagerConnection::GetForProcess()) | 301 if (ServiceManagerConnection::GetForProcess()) |
| 298 ServiceManagerConnection::DestroyForProcess(); | 302 ServiceManagerConnection::DestroyForProcess(); |
| 299 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 303 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 300 base::Bind(&DestroyConnectorOnIOThread)); | 304 base::Bind(&DestroyConnectorOnIOThread)); |
| 301 } | 305 } |
| 302 | 306 |
| 303 // static | 307 // static |
| 304 shell::Connector* ServiceManagerContext::GetConnectorForIOThread() { | 308 service_manager::Connector* ServiceManagerContext::GetConnectorForIOThread() { |
| 305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 306 return g_io_thread_connector.Get().get(); | 310 return g_io_thread_connector.Get().get(); |
| 307 } | 311 } |
| 308 | 312 |
| 309 } // namespace content | 313 } // namespace content |
| OLD | NEW |