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. 4 5 #ifndef CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_LIST_H_ 6 #define CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_LIST_H_ 7 8 #include <list> 9 10 #include "base/compiler_specific.h" 11 #include "base/memory/singleton.h" 12 #include "base/observer_list.h" 13 #include "chrome/browser/extensions/window_controller.h" 14 15 class Profile; 16 class ChromeAsyncExtensionFunction; 17 18 namespace extensions { 19 20 class WindowControllerListObserver; 21 22 // Class to maintain a list of WindowControllers. 23 class WindowControllerList { 24 public: 25 typedef std::list<WindowController*> ControllerList; 26 27 WindowControllerList(); 28 ~WindowControllerList(); 29 30 void AddExtensionWindow(WindowController* window); 31 void RemoveExtensionWindow(WindowController* window); 32 33 void AddObserver(WindowControllerListObserver* observer); 34 void RemoveObserver(WindowControllerListObserver* observer); 35 36 // Returns a window matching |id|. 37 WindowController* FindWindowById(int id) const; 38 39 // Returns a window matching the context the function was invoked in. 40 WindowController* FindWindowForFunctionById( 41 const ChromeAsyncExtensionFunction* function, 42 int id) const; 43 44 // Returns the focused or last added window matching the context the function 45 // was invoked in. 46 WindowController* CurrentWindowForFunction( 47 const ChromeAsyncExtensionFunction* function) const; 48 windows()49 const ControllerList& windows() const { return windows_; } 50 51 static WindowControllerList* GetInstance(); 52 53 private: 54 friend struct DefaultSingletonTraits<WindowControllerList>; 55 56 // Entries are not owned by this class and must be removed when destroyed. 57 ControllerList windows_; 58 59 ObserverList<WindowControllerListObserver> observers_; 60 61 DISALLOW_COPY_AND_ASSIGN(WindowControllerList); 62 }; 63 64 } // namespace extensions 65 66 #endif // CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_LIST_H_ 67