OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_ID_MAP_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_ID_MAP_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_ID_MAP_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_ID_MAP_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 | 13 |
14 // This class keeps track of a map between renderer IDs and tab/window IDs, for | 14 // This class keeps track of a map between renderer IDs and tab/window IDs, for |
15 // use on the IO thread. All methods should be called on the IO thread except | 15 // use on the IO thread. All methods should be called on the IO thread except |
16 // for Init and Shutdown. | 16 // for Init and Shutdown. |
17 class ExtensionTabIdMap { | 17 class ExtensionTabIdMap { |
18 public: | 18 public: |
19 static ExtensionTabIdMap* GetInstance(); | 19 static ExtensionTabIdMap* GetInstance(); |
20 | 20 |
21 // These are called on the UI thread to start and stop listening to tab | 21 // These are called on the UI thread to start and stop listening to tab |
22 // notifications. | 22 // notifications. |
23 void Init(); | 23 void Init(); |
24 void Shutdown(); | 24 void Shutdown(); |
25 | 25 |
26 // Looks up the tab and window ID for a given render view. Returns true | 26 // Looks up the tab and window ID for a given render view. Returns true |
27 // if we have the IDs in our map. Called on the IO thread. | 27 // if we have the IDs in our map. Called on the IO thread. |
28 bool GetTabAndWindowId( | 28 bool GetTabAndWindowId( |
29 int render_process_host_id, int routing_id, int* tab_id, int* window_id); | 29 int render_process_host_id, int routing_id, int* tab_id, int* window_id); |
| 30 bool GetProcessAndRoutingId( |
| 31 int tab_id, int* render_process_host_id, int* routing_id); |
30 | 32 |
31 private: | 33 private: |
32 class TabObserver; | 34 class TabObserver; |
33 friend class TabObserver; | 35 friend class TabObserver; |
34 friend struct DefaultSingletonTraits<ExtensionTabIdMap>; | 36 friend struct DefaultSingletonTraits<ExtensionTabIdMap>; |
35 | 37 |
36 typedef std::pair<int, int> RenderId; | 38 typedef std::pair<int, int> RenderId; |
37 typedef std::pair<int, int> TabAndWindowId; | 39 typedef std::pair<int, int> TabAndWindowId; |
38 typedef std::map<RenderId, TabAndWindowId> TabAndWindowIdMap; | 40 typedef std::map<RenderId, TabAndWindowId> TabAndWindowIdMap; |
39 | 41 |
40 ExtensionTabIdMap(); | 42 ExtensionTabIdMap(); |
41 ~ExtensionTabIdMap(); | 43 ~ExtensionTabIdMap(); |
42 | 44 |
43 // Adds or removes a render view from our map. | 45 // Adds or removes a render view from our map. |
44 void SetTabAndWindowId( | 46 void SetTabAndWindowId( |
45 int render_process_host_id, int routing_id, int tab_id, int window_id); | 47 int render_process_host_id, int routing_id, int tab_id, int window_id); |
46 void ClearTabAndWindowId( | 48 void ClearTabAndWindowId( |
47 int render_process_host_id, int routing_id); | 49 int render_process_host_id, int routing_id); |
48 | 50 |
49 TabObserver* observer_; | 51 TabObserver* observer_; |
50 TabAndWindowIdMap map_; | 52 TabAndWindowIdMap map_; |
51 | 53 |
52 DISALLOW_COPY_AND_ASSIGN(ExtensionTabIdMap); | 54 DISALLOW_COPY_AND_ASSIGN(ExtensionTabIdMap); |
53 }; | 55 }; |
54 | 56 |
55 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_ID_MAP_H_ | 57 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_ID_MAP_H_ |
OLD | NEW |