summaryrefslogtreecommitdiffstats
path: root/chrome/browser/devtools/devtools_targets_ui.h
blob: fbe96ed42f9057e0df816a3c3ca2b8cadb6a5efd (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2013 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 CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGETS_UI_H_
#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGETS_UI_H_

#include <map>
#include <string>

#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/devtools/device/devtools_android_bridge.h"

namespace base {
class ListValue;
class DictionaryValue;
}

class DevToolsTargetImpl;
class Profile;

class DevToolsTargetsUIHandler {
 public:
  typedef base::Callback<void(const std::string&,
                              const base::ListValue&)> Callback;
  typedef base::Callback<void(DevToolsTargetImpl*)> TargetCallback;

  DevToolsTargetsUIHandler(const std::string& source_id,
                           const Callback& callback);
  virtual ~DevToolsTargetsUIHandler();

  std::string source_id() const { return source_id_; }

  static scoped_ptr<DevToolsTargetsUIHandler> CreateForLocal(
      const Callback& callback);

  static scoped_ptr<DevToolsTargetsUIHandler> CreateForAdb(
      const Callback& callback, Profile* profile);

  DevToolsTargetImpl* GetTarget(const std::string& target_id);

  virtual void Open(const std::string& browser_id, const std::string& url,
                    const TargetCallback& callback);

  virtual scoped_refptr<content::DevToolsAgentHost> GetBrowserAgentHost(
      const std::string& browser_id);

  virtual void ForceUpdate();

 protected:
  base::DictionaryValue* Serialize(const DevToolsTargetImpl& target);
  void SendSerializedTargets(const base::ListValue& list);

  typedef std::map<std::string, DevToolsTargetImpl*> TargetMap;
  TargetMap targets_;

 private:
  const std::string source_id_;
  Callback callback_;

  DISALLOW_COPY_AND_ASSIGN(DevToolsTargetsUIHandler);
};

class PortForwardingStatusSerializer
    : private DevToolsAndroidBridge::PortForwardingListener {
 public:
  typedef base::Callback<void(const base::Value&)> Callback;

  PortForwardingStatusSerializer(const Callback& callback, Profile* profile);
  ~PortForwardingStatusSerializer() override;

  void PortStatusChanged(const ForwardingStatus& status) override;

 private:
  Callback callback_;
  Profile* profile_;
};

#endif  // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGETS_UI_H_