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

Side by Side Diff: apps/shell_window_registry.cc

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: Rebase 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
« no previous file with comments | « apps/shell_window_registry.h ('k') | chrome/browser/apps/chrome_apps_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "apps/apps_client.h"
5 #include "apps/native_app_window.h" 6 #include "apps/native_app_window.h"
6 #include "apps/shell_window.h" 7 #include "apps/shell_window.h"
7 #include "apps/shell_window_registry.h" 8 #include "apps/shell_window_registry.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/incognito_helpers.h" 9 #include "chrome/browser/profiles/incognito_helpers.h"
10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
12 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" 11 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h"
12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/devtools_agent_host.h" 13 #include "content/public/browser/devtools_agent_host.h"
14 #include "content/public/browser/devtools_manager.h" 14 #include "content/public/browser/devtools_manager.h"
15 #include "content/public/browser/render_process_host.h" 15 #include "content/public/browser/render_process_host.h"
16 #include "content/public/browser/render_view_host.h" 16 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/site_instance.h" 17 #include "content/public/browser/site_instance.h"
18 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 19
20 namespace { 20 namespace {
21 21
22 // Create a key that identifies a ShellWindow in a RenderViewHost across App 22 // Create a key that identifies a ShellWindow in a RenderViewHost across App
(...skipping 15 matching lines...) Expand all
38 std::string key = shell_window->extension()->id(); 38 std::string key = shell_window->extension()->id();
39 key += ':'; 39 key += ':';
40 key += shell_window->window_key(); 40 key += shell_window->window_key();
41 return key; 41 return key;
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46 namespace apps { 46 namespace apps {
47 47
48 ShellWindowRegistry::ShellWindowRegistry(Profile* profile) 48 ShellWindowRegistry::ShellWindowRegistry(content::BrowserContext* context)
49 : profile_(profile), 49 : context_(context),
50 devtools_callback_(base::Bind( 50 devtools_callback_(base::Bind(
51 &ShellWindowRegistry::OnDevToolsStateChanged, 51 &ShellWindowRegistry::OnDevToolsStateChanged,
52 base::Unretained(this))) { 52 base::Unretained(this))) {
53 content::DevToolsManager::GetInstance()->AddAgentStateCallback( 53 content::DevToolsManager::GetInstance()->AddAgentStateCallback(
54 devtools_callback_); 54 devtools_callback_);
55 } 55 }
56 56
57 ShellWindowRegistry::~ShellWindowRegistry() { 57 ShellWindowRegistry::~ShellWindowRegistry() {
58 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( 58 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback(
59 devtools_callback_); 59 devtools_callback_);
60 } 60 }
61 61
62 // static 62 // static
63 ShellWindowRegistry* ShellWindowRegistry::Get(Profile* profile) { 63 ShellWindowRegistry* ShellWindowRegistry::Get(
64 return Factory::GetForProfile(profile, true /* create */); 64 content::BrowserContext* context) {
65 return Factory::GetForBrowserContext(context, true /* create */);
65 } 66 }
66 67
67 void ShellWindowRegistry::AddShellWindow(ShellWindow* shell_window) { 68 void ShellWindowRegistry::AddShellWindow(ShellWindow* shell_window) {
68 BringToFront(shell_window); 69 BringToFront(shell_window);
69 FOR_EACH_OBSERVER(Observer, observers_, OnShellWindowAdded(shell_window)); 70 FOR_EACH_OBSERVER(Observer, observers_, OnShellWindowAdded(shell_window));
70 } 71 }
71 72
72 void ShellWindowRegistry::ShellWindowIconChanged(ShellWindow* shell_window) { 73 void ShellWindowRegistry::ShellWindowIconChanged(ShellWindow* shell_window) {
73 AddShellWindowToList(shell_window); 74 AddShellWindowToList(shell_window);
74 FOR_EACH_OBSERVER(Observer, observers_, 75 FOR_EACH_OBSERVER(Observer, observers_,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 172
172 bool ShellWindowRegistry::HadDevToolsAttached( 173 bool ShellWindowRegistry::HadDevToolsAttached(
173 content::RenderViewHost* render_view_host) const { 174 content::RenderViewHost* render_view_host) const {
174 std::string key = GetWindowKeyForRenderViewHost(this, render_view_host); 175 std::string key = GetWindowKeyForRenderViewHost(this, render_view_host);
175 return key.empty() ? false : inspected_windows_.count(key) != 0; 176 return key.empty() ? false : inspected_windows_.count(key) != 0;
176 } 177 }
177 178
178 // static 179 // static
179 ShellWindow* ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile( 180 ShellWindow* ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile(
180 gfx::NativeWindow window) { 181 gfx::NativeWindow window) {
181 std::vector<Profile*> profiles = 182 std::vector<content::BrowserContext*> contexts =
182 g_browser_process->profile_manager()->GetLoadedProfiles(); 183 AppsClient::Get()->GetLoadedBrowserContexts();
183 for (std::vector<Profile*>::const_iterator i = profiles.begin(); 184 for (std::vector<content::BrowserContext*>::const_iterator i =
184 i != profiles.end(); ++i) { 185 contexts.begin();
185 ShellWindowRegistry* registry = Factory::GetForProfile(*i, 186 i != contexts.end(); ++i) {
186 false /* create */); 187 ShellWindowRegistry* registry = Factory::GetForBrowserContext(
188 *i, false /* create */);
187 if (!registry) 189 if (!registry)
188 continue; 190 continue;
189 191
190 ShellWindow* shell_window = registry->GetShellWindowForNativeWindow(window); 192 ShellWindow* shell_window = registry->GetShellWindowForNativeWindow(window);
191 if (shell_window) 193 if (shell_window)
192 return shell_window; 194 return shell_window;
193 } 195 }
194 196
195 return NULL; 197 return NULL;
196 } 198 }
197 199
198 // static 200 // static
199 bool ShellWindowRegistry::IsShellWindowRegisteredInAnyProfile( 201 bool ShellWindowRegistry::IsShellWindowRegisteredInAnyProfile(
200 int window_type_mask) { 202 int window_type_mask) {
201 std::vector<Profile*> profiles = 203 std::vector<content::BrowserContext*> contexts =
202 g_browser_process->profile_manager()->GetLoadedProfiles(); 204 AppsClient::Get()->GetLoadedBrowserContexts();
203 for (std::vector<Profile*>::const_iterator i = profiles.begin(); 205 for (std::vector<content::BrowserContext*>::const_iterator i =
204 i != profiles.end(); ++i) { 206 contexts.begin();
205 ShellWindowRegistry* registry = Factory::GetForProfile(*i, 207 i != contexts.end(); ++i) {
206 false /* create */); 208 ShellWindowRegistry* registry = Factory::GetForBrowserContext(
209 *i, false /* create */);
207 if (!registry) 210 if (!registry)
208 continue; 211 continue;
209 212
210 const ShellWindowList& shell_windows = registry->shell_windows(); 213 const ShellWindowList& shell_windows = registry->shell_windows();
211 if (shell_windows.empty()) 214 if (shell_windows.empty())
212 continue; 215 continue;
213 216
214 if (window_type_mask == 0) 217 if (window_type_mask == 0)
215 return true; 218 return true;
216 219
217 for (const_iterator j = shell_windows.begin(); j != shell_windows.end(); 220 for (const_iterator j = shell_windows.begin(); j != shell_windows.end();
218 ++j) { 221 ++j) {
219 if ((*j)->window_type() & window_type_mask) 222 if ((*j)->window_type() & window_type_mask)
220 return true; 223 return true;
221 } 224 }
222 } 225 }
223 226
224 return false; 227 return false;
225 } 228 }
226 229
227 void ShellWindowRegistry::OnDevToolsStateChanged( 230 void ShellWindowRegistry::OnDevToolsStateChanged(
228 content::DevToolsAgentHost* agent_host, bool attached) { 231 content::DevToolsAgentHost* agent_host, bool attached) {
229 content::RenderViewHost* rvh = agent_host->GetRenderViewHost(); 232 content::RenderViewHost* rvh = agent_host->GetRenderViewHost();
230 // Ignore unrelated notifications. 233 // Ignore unrelated notifications.
231 if (!rvh || 234 if (!rvh ||
232 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != profile_) 235 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != context_)
233 return; 236 return;
237
234 std::string key = GetWindowKeyForRenderViewHost(this, rvh); 238 std::string key = GetWindowKeyForRenderViewHost(this, rvh);
235 if (key.empty()) 239 if (key.empty())
236 return; 240 return;
237 241
238 if (attached) 242 if (attached)
239 inspected_windows_.insert(key); 243 inspected_windows_.insert(key);
240 else 244 else
241 inspected_windows_.erase(key); 245 inspected_windows_.erase(key);
242 } 246 }
243 247
(...skipping 12 matching lines...) Expand all
256 shell_window); 260 shell_window);
257 if (it != shell_windows_.end()) 261 if (it != shell_windows_.end())
258 shell_windows_.erase(it); 262 shell_windows_.erase(it);
259 shell_windows_.push_front(shell_window); 263 shell_windows_.push_front(shell_window);
260 } 264 }
261 265
262 /////////////////////////////////////////////////////////////////////////////// 266 ///////////////////////////////////////////////////////////////////////////////
263 // Factory boilerplate 267 // Factory boilerplate
264 268
265 // static 269 // static
266 ShellWindowRegistry* ShellWindowRegistry::Factory::GetForProfile( 270 ShellWindowRegistry* ShellWindowRegistry::Factory::GetForBrowserContext(
267 Profile* profile, bool create) { 271 content::BrowserContext* context, bool create) {
268 return static_cast<ShellWindowRegistry*>( 272 return static_cast<ShellWindowRegistry*>(
269 GetInstance()->GetServiceForBrowserContext(profile, create)); 273 GetInstance()->GetServiceForBrowserContext(context, create));
270 } 274 }
271 275
272 ShellWindowRegistry::Factory* ShellWindowRegistry::Factory::GetInstance() { 276 ShellWindowRegistry::Factory* ShellWindowRegistry::Factory::GetInstance() {
273 return Singleton<ShellWindowRegistry::Factory>::get(); 277 return Singleton<ShellWindowRegistry::Factory>::get();
274 } 278 }
275 279
276 ShellWindowRegistry::Factory::Factory() 280 ShellWindowRegistry::Factory::Factory()
277 : BrowserContextKeyedServiceFactory( 281 : BrowserContextKeyedServiceFactory(
278 "ShellWindowRegistry", 282 "ShellWindowRegistry",
279 BrowserContextDependencyManager::GetInstance()) { 283 BrowserContextDependencyManager::GetInstance()) {
280 } 284 }
281 285
282 ShellWindowRegistry::Factory::~Factory() { 286 ShellWindowRegistry::Factory::~Factory() {
283 } 287 }
284 288
285 BrowserContextKeyedService* 289 BrowserContextKeyedService*
286 ShellWindowRegistry::Factory::BuildServiceInstanceFor( 290 ShellWindowRegistry::Factory::BuildServiceInstanceFor(
287 content::BrowserContext* profile) const { 291 content::BrowserContext* context) const {
288 return new ShellWindowRegistry(static_cast<Profile*>(profile)); 292 return new ShellWindowRegistry(context);
289 } 293 }
290 294
291 bool ShellWindowRegistry::Factory::ServiceIsCreatedWithBrowserContext() const { 295 bool ShellWindowRegistry::Factory::ServiceIsCreatedWithBrowserContext() const {
292 return true; 296 return true;
293 } 297 }
294 298
295 bool ShellWindowRegistry::Factory::ServiceIsNULLWhileTesting() const { 299 bool ShellWindowRegistry::Factory::ServiceIsNULLWhileTesting() const {
296 return false; 300 return false;
297 } 301 }
298 302
299 content::BrowserContext* ShellWindowRegistry::Factory::GetBrowserContextToUse( 303 content::BrowserContext* ShellWindowRegistry::Factory::GetBrowserContextToUse(
300 content::BrowserContext* context) const { 304 content::BrowserContext* context) const {
301 return chrome::GetBrowserContextRedirectedInIncognito(context); 305 return chrome::GetBrowserContextRedirectedInIncognito(context);
302 } 306 }
303 307
304 } // namespace extensions 308 } // namespace extensions
OLDNEW
« no previous file with comments | « apps/shell_window_registry.h ('k') | chrome/browser/apps/chrome_apps_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698