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

Side by Side Diff: ipc/sync_socket_unittest.cc

Issue 5978003: Make IPC::Channel::Listener:OnMessageReceived have a return value indicating ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years 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 | Annotate | Revision Log
« no previous file with comments | « ipc/ipc_tests.cc ('k') | ppapi/proxy/dispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/sync_socket.h" 5 #include "base/sync_socket.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <string> 8 #include <string>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // messages from the client. 100 // messages from the client.
101 class SyncSocketServerListener : public IPC::Channel::Listener { 101 class SyncSocketServerListener : public IPC::Channel::Listener {
102 public: 102 public:
103 SyncSocketServerListener() : chan_(NULL) { 103 SyncSocketServerListener() : chan_(NULL) {
104 } 104 }
105 105
106 void Init(IPC::Channel* chan) { 106 void Init(IPC::Channel* chan) {
107 chan_ = chan; 107 chan_ = chan;
108 } 108 }
109 109
110 virtual void OnMessageReceived(const IPC::Message& msg) { 110 virtual bool OnMessageReceived(const IPC::Message& msg) {
111 if (msg.routing_id() == MSG_ROUTING_CONTROL) { 111 if (msg.routing_id() == MSG_ROUTING_CONTROL) {
112 IPC_BEGIN_MESSAGE_MAP(SyncSocketServerListener, msg) 112 IPC_BEGIN_MESSAGE_MAP(SyncSocketServerListener, msg)
113 IPC_MESSAGE_HANDLER(MsgClassSetHandle, OnMsgClassSetHandle) 113 IPC_MESSAGE_HANDLER(MsgClassSetHandle, OnMsgClassSetHandle)
114 IPC_MESSAGE_HANDLER(MsgClassShutdown, OnMsgClassShutdown) 114 IPC_MESSAGE_HANDLER(MsgClassShutdown, OnMsgClassShutdown)
115 IPC_END_MESSAGE_MAP() 115 IPC_END_MESSAGE_MAP()
116 } 116 }
117 return true;
117 } 118 }
118 119
119 private: 120 private:
120 // This sort of message is sent first, causing the transfer of 121 // This sort of message is sent first, causing the transfer of
121 // the handle for the SyncSocket. This message sends a buffer 122 // the handle for the SyncSocket. This message sends a buffer
122 // on the SyncSocket and then sends a response to the client. 123 // on the SyncSocket and then sends a response to the client.
123 #if defined(OS_WIN) 124 #if defined(OS_WIN)
124 void OnMsgClassSetHandle(const base::SyncSocket::Handle handle) { 125 void OnMsgClassSetHandle(const base::SyncSocket::Handle handle) {
125 SetHandle(handle); 126 SetHandle(handle);
126 } 127 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 class SyncSocketClientListener : public IPC::Channel::Listener { 169 class SyncSocketClientListener : public IPC::Channel::Listener {
169 public: 170 public:
170 SyncSocketClientListener() { 171 SyncSocketClientListener() {
171 } 172 }
172 173
173 void Init(base::SyncSocket* socket, IPC::Channel* chan) { 174 void Init(base::SyncSocket* socket, IPC::Channel* chan) {
174 socket_ = socket; 175 socket_ = socket;
175 chan_ = chan; 176 chan_ = chan;
176 } 177 }
177 178
178 virtual void OnMessageReceived(const IPC::Message& msg) { 179 virtual bool OnMessageReceived(const IPC::Message& msg) {
179 if (msg.routing_id() == MSG_ROUTING_CONTROL) { 180 if (msg.routing_id() == MSG_ROUTING_CONTROL) {
180 IPC_BEGIN_MESSAGE_MAP(SyncSocketClientListener, msg) 181 IPC_BEGIN_MESSAGE_MAP(SyncSocketClientListener, msg)
181 IPC_MESSAGE_HANDLER(MsgClassResponse, OnMsgClassResponse) 182 IPC_MESSAGE_HANDLER(MsgClassResponse, OnMsgClassResponse)
182 IPC_END_MESSAGE_MAP() 183 IPC_END_MESSAGE_MAP()
183 } 184 }
185 return true;
184 } 186 }
185 187
186 private: 188 private:
187 // When a response is received from the server, it sends the same 189 // When a response is received from the server, it sends the same
188 // string as was written on the SyncSocket. These are compared 190 // string as was written on the SyncSocket. These are compared
189 // and a shutdown message is sent back to the server. 191 // and a shutdown message is sent back to the server.
190 void OnMsgClassResponse(const std::string& str) { 192 void OnMsgClassResponse(const std::string& str) {
191 // We rely on the order of sync_socket.Send() and chan_->Send() in 193 // We rely on the order of sync_socket.Send() and chan_->Send() in
192 // the SyncSocketServerListener object. 194 // the SyncSocketServerListener object.
193 EXPECT_EQ(kHelloStringLength, socket_->Peek()); 195 EXPECT_EQ(kHelloStringLength, socket_->Peek());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 #endif // defined(OS_WIN) 244 #endif // defined(OS_WIN)
243 EXPECT_TRUE(chan.Send(msg)); 245 EXPECT_TRUE(chan.Send(msg));
244 // Use the current thread as the I/O thread. 246 // Use the current thread as the I/O thread.
245 MessageLoop::current()->Run(); 247 MessageLoop::current()->Run();
246 // Shut down. 248 // Shut down.
247 delete pair[0]; 249 delete pair[0];
248 delete pair[1]; 250 delete pair[1];
249 EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000)); 251 EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000));
250 base::CloseProcessHandle(server_process); 252 base::CloseProcessHandle(server_process);
251 } 253 }
OLDNEW
« no previous file with comments | « ipc/ipc_tests.cc ('k') | ppapi/proxy/dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698