1 // Copyright (c) 2013 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_RENDERER_STATE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_RENDERER_STATE_H_
13 #include "base/basictypes.h"
14 #include "base/memory/singleton.h"
17 class ResourceRequestInfo
;
20 // This class keeps track of renderer state for use on the IO thread. All
21 // methods should be called on the IO thread except for Init and Shutdown.
22 class ExtensionRendererState
{
24 static ExtensionRendererState
* GetInstance();
26 // These are called on the UI thread to start and stop listening to tab
31 // Looks up the tab and window ID for a given request. Returns true if we have
32 // the IDs in our map. Called on the IO thread.
33 bool GetTabAndWindowId(
34 const content::ResourceRequestInfo
* info
, int* tab_id
, int* window_id
);
37 class RenderViewHostObserver
;
39 friend class TabObserver
;
40 friend struct DefaultSingletonTraits
<ExtensionRendererState
>;
42 typedef std::pair
<int, int> RenderId
;
43 typedef std::pair
<int, int> TabAndWindowId
;
44 typedef std::map
<RenderId
, TabAndWindowId
> TabAndWindowIdMap
;
46 ExtensionRendererState();
47 ~ExtensionRendererState();
49 // Adds or removes a render view from our map.
50 void SetTabAndWindowId(
51 int render_process_host_id
, int routing_id
, int tab_id
, int window_id
);
52 void ClearTabAndWindowId(
53 int render_process_host_id
, int routing_id
);
55 TabObserver
* observer_
;
56 TabAndWindowIdMap map_
;
58 DISALLOW_COPY_AND_ASSIGN(ExtensionRendererState
);
61 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_RENDERER_STATE_H_