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