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 "chrome/browser/service_process/service_process_control.h" | 5 #include "chrome/browser/service_process/service_process_control.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
22 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
25 #include "chrome/browser/chrome_notification_types.h" | 25 #include "chrome/browser/chrome_notification_types.h" |
26 #include "chrome/browser/upgrade_detector.h" | 26 #include "chrome/browser/upgrade_detector.h" |
27 #include "chrome/common/service_messages.h" | 27 #include "chrome/common/service_messages.h" |
28 #include "chrome/common/service_process_util.h" | 28 #include "chrome/common/service_process_util.h" |
29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
30 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 31 #include "ipc/ipc_channel_mojo.h" |
| 32 #include "mojo/edk/embedder/embedder.h" |
| 33 #include "mojo/edk/embedder/named_platform_handle.h" |
| 34 #include "mojo/edk/embedder/named_platform_handle_utils.h" |
31 | 35 |
32 using content::BrowserThread; | 36 using content::BrowserThread; |
33 | 37 |
| 38 namespace { |
| 39 |
| 40 void ConnectOnBlockingPool(mojo::ScopedMessagePipeHandle handle, |
| 41 mojo::edk::NamedPlatformHandle os_pipe) { |
| 42 mojo::edk::ScopedPlatformHandle os_pipe_handle = |
| 43 mojo::edk::CreateClientHandle(os_pipe); |
| 44 if (!os_pipe_handle.is_valid()) |
| 45 return; |
| 46 |
| 47 mojo::FuseMessagePipes( |
| 48 mojo::edk::ConnectToPeerProcess(std::move(os_pipe_handle)), |
| 49 std::move(handle)); |
| 50 } |
| 51 |
| 52 } // namespace |
| 53 |
34 // ServiceProcessControl implementation. | 54 // ServiceProcessControl implementation. |
35 ServiceProcessControl::ServiceProcessControl() { | 55 ServiceProcessControl::ServiceProcessControl() { |
36 } | 56 } |
37 | 57 |
38 ServiceProcessControl::~ServiceProcessControl() { | 58 ServiceProcessControl::~ServiceProcessControl() { |
39 } | 59 } |
40 | 60 |
41 void ServiceProcessControl::ConnectInternal() { | 61 void ServiceProcessControl::ConnectInternal() { |
42 // If the channel has already been established then we run the task | 62 // If the channel has already been established then we run the task |
43 // and return. | 63 // and return. |
44 if (channel_.get()) { | 64 if (channel_.get()) { |
45 RunConnectDoneTasks(); | 65 RunConnectDoneTasks(); |
46 return; | 66 return; |
47 } | 67 } |
48 | 68 |
49 // Actually going to connect. | 69 // Actually going to connect. |
50 DVLOG(1) << "Connecting to Service Process IPC Server"; | 70 DVLOG(1) << "Connecting to Service Process IPC Server"; |
51 | 71 |
| 72 mojo::MessagePipe pipe; |
| 73 BrowserThread::PostBlockingPoolTask( |
| 74 FROM_HERE, base::Bind(&ConnectOnBlockingPool, base::Passed(&pipe.handle1), |
| 75 mojo::edk::NamedPlatformHandle( |
| 76 GetServiceProcessChannel().name))); |
52 // TODO(hclam): Handle error connecting to channel. | 77 // TODO(hclam): Handle error connecting to channel. |
53 const IPC::ChannelHandle channel_id = GetServiceProcessChannel(); | 78 auto io_task_runner = |
54 SetChannel(IPC::ChannelProxy::Create( | 79 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); |
55 channel_id, IPC::Channel::MODE_NAMED_CLIENT, this, | 80 SetChannel( |
56 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get())); | 81 IPC::ChannelProxy::Create(IPC::ChannelMojo::CreateClientFactory( |
| 82 std::move(pipe.handle0), io_task_runner), |
| 83 this, io_task_runner)); |
57 } | 84 } |
58 | 85 |
59 void ServiceProcessControl::SetChannel( | 86 void ServiceProcessControl::SetChannel( |
60 std::unique_ptr<IPC::ChannelProxy> channel) { | 87 std::unique_ptr<IPC::ChannelProxy> channel) { |
61 channel_ = std::move(channel); | 88 channel_ = std::move(channel); |
62 } | 89 } |
63 | 90 |
64 void ServiceProcessControl::RunConnectDoneTasks() { | 91 void ServiceProcessControl::RunConnectDoneTasks() { |
65 // The tasks executed here may add more tasks to the vector. So copy | 92 // The tasks executed here may add more tasks to the vector. So copy |
66 // them to the stack before executing them. This way recursion is | 93 // them to the stack before executing them. This way recursion is |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 if (process_.IsValid()) { | 408 if (process_.IsValid()) { |
382 BrowserThread::PostTask( | 409 BrowserThread::PostTask( |
383 BrowserThread::IO, FROM_HERE, | 410 BrowserThread::IO, FROM_HERE, |
384 base::Bind(&Launcher::DoDetectLaunched, this)); | 411 base::Bind(&Launcher::DoDetectLaunched, this)); |
385 } else { | 412 } else { |
386 BrowserThread::PostTask( | 413 BrowserThread::PostTask( |
387 BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this)); | 414 BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this)); |
388 } | 415 } |
389 } | 416 } |
390 #endif // !OS_MACOSX | 417 #endif // !OS_MACOSX |
OLD | NEW |