Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(567)

Side by Side Diff: ipc/mojo/ipc_mojo_bootstrap.cc

Issue 1350023003: Add a Mojo EDK for Chrome that uses one OS pipe per message pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more cleanup Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/process/process_handle.h" 10 #include "base/process/process_handle.h"
(...skipping 13 matching lines...) Expand all
24 24
25 private: 25 private:
26 void SendClientPipe(int32_t peer_pid); 26 void SendClientPipe(int32_t peer_pid);
27 27
28 // Listener implementations 28 // Listener implementations
29 bool OnMessageReceived(const Message& message) override; 29 bool OnMessageReceived(const Message& message) override;
30 void OnChannelConnected(int32_t peer_pid) override; 30 void OnChannelConnected(int32_t peer_pid) override;
31 31
32 mojo::embedder::ScopedPlatformHandle server_pipe_; 32 mojo::embedder::ScopedPlatformHandle server_pipe_;
33 bool connected_; 33 bool connected_;
34 int32_t peer_pid_;
34 35
35 DISALLOW_COPY_AND_ASSIGN(MojoServerBootstrap); 36 DISALLOW_COPY_AND_ASSIGN(MojoServerBootstrap);
36 }; 37 };
37 38
38 MojoServerBootstrap::MojoServerBootstrap() : connected_(false) { 39 MojoServerBootstrap::MojoServerBootstrap() : connected_(false), peer_pid_(0) {
39 } 40 }
40 41
41 void MojoServerBootstrap::SendClientPipe(int32_t peer_pid) { 42 void MojoServerBootstrap::SendClientPipe(int32_t peer_pid) {
42 DCHECK_EQ(state(), STATE_INITIALIZED); 43 DCHECK_EQ(state(), STATE_INITIALIZED);
43 DCHECK(connected_); 44 DCHECK(connected_);
44 45
45 mojo::embedder::PlatformChannelPair channel_pair; 46 mojo::embedder::PlatformChannelPair channel_pair;
46 server_pipe_ = channel_pair.PassServerHandle(); 47 server_pipe_ = channel_pair.PassServerHandle();
47 48
48 base::Process peer_process = 49 base::Process peer_process =
(...skipping 22 matching lines...) Expand all
71 scoped_ptr<Message> message(new Message()); 72 scoped_ptr<Message> message(new Message());
72 ParamTraits<PlatformFileForTransit>::Write(message.get(), client_pipe); 73 ParamTraits<PlatformFileForTransit>::Write(message.get(), client_pipe);
73 Send(message.release()); 74 Send(message.release());
74 75
75 set_state(STATE_WAITING_ACK); 76 set_state(STATE_WAITING_ACK);
76 } 77 }
77 78
78 void MojoServerBootstrap::OnChannelConnected(int32_t peer_pid) { 79 void MojoServerBootstrap::OnChannelConnected(int32_t peer_pid) {
79 DCHECK_EQ(state(), STATE_INITIALIZED); 80 DCHECK_EQ(state(), STATE_INITIALIZED);
80 connected_ = true; 81 connected_ = true;
82 peer_pid_ = peer_pid;
81 SendClientPipe(peer_pid); 83 SendClientPipe(peer_pid);
82 } 84 }
83 85
84 bool MojoServerBootstrap::OnMessageReceived(const Message&) { 86 bool MojoServerBootstrap::OnMessageReceived(const Message&) {
85 if (state() != STATE_WAITING_ACK) { 87 if (state() != STATE_WAITING_ACK) {
86 set_state(STATE_ERROR); 88 set_state(STATE_ERROR);
87 LOG(ERROR) << "Got inconsistent message from client."; 89 LOG(ERROR) << "Got inconsistent message from client.";
88 return false; 90 return false;
89 } 91 }
90 92
91 set_state(STATE_READY); 93 set_state(STATE_READY);
92 CHECK(server_pipe_.is_valid()); 94 CHECK(server_pipe_.is_valid());
93 delegate()->OnPipeAvailable( 95 delegate()->OnPipeAvailable(
94 mojo::embedder::ScopedPlatformHandle(server_pipe_.release())); 96 mojo::embedder::ScopedPlatformHandle(server_pipe_.release()), peer_pid_);
95 97
96 return true; 98 return true;
97 } 99 }
98 100
99 // MojoBootstrap for client processes. You should create the instance 101 // MojoBootstrap for client processes. You should create the instance
100 // using MojoBootstrap::Create(). 102 // using MojoBootstrap::Create().
101 class MojoClientBootstrap : public MojoBootstrap { 103 class MojoClientBootstrap : public MojoBootstrap {
102 public: 104 public:
103 MojoClientBootstrap(); 105 MojoClientBootstrap();
104 106
105 private: 107 private:
106 // Listener implementations 108 // Listener implementations
107 bool OnMessageReceived(const Message& message) override; 109 bool OnMessageReceived(const Message& message) override;
108 void OnChannelConnected(int32_t peer_pid) override; 110 void OnChannelConnected(int32_t peer_pid) override;
109 111
112 int32 peer_pid_;
113
110 DISALLOW_COPY_AND_ASSIGN(MojoClientBootstrap); 114 DISALLOW_COPY_AND_ASSIGN(MojoClientBootstrap);
111 }; 115 };
112 116
113 MojoClientBootstrap::MojoClientBootstrap() { 117 MojoClientBootstrap::MojoClientBootstrap() : peer_pid_(0) {
114 } 118 }
115 119
116 bool MojoClientBootstrap::OnMessageReceived(const Message& message) { 120 bool MojoClientBootstrap::OnMessageReceived(const Message& message) {
117 if (state() != STATE_INITIALIZED) { 121 if (state() != STATE_INITIALIZED) {
118 set_state(STATE_ERROR); 122 set_state(STATE_ERROR);
119 LOG(ERROR) << "Got inconsistent message from server."; 123 LOG(ERROR) << "Got inconsistent message from server.";
120 return false; 124 return false;
121 } 125 }
122 126
123 PlatformFileForTransit pipe; 127 PlatformFileForTransit pipe;
124 base::PickleIterator iter(message); 128 base::PickleIterator iter(message);
125 if (!ParamTraits<PlatformFileForTransit>::Read(&message, &iter, &pipe)) { 129 if (!ParamTraits<PlatformFileForTransit>::Read(&message, &iter, &pipe)) {
126 LOG(WARNING) << "Failed to read a file handle from bootstrap channel."; 130 LOG(WARNING) << "Failed to read a file handle from bootstrap channel.";
127 message.set_dispatch_error(); 131 message.set_dispatch_error();
128 return false; 132 return false;
129 } 133 }
130 134
131 // Sends ACK back. 135 // Sends ACK back.
132 Send(new Message()); 136 Send(new Message());
133 set_state(STATE_READY); 137 set_state(STATE_READY);
134 delegate()->OnPipeAvailable( 138 delegate()->OnPipeAvailable(
135 mojo::embedder::ScopedPlatformHandle(mojo::embedder::PlatformHandle( 139 mojo::embedder::ScopedPlatformHandle(mojo::embedder::PlatformHandle(
136 PlatformFileForTransitToPlatformFile(pipe)))); 140 PlatformFileForTransitToPlatformFile(pipe))), peer_pid_);
137 141
138 return true; 142 return true;
139 } 143 }
140 144
141 void MojoClientBootstrap::OnChannelConnected(int32_t peer_pid) { 145 void MojoClientBootstrap::OnChannelConnected(int32_t peer_pid) {
146 peer_pid_ = peer_pid;
142 } 147 }
143 148
144 } // namespace 149 } // namespace
145 150
146 // MojoBootstrap 151 // MojoBootstrap
147 152
148 // static 153 // static
149 scoped_ptr<MojoBootstrap> MojoBootstrap::Create(ChannelHandle handle, 154 scoped_ptr<MojoBootstrap> MojoBootstrap::Create(ChannelHandle handle,
150 Channel::Mode mode, 155 Channel::Mode mode,
151 Delegate* delegate) { 156 Delegate* delegate) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 int MojoBootstrap::GetClientFileDescriptor() const { 213 int MojoBootstrap::GetClientFileDescriptor() const {
209 return channel_->GetClientFileDescriptor(); 214 return channel_->GetClientFileDescriptor();
210 } 215 }
211 216
212 base::ScopedFD MojoBootstrap::TakeClientFileDescriptor() { 217 base::ScopedFD MojoBootstrap::TakeClientFileDescriptor() {
213 return channel_->TakeClientFileDescriptor(); 218 return channel_->TakeClientFileDescriptor();
214 } 219 }
215 #endif // defined(OS_POSIX) && !defined(OS_NACL) 220 #endif // defined(OS_POSIX) && !defined(OS_NACL)
216 221
217 } // namespace IPC 222 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698