Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / browser / devtools / devtools_manager.h
blobcaedf01f9dfcb7816f8581eac6cf42603007c8f7
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_H_
6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_H_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
13 #include "base/cancelable_callback.h"
14 #include "base/compiler_specific.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"
20 namespace content {
22 class DevToolsAgentHost;
23 class RenderViewHost;
24 class WebContents;
26 // This class is a singleton that manage global DevTools state for the whole
27 // browser.
28 class CONTENT_EXPORT DevToolsManager {
29 public:
30 class Observer {
31 public:
32 virtual ~Observer() {}
34 typedef DevToolsManagerDelegate::TargetList TargetList;
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) {}
42 // Returns single instance of this class. The instance is destroyed on the
43 // browser main loop exit so this method MUST NOT be called after that point.
44 static DevToolsManager* GetInstance();
46 DevToolsManager();
47 virtual ~DevToolsManager();
49 DevToolsManagerDelegate* delegate() const { return delegate_.get(); }
51 void AddObserver(Observer* observer);
52 void RemoveObserver(Observer* observer);
54 void RenderViewCreated(WebContents* web_contents, RenderViewHost* rvh);
55 void AgentHostChanged(scoped_refptr<DevToolsAgentHost> agent_host);
57 typedef base::Callback<void(base::Closure)> Scheduler;
58 void SetUpForTest(Scheduler scheduler);
60 private:
61 friend struct DefaultSingletonTraits<DevToolsManager>;
63 void UpdateTargetList();
64 void UpdateTargetListThrottled();
65 void NotifyTargetListChanged(const Observer::TargetList& targets);
67 scoped_ptr<DevToolsManagerDelegate> delegate_;
68 ObserverList<Observer> observer_list_;
69 std::set<DevToolsAgentHost*> attached_hosts_;
70 bool update_target_list_required_;
71 bool update_target_list_scheduled_;
72 base::CancelableClosure update_target_list_callback_;
73 Scheduler scheduler_;
75 DISALLOW_COPY_AND_ASSIGN(DevToolsManager);
78 } // namespace content
80 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_H_