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_
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"
22 class DevToolsAgentHost
;
26 // This class is a singleton that manage global DevTools state for the whole
28 class CONTENT_EXPORT DevToolsManager
{
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
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();
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
);
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_
;
75 DISALLOW_COPY_AND_ASSIGN(DevToolsManager
);
78 } // namespace content
80 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_H_