| 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> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
| 9 #include "ipc/ipc_message_utils.h" | 11 #include "ipc/ipc_message_utils.h" |
| 10 #include "ipc/ipc_platform_file.h" | 12 #include "ipc/ipc_platform_file.h" |
| 11 #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h" | 13 #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h" |
| 12 | 14 |
| 13 namespace IPC { | 15 namespace IPC { |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 // MojoBootstrap for the server process. You should create the instance | 19 // MojoBootstrap for the server process. You should create the instance |
| 18 // using MojoBootstrap::Create(). | 20 // using MojoBootstrap::Create(). |
| 19 class MojoServerBootstrap : public MojoBootstrap { | 21 class MojoServerBootstrap : public MojoBootstrap { |
| 20 public: | 22 public: |
| 21 MojoServerBootstrap(); | 23 MojoServerBootstrap(); |
| 22 | 24 |
| 23 private: | 25 private: |
| 24 void SendClientPipe(int32 peer_pid); | 26 void SendClientPipe(int32_t peer_pid); |
| 25 | 27 |
| 26 // Listener implementations | 28 // Listener implementations |
| 27 bool OnMessageReceived(const Message& message) override; | 29 bool OnMessageReceived(const Message& message) override; |
| 28 void OnChannelConnected(int32 peer_pid) override; | 30 void OnChannelConnected(int32_t peer_pid) override; |
| 29 | 31 |
| 30 mojo::embedder::ScopedPlatformHandle server_pipe_; | 32 mojo::embedder::ScopedPlatformHandle server_pipe_; |
| 31 bool connected_; | 33 bool connected_; |
| 32 | 34 |
| 33 DISALLOW_COPY_AND_ASSIGN(MojoServerBootstrap); | 35 DISALLOW_COPY_AND_ASSIGN(MojoServerBootstrap); |
| 34 }; | 36 }; |
| 35 | 37 |
| 36 MojoServerBootstrap::MojoServerBootstrap() : connected_(false) { | 38 MojoServerBootstrap::MojoServerBootstrap() : connected_(false) { |
| 37 } | 39 } |
| 38 | 40 |
| 39 void MojoServerBootstrap::SendClientPipe(int32 peer_pid) { | 41 void MojoServerBootstrap::SendClientPipe(int32_t peer_pid) { |
| 40 DCHECK_EQ(state(), STATE_INITIALIZED); | 42 DCHECK_EQ(state(), STATE_INITIALIZED); |
| 41 DCHECK(connected_); | 43 DCHECK(connected_); |
| 42 | 44 |
| 43 mojo::embedder::PlatformChannelPair channel_pair; | 45 mojo::embedder::PlatformChannelPair channel_pair; |
| 44 server_pipe_ = channel_pair.PassServerHandle(); | 46 server_pipe_ = channel_pair.PassServerHandle(); |
| 45 | 47 |
| 46 base::Process peer_process = | 48 base::Process peer_process = |
| 47 #if defined(OS_WIN) | 49 #if defined(OS_WIN) |
| 48 base::Process::OpenWithAccess(peer_pid, PROCESS_DUP_HANDLE); | 50 base::Process::OpenWithAccess(peer_pid, PROCESS_DUP_HANDLE); |
| 49 #else | 51 #else |
| (...skipping 16 matching lines...) Expand all Loading... |
| 66 return; | 68 return; |
| 67 } | 69 } |
| 68 | 70 |
| 69 scoped_ptr<Message> message(new Message()); | 71 scoped_ptr<Message> message(new Message()); |
| 70 ParamTraits<PlatformFileForTransit>::Write(message.get(), client_pipe); | 72 ParamTraits<PlatformFileForTransit>::Write(message.get(), client_pipe); |
| 71 Send(message.release()); | 73 Send(message.release()); |
| 72 | 74 |
| 73 set_state(STATE_WAITING_ACK); | 75 set_state(STATE_WAITING_ACK); |
| 74 } | 76 } |
| 75 | 77 |
| 76 void MojoServerBootstrap::OnChannelConnected(int32 peer_pid) { | 78 void MojoServerBootstrap::OnChannelConnected(int32_t peer_pid) { |
| 77 DCHECK_EQ(state(), STATE_INITIALIZED); | 79 DCHECK_EQ(state(), STATE_INITIALIZED); |
| 78 connected_ = true; | 80 connected_ = true; |
| 79 SendClientPipe(peer_pid); | 81 SendClientPipe(peer_pid); |
| 80 } | 82 } |
| 81 | 83 |
| 82 bool MojoServerBootstrap::OnMessageReceived(const Message&) { | 84 bool MojoServerBootstrap::OnMessageReceived(const Message&) { |
| 83 if (state() != STATE_WAITING_ACK) { | 85 if (state() != STATE_WAITING_ACK) { |
| 84 set_state(STATE_ERROR); | 86 set_state(STATE_ERROR); |
| 85 LOG(ERROR) << "Got inconsistent message from client."; | 87 LOG(ERROR) << "Got inconsistent message from client."; |
| 86 return false; | 88 return false; |
| 87 } | 89 } |
| 88 | 90 |
| 89 set_state(STATE_READY); | 91 set_state(STATE_READY); |
| 90 CHECK(server_pipe_.is_valid()); | 92 CHECK(server_pipe_.is_valid()); |
| 91 delegate()->OnPipeAvailable( | 93 delegate()->OnPipeAvailable( |
| 92 mojo::embedder::ScopedPlatformHandle(server_pipe_.release())); | 94 mojo::embedder::ScopedPlatformHandle(server_pipe_.release())); |
| 93 | 95 |
| 94 return true; | 96 return true; |
| 95 } | 97 } |
| 96 | 98 |
| 97 // MojoBootstrap for client processes. You should create the instance | 99 // MojoBootstrap for client processes. You should create the instance |
| 98 // using MojoBootstrap::Create(). | 100 // using MojoBootstrap::Create(). |
| 99 class MojoClientBootstrap : public MojoBootstrap { | 101 class MojoClientBootstrap : public MojoBootstrap { |
| 100 public: | 102 public: |
| 101 MojoClientBootstrap(); | 103 MojoClientBootstrap(); |
| 102 | 104 |
| 103 private: | 105 private: |
| 104 // Listener implementations | 106 // Listener implementations |
| 105 bool OnMessageReceived(const Message& message) override; | 107 bool OnMessageReceived(const Message& message) override; |
| 106 void OnChannelConnected(int32 peer_pid) override; | 108 void OnChannelConnected(int32_t peer_pid) override; |
| 107 | 109 |
| 108 DISALLOW_COPY_AND_ASSIGN(MojoClientBootstrap); | 110 DISALLOW_COPY_AND_ASSIGN(MojoClientBootstrap); |
| 109 }; | 111 }; |
| 110 | 112 |
| 111 MojoClientBootstrap::MojoClientBootstrap() { | 113 MojoClientBootstrap::MojoClientBootstrap() { |
| 112 } | 114 } |
| 113 | 115 |
| 114 bool MojoClientBootstrap::OnMessageReceived(const Message& message) { | 116 bool MojoClientBootstrap::OnMessageReceived(const Message& message) { |
| 115 if (state() != STATE_INITIALIZED) { | 117 if (state() != STATE_INITIALIZED) { |
| 116 set_state(STATE_ERROR); | 118 set_state(STATE_ERROR); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 129 // Sends ACK back. | 131 // Sends ACK back. |
| 130 Send(new Message()); | 132 Send(new Message()); |
| 131 set_state(STATE_READY); | 133 set_state(STATE_READY); |
| 132 delegate()->OnPipeAvailable( | 134 delegate()->OnPipeAvailable( |
| 133 mojo::embedder::ScopedPlatformHandle(mojo::embedder::PlatformHandle( | 135 mojo::embedder::ScopedPlatformHandle(mojo::embedder::PlatformHandle( |
| 134 PlatformFileForTransitToPlatformFile(pipe)))); | 136 PlatformFileForTransitToPlatformFile(pipe)))); |
| 135 | 137 |
| 136 return true; | 138 return true; |
| 137 } | 139 } |
| 138 | 140 |
| 139 void MojoClientBootstrap::OnChannelConnected(int32 peer_pid) { | 141 void MojoClientBootstrap::OnChannelConnected(int32_t peer_pid) { |
| 140 } | 142 } |
| 141 | 143 |
| 142 } // namespace | 144 } // namespace |
| 143 | 145 |
| 144 // MojoBootstrap | 146 // MojoBootstrap |
| 145 | 147 |
| 146 // static | 148 // static |
| 147 scoped_ptr<MojoBootstrap> MojoBootstrap::Create(ChannelHandle handle, | 149 scoped_ptr<MojoBootstrap> MojoBootstrap::Create(ChannelHandle handle, |
| 148 Channel::Mode mode, | 150 Channel::Mode mode, |
| 149 Delegate* delegate, | 151 Delegate* delegate, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 int MojoBootstrap::GetClientFileDescriptor() const { | 209 int MojoBootstrap::GetClientFileDescriptor() const { |
| 208 return channel_->GetClientFileDescriptor(); | 210 return channel_->GetClientFileDescriptor(); |
| 209 } | 211 } |
| 210 | 212 |
| 211 base::ScopedFD MojoBootstrap::TakeClientFileDescriptor() { | 213 base::ScopedFD MojoBootstrap::TakeClientFileDescriptor() { |
| 212 return channel_->TakeClientFileDescriptor(); | 214 return channel_->TakeClientFileDescriptor(); |
| 213 } | 215 } |
| 214 #endif // defined(OS_POSIX) && !defined(OS_NACL) | 216 #endif // defined(OS_POSIX) && !defined(OS_NACL) |
| 215 | 217 |
| 216 } // namespace IPC | 218 } // namespace IPC |
| OLD | NEW |