| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 SendClientPipeIfReady(); | 93 SendClientPipeIfReady(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void MojoServerBootstrap::OnChannelConnected(int32 peer_pid) { | 96 void MojoServerBootstrap::OnChannelConnected(int32 peer_pid) { |
| 97 DCHECK_EQ(state(), STATE_INITIALIZED); | 97 DCHECK_EQ(state(), STATE_INITIALIZED); |
| 98 connected_ = true; | 98 connected_ = true; |
| 99 SendClientPipeIfReady(); | 99 SendClientPipeIfReady(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool MojoServerBootstrap::OnMessageReceived(const Message&) { | 102 bool MojoServerBootstrap::OnMessageReceived(const Message&) { |
| 103 if (state() != STATE_WAITING_ACK) { | 103 DCHECK_EQ(state(), STATE_WAITING_ACK); |
| 104 set_state(STATE_ERROR); | 104 set_state(STATE_READY); |
| 105 LOG(ERROR) << "Got inconsistent message from client."; | |
| 106 return false; | |
| 107 } | |
| 108 | 105 |
| 109 set_state(STATE_READY); | |
| 110 CHECK(server_pipe_.is_valid()); | |
| 111 delegate()->OnPipeAvailable( | 106 delegate()->OnPipeAvailable( |
| 112 mojo::embedder::ScopedPlatformHandle(server_pipe_.release())); | 107 mojo::embedder::ScopedPlatformHandle(server_pipe_.release())); |
| 113 | 108 |
| 114 return true; | 109 return true; |
| 115 } | 110 } |
| 116 | 111 |
| 117 // MojoBootstrap for client processes. You should create the instance | 112 // MojoBootstrap for client processes. You should create the instance |
| 118 // using MojoBootstrap::Create(). | 113 // using MojoBootstrap::Create(). |
| 119 class MojoClientBootstrap : public MojoBootstrap { | 114 class MojoClientBootstrap : public MojoBootstrap { |
| 120 public: | 115 public: |
| 121 MojoClientBootstrap(); | 116 MojoClientBootstrap(); |
| 122 | 117 |
| 123 void OnClientLaunched(base::ProcessHandle process) override; | 118 void OnClientLaunched(base::ProcessHandle process) override; |
| 124 | 119 |
| 125 private: | 120 private: |
| 126 // Listener implementations | 121 // Listener implementations |
| 127 bool OnMessageReceived(const Message& message) override; | 122 bool OnMessageReceived(const Message& message) override; |
| 128 void OnChannelConnected(int32 peer_pid) override; | 123 void OnChannelConnected(int32 peer_pid) override; |
| 129 | 124 |
| 130 DISALLOW_COPY_AND_ASSIGN(MojoClientBootstrap); | 125 DISALLOW_COPY_AND_ASSIGN(MojoClientBootstrap); |
| 131 }; | 126 }; |
| 132 | 127 |
| 133 MojoClientBootstrap::MojoClientBootstrap() { | 128 MojoClientBootstrap::MojoClientBootstrap() { |
| 134 } | 129 } |
| 135 | 130 |
| 136 bool MojoClientBootstrap::OnMessageReceived(const Message& message) { | 131 bool MojoClientBootstrap::OnMessageReceived(const Message& message) { |
| 137 if (state() != STATE_INITIALIZED) { | |
| 138 set_state(STATE_ERROR); | |
| 139 LOG(ERROR) << "Got inconsistent message from server."; | |
| 140 return false; | |
| 141 } | |
| 142 | |
| 143 PlatformFileForTransit pipe; | 132 PlatformFileForTransit pipe; |
| 144 PickleIterator iter(message); | 133 PickleIterator iter(message); |
| 145 if (!ParamTraits<PlatformFileForTransit>::Read(&message, &iter, &pipe)) { | 134 if (!ParamTraits<PlatformFileForTransit>::Read(&message, &iter, &pipe)) { |
| 146 DLOG(WARNING) << "Failed to read a file handle from bootstrap channel."; | 135 DLOG(WARNING) << "Failed to read a file handle from bootstrap channel."; |
| 147 message.set_dispatch_error(); | 136 message.set_dispatch_error(); |
| 148 return false; | 137 return false; |
| 149 } | 138 } |
| 150 | 139 |
| 151 // Sends ACK back. | 140 // Sends ACK back. |
| 152 Send(new Message()); | 141 Send(new Message()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 int MojoBootstrap::GetClientFileDescriptor() const { | 217 int MojoBootstrap::GetClientFileDescriptor() const { |
| 229 return channel_->GetClientFileDescriptor(); | 218 return channel_->GetClientFileDescriptor(); |
| 230 } | 219 } |
| 231 | 220 |
| 232 base::ScopedFD MojoBootstrap::TakeClientFileDescriptor() { | 221 base::ScopedFD MojoBootstrap::TakeClientFileDescriptor() { |
| 233 return channel_->TakeClientFileDescriptor(); | 222 return channel_->TakeClientFileDescriptor(); |
| 234 } | 223 } |
| 235 #endif // defined(OS_POSIX) && !defined(OS_NACL) | 224 #endif // defined(OS_POSIX) && !defined(OS_NACL) |
| 236 | 225 |
| 237 } // namespace IPC | 226 } // namespace IPC |
| OLD | NEW |