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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/process/process_handle.h" | 8 #include "base/process/process_handle.h" |
9 #include "ipc/ipc_message_utils.h" | 9 #include "ipc/ipc_message_utils.h" |
10 #include "ipc/ipc_platform_file.h" | 10 #include "ipc/ipc_platform_file.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 mojo::embedder::PlatformChannelPair channel_pair; | 49 mojo::embedder::PlatformChannelPair channel_pair; |
50 server_pipe_ = channel_pair.PassServerHandle(); | 50 server_pipe_ = channel_pair.PassServerHandle(); |
51 PlatformFileForTransit client_pipe = GetFileHandleForProcess( | 51 PlatformFileForTransit client_pipe = GetFileHandleForProcess( |
52 #if defined(OS_POSIX) | 52 #if defined(OS_POSIX) |
53 channel_pair.PassClientHandle().release().fd, | 53 channel_pair.PassClientHandle().release().fd, |
54 #else | 54 #else |
55 channel_pair.PassClientHandle().release().handle, | 55 channel_pair.PassClientHandle().release().handle, |
56 #endif | 56 #endif |
57 client_process_, | 57 client_process_, |
58 true); | 58 true); |
59 CHECK(client_pipe != IPC::InvalidPlatformFileForTransit()); | 59 if (client_pipe == IPC::InvalidPlatformFileForTransit()) { |
| 60 #if !defined(OS_WIN) |
| 61 // GetFileHandleForProcess() only fails on Windows. |
| 62 NOTREACHED(); |
| 63 #endif |
| 64 DLOG(WARNING) << "Failed to translate file handle for client process."; |
| 65 Fail(); |
| 66 return; |
| 67 } |
| 68 |
60 scoped_ptr<Message> message(new Message()); | 69 scoped_ptr<Message> message(new Message()); |
61 ParamTraits<PlatformFileForTransit>::Write(message.get(), client_pipe); | 70 ParamTraits<PlatformFileForTransit>::Write(message.get(), client_pipe); |
62 Send(message.release()); | 71 Send(message.release()); |
63 | 72 |
64 set_state(STATE_WAITING_ACK); | 73 set_state(STATE_WAITING_ACK); |
65 } | 74 } |
66 | 75 |
67 void MojoServerBootstrap::SendClientPipeIfReady() { | 76 void MojoServerBootstrap::SendClientPipeIfReady() { |
68 // Is the client launched? | 77 // Is the client launched? |
69 if (client_process_ == base::kNullProcessHandle) | 78 if (client_process_ == base::kNullProcessHandle) |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 void MojoBootstrap::Init(scoped_ptr<Channel> channel, Delegate* delegate) { | 180 void MojoBootstrap::Init(scoped_ptr<Channel> channel, Delegate* delegate) { |
172 channel_ = channel.Pass(); | 181 channel_ = channel.Pass(); |
173 delegate_ = delegate; | 182 delegate_ = delegate; |
174 } | 183 } |
175 | 184 |
176 bool MojoBootstrap::Connect() { | 185 bool MojoBootstrap::Connect() { |
177 return channel_->Connect(); | 186 return channel_->Connect(); |
178 } | 187 } |
179 | 188 |
180 void MojoBootstrap::OnBadMessageReceived(const Message& message) { | 189 void MojoBootstrap::OnBadMessageReceived(const Message& message) { |
181 delegate_->OnBootstrapError(); | 190 Fail(); |
182 } | 191 } |
183 | 192 |
184 void MojoBootstrap::OnChannelError() { | 193 void MojoBootstrap::OnChannelError() { |
185 if (state_ == STATE_READY) | 194 if (state_ == STATE_READY || state_ == STATE_ERROR) |
186 return; | 195 return; |
187 DLOG(WARNING) << "Detected error on Mojo bootstrap channel."; | 196 DLOG(WARNING) << "Detected error on Mojo bootstrap channel."; |
| 197 Fail(); |
| 198 } |
| 199 |
| 200 void MojoBootstrap::Fail() { |
| 201 set_state(STATE_ERROR); |
188 delegate()->OnBootstrapError(); | 202 delegate()->OnBootstrapError(); |
189 } | 203 } |
190 | 204 |
191 bool MojoBootstrap::Send(Message* message) { | 205 bool MojoBootstrap::Send(Message* message) { |
192 return channel_->Send(message); | 206 return channel_->Send(message); |
193 } | 207 } |
194 | 208 |
195 #if defined(OS_POSIX) && !defined(OS_NACL) | 209 #if defined(OS_POSIX) && !defined(OS_NACL) |
196 int MojoBootstrap::GetClientFileDescriptor() const { | 210 int MojoBootstrap::GetClientFileDescriptor() const { |
197 return channel_->GetClientFileDescriptor(); | 211 return channel_->GetClientFileDescriptor(); |
198 } | 212 } |
199 | 213 |
200 int MojoBootstrap::TakeClientFileDescriptor() { | 214 int MojoBootstrap::TakeClientFileDescriptor() { |
201 return channel_->TakeClientFileDescriptor(); | 215 return channel_->TakeClientFileDescriptor(); |
202 } | 216 } |
203 #endif // defined(OS_POSIX) && !defined(OS_NACL) | 217 #endif // defined(OS_POSIX) && !defined(OS_NACL) |
204 | 218 |
205 } // namespace IPC | 219 } // namespace IPC |
OLD | NEW |