OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/mojo/mojo_application_host.h" | 5 #include "content/browser/mojo/mojo_application_host.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "content/common/mojo/mojo_messages.h" | 10 #include "content/common/mojo/mojo_messages.h" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 #include "ipc/ipc_sender.h" | 12 #include "ipc/ipc_sender.h" |
13 #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h" | 13 #include "mojo/edk/embedder/platform_channel_pair.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 namespace { | 16 namespace { |
17 | 17 |
18 base::PlatformFile PlatformFileFromScopedPlatformHandle( | |
19 mojo::embedder::ScopedPlatformHandle handle) { | |
20 #if defined(OS_POSIX) | |
21 return handle.release().fd; | |
22 #elif defined(OS_WIN) | |
23 return handle.release().handle; | |
24 #endif | |
25 } | |
26 | |
27 class ApplicationSetupImpl : public ApplicationSetup { | 18 class ApplicationSetupImpl : public ApplicationSetup { |
28 public: | 19 public: |
29 ApplicationSetupImpl(ServiceRegistryImpl* service_registry, | 20 ApplicationSetupImpl(ServiceRegistryImpl* service_registry, |
30 mojo::InterfaceRequest<ApplicationSetup> request) | 21 mojo::InterfaceRequest<ApplicationSetup> request) |
31 : binding_(this, std::move(request)), | 22 : binding_(this, std::move(request)), |
32 service_registry_(service_registry) {} | 23 service_registry_(service_registry) {} |
33 | 24 |
34 ~ApplicationSetupImpl() override { | 25 ~ApplicationSetupImpl() override { |
35 } | 26 } |
36 | 27 |
(...skipping 19 matching lines...) Expand all Loading... |
56 new ServiceRegistryAndroid(&service_registry_)); | 47 new ServiceRegistryAndroid(&service_registry_)); |
57 #endif | 48 #endif |
58 } | 49 } |
59 | 50 |
60 MojoApplicationHost::~MojoApplicationHost() { | 51 MojoApplicationHost::~MojoApplicationHost() { |
61 } | 52 } |
62 | 53 |
63 bool MojoApplicationHost::Init() { | 54 bool MojoApplicationHost::Init() { |
64 DCHECK(!client_handle_.is_valid()) << "Already initialized!"; | 55 DCHECK(!client_handle_.is_valid()) << "Already initialized!"; |
65 | 56 |
66 mojo::embedder::PlatformChannelPair channel_pair; | 57 mojo::edk::PlatformChannelPair channel_pair; |
67 | 58 |
68 scoped_refptr<base::TaskRunner> io_task_runner; | 59 scoped_refptr<base::TaskRunner> io_task_runner; |
69 if (io_task_runner_override_) { | 60 if (io_task_runner_override_) { |
70 io_task_runner = io_task_runner_override_; | 61 io_task_runner = io_task_runner_override_; |
71 } else { | 62 } else { |
72 io_task_runner = | 63 io_task_runner = |
73 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) | 64 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) |
74 ->task_runner(); | 65 ->task_runner(); |
75 } | 66 } |
76 | 67 |
77 mojo::ScopedMessagePipeHandle message_pipe = channel_init_.Init( | 68 mojo::ScopedMessagePipeHandle message_pipe = channel_init_.Init( |
78 PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()), | 69 channel_pair.PassServerHandle().release().handle, |
79 io_task_runner); | 70 io_task_runner); |
80 if (!message_pipe.is_valid()) | 71 if (!message_pipe.is_valid()) |
81 return false; | 72 return false; |
82 | 73 |
83 // Forward this to the client once we know its process handle. | 74 // Forward this to the client once we know its process handle. |
84 client_handle_ = channel_pair.PassClientHandle(); | 75 client_handle_ = channel_pair.PassClientHandle(); |
85 | 76 |
86 application_setup_.reset(new ApplicationSetupImpl( | 77 application_setup_.reset(new ApplicationSetupImpl( |
87 &service_registry_, | 78 &service_registry_, |
88 mojo::MakeRequest<ApplicationSetup>(std::move(message_pipe)))); | 79 mojo::MakeRequest<ApplicationSetup>(std::move(message_pipe)))); |
89 return true; | 80 return true; |
90 } | 81 } |
91 | 82 |
92 void MojoApplicationHost::Activate(IPC::Sender* sender, | 83 void MojoApplicationHost::Activate(IPC::Sender* sender, |
93 base::ProcessHandle process_handle) { | 84 base::ProcessHandle process_handle) { |
94 DCHECK(!did_activate_); | 85 DCHECK(!did_activate_); |
95 DCHECK(client_handle_.is_valid()); | 86 DCHECK(client_handle_.is_valid()); |
96 | 87 |
97 base::PlatformFile client_file = | 88 base::PlatformFile client_file = std::move(client_handle_).release().handle; |
98 PlatformFileFromScopedPlatformHandle(std::move(client_handle_)); | |
99 did_activate_ = sender->Send(new MojoMsg_Activate( | 89 did_activate_ = sender->Send(new MojoMsg_Activate( |
100 IPC::GetFileHandleForProcess(client_file, process_handle, true))); | 90 IPC::GetFileHandleForProcess(client_file, process_handle, true))); |
101 } | 91 } |
102 | 92 |
103 void MojoApplicationHost::WillDestroySoon() { | |
104 channel_init_.WillDestroySoon(); | |
105 } | |
106 | |
107 void MojoApplicationHost::OverrideIOTaskRunnerForTest( | 93 void MojoApplicationHost::OverrideIOTaskRunnerForTest( |
108 scoped_refptr<base::TaskRunner> io_task_runner) { | 94 scoped_refptr<base::TaskRunner> io_task_runner) { |
109 io_task_runner_override_ = io_task_runner; | 95 io_task_runner_override_ = io_task_runner; |
110 } | 96 } |
111 | 97 |
112 } // namespace content | 98 } // namespace content |
OLD | NEW |