diff options
author | benwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-26 15:08:01 +0000 |
---|---|---|
committer | benwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-26 15:08:01 +0000 |
commit | 1298131894063dc1bc69268dd9769135805010ae (patch) | |
tree | eceb385dd0530cfedb0b3e903b8524b63c08b8a0 /apps | |
parent | 47348e5a21fda63b246c1d9ab9581da5970f0a0e (diff) | |
download | chromium_src-1298131894063dc1bc69268dd9769135805010ae.zip chromium_src-1298131894063dc1bc69268dd9769135805010ae.tar.gz chromium_src-1298131894063dc1bc69268dd9769135805010ae.tar.bz2 |
Move app shortcut manager into chrome/browser/apps
This code was previously in src/apps, which is meant to be independent
of chrome. The shortcut creation code is chrome specific so has been
moved to a new folder chrome/browser/apps, which is where chrome
specific apps non-ui code should now go.
BUG=159366
Review URL: https://chromiumcodereview.appspot.com/20286002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213919 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'apps')
-rw-r--r-- | apps/apps.gypi | 4 | ||||
-rw-r--r-- | apps/shortcut_manager.cc | 193 | ||||
-rw-r--r-- | apps/shortcut_manager.h | 58 | ||||
-rw-r--r-- | apps/shortcut_manager_factory.cc | 41 | ||||
-rw-r--r-- | apps/shortcut_manager_factory.h | 42 |
5 files changed, 0 insertions, 338 deletions
diff --git a/apps/apps.gypi b/apps/apps.gypi index 92a74a7..cb800dd 100644 --- a/apps/apps.gypi +++ b/apps/apps.gypi @@ -64,10 +64,6 @@ 'shell_window.h', 'shell_window_geometry_cache.cc', 'shell_window_geometry_cache.h', - 'shortcut_manager.cc', - 'shortcut_manager.h', - 'shortcut_manager_factory.cc', - 'shortcut_manager_factory.h', 'switches.cc', 'switches.h', ], diff --git a/apps/shortcut_manager.cc b/apps/shortcut_manager.cc deleted file mode 100644 index f744de2..0000000 --- a/apps/shortcut_manager.cc +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright (c) 2012 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/shortcut_manager.h" - -#include "apps/pref_names.h" -#include "base/bind.h" -#include "base/command_line.h" -#include "base/compiler_specific.h" -#include "base/prefs/pref_service.h" -#include "base/strings/string16.h" -#include "base/strings/utf_string_conversions.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/extensions/extension_system.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_info_cache.h" -#include "chrome/browser/profiles/profile_manager.h" -#include "chrome/browser/shell_integration.h" -#include "chrome/browser/ui/web_applications/web_app_ui.h" -#include "chrome/browser/web_applications/web_app.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/extensions/extension_set.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_source.h" - -using extensions::Extension; - -namespace { - -// Creates a shortcut for an application in the applications menu, if there is -// not already one present. -void CreateShortcutsInApplicationsMenu( - const ShellIntegration::ShortcutInfo& shortcut_info) { - ShellIntegration::ShortcutLocations creation_locations; - creation_locations.in_applications_menu = true; - // Create the shortcut in the Chrome Apps subdir. - creation_locations.applications_menu_subdir = - web_app::GetAppShortcutsSubdirName(); - web_app::CreateShortcuts(shortcut_info, creation_locations, - web_app::SHORTCUT_CREATION_AUTOMATED); -} - -bool ShouldCreateShortcutFor(const extensions::Extension* extension) { - return extension->is_platform_app() && - extension->location() != extensions::Manifest::COMPONENT && - extension->ShouldDisplayInAppLauncher(); -} - -} // namespace - -namespace apps { - -ShortcutManager::ShortcutManager(Profile* profile) - : profile_(profile), - is_profile_info_cache_observer_(false), - prefs_(profile->GetPrefs()), - weak_factory_(this) { - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, - content::Source<Profile>(profile_)); - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, - content::Source<Profile>(profile_)); - // Wait for extensions to be ready before running OnceOffCreateShortcuts. - registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, - content::Source<Profile>(profile_)); - - // TODO(mgiuca): This use of g_browser_process should be DCHECKed for - // content::BrowserThread::CurrentlyOn(content::BrowserThread::UI). This check - // currently fails browser_tests, due to http://crbug.com/251191. - ProfileManager* profile_manager = g_browser_process->profile_manager(); - // profile_manager might be NULL in testing environments. - if (profile_manager) { - profile_manager->GetProfileInfoCache().AddObserver(this); - is_profile_info_cache_observer_ = true; - } -} - -ShortcutManager::~ShortcutManager() { - if (g_browser_process && is_profile_info_cache_observer_) { - ProfileManager* profile_manager = g_browser_process->profile_manager(); - // profile_manager might be NULL in testing environments or during shutdown. - if (profile_manager) - profile_manager->GetProfileInfoCache().RemoveObserver(this); - } -} - -void ShortcutManager::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - switch (type) { - case chrome::NOTIFICATION_EXTENSIONS_READY: { - OnceOffCreateShortcuts(); - break; - } - case chrome::NOTIFICATION_EXTENSION_INSTALLED: { -#if defined(OS_MACOSX) - if (!CommandLine::ForCurrentProcess()-> - HasSwitch(switches::kEnableAppShims)) - break; -#endif // defined(OS_MACOSX) - - const extensions::InstalledExtensionInfo* installed_info = - content::Details<const extensions::InstalledExtensionInfo>(details) - .ptr(); - const Extension* extension = installed_info->extension; - if (ShouldCreateShortcutFor(extension)) { - // If the app is being updated, update any existing shortcuts but do not - // create new ones. If it is being installed, automatically create a - // shortcut in the applications menu (e.g., Start Menu). - base::Callback<void(const ShellIntegration::ShortcutInfo&)> - create_or_update; - if (installed_info->is_update) { - string16 old_title = UTF8ToUTF16(installed_info->old_name); - create_or_update = base::Bind(&web_app::UpdateAllShortcuts, - old_title); - } else { - create_or_update = base::Bind(&CreateShortcutsInApplicationsMenu); - } - - web_app::UpdateShortcutInfoAndIconForApp(*extension, profile_, - create_or_update); - } - break; - } - case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { - const Extension* extension = content::Details<const Extension>( - details).ptr(); - DeleteApplicationShortcuts(extension); - break; - } - default: - NOTREACHED(); - } -} - -void ShortcutManager::OnProfileWillBeRemoved( - const base::FilePath& profile_path) { - if (profile_path != profile_->GetPath()) - return; - content::BrowserThread::PostTask( - content::BrowserThread::FILE, FROM_HERE, - base::Bind(&web_app::internals::DeleteAllShortcutsForProfile, - profile_path)); -} - -void ShortcutManager::OnceOffCreateShortcuts() { - bool was_enabled = prefs_->GetBoolean(apps::prefs::kShortcutsHaveBeenCreated); - - // Creation of shortcuts on Mac currently sits behind --enable-app-shims. - // Until it is enabled permanently, we need to check the flag, and set the - // pref accordingly. -#if defined(OS_MACOSX) - bool is_now_enabled = - CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppShims); -#else - bool is_now_enabled = true; -#endif // defined(OS_MACOSX) - - if (was_enabled != is_now_enabled) - prefs_->SetBoolean(apps::prefs::kShortcutsHaveBeenCreated, is_now_enabled); - - if (was_enabled || !is_now_enabled) - return; - - // Check if extension system/service are available. They might not be in - // tests. - extensions::ExtensionSystem* extension_system; - ExtensionServiceInterface* extension_service; - if (!(extension_system = extensions::ExtensionSystem::Get(profile_)) || - !(extension_service = extension_system->extension_service())) - return; - - // Create an applications menu shortcut for each app in this profile. - const ExtensionSet* apps = extension_service->extensions(); - for (ExtensionSet::const_iterator it = apps->begin(); - it != apps->end(); ++it) { - if (ShouldCreateShortcutFor(it->get())) - web_app::UpdateShortcutInfoAndIconForApp( - *it->get(), profile_, base::Bind(&CreateShortcutsInApplicationsMenu)); - } -} - -void ShortcutManager::DeleteApplicationShortcuts( - const Extension* extension) { - ShellIntegration::ShortcutInfo delete_info = - web_app::ShortcutInfoForExtensionAndProfile(extension, profile_); - web_app::DeleteAllShortcuts(delete_info); -} - -} // namespace apps diff --git a/apps/shortcut_manager.h b/apps/shortcut_manager.h deleted file mode 100644 index 408802a..0000000 --- a/apps/shortcut_manager.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2012 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_SHORTCUT_MANAGER_H_ -#define APPS_SHORTCUT_MANAGER_H_ - -#include "base/memory/weak_ptr.h" -#include "chrome/browser/profiles/profile_info_cache_observer.h" -#include "chrome/common/extensions/extension.h" -#include "components/browser_context_keyed_service/browser_context_keyed_service.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" - -class PrefService; -class Profile; - -namespace apps { - -// This class manages the installation of shortcuts for platform apps. -class ShortcutManager : public BrowserContextKeyedService, - public content::NotificationObserver, - public ProfileInfoCacheObserver { - public: - explicit ShortcutManager(Profile* profile); - - virtual ~ShortcutManager(); - - // content::NotificationObserver - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - - // ProfileInfoCacheObserver - virtual void OnProfileWillBeRemoved( - const base::FilePath& profile_path) OVERRIDE; - - private: - // Checks if kShortcutsEnabled is set in prefs. If not, this sets it and - // creates shortcuts for all apps. - void OnceOffCreateShortcuts(); - - void DeleteApplicationShortcuts(const extensions::Extension* extension); - - content::NotificationRegistrar registrar_; - Profile* profile_; - bool is_profile_info_cache_observer_; - PrefService* prefs_; - - // Fields used when installing application shortcuts. - base::WeakPtrFactory<ShortcutManager> weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(ShortcutManager); -}; - -} // namespace apps - -#endif // APPS_SHORTCUT_MANAGER_H_ diff --git a/apps/shortcut_manager_factory.cc b/apps/shortcut_manager_factory.cc deleted file mode 100644 index f59e575..0000000 --- a/apps/shortcut_manager_factory.cc +++ /dev/null @@ -1,41 +0,0 @@ -// 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/shortcut_manager_factory.h" - -#include "apps/shortcut_manager.h" -#include "chrome/browser/profiles/profile.h" -#include "components/browser_context_keyed_service/browser_context_dependency_manager.h" - -namespace apps { - -// static -ShortcutManager* ShortcutManagerFactory::GetForProfile(Profile* profile) { - return static_cast<ShortcutManager*>( - GetInstance()->GetServiceForBrowserContext(profile, true)); -} - -ShortcutManagerFactory* ShortcutManagerFactory::GetInstance() { - return Singleton<ShortcutManagerFactory>::get(); -} - -ShortcutManagerFactory::ShortcutManagerFactory() - : BrowserContextKeyedServiceFactory( - "ShortcutManager", - BrowserContextDependencyManager::GetInstance()) { -} - -ShortcutManagerFactory::~ShortcutManagerFactory() { -} - -BrowserContextKeyedService* ShortcutManagerFactory::BuildServiceInstanceFor( - content::BrowserContext* profile) const { - return new ShortcutManager(static_cast<Profile*>(profile)); -} - -bool ShortcutManagerFactory::ServiceIsCreatedWithBrowserContext() const { - return true; -} - -} // namespace apps diff --git a/apps/shortcut_manager_factory.h b/apps/shortcut_manager_factory.h deleted file mode 100644 index 8b41f06..0000000 --- a/apps/shortcut_manager_factory.h +++ /dev/null @@ -1,42 +0,0 @@ -// 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_SHORTCUT_MANAGER_FACTORY_H_ -#define APPS_SHORTCUT_MANAGER_FACTORY_H_ - -#include "components/browser_context_keyed_service/browser_context_keyed_service_factory.h" - -template<typename Type> struct DefaultSingletonTraits; - -class Profile; - -namespace apps { - -class ShortcutManager; - -// Singleton that owns all ShortcutManagers and associates them with -// Profiles. Listens for the Profile's destruction notification and cleans up -// the associated ShortcutManager. -// ShortcutManagers should not exist in incognito profiles. -class ShortcutManagerFactory : public BrowserContextKeyedServiceFactory { - public: - static ShortcutManager* GetForProfile(Profile* profile); - - static ShortcutManagerFactory* GetInstance(); - - private: - friend struct DefaultSingletonTraits<ShortcutManagerFactory>; - - ShortcutManagerFactory(); - virtual ~ShortcutManagerFactory(); - - // BrowserContextKeyedServiceFactory: - virtual BrowserContextKeyedService* BuildServiceInstanceFor( - content::BrowserContext* profile) const OVERRIDE; - virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE; -}; - -} // namespace apps - -#endif // APPS_SHORTCUT_MANAGER_FACTORY_H_ |