Index: chrome/browser/apps/shortcut_manager.cc |
diff --git a/chrome/browser/apps/shortcut_manager.cc b/chrome/browser/apps/shortcut_manager.cc |
index e909e82eb9c3dd149b1569ab95a9f67ac75cbb00..95ff76bc9e7ae5fc6d7a24cf912dee687f2104c5 100644 |
--- a/chrome/browser/apps/shortcut_manager.cc |
+++ b/chrome/browser/apps/shortcut_manager.cc |
@@ -12,7 +12,6 @@ |
#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/profiles/profile.h" |
#include "chrome/browser/profiles/profile_info_cache.h" |
#include "chrome/browser/profiles/profile_manager.h" |
@@ -24,8 +23,6 @@ |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/notification_details.h" |
#include "content/public/browser/notification_source.h" |
-#include "extensions/browser/extension_system.h" |
-#include "extensions/common/extension_set.h" |
#if defined(OS_MACOSX) |
#include "apps/app_shim/app_shim_mac.h" |
@@ -35,6 +32,11 @@ using extensions::Extension; |
namespace { |
+// This version number is stored in local prefs to check whether app shortcuts |
+// need to be recreated. This might happen when we change various aspects of app |
+// shortcuts like command line flags or associated icons, binaries, etc. |
Matt Giuca
2014/05/23 07:01:57
Nit: command-line
jackhou1
2014/05/26 07:57:37
Done.
|
+const int kCurrentAppShortcutsVersion = 1; |
+ |
// Creates a shortcut for an application in the applications menu, if there is |
// not already one present. |
void CreateShortcutsInApplicationsMenu(Profile* profile, |
@@ -47,20 +49,14 @@ void CreateShortcutsInApplicationsMenu(Profile* profile, |
web_app::SHORTCUT_CREATION_AUTOMATED, creation_locations, profile, app); |
} |
-bool ShouldCreateShortcutFor(const Extension* extension) { |
- return extension->is_platform_app() && |
- extension->location() != extensions::Manifest::COMPONENT && |
- extension->ShouldDisplayInAppLauncher(); |
-} |
- |
} // namespace |
// static |
void AppShortcutManager::RegisterProfilePrefs( |
user_prefs::PrefRegistrySyncable* registry) { |
// Indicates whether app shortcuts have been created. |
- registry->RegisterBooleanPref( |
- prefs::kAppShortcutsHaveBeenCreated, false, |
+ registry->RegisterIntegerPref( |
+ prefs::kAppShortcutsVersion, 0, |
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
} |
@@ -78,7 +74,8 @@ AppShortcutManager::AppShortcutManager(Profile* profile) |
content::Source<Profile>(profile_)); |
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
content::Source<Profile>(profile_)); |
- // Wait for extensions to be ready before running OnceOffCreateShortcuts. |
+ // Wait for extensions to be ready before running |
+ // UpdateShortcutsForAllAppsIfNeeded. |
registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
content::Source<Profile>(profile_)); |
@@ -104,7 +101,7 @@ void AppShortcutManager::Observe(int type, |
const content::NotificationDetails& details) { |
switch (type) { |
case chrome::NOTIFICATION_EXTENSIONS_READY: { |
- OnceOffCreateShortcuts(); |
+ UpdateShortcutsForAllAppsIfNeeded(); |
break; |
} |
case chrome::NOTIFICATION_EXTENSION_INSTALLED: { |
@@ -123,7 +120,7 @@ void AppShortcutManager::Observe(int type, |
if (installed_info->is_update) { |
web_app::UpdateAllShortcuts( |
base::UTF8ToUTF16(installed_info->old_name), profile_, extension); |
- } else if (ShouldCreateShortcutFor(extension)) { |
+ } else { |
CreateShortcutsInApplicationsMenu(profile_, extension); |
} |
break; |
@@ -149,36 +146,11 @@ void AppShortcutManager::OnProfileWillBeRemoved( |
profile_path)); |
} |
-void AppShortcutManager::OnceOffCreateShortcuts() { |
- bool was_enabled = prefs_->GetBoolean(prefs::kAppShortcutsHaveBeenCreated); |
- |
- // Creation of shortcuts on Mac currently can be disabled with |
- // --disable-app-shims, so check the flag, and set the pref accordingly. |
-#if defined(OS_MACOSX) |
- bool is_now_enabled = apps::IsAppShimsEnabled(); |
-#else |
- bool is_now_enabled = true; |
-#endif // defined(OS_MACOSX) |
- |
- if (was_enabled != is_now_enabled) |
- prefs_->SetBoolean(prefs::kAppShortcutsHaveBeenCreated, is_now_enabled); |
- |
- if (was_enabled || !is_now_enabled) |
+void AppShortcutManager::UpdateShortcutsForAllAppsIfNeeded() { |
+ int last_version = prefs_->GetInteger(prefs::kAppShortcutsVersion); |
+ if (last_version >= kCurrentAppShortcutsVersion) |
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 extensions::ExtensionSet* apps = extension_service->extensions(); |
- for (extensions::ExtensionSet::const_iterator it = apps->begin(); |
- it != apps->end(); ++it) { |
- if (ShouldCreateShortcutFor(it->get())) |
- CreateShortcutsInApplicationsMenu(profile_, it->get()); |
- } |
+ web_app::UpdateShortcutsForAllApps(profile_); |
+ prefs_->SetInteger(prefs::kAppShortcutsVersion, kCurrentAppShortcutsVersion); |
} |