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 "ipc/mojo/ipc_mojo_bootstrap.h" | 5 #include "ipc/mojo/ipc_mojo_bootstrap.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/process/process_handle.h" | 12 #include "base/process/process_handle.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "ipc/ipc_message_utils.h" | 14 #include "ipc/ipc_message_utils.h" |
15 #include "ipc/ipc_platform_file.h" | 15 #include "ipc/ipc_platform_file.h" |
16 #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h" | 16 #include "mojo/edk/embedder/platform_channel_pair.h" |
17 | 17 |
18 namespace IPC { | 18 namespace IPC { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // MojoBootstrap for the server process. You should create the instance | 22 // MojoBootstrap for the server process. You should create the instance |
23 // using MojoBootstrap::Create(). | 23 // using MojoBootstrap::Create(). |
24 class MojoServerBootstrap : public MojoBootstrap { | 24 class MojoServerBootstrap : public MojoBootstrap { |
25 public: | 25 public: |
26 MojoServerBootstrap(); | 26 MojoServerBootstrap(); |
27 | 27 |
28 private: | 28 private: |
29 void SendClientPipe(int32_t peer_pid); | 29 void SendClientPipe(int32_t peer_pid); |
30 | 30 |
31 // Listener implementations | 31 // Listener implementations |
32 bool OnMessageReceived(const Message& message) override; | 32 bool OnMessageReceived(const Message& message) override; |
33 void OnChannelConnected(int32_t peer_pid) override; | 33 void OnChannelConnected(int32_t peer_pid) override; |
34 | 34 |
35 mojo::embedder::ScopedPlatformHandle server_pipe_; | 35 mojo::edk::ScopedPlatformHandle server_pipe_; |
36 bool connected_; | 36 bool connected_; |
37 int32_t peer_pid_; | 37 int32_t peer_pid_; |
38 | 38 |
39 DISALLOW_COPY_AND_ASSIGN(MojoServerBootstrap); | 39 DISALLOW_COPY_AND_ASSIGN(MojoServerBootstrap); |
40 }; | 40 }; |
41 | 41 |
42 MojoServerBootstrap::MojoServerBootstrap() : connected_(false), peer_pid_(0) { | 42 MojoServerBootstrap::MojoServerBootstrap() : connected_(false), peer_pid_(0) { |
43 } | 43 } |
44 | 44 |
45 void MojoServerBootstrap::SendClientPipe(int32_t peer_pid) { | 45 void MojoServerBootstrap::SendClientPipe(int32_t peer_pid) { |
46 DCHECK_EQ(state(), STATE_INITIALIZED); | 46 DCHECK_EQ(state(), STATE_INITIALIZED); |
47 DCHECK(connected_); | 47 DCHECK(connected_); |
48 | 48 |
49 mojo::embedder::PlatformChannelPair channel_pair; | 49 mojo::edk::PlatformChannelPair channel_pair; |
50 server_pipe_ = channel_pair.PassServerHandle(); | 50 server_pipe_ = channel_pair.PassServerHandle(); |
51 | 51 |
52 base::Process peer_process = | 52 base::Process peer_process = |
53 #if defined(OS_WIN) | 53 #if defined(OS_WIN) |
54 base::Process::OpenWithAccess(peer_pid, PROCESS_DUP_HANDLE); | 54 base::Process::OpenWithAccess(peer_pid, PROCESS_DUP_HANDLE); |
55 #else | 55 #else |
56 base::Process::Open(peer_pid); | 56 base::Process::Open(peer_pid); |
57 #endif | 57 #endif |
58 PlatformFileForTransit client_pipe = GetFileHandleForProcess( | 58 PlatformFileForTransit client_pipe = GetFileHandleForProcess( |
59 #if defined(OS_POSIX) | |
60 channel_pair.PassClientHandle().release().fd, | |
61 #else | |
62 channel_pair.PassClientHandle().release().handle, | 59 channel_pair.PassClientHandle().release().handle, |
63 #endif | |
64 peer_process.Handle(), true); | 60 peer_process.Handle(), true); |
65 if (client_pipe == IPC::InvalidPlatformFileForTransit()) { | 61 if (client_pipe == IPC::InvalidPlatformFileForTransit()) { |
66 #if !defined(OS_WIN) | 62 #if !defined(OS_WIN) |
67 // GetFileHandleForProcess() only fails on Windows. | 63 // GetFileHandleForProcess() only fails on Windows. |
68 NOTREACHED(); | 64 NOTREACHED(); |
69 #endif | 65 #endif |
70 LOG(WARNING) << "Failed to translate file handle for client process."; | 66 LOG(WARNING) << "Failed to translate file handle for client process."; |
71 Fail(); | 67 Fail(); |
72 return; | 68 return; |
73 } | 69 } |
(...skipping 15 matching lines...) Expand all Loading... |
89 bool MojoServerBootstrap::OnMessageReceived(const Message&) { | 85 bool MojoServerBootstrap::OnMessageReceived(const Message&) { |
90 if (state() != STATE_WAITING_ACK) { | 86 if (state() != STATE_WAITING_ACK) { |
91 set_state(STATE_ERROR); | 87 set_state(STATE_ERROR); |
92 LOG(ERROR) << "Got inconsistent message from client."; | 88 LOG(ERROR) << "Got inconsistent message from client."; |
93 return false; | 89 return false; |
94 } | 90 } |
95 | 91 |
96 set_state(STATE_READY); | 92 set_state(STATE_READY); |
97 CHECK(server_pipe_.is_valid()); | 93 CHECK(server_pipe_.is_valid()); |
98 delegate()->OnPipeAvailable( | 94 delegate()->OnPipeAvailable( |
99 mojo::embedder::ScopedPlatformHandle(server_pipe_.release()), peer_pid_); | 95 mojo::edk::ScopedPlatformHandle(server_pipe_.release()), peer_pid_); |
100 | 96 |
101 return true; | 97 return true; |
102 } | 98 } |
103 | 99 |
104 // MojoBootstrap for client processes. You should create the instance | 100 // MojoBootstrap for client processes. You should create the instance |
105 // using MojoBootstrap::Create(). | 101 // using MojoBootstrap::Create(). |
106 class MojoClientBootstrap : public MojoBootstrap { | 102 class MojoClientBootstrap : public MojoBootstrap { |
107 public: | 103 public: |
108 MojoClientBootstrap(); | 104 MojoClientBootstrap(); |
109 | 105 |
(...skipping 22 matching lines...) Expand all Loading... |
132 if (!ParamTraits<PlatformFileForTransit>::Read(&message, &iter, &pipe)) { | 128 if (!ParamTraits<PlatformFileForTransit>::Read(&message, &iter, &pipe)) { |
133 LOG(WARNING) << "Failed to read a file handle from bootstrap channel."; | 129 LOG(WARNING) << "Failed to read a file handle from bootstrap channel."; |
134 message.set_dispatch_error(); | 130 message.set_dispatch_error(); |
135 return false; | 131 return false; |
136 } | 132 } |
137 | 133 |
138 // Sends ACK back. | 134 // Sends ACK back. |
139 Send(new Message()); | 135 Send(new Message()); |
140 set_state(STATE_READY); | 136 set_state(STATE_READY); |
141 delegate()->OnPipeAvailable( | 137 delegate()->OnPipeAvailable( |
142 mojo::embedder::ScopedPlatformHandle(mojo::embedder::PlatformHandle( | 138 mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle( |
143 PlatformFileForTransitToPlatformFile(pipe))), peer_pid_); | 139 PlatformFileForTransitToPlatformFile(pipe))), |
| 140 peer_pid_); |
144 | 141 |
145 return true; | 142 return true; |
146 } | 143 } |
147 | 144 |
148 void MojoClientBootstrap::OnChannelConnected(int32_t peer_pid) { | 145 void MojoClientBootstrap::OnChannelConnected(int32_t peer_pid) { |
149 peer_pid_ = peer_pid; | 146 peer_pid_ = peer_pid; |
150 } | 147 } |
151 | 148 |
152 } // namespace | 149 } // namespace |
153 | 150 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 int MojoBootstrap::GetClientFileDescriptor() const { | 213 int MojoBootstrap::GetClientFileDescriptor() const { |
217 return channel_->GetClientFileDescriptor(); | 214 return channel_->GetClientFileDescriptor(); |
218 } | 215 } |
219 | 216 |
220 base::ScopedFD MojoBootstrap::TakeClientFileDescriptor() { | 217 base::ScopedFD MojoBootstrap::TakeClientFileDescriptor() { |
221 return channel_->TakeClientFileDescriptor(); | 218 return channel_->TakeClientFileDescriptor(); |
222 } | 219 } |
223 #endif // defined(OS_POSIX) && !defined(OS_NACL) | 220 #endif // defined(OS_POSIX) && !defined(OS_NACL) |
224 | 221 |
225 } // namespace IPC | 222 } // namespace IPC |
OLD | NEW |