diff options
19 files changed, 181 insertions, 44 deletions
diff --git a/apps/app_lifetime_monitor.cc b/apps/app_lifetime_monitor.cc index 8547be9..e43fb6b 100644 --- a/apps/app_lifetime_monitor.cc +++ b/apps/app_lifetime_monitor.cc @@ -7,6 +7,7 @@ #include "apps/shell_window.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/extensions/extension_host.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/extension.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_service.h" @@ -29,7 +30,7 @@ AppLifetimeMonitor::AppLifetimeMonitor(Profile* profile) content::NotificationService::AllSources()); ShellWindowRegistry* shell_window_registry = - ShellWindowRegistry::Factory::GetForProfile( + ShellWindowRegistry::Factory::GetForBrowserContext( profile_, false /* create */); DCHECK(shell_window_registry); shell_window_registry->AddObserver(this); @@ -99,7 +100,7 @@ void AppLifetimeMonitor::OnShellWindowRemoved(ShellWindow* shell_window) { void AppLifetimeMonitor::Shutdown() { ShellWindowRegistry* shell_window_registry = - ShellWindowRegistry::Factory::GetForProfile( + ShellWindowRegistry::Factory::GetForBrowserContext( profile_, false /* create */); if (shell_window_registry) shell_window_registry->RemoveObserver(this); diff --git a/apps/apps.gypi b/apps/apps.gypi index bd2bffc..9724dc6 100644 --- a/apps/apps.gypi +++ b/apps/apps.gypi @@ -52,6 +52,8 @@ 'app_shim/extension_app_shim_handler_mac.h', 'app_window_contents.cc', 'app_window_contents.h', + 'apps_client.cc', + 'apps_client.h', 'field_trial_names.cc', 'field_trial_names.h', 'launcher.cc', diff --git a/apps/apps_client.cc b/apps/apps_client.cc new file mode 100644 index 0000000..dbdb546 --- /dev/null +++ b/apps/apps_client.cc @@ -0,0 +1,29 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "apps/apps_client.h" + +#include "base/basictypes.h" + +namespace apps { + +namespace { + +AppsClient* g_client = NULL; + +} // namespace + +AppsClient* AppsClient::Get() { + return g_client; +} + +void AppsClient::Set(AppsClient* client) { + // This can happen in unit tests, where the utility thread runs in-process. + if (g_client) + return; + + g_client = client; +} + +} // namespace apps diff --git a/apps/apps_client.h b/apps/apps_client.h new file mode 100644 index 0000000..c3a58ca --- /dev/null +++ b/apps/apps_client.h @@ -0,0 +1,32 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef APPS_APPS_CLIENT_H_ +#define APPS_APPS_CLIENT_H_ + +#include <vector> + +namespace content { +class BrowserContext; +} + +namespace apps { + +// Sets up global state for the apps system. Should be Set() once in each +// process. This should be implemented by the client of the apps system. +class AppsClient { + public: + // Get all loaded browser contexts. + virtual std::vector<content::BrowserContext*> GetLoadedBrowserContexts() = 0; + + // Return the apps client. + static AppsClient* Get(); + + // Initialize the apps system with this apps client. + static void Set(AppsClient* client); +}; + +} // namespace apps + +#endif // APPS_APPS_CLIENT_H_ diff --git a/apps/shell_window_registry.cc b/apps/shell_window_registry.cc index 301bcf1..677a8c6 100644 --- a/apps/shell_window_registry.cc +++ b/apps/shell_window_registry.cc @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "apps/apps_client.h" #include "apps/native_app_window.h" #include "apps/shell_window.h" #include "apps/shell_window_registry.h" -#include "chrome/browser/browser_process.h" #include "chrome/browser/profiles/incognito_helpers.h" -#include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/extensions/extension.h" #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" +#include "content/public/browser/browser_context.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_manager.h" #include "content/public/browser/render_process_host.h" @@ -45,8 +45,8 @@ std::string GetWindowKeyForRenderViewHost( namespace apps { -ShellWindowRegistry::ShellWindowRegistry(Profile* profile) - : profile_(profile), +ShellWindowRegistry::ShellWindowRegistry(content::BrowserContext* context) + : context_(context), devtools_callback_(base::Bind( &ShellWindowRegistry::OnDevToolsStateChanged, base::Unretained(this))) { @@ -60,8 +60,9 @@ ShellWindowRegistry::~ShellWindowRegistry() { } // static -ShellWindowRegistry* ShellWindowRegistry::Get(Profile* profile) { - return Factory::GetForProfile(profile, true /* create */); +ShellWindowRegistry* ShellWindowRegistry::Get( + content::BrowserContext* context) { + return Factory::GetForBrowserContext(context, true /* create */); } void ShellWindowRegistry::AddShellWindow(ShellWindow* shell_window) { @@ -178,12 +179,13 @@ bool ShellWindowRegistry::HadDevToolsAttached( // static ShellWindow* ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile( gfx::NativeWindow window) { - std::vector<Profile*> profiles = - g_browser_process->profile_manager()->GetLoadedProfiles(); - for (std::vector<Profile*>::const_iterator i = profiles.begin(); - i != profiles.end(); ++i) { - ShellWindowRegistry* registry = Factory::GetForProfile(*i, - false /* create */); + std::vector<content::BrowserContext*> contexts = + AppsClient::Get()->GetLoadedBrowserContexts(); + for (std::vector<content::BrowserContext*>::const_iterator i = + contexts.begin(); + i != contexts.end(); ++i) { + ShellWindowRegistry* registry = Factory::GetForBrowserContext( + *i, false /* create */); if (!registry) continue; @@ -198,12 +200,13 @@ ShellWindow* ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile( // static bool ShellWindowRegistry::IsShellWindowRegisteredInAnyProfile( int window_type_mask) { - std::vector<Profile*> profiles = - g_browser_process->profile_manager()->GetLoadedProfiles(); - for (std::vector<Profile*>::const_iterator i = profiles.begin(); - i != profiles.end(); ++i) { - ShellWindowRegistry* registry = Factory::GetForProfile(*i, - false /* create */); + std::vector<content::BrowserContext*> contexts = + AppsClient::Get()->GetLoadedBrowserContexts(); + for (std::vector<content::BrowserContext*>::const_iterator i = + contexts.begin(); + i != contexts.end(); ++i) { + ShellWindowRegistry* registry = Factory::GetForBrowserContext( + *i, false /* create */); if (!registry) continue; @@ -229,8 +232,9 @@ void ShellWindowRegistry::OnDevToolsStateChanged( content::RenderViewHost* rvh = agent_host->GetRenderViewHost(); // Ignore unrelated notifications. if (!rvh || - rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != profile_) + rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != context_) return; + std::string key = GetWindowKeyForRenderViewHost(this, rvh); if (key.empty()) return; @@ -263,10 +267,10 @@ void ShellWindowRegistry::BringToFront(ShellWindow* shell_window) { // Factory boilerplate // static -ShellWindowRegistry* ShellWindowRegistry::Factory::GetForProfile( - Profile* profile, bool create) { +ShellWindowRegistry* ShellWindowRegistry::Factory::GetForBrowserContext( + content::BrowserContext* context, bool create) { return static_cast<ShellWindowRegistry*>( - GetInstance()->GetServiceForBrowserContext(profile, create)); + GetInstance()->GetServiceForBrowserContext(context, create)); } ShellWindowRegistry::Factory* ShellWindowRegistry::Factory::GetInstance() { @@ -284,8 +288,8 @@ ShellWindowRegistry::Factory::~Factory() { BrowserContextKeyedService* ShellWindowRegistry::Factory::BuildServiceInstanceFor( - content::BrowserContext* profile) const { - return new ShellWindowRegistry(static_cast<Profile*>(profile)); + content::BrowserContext* context) const { + return new ShellWindowRegistry(context); } bool ShellWindowRegistry::Factory::ServiceIsCreatedWithBrowserContext() const { diff --git a/apps/shell_window_registry.h b/apps/shell_window_registry.h index e23c5e9..f32b39b 100644 --- a/apps/shell_window_registry.h +++ b/apps/shell_window_registry.h @@ -15,9 +15,8 @@ #include "components/browser_context_keyed_service/browser_context_keyed_service_factory.h" #include "ui/gfx/native_widget_types.h" -class Profile; - namespace content { +class BrowserContext; class DevToolsAgentHost; class RenderViewHost; } @@ -27,12 +26,7 @@ namespace apps { class ShellWindow; // The ShellWindowRegistry tracks the ShellWindows for all platform apps for a -// particular profile. -// This class is planned to evolve into tracking all PlatformApps for a -// particular profile, with a PlatformApp encapsulating all views (background -// page, shell windows, tray view, panels etc.) and other app level behaviour -// (e.g. notifications the app is interested in, lifetime of the background -// page). +// particular browser context. class ShellWindowRegistry : public BrowserContextKeyedService { public: class Observer { @@ -52,12 +46,13 @@ class ShellWindowRegistry : public BrowserContextKeyedService { typedef ShellWindowList::const_iterator const_iterator; typedef std::set<std::string> InspectedWindowSet; - explicit ShellWindowRegistry(Profile* profile); + explicit ShellWindowRegistry(content::BrowserContext* context); virtual ~ShellWindowRegistry(); - // Returns the instance for the given profile, or NULL if none. This is - // a convenience wrapper around ShellWindowRegistry::Factory::GetForProfile. - static ShellWindowRegistry* Get(Profile* profile); + // Returns the instance for the given browser context, or NULL if none. This + // is a convenience wrapper around + // ShellWindowRegistry::Factory::GetForBrowserContext(). + static ShellWindowRegistry* Get(content::BrowserContext* context); void AddShellWindow(apps::ShellWindow* shell_window); void ShellWindowIconChanged(apps::ShellWindow* shell_window); @@ -98,18 +93,19 @@ class ShellWindowRegistry : public BrowserContextKeyedService { // newly created |render_view_host|. bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const; - // Returns the shell window for |window|, looking in all profiles. + // Returns the shell window for |window|, looking in all browser contexts. static apps::ShellWindow* GetShellWindowForNativeWindowAnyProfile( gfx::NativeWindow window); - // Returns true if the number of shell windows registered across all profiles - // is non-zero. |window_type_mask| is a bitwise OR filter of + // Returns true if the number of shell windows registered across all browser + // contexts is non-zero. |window_type_mask| is a bitwise OR filter of // ShellWindow::WindowType, or 0 for any window type. static bool IsShellWindowRegisteredInAnyProfile(int window_type_mask); class Factory : public BrowserContextKeyedServiceFactory { public: - static ShellWindowRegistry* GetForProfile(Profile* profile, bool create); + static ShellWindowRegistry* GetForBrowserContext( + content::BrowserContext* context, bool create); static Factory* GetInstance(); private: @@ -120,7 +116,7 @@ class ShellWindowRegistry : public BrowserContextKeyedService { // BrowserContextKeyedServiceFactory virtual BrowserContextKeyedService* BuildServiceInstanceFor( - content::BrowserContext* profile) const OVERRIDE; + content::BrowserContext* context) const OVERRIDE; virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE; virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; virtual content::BrowserContext* GetBrowserContextToUse( @@ -139,7 +135,7 @@ class ShellWindowRegistry : public BrowserContextKeyedService { // list, add it first. void BringToFront(apps::ShellWindow* shell_window); - Profile* profile_; + content::BrowserContext* context_; ShellWindowList shell_windows_; InspectedWindowSet inspected_windows_; ObserverList<Observer> observers_; diff --git a/chrome/browser/apps/chrome_apps_client.cc b/chrome/browser/apps/chrome_apps_client.cc new file mode 100644 index 0000000..4a9f4ca --- /dev/null +++ b/chrome/browser/apps/chrome_apps_client.cc @@ -0,0 +1,27 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/apps/chrome_apps_client.h" + +#include "base/memory/singleton.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/profiles/profile_manager.h" + +ChromeAppsClient::ChromeAppsClient() {} + +ChromeAppsClient::~ChromeAppsClient() {} + +// static +ChromeAppsClient* ChromeAppsClient::GetInstance() { + return Singleton<ChromeAppsClient, + LeakySingletonTraits<ChromeAppsClient> >::get(); +} + +std::vector<content::BrowserContext*> + ChromeAppsClient::GetLoadedBrowserContexts() { + std::vector<Profile*> profiles = + g_browser_process->profile_manager()->GetLoadedProfiles(); + return std::vector<content::BrowserContext*>(profiles.begin(), + profiles.end()); +} diff --git a/chrome/browser/apps/chrome_apps_client.h b/chrome/browser/apps/chrome_apps_client.h new file mode 100644 index 0000000..7788961 --- /dev/null +++ b/chrome/browser/apps/chrome_apps_client.h @@ -0,0 +1,33 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_APPS_CHROME_APPS_CLIENT_H_ +#define CHROME_BROWSER_APPS_CHROME_APPS_CLIENT_H_ + +#include "apps/apps_client.h" +#include "base/basictypes.h" +#include "base/compiler_specific.h" + +template<typename T> struct DefaultSingletonTraits; + +// The implementation of AppsClient for Chrome. +class ChromeAppsClient : public apps::AppsClient { + public: + ChromeAppsClient(); + virtual ~ChromeAppsClient(); + + // Get the LazyInstance for ChromeAppsClient. + static ChromeAppsClient* GetInstance(); + + private: + friend struct DefaultSingletonTraits<ChromeAppsClient>; + + // apps::AppsClient + virtual std::vector<content::BrowserContext*> GetLoadedBrowserContexts() + OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(ChromeAppsClient); +}; + +#endif // CHROME_BROWSER_APPS_CHROME_APPS_CLIENT_H_ diff --git a/chrome/browser/apps/web_view_interactive_browsertest.cc b/chrome/browser/apps/web_view_interactive_browsertest.cc index 5444150..40d8a06 100644 --- a/chrome/browser/apps/web_view_interactive_browsertest.cc +++ b/chrome/browser/apps/web_view_interactive_browsertest.cc @@ -8,6 +8,7 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/apps/app_browsertest_util.h" #include "chrome/browser/extensions/extension_test_message_listener.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/test/base/interactive_test_utils.h" #include "chrome/test/base/test_launcher_utils.h" #include "chrome/test/base/ui_test_utils.h" diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 5c38861..bd3d3e1 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -19,6 +19,7 @@ #include "base/synchronization/waitable_event.h" #include "base/threading/thread.h" #include "base/threading/thread_restrictions.h" +#include "chrome/browser/apps/chrome_apps_client.h" #include "chrome/browser/automation/automation_provider_list.h" #include "chrome/browser/background/background_mode_manager.h" #include "chrome/browser/chrome_browser_main.h" @@ -182,6 +183,7 @@ BrowserProcessImpl::BrowserProcessImpl( InitIdleMonitor(); #endif + apps::AppsClient::Set(ChromeAppsClient::GetInstance()); extensions::ExtensionsClient::Set( extensions::ChromeExtensionsClient::GetInstance()); extension_event_router_forwarder_ = new extensions::EventRouterForwarder; diff --git a/chrome/browser/chromeos/app_mode/app_session_lifetime.cc b/chrome/browser/chromeos/app_mode/app_session_lifetime.cc index e140e882..6209fdb68 100644 --- a/chrome/browser/chromeos/app_mode/app_session_lifetime.cc +++ b/chrome/browser/chromeos/app_mode/app_session_lifetime.cc @@ -12,6 +12,7 @@ #include "chrome/browser/chromeos/app_mode/kiosk_app_update_service.h" #include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/policy/browser_policy_connector.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/common/pref_names.h" using apps::ShellWindowRegistry; diff --git a/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc b/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc index d69b2cf..8aa550d 100644 --- a/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc +++ b/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc @@ -8,6 +8,7 @@ #include "apps/shell_window.h" #include "apps/shell_window_registry.h" #include "base/command_line.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/api/app_current_window_internal.h" #include "chrome/common/extensions/api/app_window.h" #include "chrome/common/extensions/features/feature_channel.h" diff --git a/chrome/browser/extensions/api/file_system/file_system_api.cc b/chrome/browser/extensions/api/file_system/file_system_api.cc index dc10a6b..d66afb6 100644 --- a/chrome/browser/extensions/api/file_system/file_system_api.cc +++ b/chrome/browser/extensions/api/file_system/file_system_api.cc @@ -22,6 +22,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/platform_util.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/apps/directory_access_confirmation_dialog.h" #include "chrome/browser/ui/chrome_select_file_policy.h" #include "chrome/common/chrome_paths.h" diff --git a/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc b/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc index ae73a0d..42a6b49 100644 --- a/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc +++ b/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc @@ -20,6 +20,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/media_galleries/media_file_system_registry.h" #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/storage_monitor/storage_monitor.h" #include "chrome/browser/ui/chrome_select_file_policy.h" #include "chrome/common/extensions/api/media_galleries.h" diff --git a/chrome/browser/extensions/window_open_apitest.cc b/chrome/browser/extensions/window_open_apitest.cc index b16edc1bf..531f65d 100644 --- a/chrome/browser/extensions/window_open_apitest.cc +++ b/chrome/browser/extensions/window_open_apitest.cc @@ -10,6 +10,7 @@ #include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/extension_test_message_listener.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_iterator.h" diff --git a/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc b/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc index 618397c..70f78a9 100644 --- a/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc +++ b/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc @@ -9,6 +9,7 @@ #include "ash/wm/window_util.h" #include "base/stl_util.h" #include "base/strings/stringprintf.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h" #include "ui/aura/client/activation_client.h" diff --git a/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac_browsertest.mm b/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac_browsertest.mm index e3fe7d4..8d282dd 100644 --- a/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac_browsertest.mm +++ b/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac_browsertest.mm @@ -13,6 +13,7 @@ #include "chrome/browser/apps/app_browsertest_util.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_test_message_listener.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" diff --git a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm index 9b203a8..bdedb8c 100644 --- a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm +++ b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm @@ -9,6 +9,7 @@ #include "apps/shell_window_registry.h" #include "chrome/browser/apps/app_browsertest_util.h" #include "chrome/browser/ui/extensions/application_launch.h" +#include "chrome/browser/profiles/profile.h" #include "content/public/browser/notification_service.h" #include "content/public/test/test_utils.h" diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi index 72a824f..301b965 100644 --- a/chrome/chrome_browser_extensions.gypi +++ b/chrome/chrome_browser_extensions.gypi @@ -67,6 +67,8 @@ '../extensions/browser/view_type_utils.h', 'browser/apps/app_url_redirector.cc', 'browser/apps/app_url_redirector.h', + 'browser/apps/chrome_apps_client.cc', + 'browser/apps/chrome_apps_client.h', 'browser/apps/shortcut_manager.cc', 'browser/apps/shortcut_manager.h', 'browser/apps/shortcut_manager_factory.cc', |