12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_RENDERER_STATE_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_EXTENSIONS_EXTENSION_RENDERER_STATE_H_ 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <map> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <set> 104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include <string> 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <utility> 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/basictypes.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/singleton.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace content { 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class ResourceRequestInfo; 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This class keeps track of renderer state for use on the IO thread. All 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// methods should be called on the IO thread except for Init and Shutdown. 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ExtensionRendererState { 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static ExtensionRendererState* GetInstance(); 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // These are called on the UI thread to start and stop listening to tab 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // notifications. 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void Init(); 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void Shutdown(); 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Looks up the tab and window ID for a given request. Returns true if we have 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // the IDs in our map. Called on the IO thread. 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool GetTabAndWindowId( 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const content::ResourceRequestInfo* info, int* tab_id, int* window_id); 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) class RenderViewHostObserver; 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) class TabObserver; 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) friend class TabObserver; 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) friend struct DefaultSingletonTraits<ExtensionRendererState>; 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) typedef std::pair<int, int> RenderId; 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) typedef std::pair<int, int> TabAndWindowId; 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) typedef std::map<RenderId, TabAndWindowId> TabAndWindowIdMap; 456d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ExtensionRendererState(); 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ~ExtensionRendererState(); 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Adds or removes a render view from our map. 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetTabAndWindowId( 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int render_process_host_id, int routing_id, int tab_id, int window_id); 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void ClearTabAndWindowId( 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int render_process_host_id, int routing_id); 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TabObserver* observer_; 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TabAndWindowIdMap map_; 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ExtensionRendererState); 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_RENDERER_STATE_H_ 62