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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_LIST_H_
6 #define CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_LIST_H_
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"
16 class ChromeExtensionFunctionDetails
;
18 namespace extensions
{
20 class WindowControllerListObserver
;
22 // Class to maintain a list of WindowControllers.
23 class WindowControllerList
{
25 typedef std::list
<WindowController
*> ControllerList
;
27 WindowControllerList();
28 ~WindowControllerList();
30 void AddExtensionWindow(WindowController
* window
);
31 void RemoveExtensionWindow(WindowController
* window
);
33 void AddObserver(WindowControllerListObserver
* observer
);
34 void RemoveObserver(WindowControllerListObserver
* observer
);
36 // Returns a window matching |id|.
37 WindowController
* FindWindowById(int id
) const;
39 // Returns a window matching the context the function was invoked in.
40 WindowController
* FindWindowForFunctionById(
41 const ChromeExtensionFunctionDetails
& function_details
,
44 // Returns the focused or last added window matching the context the function
46 WindowController
* CurrentWindowForFunction(
47 const ChromeExtensionFunctionDetails
& function_details
) const;
49 const ControllerList
& windows() const { return windows_
; }
51 static WindowControllerList
* GetInstance();
54 friend struct DefaultSingletonTraits
<WindowControllerList
>;
56 // Entries are not owned by this class and must be removed when destroyed.
57 ControllerList windows_
;
59 ObserverList
<WindowControllerListObserver
> observers_
;
61 DISALLOW_COPY_AND_ASSIGN(WindowControllerList
);
64 } // namespace extensions
66 #endif // CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_LIST_H_