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 "content/common/mojo/mojo_messages.h" | 7 #include "content/common/mojo/mojo_messages.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 #include "ipc/ipc_sender.h" | 9 #include "ipc/ipc_sender.h" |
10 #include "mojo/embedder/platform_channel_pair.h" | 10 #include "mojo/embedder/platform_channel_pair.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 namespace { | |
14 | |
15 base::PlatformFile PlatformFileFromScopedPlatformHandle( | |
16 mojo::embedder::ScopedPlatformHandle handle) { | |
17 #if defined(OS_POSIX) | |
18 return handle.release().fd; | |
19 #elif defined(OS_WIN) | |
20 return handle.release().handle; | |
21 #endif | |
22 } | |
23 | |
24 } // namespace | |
25 | 13 |
26 MojoApplicationHost::MojoApplicationHost() : did_activate_(false) { | 14 MojoApplicationHost::MojoApplicationHost() : did_activate_(false) { |
27 } | 15 } |
28 | 16 |
29 MojoApplicationHost::~MojoApplicationHost() { | 17 MojoApplicationHost::~MojoApplicationHost() { |
30 } | 18 } |
31 | 19 |
32 bool MojoApplicationHost::Init() { | 20 bool MojoApplicationHost::Init() { |
33 DCHECK(!client_handle_.is_valid()) << "Already initialized!"; | 21 DCHECK(!client_handle_.is_valid()) << "Already initialized!"; |
34 | 22 |
35 mojo::embedder::PlatformChannelPair channel_pair; | 23 mojo::embedder::PlatformChannelPair channel_pair; |
36 | 24 |
37 mojo::ScopedMessagePipeHandle message_pipe = channel_init_.Init( | 25 mojo::ScopedMessagePipeHandle message_pipe = channel_init_.Init( |
38 PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()), | 26 channel_pair.PassServerHandle().release().platform_file(), |
39 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 27 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
40 if (!message_pipe.is_valid()) | 28 if (!message_pipe.is_valid()) |
41 return false; | 29 return false; |
42 | 30 |
43 // Forward this to the client once we know its process handle. | 31 // Forward this to the client once we know its process handle. |
44 client_handle_ = channel_pair.PassClientHandle(); | 32 client_handle_ = channel_pair.PassClientHandle(); |
45 | 33 |
46 service_registry_.BindRemoteServiceProvider(message_pipe.Pass()); | 34 service_registry_.BindRemoteServiceProvider(message_pipe.Pass()); |
47 return true; | 35 return true; |
48 } | 36 } |
49 | 37 |
50 bool MojoApplicationHost::Activate(IPC::Sender* sender, | 38 bool MojoApplicationHost::Activate(IPC::Sender* sender, |
51 base::ProcessHandle process_handle) { | 39 base::ProcessHandle process_handle) { |
52 DCHECK(!did_activate_); | 40 DCHECK(!did_activate_); |
53 DCHECK(client_handle_.is_valid()); | 41 DCHECK(client_handle_.is_valid()); |
54 | 42 |
55 base::PlatformFile client_file = | 43 base::PlatformFile client_file = client_handle_.release().platform_file(); |
56 PlatformFileFromScopedPlatformHandle(client_handle_.Pass()); | |
57 did_activate_ = sender->Send(new MojoMsg_Activate( | 44 did_activate_ = sender->Send(new MojoMsg_Activate( |
58 IPC::GetFileHandleForProcess(client_file, process_handle, true))); | 45 IPC::GetFileHandleForProcess(client_file, process_handle, true))); |
59 return did_activate_; | 46 return did_activate_; |
60 } | 47 } |
61 | 48 |
62 void MojoApplicationHost::WillDestroySoon() { | 49 void MojoApplicationHost::WillDestroySoon() { |
63 channel_init_.WillDestroySoon(); | 50 channel_init_.WillDestroySoon(); |
64 } | 51 } |
65 | 52 |
66 } // namespace content | 53 } // namespace content |
OLD | NEW |