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 18 matching lines...) Expand all Loading... |
55 new ServiceRegistryAndroid(&service_registry_)); | 46 new ServiceRegistryAndroid(&service_registry_)); |
56 #endif | 47 #endif |
57 } | 48 } |
58 | 49 |
59 MojoApplicationHost::~MojoApplicationHost() { | 50 MojoApplicationHost::~MojoApplicationHost() { |
60 } | 51 } |
61 | 52 |
62 bool MojoApplicationHost::Init() { | 53 bool MojoApplicationHost::Init() { |
63 DCHECK(!client_handle_.is_valid()) << "Already initialized!"; | 54 DCHECK(!client_handle_.is_valid()) << "Already initialized!"; |
64 | 55 |
65 mojo::embedder::PlatformChannelPair channel_pair; | 56 mojo::edk::PlatformChannelPair channel_pair; |
66 | 57 |
67 scoped_refptr<base::TaskRunner> io_task_runner; | 58 scoped_refptr<base::TaskRunner> io_task_runner; |
68 if (io_task_runner_override_) { | 59 if (io_task_runner_override_) { |
69 io_task_runner = io_task_runner_override_; | 60 io_task_runner = io_task_runner_override_; |
70 } else { | 61 } else { |
71 io_task_runner = | 62 io_task_runner = |
72 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) | 63 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) |
73 ->task_runner(); | 64 ->task_runner(); |
74 } | 65 } |
75 | 66 |
76 // Forward this to the client once we know its process handle. | 67 // Forward this to the client once we know its process handle. |
77 client_handle_ = channel_pair.PassClientHandle(); | 68 client_handle_ = channel_pair.PassClientHandle(); |
78 mojo::ScopedMessagePipeHandle pipe = channel_init_.Init( | 69 mojo::ScopedMessagePipeHandle pipe = channel_init_.Init( |
79 PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()), | 70 channel_pair.PassServerHandle().release().handle, io_task_runner); |
80 io_task_runner); | |
81 application_setup_.reset(new ApplicationSetupImpl( | 71 application_setup_.reset(new ApplicationSetupImpl( |
82 &service_registry_, | 72 &service_registry_, |
83 mojo::MakeRequest<ApplicationSetup>(std::move(pipe)))); | 73 mojo::MakeRequest<ApplicationSetup>(std::move(pipe)))); |
84 return true; | 74 return true; |
85 } | 75 } |
86 | 76 |
87 void MojoApplicationHost::Activate(IPC::Sender* sender, | 77 void MojoApplicationHost::Activate(IPC::Sender* sender, |
88 base::ProcessHandle process_handle) { | 78 base::ProcessHandle process_handle) { |
89 DCHECK(!did_activate_); | 79 DCHECK(!did_activate_); |
90 DCHECK(client_handle_.is_valid()); | 80 DCHECK(client_handle_.is_valid()); |
91 | 81 |
92 base::PlatformFile client_file = | 82 base::PlatformFile client_file = client_handle_.release().handle; |
93 PlatformFileFromScopedPlatformHandle(std::move(client_handle_)); | |
94 did_activate_ = sender->Send(new MojoMsg_Activate( | 83 did_activate_ = sender->Send(new MojoMsg_Activate( |
95 IPC::GetFileHandleForProcess(client_file, process_handle, true))); | 84 IPC::GetFileHandleForProcess(client_file, process_handle, true))); |
96 } | 85 } |
97 | 86 |
98 void MojoApplicationHost::WillDestroySoon() { | |
99 channel_init_.WillDestroySoon(); | |
100 } | |
101 | |
102 void MojoApplicationHost::OverrideIOTaskRunnerForTest( | 87 void MojoApplicationHost::OverrideIOTaskRunnerForTest( |
103 scoped_refptr<base::TaskRunner> io_task_runner) { | 88 scoped_refptr<base::TaskRunner> io_task_runner) { |
104 io_task_runner_override_ = io_task_runner; | 89 io_task_runner_override_ = io_task_runner; |
105 } | 90 } |
106 | 91 |
107 | 92 |
108 } // namespace content | 93 } // namespace content |
OLD | NEW |