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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: mojo/spy/spy_server_impl.cc
diff --git a/mojo/spy/spy_server_impl.cc b/mojo/spy/spy_server_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e79b187bdf8c85e07c9e6ba1312003dd8366fb20
--- /dev/null
+++ b/mojo/spy/spy_server_impl.cc
@@ -0,0 +1,93 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/spy/spy_server_impl.h"
+
+#include "mojo/public/cpp/bindings/allocation_scope.h"
+#include "mojo/public/cpp/system/core.h"
+
+namespace {
+
+bool NextId(uint32_t* out_id) {
+ static uint32_t id = 1;
+ if (!++id)
+ return false;
+ *out_id = id;
+ return true;
+}
+
+} // namespace
+
+namespace mojo {
+
+struct SpyServerImpl::Item {
+ enum Type {
+ kServiceIntercept,
+ kMessage
+ };
+
+ uint32_t id;
+ Type type;
+
+ Item(uint32_t id, Type type) : id(id), type(type) {}
+};
+
+SpyServerImpl::SpyServerImpl() : has_session_(false) {
+ BindToPipe(this, pipe_.handle0.Pass());
+}
+
+void SpyServerImpl::StartSession(
+ const spy_api::Version& version,
+ const mojo::Callback<void(spy_api::Result, mojo::String)>& callback) {
+ AllocationScope scope;
+ if (has_session_) {
+ callback.Run(spy_api::RESOURCE_LIMIT, "");
+ return;
+ }
+ callback.Run(spy_api::ALL_OK, "session 0");
+ has_session_ = true;
+}
+
+void SpyServerImpl::StopSession(
+ const mojo::Callback<void(spy_api::Result)>& callback) {
+ AllocationScope scope;
+ if (!has_session_) {
+ callback.Run(spy_api::INVALID_CALL);
+ return;
+ }
+ callback.Run(spy_api::ALL_OK);
+ has_session_ = false;
+}
+
+void SpyServerImpl::TrackConnection(
+ uint32_t id,
+ spy_api::ConnectionOptions options,
+ const mojo::Callback<void(spy_api::Result)>& callback) {
+}
+
+void SpyServerImpl::OnConnectionError() {
+ // Pipe got disconnected.
+}
+
+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.
+ if (!has_session_)
+ return;
+
+ AllocationScope scope;
+ uint32_t id;
+ if (!NextId(&id)) {
+ 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
+ return;
+ }
+
+ items_[id] = new Item(id, Item::kServiceIntercept);
+ client()->OnClientConnection(
+ url.possibly_invalid_spec(), id, spy_api::PEEK_MESSAGES);
+}
+
+ScopedMessagePipeHandle SpyServerImpl::ServerPipe() {
+ return ScopedMessagePipeHandle(pipe_.handle1.Pass()).Pass();
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698