• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/devtools_android_bridge.h"
14 
15 namespace base {
16 class ListValue;
17 class DictionaryValue;
18 }
19 
20 class DevToolsTargetImpl;
21 class Profile;
22 
23 class DevToolsTargetsUIHandler {
24  public:
25   typedef base::Callback<void(const std::string&,
26                               const base::ListValue&)> Callback;
27   typedef base::Callback<void(DevToolsTargetImpl*)> TargetCallback;
28 
29   DevToolsTargetsUIHandler(const std::string& source_id,
30                            const Callback& callback);
31   virtual ~DevToolsTargetsUIHandler();
32 
source_id()33   std::string source_id() const { return source_id_; }
34 
35   static scoped_ptr<DevToolsTargetsUIHandler> CreateForLocal(
36       const Callback& callback);
37 
38   static scoped_ptr<DevToolsTargetsUIHandler> CreateForAdb(
39       const Callback& callback, Profile* profile);
40 
41   DevToolsTargetImpl* GetTarget(const std::string& target_id);
42 
43   virtual void Open(const std::string& browser_id, const std::string& url,
44                     const TargetCallback& callback);
45 
46   virtual scoped_refptr<content::DevToolsAgentHost> GetBrowserAgentHost(
47       const std::string& browser_id);
48 
49   virtual void ForceUpdate();
50 
51  protected:
52   base::DictionaryValue* Serialize(const DevToolsTargetImpl& target);
53   void SendSerializedTargets(const base::ListValue& list);
54 
55   typedef std::map<std::string, DevToolsTargetImpl*> TargetMap;
56   TargetMap targets_;
57 
58  private:
59   const std::string source_id_;
60   Callback callback_;
61 
62   DISALLOW_COPY_AND_ASSIGN(DevToolsTargetsUIHandler);
63 };
64 
65 class PortForwardingStatusSerializer
66     : private DevToolsAndroidBridge::PortForwardingListener {
67  public:
68   typedef base::Callback<void(const base::Value&)> Callback;
69 
70   PortForwardingStatusSerializer(const Callback& callback, Profile* profile);
71   virtual ~PortForwardingStatusSerializer();
72 
73   virtual void PortStatusChanged(const DevicesStatus&) OVERRIDE;
74 
75  private:
76   Callback callback_;
77   Profile* profile_;
78 };
79 
80 #endif  // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGETS_UI_H_
81