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.
5 #include "mojo/spy/spy_server_impl.h"
7 #include "mojo/public/cpp/system/core.h"
11 bool NextId(uint32_t* out_id
) {
12 static uint32_t id
= 1;
23 struct SpyServerImpl::Item
{
32 Item(uint32_t id
, Type type
) : id(id
), type(type
) {}
35 SpyServerImpl::SpyServerImpl() : has_session_(false) {
36 BindToPipe(this, pipe_
.handle0
.Pass());
39 SpyServerImpl::~SpyServerImpl() {
42 void SpyServerImpl::StartSession(
43 spy_api::VersionPtr version
,
44 const mojo::Callback
<void(spy_api::Result
, mojo::String
)>& callback
) {
46 callback
.Run(spy_api::RESULT_RESOURCE_LIMIT
, "");
49 callback
.Run(spy_api::RESULT_ALL_OK
, "session 0");
53 void SpyServerImpl::StopSession(
54 const mojo::Callback
<void(spy_api::Result
)>& callback
) {
56 callback
.Run(spy_api::RESULT_INVALID_CALL
);
59 callback
.Run(spy_api::RESULT_ALL_OK
);
63 void SpyServerImpl::TrackConnection(
65 spy_api::ConnectionOptions options
,
66 const mojo::Callback
<void(spy_api::Result
)>& callback
) {
69 void SpyServerImpl::OnConnectionError() {
70 // Pipe got disconnected.
73 void SpyServerImpl::OnIntercept(const GURL
& url
) {
78 client()->OnFatalError(spy_api::RESULT_NO_MORE_IDS
);
82 items_
[id
] = new Item(id
, Item::kServiceIntercept
);
83 client()->OnClientConnection(url
.possibly_invalid_spec(),
85 spy_api::CONNECTION_OPTIONS_PEEK_MESSAGES
);
88 ScopedMessagePipeHandle
SpyServerImpl::ServerPipe() {
89 return ScopedMessagePipeHandle(pipe_
.handle1
.Pass()).Pass();