[Android] Allow multiple --install in bb_device_steps.py.
[chromium-blink-merge.git] / chrome / browser / apps / app_window_registry_util.cc
blobd6917ce868b4d658241df90a2d1484c45263297d
1 // Copyright 2014 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 #include "chrome/browser/apps/app_window_registry_util.h"
7 #include <vector>
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "extensions/browser/app_window/app_window.h"
13 #include "extensions/browser/app_window/app_window_registry.h"
14 #include "extensions/browser/app_window/native_app_window.h"
16 using extensions::AppWindow;
17 using extensions::AppWindowRegistry;
19 typedef AppWindowRegistry::AppWindowList AppWindowList;
20 typedef AppWindowRegistry::Factory Factory;
22 // static
23 AppWindow* AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
24 gfx::NativeWindow window) {
25 std::vector<Profile*> profiles =
26 g_browser_process->profile_manager()->GetLoadedProfiles();
27 for (std::vector<Profile*>::const_iterator i = profiles.begin();
28 i != profiles.end();
29 ++i) {
30 AppWindowRegistry* registry =
31 Factory::GetForBrowserContext(*i, false /* create */);
32 if (!registry)
33 continue;
35 AppWindow* app_window = registry->GetAppWindowForNativeWindow(window);
36 if (app_window)
37 return app_window;
40 return NULL;
43 // static
44 bool AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile(
45 int window_type_mask) {
46 std::vector<Profile*> profiles =
47 g_browser_process->profile_manager()->GetLoadedProfiles();
48 for (std::vector<Profile*>::const_iterator i = profiles.begin();
49 i != profiles.end();
50 ++i) {
51 AppWindowRegistry* registry =
52 Factory::GetForBrowserContext(*i, false /* create */);
53 if (!registry)
54 continue;
56 const AppWindowList& app_windows = registry->app_windows();
57 if (app_windows.empty())
58 continue;
60 if (window_type_mask == 0)
61 return true;
63 for (AppWindowList::const_iterator j = app_windows.begin();
64 j != app_windows.end(); ++j) {
65 if ((*j)->window_type() & window_type_mask)
66 return true;
70 return false;
73 // static
74 void AppWindowRegistryUtil::CloseAllAppWindows() {
75 std::vector<Profile*> profiles =
76 g_browser_process->profile_manager()->GetLoadedProfiles();
77 for (std::vector<Profile*>::const_iterator i = profiles.begin();
78 i != profiles.end();
79 ++i) {
80 AppWindowRegistry* registry =
81 Factory::GetForBrowserContext(*i, false /* create */);
82 if (!registry)
83 continue;
85 while (!registry->app_windows().empty())
86 registry->app_windows().front()->GetBaseWindow()->Close();