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

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

Issue 379753002: Redo: Adding a mojo interface to the mojo spy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bindings clash fix 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 | « mojo/spy/spy_server_impl.h ('k') | mojo/spy/websocket_server.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/system/core.h"
8
9 namespace {
10
11 bool NextId(uint32_t* out_id) {
12 static uint32_t id = 1;
13 if (!++id)
14 return false;
15 *out_id = id;
16 return true;
17 }
18
19 } // namespace
20
21 namespace mojo {
22
23 struct SpyServerImpl::Item {
24 enum Type {
25 kServiceIntercept,
26 kMessage
27 };
28
29 uint32_t id;
30 Type type;
31
32 Item(uint32_t id, Type type) : id(id), type(type) {}
33 };
34
35 SpyServerImpl::SpyServerImpl() : has_session_(false) {
36 BindToPipe(this, pipe_.handle0.Pass());
37 }
38
39 SpyServerImpl::~SpyServerImpl() {
40 }
41
42 void SpyServerImpl::StartSession(
43 spy_api::VersionPtr version,
44 const mojo::Callback<void(spy_api::Result, mojo::String)>& callback) {
45 if (has_session_) {
46 callback.Run(spy_api::RESOURCE_LIMIT, "");
47 return;
48 }
49 callback.Run(spy_api::ALL_OK, "session 0");
50 has_session_ = true;
51 }
52
53 void SpyServerImpl::StopSession(
54 const mojo::Callback<void(spy_api::Result)>& callback) {
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(const GURL& url) {
74 if (!has_session_)
75 return;
76 uint32_t id;
77 if (!NextId(&id)) {
78 client()->OnFatalError(spy_api::NO_MORE_IDS);
79 return;
80 }
81
82 items_[id] = new Item(id, Item::kServiceIntercept);
83 client()->OnClientConnection(
84 url.possibly_invalid_spec(), id, spy_api::PEEK_MESSAGES);
85 }
86
87 ScopedMessagePipeHandle SpyServerImpl::ServerPipe() {
88 return ScopedMessagePipeHandle(pipe_.handle1.Pass()).Pass();
89 }
90
91 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/spy/spy_server_impl.h ('k') | mojo/spy/websocket_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698