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

Side by Side Diff: mojo/spy/spy.cc

Issue 391233002: Add support in mojo to check if a MojoHandle identifies a message pipe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use MojoReadMessage to identify a message pipe. Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "mojo/spy/spy.h" 5 #include "mojo/spy/spy.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 28 matching lines...) Expand all
39 } 39 }
40 40
41 // In charge of processing messages that flow over a 41 // In charge of processing messages that flow over a
42 // single message pipe. 42 // single message pipe.
43 class MessageProcessor : 43 class MessageProcessor :
44 public base::RefCountedThreadSafe<MessageProcessor> { 44 public base::RefCountedThreadSafe<MessageProcessor> {
45 public: 45 public:
46 MessageProcessor(base::MessageLoopProxy* control_loop_proxy) 46 MessageProcessor(base::MessageLoopProxy* control_loop_proxy)
47 : last_result_(MOJO_RESULT_OK), 47 : last_result_(MOJO_RESULT_OK),
48 bytes_transfered_(0), 48 bytes_transfered_(0),
49 control_loop_proxy_(control_loop_proxy), 49 control_loop_proxy_(control_loop_proxy) {
50 service_vendor_message_pipe_received_(false) {
51 message_count_[0] = 0; 50 message_count_[0] = 0;
52 message_count_[1] = 0; 51 message_count_[1] = 0;
53 handle_count_[0] = 0; 52 handle_count_[0] = 0;
54 handle_count_[1] = 0; 53 handle_count_[1] = 0;
55 } 54 }
56 55
57 void Start(mojo::ScopedMessagePipeHandle client, 56 void Start(mojo::ScopedMessagePipeHandle client,
58 mojo::ScopedMessagePipeHandle interceptor, 57 mojo::ScopedMessagePipeHandle interceptor,
59 const GURL& url) { 58 const GURL& url) {
60 std::vector<mojo::MessagePipeHandle> pipes; 59 std::vector<mojo::MessagePipeHandle> pipes;
(...skipping 28 matching lines...) Expand all
89 hbuf.get(), &handles_read, 88 hbuf.get(), &handles_read,
90 MOJO_READ_MESSAGE_FLAG_NONE))) 89 MOJO_READ_MESSAGE_FLAG_NONE)))
91 break; 90 break;
92 91
93 if (!bytes_read && !handles_read) 92 if (!bytes_read && !handles_read)
94 continue; 93 continue;
95 94
96 if (handles_read) { 95 if (handles_read) {
97 handle_count_[r] += handles_read; 96 handle_count_[r] += handles_read;
98 97
99 // Intercept the first set of handles to message pipes with the 98 // Intercept message pipes which are returned via the ReadMessageRaw
100 // assumption that these would be used for vending mojo services. 99 // call
101 // TODO(ananta) 100 for (uint32_t i = 0; i < handles_read; i++) {
102 // The above approach is hacky and could cause us to miss other message 101 // Hack to determine if a handle is a message pipe.
103 // pipes which could be exchanged between the client and the server. 102 // TODO(ananta)
104 // Look into a cleaner way of identifying message pipe handles. 103 // We should have an API which given a handle returns its type.
105 if (!service_vendor_message_pipe_received_) { 104 if (MojoReadMessage(hbuf[i], NULL, NULL, NULL, NULL,
106 service_vendor_message_pipe_received_ = true; 105 MOJO_READ_MESSAGE_FLAG_NONE) ==
107 for (uint32_t i = 0; i < handles_read; i++) { 106 MOJO_RESULT_RESOURCE_EXHAUSTED) {
viettrungluu 2014/07/16 02:40:48 I believe it'll return MOJO_RESULT_SHOULD_WAIT if
ananta 2014/07/16 21:06:05 Checked that. It returns MOJO_RESULT_SHOULD_WAIT o
108 mojo::ScopedMessagePipeHandle message_pipe_handle; 107 mojo::ScopedMessagePipeHandle message_pipe_handle;
109 message_pipe_handle.reset(mojo::MessagePipeHandle(hbuf[i])); 108 message_pipe_handle.reset(mojo::MessagePipeHandle(hbuf[i]));
110 109
111 mojo::ScopedMessagePipeHandle faux_client; 110 mojo::ScopedMessagePipeHandle faux_client;
112 mojo::ScopedMessagePipeHandle interceptor; 111 mojo::ScopedMessagePipeHandle interceptor;
113 CreateMessagePipe(NULL, &faux_client, &interceptor); 112 CreateMessagePipe(NULL, &faux_client, &interceptor);
114 113
115 base::WorkerPool::PostTask( 114 base::WorkerPool::PostTask(
116 FROM_HERE, 115 FROM_HERE,
117 base::Bind(&MessageProcessor::Start, 116 base::Bind(&MessageProcessor::Start,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 base::Unretained(ws_server), 211 base::Unretained(ws_server),
213 message_data->header, url, base::Time::Now())); 212 message_data->header, url, base::Time::Now()));
214 } 213 }
215 } 214 }
216 215
217 MojoResult last_result_; 216 MojoResult last_result_;
218 uint32_t bytes_transfered_; 217 uint32_t bytes_transfered_;
219 uint32_t message_count_[2]; 218 uint32_t message_count_[2];
220 uint32_t handle_count_[2]; 219 uint32_t handle_count_[2];
221 scoped_refptr<base::MessageLoopProxy> control_loop_proxy_; 220 scoped_refptr<base::MessageLoopProxy> control_loop_proxy_;
222 // This flag helps us intercept the first message pipe exchanged between
223 // the client and the service vendor.
224 bool service_vendor_message_pipe_received_;
225 }; 221 };
226 222
227 // In charge of intercepting access to the service manager. 223 // In charge of intercepting access to the service manager.
228 class SpyInterceptor : public mojo::ServiceManager::Interceptor { 224 class SpyInterceptor : public mojo::ServiceManager::Interceptor {
229 public: 225 public:
230 explicit SpyInterceptor(scoped_refptr<mojo::SpyServerImpl> spy_server, 226 explicit SpyInterceptor(scoped_refptr<mojo::SpyServerImpl> spy_server,
231 base::MessageLoopProxy* control_loop_proxy) 227 base::MessageLoopProxy* control_loop_proxy)
232 : spy_server_(spy_server), 228 : spy_server_(spy_server),
233 proxy_(base::MessageLoopProxy::current()), 229 proxy_(base::MessageLoopProxy::current()),
234 control_loop_proxy_(control_loop_proxy){ 230 control_loop_proxy_(control_loop_proxy){
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 service_manager->SetInterceptor(new SpyInterceptor( 327 service_manager->SetInterceptor(new SpyInterceptor(
332 spy_server_, control_thread_->message_loop_proxy())); 328 spy_server_, control_thread_->message_loop_proxy()));
333 } 329 }
334 330
335 Spy::~Spy() { 331 Spy::~Spy() {
336 // TODO(cpu): Do not leak the interceptor. Lifetime between the 332 // TODO(cpu): Do not leak the interceptor. Lifetime between the
337 // service_manager and the spy is still unclear hence the leak. 333 // service_manager and the spy is still unclear hence the leak.
338 } 334 }
339 335
340 } // namespace mojo 336 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698