OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_H_ |
6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <set> |
9 #include <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
| 13 #include "base/cancelable_callback.h" |
12 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
13 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 16 #include "base/observer_list.h" |
| 17 #include "content/common/content_export.h" |
| 18 #include "content/public/browser/devtools_manager_delegate.h" |
14 | 19 |
15 namespace content { | 20 namespace content { |
16 | 21 |
17 class DevToolsManagerDelegate; | 22 class DevToolsAgentHost; |
| 23 class RenderViewHost; |
| 24 class WebContents; |
18 | 25 |
19 // This class is a singleton that manage global DevTools state for the whole | 26 // This class is a singleton that manage global DevTools state for the whole |
20 // browser. | 27 // browser. |
21 class DevToolsManager { | 28 class CONTENT_EXPORT DevToolsManager { |
22 public: | 29 public: |
| 30 class Observer { |
| 31 public: |
| 32 virtual ~Observer() {} |
| 33 |
| 34 typedef DevToolsManagerDelegate::TargetList TargetList; |
| 35 |
| 36 // Called when any target information changed. Targets in the list are |
| 37 // owned by DevToolsManager, so they should not be accessed outside of |
| 38 // this method. |
| 39 virtual void TargetListChanged(const TargetList& targets) {} |
| 40 }; |
| 41 |
23 // Returns single instance of this class. The instance is destroyed on the | 42 // Returns single instance of this class. The instance is destroyed on the |
24 // browser main loop exit so this method MUST NOT be called after that point. | 43 // browser main loop exit so this method MUST NOT be called after that point. |
25 static DevToolsManager* GetInstance(); | 44 static DevToolsManager* GetInstance(); |
26 | 45 |
27 DevToolsManager(); | 46 DevToolsManager(); |
28 virtual ~DevToolsManager(); | 47 virtual ~DevToolsManager(); |
29 | 48 |
30 DevToolsManagerDelegate* delegate() const { return delegate_.get(); } | 49 DevToolsManagerDelegate* delegate() const { return delegate_.get(); } |
31 void OnClientAttached(); | 50 |
32 void OnClientDetached(); | 51 void AddObserver(Observer* observer); |
| 52 void RemoveObserver(Observer* observer); |
| 53 |
| 54 void RenderViewCreated(WebContents* web_contents, RenderViewHost* rvh); |
| 55 void AgentHostChanged(scoped_refptr<DevToolsAgentHost> agent_host); |
| 56 |
| 57 static void SetObserverThrottleIntervalForTest(base::TimeDelta interval); |
33 | 58 |
34 private: | 59 private: |
35 friend struct DefaultSingletonTraits<DevToolsManager>; | 60 friend struct DefaultSingletonTraits<DevToolsManager>; |
36 | 61 |
| 62 void UpdateTargetList(); |
| 63 void UpdateTargetListThrottled(); |
| 64 void NotifyTargetListChanged(const Observer::TargetList& targets); |
| 65 |
37 scoped_ptr<DevToolsManagerDelegate> delegate_; | 66 scoped_ptr<DevToolsManagerDelegate> delegate_; |
38 int client_count_; | 67 ObserverList<Observer> observer_list_; |
| 68 std::set<DevToolsAgentHost*> attached_hosts_; |
| 69 bool update_target_list_required_; |
| 70 bool update_target_list_scheduled_; |
| 71 base::CancelableClosure update_target_list_callback_; |
| 72 |
| 73 static base::TimeDelta observer_throttle_interval_; |
39 | 74 |
40 DISALLOW_COPY_AND_ASSIGN(DevToolsManager); | 75 DISALLOW_COPY_AND_ASSIGN(DevToolsManager); |
41 }; | 76 }; |
42 | 77 |
43 } // namespace content | 78 } // namespace content |
44 | 79 |
45 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_H_ | 80 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_H_ |
OLD | NEW |