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 UIThreadExtensionFunction
;
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 |id| using |filter|.
40 WindowController
* FindWindowByIdWithFilter(
42 WindowController::TypeFilter filter
) const;
44 // Returns a window matching the context the function was invoked in
46 WindowController
* FindWindowForFunctionByIdWithFilter(
47 const UIThreadExtensionFunction
* function
,
49 WindowController::TypeFilter filter
) const;
51 // Returns the focused or last added window matching the context the function
53 WindowController
* CurrentWindowForFunction(
54 const UIThreadExtensionFunction
* function
) const;
56 // Returns the focused or last added window matching the context the function
57 // was invoked in using |filter|.
58 WindowController
* CurrentWindowForFunctionWithFilter(
59 const UIThreadExtensionFunction
* function
,
60 WindowController::TypeFilter filter
) const;
62 const ControllerList
& windows() const { return windows_
; }
64 static WindowControllerList
* GetInstance();
67 friend struct DefaultSingletonTraits
<WindowControllerList
>;
69 // Entries are not owned by this class and must be removed when destroyed.
70 ControllerList windows_
;
72 base::ObserverList
<WindowControllerListObserver
> observers_
;
74 DISALLOW_COPY_AND_ASSIGN(WindowControllerList
);
77 } // namespace extensions
79 #endif // CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_LIST_H_