Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / apps / app_window_registry_util.cc
blob6a4f2fe2e9f7d2d203ff8b930989e321c6fad366
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::IsAppWindowVisibleInAnyProfile(
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 for (const AppWindow* window : app_windows) {
61 if (!window->is_hidden() &&
62 (window_type_mask == 0 ||
63 (window->window_type() & window_type_mask)))
64 return true;
68 return false;
71 // static
72 void AppWindowRegistryUtil::CloseAllAppWindows() {
73 std::vector<Profile*> profiles =
74 g_browser_process->profile_manager()->GetLoadedProfiles();
75 for (std::vector<Profile*>::const_iterator i = profiles.begin();
76 i != profiles.end();
77 ++i) {
78 AppWindowRegistry* registry =
79 Factory::GetForBrowserContext(*i, false /* create */);
80 if (!registry)
81 continue;
83 while (!registry->app_windows().empty())
84 registry->app_windows().front()->GetBaseWindow()->Close();