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

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

Issue 284743002: Adding a mojo interface to the mojo spy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 6 years, 7 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/spy/spy_server_impl.h"
6
7 #include "mojo/public/cpp/bindings/allocation_scope.h"
8 #include "mojo/public/cpp/system/core.h"
9
10 namespace {
11
12 bool NextId(uint32_t* out_id) {
13 static uint32_t id = 1;
14 if (!++id)
15 return false;
16 *out_id = id;
17 return true;
18 }
19
20 } // namespace
21
22 namespace mojo {
23
24 struct SpyServerImpl::Item {
25 enum Type {
26 kServiceIntercept,
27 kMessage
28 };
29
30 uint32_t id;
31 Type type;
32
33 Item(uint32_t id, Type type) : id(id), type(type) {}
34 };
35
36 SpyServerImpl::SpyServerImpl() : has_session_(false) {
37 BindToPipe(this, pipe_.handle0.Pass());
38 }
39
40 void SpyServerImpl::StartSession(
41 const spy_api::Version& version,
42 const mojo::Callback<void(spy_api::Result, mojo::String)>& callback) {
43 AllocationScope scope;
44 if (has_session_) {
45 callback.Run(spy_api::RESOURCE_LIMIT, "");
46 return;
47 }
48 callback.Run(spy_api::ALL_OK, "session 0");
49 has_session_ = true;
50 }
51
52 void SpyServerImpl::StopSession(
53 const mojo::Callback<void(spy_api::Result)>& callback) {
54 AllocationScope scope;
55 if (!has_session_) {
56 callback.Run(spy_api::INVALID_CALL);
57 return;
58 }
59 callback.Run(spy_api::ALL_OK);
60 has_session_ = false;
61 }
62
63 void SpyServerImpl::TrackConnection(
64 uint32_t id,
65 spy_api::ConnectionOptions options,
66 const mojo::Callback<void(spy_api::Result)>& callback) {
67 }
68
69 void SpyServerImpl::OnConnectionError() {
70 // Pipe got disconnected.
71 }
72
73 void SpyServerImpl::OnIntercept(GURL url) {
darin (slow to review) 2014/05/17 02:37:58 nit: |const GURL&|
cpu_(ooo_6.6-7.5) 2014/05/19 20:09:34 Done.
74 if (!has_session_)
75 return;
76
77 AllocationScope scope;
78 uint32_t id;
79 if (!NextId(&id)) {
80 client()->FatalError(spy_api::NO_MORE_IDS);
darin (slow to review) 2014/05/17 02:37:58 is this something you plan to mitigate later or do
cpu_(ooo_6.6-7.5) 2014/05/19 20:09:34 It is an interesting question. In theory the front
81 return;
82 }
83
84 items_[id] = new Item(id, Item::kServiceIntercept);
85 client()->OnClientConnection(
86 url.possibly_invalid_spec(), id, spy_api::PEEK_MESSAGES);
87 }
88
89 ScopedMessagePipeHandle SpyServerImpl::ServerPipe() {
90 return ScopedMessagePipeHandle(pipe_.handle1.Pass()).Pass();
91 }
92
93 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698