devtools_targets_ui.h revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
1// Copyright 2013 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#ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGETS_UI_H_
6#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGETS_UI_H_
7
8#include <map>
9#include <string>
10
11#include "base/callback.h"
12#include "base/memory/scoped_ptr.h"
13#include "chrome/browser/devtools/device/port_forwarding_controller.h"
14
15namespace base {
16class ListValue;
17class DictionaryValue;
18}
19
20class DevToolsTargetImpl;
21class Profile;
22
23class DevToolsTargetsUIHandler {
24 public:
25  typedef base::Callback<void(const std::string&,
26                              scoped_ptr<base::ListValue>)> Callback;
27  typedef base::Callback<void(DevToolsTargetImpl*)> TargetCallback;
28
29  DevToolsTargetsUIHandler(const std::string& source_id, Callback callback);
30  virtual ~DevToolsTargetsUIHandler();
31
32  std::string source_id() const { return source_id_; }
33
34  static scoped_ptr<DevToolsTargetsUIHandler> CreateForRenderers(
35      Callback callback);
36
37  static scoped_ptr<DevToolsTargetsUIHandler> CreateForWorkers(
38      Callback callback);
39
40  static scoped_ptr<DevToolsTargetsUIHandler> CreateForAdb(
41      Callback callback, Profile* profile);
42
43  DevToolsTargetImpl* GetTarget(const std::string& target_id);
44
45  virtual void Open(const std::string& browser_id, const std::string& url,
46                    const TargetCallback& callback);
47
48 protected:
49  base::DictionaryValue* Serialize(const DevToolsTargetImpl& target);
50  void SendSerializedTargets(scoped_ptr<base::ListValue> list);
51
52  typedef std::map<std::string, DevToolsTargetImpl*> TargetMap;
53  TargetMap targets_;
54
55 private:
56  const std::string source_id_;
57  Callback callback_;
58
59  DISALLOW_COPY_AND_ASSIGN(DevToolsTargetsUIHandler);
60};
61
62class PortForwardingStatusSerializer
63    : private PortForwardingController::Listener {
64 public:
65  typedef base::Callback<void(const base::Value&)> Callback;
66
67  PortForwardingStatusSerializer(const Callback& callback, Profile* profile);
68  virtual ~PortForwardingStatusSerializer();
69
70  virtual void PortStatusChanged(const DevicesStatus&) OVERRIDE;
71
72 private:
73  Callback callback_;
74  Profile* profile_;
75};
76
77#endif  // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGETS_UI_H_
78