Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: content/browser/utility_process_host_impl.cc

Issue 2832633002: Add PDF compositor service (Closed)
Patch Set: rebase more Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/base_switches.h" 10 #include "base/base_switches.h"
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
14 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
17 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
18 #include "base/process/process_handle.h" 19 #include "base/process/process_handle.h"
19 #include "base/run_loop.h" 20 #include "base/run_loop.h"
20 #include "base/sequenced_task_runner.h" 21 #include "base/sequenced_task_runner.h"
21 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
22 #include "base/synchronization/lock.h" 23 #include "base/synchronization/lock.h"
23 #include "base/synchronization/waitable_event.h" 24 #include "base/synchronization/waitable_event.h"
24 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "components/discardable_memory/service/discardable_shared_memory_manage r.h"
25 #include "content/browser/browser_child_process_host_impl.h" 27 #include "content/browser/browser_child_process_host_impl.h"
28 #include "content/browser/browser_main_loop.h"
26 #include "content/browser/renderer_host/render_process_host_impl.h" 29 #include "content/browser/renderer_host/render_process_host_impl.h"
27 #include "content/browser/service_manager/service_manager_context.h" 30 #include "content/browser/service_manager/service_manager_context.h"
28 #include "content/common/child_process_host_impl.h" 31 #include "content/common/child_process_host_impl.h"
29 #include "content/common/in_process_child_thread_params.h" 32 #include "content/common/in_process_child_thread_params.h"
30 #include "content/common/service_manager/child_connection.h" 33 #include "content/common/service_manager/child_connection.h"
31 #include "content/common/utility_messages.h" 34 #include "content/common/utility_messages.h"
32 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
33 #include "content/public/browser/content_browser_client.h" 36 #include "content/public/browser/content_browser_client.h"
34 #include "content/public/browser/utility_process_host_client.h" 37 #include "content/public/browser/utility_process_host_client.h"
38 #include "content/public/common/connection_filter.h"
35 #include "content/public/common/content_switches.h" 39 #include "content/public/common/content_switches.h"
36 #include "content/public/common/mojo_channel_switches.h" 40 #include "content/public/common/mojo_channel_switches.h"
37 #include "content/public/common/process_type.h" 41 #include "content/public/common/process_type.h"
38 #include "content/public/common/sandbox_type.h" 42 #include "content/public/common/sandbox_type.h"
39 #include "content/public/common/sandboxed_process_launcher_delegate.h" 43 #include "content/public/common/sandboxed_process_launcher_delegate.h"
40 #include "content/public/common/service_manager_connection.h" 44 #include "content/public/common/service_manager_connection.h"
41 #include "content/public/common/service_names.mojom.h" 45 #include "content/public/common/service_names.mojom.h"
42 #include "mojo/edk/embedder/embedder.h" 46 #include "mojo/edk/embedder/embedder.h"
47 #include "services/service_manager/public/cpp/bind_source_info.h"
48 #include "services/service_manager/public/cpp/binder_registry.h"
43 #include "services/service_manager/public/cpp/interface_provider.h" 49 #include "services/service_manager/public/cpp/interface_provider.h"
44 #include "ui/base/ui_base_switches.h" 50 #include "ui/base/ui_base_switches.h"
45 51
46 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) 52 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
47 #include "content/public/browser/zygote_handle_linux.h" 53 #include "content/public/browser/zygote_handle_linux.h"
48 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) 54 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
49 55
50 #if defined(OS_WIN) 56 #if defined(OS_WIN)
51 #include "sandbox/win/src/sandbox_policy.h" 57 #include "sandbox/win/src/sandbox_policy.h"
52 #include "sandbox/win/src/sandbox_types.h" 58 #include "sandbox/win/src/sandbox_types.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 #elif defined(OS_POSIX) 127 #elif defined(OS_POSIX)
122 base::EnvironmentMap env_; 128 base::EnvironmentMap env_;
123 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) 129 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
124 bool no_sandbox_; 130 bool no_sandbox_;
125 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID) 131 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID)
126 #endif // OS_WIN 132 #endif // OS_WIN
127 }; 133 };
128 134
129 UtilityMainThreadFactoryFunction g_utility_main_thread_factory = NULL; 135 UtilityMainThreadFactoryFunction g_utility_main_thread_factory = NULL;
130 136
137 class UtilityProcessHostImpl::ConnectionFilterImpl : public ConnectionFilter {
138 public:
139 explicit ConnectionFilterImpl(
140 std::unique_ptr<service_manager::BinderRegistry> registry)
141 : registry_(std::move(registry)) {}
142
143 private:
144 // ConnectionFilter:
145 void OnBindInterface(const service_manager::BindSourceInfo& source_info,
146 const std::string& interface_name,
147 mojo::ScopedMessagePipeHandle* interface_pipe,
148 service_manager::Connector* connector) override {
149 if (registry_->CanBindInterface(interface_name)) {
150 registry_->BindInterface(source_info, interface_name,
151 std::move(*interface_pipe));
152 }
153 }
154
155 std::unique_ptr<service_manager::BinderRegistry> registry_;
156
157 DISALLOW_COPY_AND_ASSIGN(ConnectionFilterImpl);
158 };
159
131 UtilityProcessHost* UtilityProcessHost::Create( 160 UtilityProcessHost* UtilityProcessHost::Create(
132 const scoped_refptr<UtilityProcessHostClient>& client, 161 const scoped_refptr<UtilityProcessHostClient>& client,
133 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner) { 162 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner) {
134 return new UtilityProcessHostImpl(client, client_task_runner); 163 return new UtilityProcessHostImpl(client, client_task_runner);
135 } 164 }
136 165
137 void UtilityProcessHostImpl::RegisterUtilityMainThreadFactory( 166 void UtilityProcessHostImpl::RegisterUtilityMainThreadFactory(
138 UtilityMainThreadFactoryFunction create) { 167 UtilityMainThreadFactoryFunction create) {
139 g_utility_main_thread_factory = create; 168 g_utility_main_thread_factory = create;
140 } 169 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 return StartProcess(); 249 return StartProcess();
221 } 250 }
222 251
223 void UtilityProcessHostImpl::BindInterface( 252 void UtilityProcessHostImpl::BindInterface(
224 const std::string& interface_name, 253 const std::string& interface_name,
225 mojo::ScopedMessagePipeHandle interface_pipe) { 254 mojo::ScopedMessagePipeHandle interface_pipe) {
226 process_->child_connection()->BindInterface(interface_name, 255 process_->child_connection()->BindInterface(interface_name,
227 std::move(interface_pipe)); 256 std::move(interface_pipe));
228 } 257 }
229 258
259 void UtilityProcessHostImpl::RegisterMojoServices() {
260 auto registry = base::MakeUnique<service_manager::BinderRegistry>();
261 // May be null during test execution.
262 if (ServiceManagerConnection::GetForProcess()) {
263 registry->AddInterface(base::Bind(
264 &memory_instrumentation::CoordinatorImpl::BindCoordinatorRequest,
265 base::Unretained(
266 memory_instrumentation::CoordinatorImpl::GetInstance())));
dcheng 2017/05/10 07:36:48 Not entirely clear to me why memory_instrumentatio
Wei Li 2017/05/11 16:53:02 It is needed for some memory dump functions. Anywa
267
268 discardable_memory::DiscardableSharedMemoryManager* manager =
269 BrowserMainLoop::GetInstance()->discardable_shared_memory_manager();
270 registry->AddInterface(
271 base::Bind(&discardable_memory::DiscardableSharedMemoryManager::Bind,
272 base::Unretained(manager)));
273
274 ServiceManagerConnection::GetForProcess()->AddConnectionFilter(
275 base::MakeUnique<ConnectionFilterImpl>(std::move(registry)));
276 }
277 }
278
230 void UtilityProcessHostImpl::SetName(const base::string16& name) { 279 void UtilityProcessHostImpl::SetName(const base::string16& name) {
231 name_ = name; 280 name_ = name;
232 } 281 }
233 282
234 bool UtilityProcessHostImpl::StartProcess() { 283 bool UtilityProcessHostImpl::StartProcess() {
235 if (started_) 284 if (started_)
236 return true; 285 return true;
237 started_ = true; 286 started_ = true;
238 287
239 if (is_batch_mode_) 288 if (is_batch_mode_)
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 base::WeakPtr<UtilityProcessHostImpl> host, 438 base::WeakPtr<UtilityProcessHostImpl> host,
390 int error_code) { 439 int error_code) {
391 if (!host) 440 if (!host)
392 return; 441 return;
393 442
394 host->OnProcessLaunchFailed(error_code); 443 host->OnProcessLaunchFailed(error_code);
395 delete host.get(); 444 delete host.get();
396 } 445 }
397 446
398 } // namespace content 447 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698