Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: apps/shell_window_registry.h

Issue 23524005: Introduce AppsClient and use it in apps to get the loaded profiles list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compile, self nits Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef APPS_SHELL_WINDOW_REGISTRY_H_ 5 #ifndef APPS_SHELL_WINDOW_REGISTRY_H_
6 #define APPS_SHELL_WINDOW_REGISTRY_H_ 6 #define APPS_SHELL_WINDOW_REGISTRY_H_
7 7
8 #include <list> 8 #include <list>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" 14 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
15 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" 15 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h"
16 #include "ui/gfx/native_widget_types.h" 16 #include "ui/gfx/native_widget_types.h"
17 17
18 class Profile;
19
20 namespace content { 18 namespace content {
21 class DevToolsAgentHost; 19 class DevToolsAgentHost;
22 class RenderViewHost; 20 class RenderViewHost;
23 } 21 }
24 22
25 namespace apps { 23 namespace apps {
26 24
27 class ShellWindow; 25 class ShellWindow;
28 26
29 // The ShellWindowRegistry tracks the ShellWindows for all platform apps for a 27 // The ShellWindowRegistry tracks the ShellWindows for all platform apps for a
30 // particular profile. 28 // particular browser context.
31 // This class is planned to evolve into tracking all PlatformApps for a
32 // particular profile, with a PlatformApp encapsulating all views (background
33 // page, shell windows, tray view, panels etc.) and other app level behaviour
34 // (e.g. notifications the app is interested in, lifetime of the background
35 // page).
36 class ShellWindowRegistry : public BrowserContextKeyedService { 29 class ShellWindowRegistry : public BrowserContextKeyedService {
37 public: 30 public:
38 class Observer { 31 class Observer {
39 public: 32 public:
40 // Called just after a shell window was added. 33 // Called just after a shell window was added.
41 virtual void OnShellWindowAdded(apps::ShellWindow* shell_window) = 0; 34 virtual void OnShellWindowAdded(apps::ShellWindow* shell_window) = 0;
42 // Called when the window icon changes. 35 // Called when the window icon changes.
43 virtual void OnShellWindowIconChanged(apps::ShellWindow* shell_window) = 0; 36 virtual void OnShellWindowIconChanged(apps::ShellWindow* shell_window) = 0;
44 // Called just after a shell window was removed. 37 // Called just after a shell window was removed.
45 virtual void OnShellWindowRemoved(apps::ShellWindow* shell_window) = 0; 38 virtual void OnShellWindowRemoved(apps::ShellWindow* shell_window) = 0;
46 39
47 protected: 40 protected:
48 virtual ~Observer() {} 41 virtual ~Observer() {}
49 }; 42 };
50 43
51 typedef std::list<apps::ShellWindow*> ShellWindowList; 44 typedef std::list<apps::ShellWindow*> ShellWindowList;
52 typedef ShellWindowList::const_iterator const_iterator; 45 typedef ShellWindowList::const_iterator const_iterator;
53 typedef std::set<std::string> InspectedWindowSet; 46 typedef std::set<std::string> InspectedWindowSet;
54 47
55 explicit ShellWindowRegistry(Profile* profile); 48 explicit ShellWindowRegistry(content::BrowserContext* context);
tapted 2013/09/04 01:08:35 nit: should this be forward-declared? It's probabl
benwells 2013/09/10 16:48:50 Done.
56 virtual ~ShellWindowRegistry(); 49 virtual ~ShellWindowRegistry();
57 50
58 // Returns the instance for the given profile, or NULL if none. This is 51 // Returns the instance for the given browser context, or NULL if none. This
59 // a convenience wrapper around ShellWindowRegistry::Factory::GetForProfile. 52 // is a convenience wrapper around
60 static ShellWindowRegistry* Get(Profile* profile); 53 // ShellWindowRegistry::Factory::GetForBrowserContext.
tapted 2013/09/04 01:08:35 nit: usually I see ShellWindowRegistry::Factory::G
benwells 2013/09/10 16:48:50 Done.
54 static ShellWindowRegistry* Get(content::BrowserContext* context);
61 55
62 void AddShellWindow(apps::ShellWindow* shell_window); 56 void AddShellWindow(apps::ShellWindow* shell_window);
63 void ShellWindowIconChanged(apps::ShellWindow* shell_window); 57 void ShellWindowIconChanged(apps::ShellWindow* shell_window);
64 // Called by |shell_window| when it is activated. 58 // Called by |shell_window| when it is activated.
65 void ShellWindowActivated(apps::ShellWindow* shell_window); 59 void ShellWindowActivated(apps::ShellWindow* shell_window);
66 void RemoveShellWindow(apps::ShellWindow* shell_window); 60 void RemoveShellWindow(apps::ShellWindow* shell_window);
67 61
68 void AddObserver(Observer* observer); 62 void AddObserver(Observer* observer);
69 void RemoveObserver(Observer* observer); 63 void RemoveObserver(Observer* observer);
70 64
(...skipping 20 matching lines...) Expand all
91 // window will be returned. 85 // window will be returned.
92 apps::ShellWindow* GetShellWindowForAppAndKey( 86 apps::ShellWindow* GetShellWindowForAppAndKey(
93 const std::string& app_id, 87 const std::string& app_id,
94 const std::string& window_key) const; 88 const std::string& window_key) const;
95 89
96 // Returns whether a ShellWindow's ID was last known to have a DevToolsAgent 90 // Returns whether a ShellWindow's ID was last known to have a DevToolsAgent
97 // attached to it, which should be restored during a reload of a corresponding 91 // attached to it, which should be restored during a reload of a corresponding
98 // newly created |render_view_host|. 92 // newly created |render_view_host|.
99 bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const; 93 bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const;
100 94
101 // Returns the shell window for |window|, looking in all profiles. 95 // Returns the shell window for |window|, looking in all browser contexts.
102 static apps::ShellWindow* GetShellWindowForNativeWindowAnyProfile( 96 static apps::ShellWindow* GetShellWindowForNativeWindowAnyProfile(
103 gfx::NativeWindow window); 97 gfx::NativeWindow window);
104 98
105 // Returns true if the number of shell windows registered across all profiles 99 // Returns true if the number of shell windows registered across all browser
106 // is non-zero. |window_type_mask| is a bitwise OR filter of 100 // contexts is non-zero. |window_type_mask| is a bitwise OR filter of
107 // ShellWindow::WindowType, or 0 for any window type. 101 // ShellWindow::WindowType, or 0 for any window type.
108 static bool IsShellWindowRegisteredInAnyProfile(int window_type_mask); 102 static bool IsShellWindowRegisteredInAnyProfile(int window_type_mask);
109 103
110 class Factory : public BrowserContextKeyedServiceFactory { 104 class Factory : public BrowserContextKeyedServiceFactory {
111 public: 105 public:
112 static ShellWindowRegistry* GetForProfile(Profile* profile, bool create); 106 static ShellWindowRegistry* GetForBrowserContext(
107 content::BrowserContext* context, bool create);
113 108
114 static Factory* GetInstance(); 109 static Factory* GetInstance();
115 private: 110 private:
116 friend struct DefaultSingletonTraits<Factory>; 111 friend struct DefaultSingletonTraits<Factory>;
117 112
118 Factory(); 113 Factory();
119 virtual ~Factory(); 114 virtual ~Factory();
120 115
121 // BrowserContextKeyedServiceFactory 116 // BrowserContextKeyedServiceFactory
122 virtual BrowserContextKeyedService* BuildServiceInstanceFor( 117 virtual BrowserContextKeyedService* BuildServiceInstanceFor(
123 content::BrowserContext* profile) const OVERRIDE; 118 content::BrowserContext* context) const OVERRIDE;
124 virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE; 119 virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE;
125 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; 120 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE;
126 virtual content::BrowserContext* GetBrowserContextToUse( 121 virtual content::BrowserContext* GetBrowserContextToUse(
127 content::BrowserContext* context) const OVERRIDE; 122 content::BrowserContext* context) const OVERRIDE;
128 }; 123 };
129 124
130 protected: 125 protected:
131 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached); 126 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached);
132 127
133 private: 128 private:
134 // Ensures the specified |shell_window| is included in |shell_windows_|. 129 // Ensures the specified |shell_window| is included in |shell_windows_|.
135 // Otherwise adds |shell_window| to the back of |shell_windows_|. 130 // Otherwise adds |shell_window| to the back of |shell_windows_|.
136 void AddShellWindowToList(apps::ShellWindow* shell_window); 131 void AddShellWindowToList(apps::ShellWindow* shell_window);
137 132
138 // Bring |shell_window| to the front of |shell_windows_|. If it is not in the 133 // Bring |shell_window| to the front of |shell_windows_|. If it is not in the
139 // list, add it first. 134 // list, add it first.
140 void BringToFront(apps::ShellWindow* shell_window); 135 void BringToFront(apps::ShellWindow* shell_window);
141 136
142 Profile* profile_; 137 content::BrowserContext* context_;
143 ShellWindowList shell_windows_; 138 ShellWindowList shell_windows_;
144 InspectedWindowSet inspected_windows_; 139 InspectedWindowSet inspected_windows_;
145 ObserverList<Observer> observers_; 140 ObserverList<Observer> observers_;
146 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; 141 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_;
147 }; 142 };
148 143
149 } // namespace extensions 144 } // namespace extensions
150 145
151 #endif // APPS_SHELL_WINDOW_REGISTRY_H_ 146 #endif // APPS_SHELL_WINDOW_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698