blob: dc2845613af67fbb253ab531e323bd4db4c28e94 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DEVTOOLS_MANAGER_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_DEVTOOLS_MANAGER_H_
#pragma once
#include <map>
#include <set>
#include <string>
#include "base/linked_ptr.h"
#include "base/ref_counted.h"
class ExtensionDevToolsBridge;
class MessageLoop;
class Profile;
// This class manages the lifetimes of ExtensionDevToolsBridge objects.
// The manager is owned by the Profile.
//
// The lifetime of an ExtensionDevToolsBridge object is determined by:
// * the existence of registered event handlers for the bridge's tab
// * the lifetime of the inspected tab
//
// The manager is alerted whenever an event listener is added or removed and
// keeps track of the set of renderers with event listeners registered for each
// tab. A new bridge object is created for a tab when the first event listener
// is registered on that tab. A bridge object is destroyed when all event
// listeners are removed, the inspected tab closes, or when the manager itself
// is destroyed.
class ExtensionDevToolsManager
: public base::RefCountedThreadSafe<ExtensionDevToolsManager> {
public:
// UI thread only:
explicit ExtensionDevToolsManager(Profile* profile);
void AddEventListener(const std::string& event_name,
int render_process_id);
void RemoveEventListener(const std::string& event_name,
int render_process_id);
void BridgeClosingForTab(int tab_id);
private:
friend class base::RefCountedThreadSafe<ExtensionDevToolsManager>;
~ExtensionDevToolsManager();
// Map of tab IDs to the ExtensionDevToolsBridge connected to the tab
std::map<int, linked_ptr<ExtensionDevToolsBridge> > tab_id_to_bridge_;
// Map of tab IDs to the set of render_process_ids that have registered
// event handlers for the tab.
std::map<int, std::set<int> > tab_id_to_render_process_ids_;
Profile* profile_;
MessageLoop* ui_loop_;
DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsManager);
};
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DEVTOOLS_MANAGER_H_
|