Index: chrome/browser/apps/shortcut_manager.cc |
diff --git a/chrome/browser/apps/shortcut_manager.cc b/chrome/browser/apps/shortcut_manager.cc |
index 2e5221a4471cb009e326bd06480383a39715113b..4466ac6375975b69c5f70999cb25facb892508d1 100644 |
--- a/chrome/browser/apps/shortcut_manager.cc |
+++ b/chrome/browser/apps/shortcut_manager.cc |
@@ -12,8 +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/extensions/extension_ui_util.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/profiles/profile_info_cache.h" |
#include "chrome/browser/profiles/profile_manager.h" |
@@ -25,13 +23,16 @@ |
#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" |
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. |
+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, |
@@ -44,20 +45,14 @@ void CreateShortcutsInApplicationsMenu(Profile* profile, |
web_app::SHORTCUT_CREATION_AUTOMATED, creation_locations, profile, app); |
} |
-bool ShouldCreateShortcutFor(Profile* profile, const Extension* extension) { |
- return extension->is_platform_app() && |
- extension->location() != extensions::Manifest::COMPONENT && |
- extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile); |
-} |
- |
} // 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); |
} |
@@ -76,7 +71,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_)); |
@@ -102,7 +98,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_DEPRECATED: { |
@@ -116,7 +112,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(profile_, extension)) { |
+ } else { |
CreateShortcutsInApplicationsMenu(profile_, extension); |
} |
break; |
@@ -142,25 +138,11 @@ void AppShortcutManager::OnProfileWillBeRemoved( |
profile_path)); |
} |
-void AppShortcutManager::OnceOffCreateShortcuts() { |
- if (prefs_->GetBoolean(prefs::kAppShortcutsHaveBeenCreated)) |
tapted
2014/05/29 08:56:40
Is this pref still used elsewhere? (delete it?)
tapted
2014/05/29 13:07:44
oops - I was looking for red deletey text :o. It's
|
+void AppShortcutManager::UpdateShortcutsForAllAppsIfNeeded() { |
+ int last_version = prefs_->GetInteger(prefs::kAppShortcutsVersion); |
+ if (last_version >= kCurrentAppShortcutsVersion) |
return; |
- prefs_->SetBoolean(prefs::kAppShortcutsHaveBeenCreated, true); |
- |
- // 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(profile_, it->get())) |
- CreateShortcutsInApplicationsMenu(profile_, it->get()); |
- } |
+ web_app::UpdateShortcutsForAllApps(profile_); |
+ prefs_->SetInteger(prefs::kAppShortcutsVersion, kCurrentAppShortcutsVersion); |
} |