summaryrefslogtreecommitdiffstats
path: root/mojo/spy/spy_server_impl.h
blob: 368e69a96097c1f2748903a6f2d4e50837c7b966 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// 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.

#ifndef MOJO_SPY_SPY_SERVER_IMPL_H_
#define MOJO_SPY_SPY_SERVER_IMPL_H_

#include <map>

#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/spy/public/spy.mojom.h"
#include "url/gurl.h"

namespace mojo {

class SpyServerImpl :
    public base::RefCounted<SpyServerImpl>,
    public InterfaceImpl<spy_api::SpyServer> {
 public:
  SpyServerImpl();

  // spy_api::SpyServer implementation.
  virtual void StartSession(
      spy_api::VersionPtr version,
      const mojo::Callback<void(spy_api::Result,
                                mojo::String)>& callback) OVERRIDE;

  virtual void StopSession(
      const mojo::Callback<void(spy_api::Result)>& callback) OVERRIDE;

  virtual void TrackConnection(
      uint32_t id,
      spy_api::ConnectionOptions options,
      const mojo::Callback<void(spy_api::Result)>& callback) OVERRIDE;

  virtual void OnConnectionError() OVERRIDE;

  // SpyServerImpl own methods.
  void OnIntercept(const GURL& url);

  ScopedMessagePipeHandle ServerPipe();

 private:
  friend class base::RefCounted<SpyServerImpl>;
  virtual ~SpyServerImpl();

  // Item models the entities that we track by IDs.
  struct Item;

  MessagePipe pipe_;
  bool has_session_;
  std::map<uint32_t, Item*> items_;
};

}  // namespace mojo

#endif  // MOJO_SPY_SPY_SERVER_IMPL_H_