| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/apps/shortcut_manager.h" | 5 #include "chrome/browser/apps/shortcut_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 9 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_ui_util.h" | 15 #include "chrome/browser/extensions/extension_ui_util.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/profiles/profile_info_cache.h" | 17 #include "chrome/browser/profiles/profile_info_cache.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/browser/shell_integration.h" | 19 #include "chrome/browser/shell_integration.h" |
| 19 #include "chrome/browser/web_applications/web_app.h" | 20 #include "chrome/browser/web_applications/web_app.h" |
| 21 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 21 #include "components/pref_registry/pref_registry_syncable.h" | 23 #include "components/pref_registry/pref_registry_syncable.h" |
| 22 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 23 #include "extensions/browser/extension_registry.h" | 25 #include "extensions/browser/extension_registry.h" |
| 24 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
| 25 #include "extensions/browser/extension_util.h" | 27 #include "extensions/browser/extension_util.h" |
| 26 #include "extensions/common/extension_set.h" | 28 #include "extensions/common/extension_set.h" |
| 27 #include "extensions/common/one_shot_event.h" | 29 #include "extensions/common/one_shot_event.h" |
| 28 | 30 |
| 29 using extensions::Extension; | 31 using extensions::Extension; |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| 33 // This version number is stored in local prefs to check whether app shortcuts | 35 // This version number is stored in local prefs to check whether app shortcuts |
| 34 // need to be recreated. This might happen when we change various aspects of app | 36 // need to be recreated. This might happen when we change various aspects of app |
| 35 // shortcuts like command-line flags or associated icons, binaries, etc. | 37 // shortcuts like command-line flags or associated icons, binaries, etc. |
| 38 #if defined(OS_MACOSX) |
| 39 const int kCurrentAppShortcutsVersion = 1; |
| 40 #else |
| 36 const int kCurrentAppShortcutsVersion = 0; | 41 const int kCurrentAppShortcutsVersion = 0; |
| 42 #endif |
| 37 | 43 |
| 38 // Delay in seconds before running UpdateShortcutsForAllApps. | 44 // Delay in seconds before running UpdateShortcutsForAllApps. |
| 39 const int kUpdateShortcutsForAllAppsDelay = 10; | 45 const int kUpdateShortcutsForAllAppsDelay = 10; |
| 40 | 46 |
| 41 void CreateShortcutsForApp(Profile* profile, const Extension* app) { | 47 void CreateShortcutsForApp(Profile* profile, const Extension* app) { |
| 42 web_app::ShortcutLocations creation_locations; | 48 web_app::ShortcutLocations creation_locations; |
| 43 | 49 |
| 44 if (extensions::util::IsEphemeralApp(app->id(), profile)) { | 50 if (extensions::util::IsEphemeralApp(app->id(), profile)) { |
| 45 // Ephemeral apps should not have visible shortcuts, but may still require | 51 // Ephemeral apps should not have visible shortcuts, but may still require |
| 46 // platform-specific handling. | 52 // platform-specific handling. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 const base::FilePath& profile_path) { | 146 const base::FilePath& profile_path) { |
| 141 if (profile_path != profile_->GetPath()) | 147 if (profile_path != profile_->GetPath()) |
| 142 return; | 148 return; |
| 143 content::BrowserThread::PostTask( | 149 content::BrowserThread::PostTask( |
| 144 content::BrowserThread::FILE, FROM_HERE, | 150 content::BrowserThread::FILE, FROM_HERE, |
| 145 base::Bind(&web_app::internals::DeleteAllShortcutsForProfile, | 151 base::Bind(&web_app::internals::DeleteAllShortcutsForProfile, |
| 146 profile_path)); | 152 profile_path)); |
| 147 } | 153 } |
| 148 | 154 |
| 149 void AppShortcutManager::UpdateShortcutsForAllAppsIfNeeded() { | 155 void AppShortcutManager::UpdateShortcutsForAllAppsIfNeeded() { |
| 156 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) |
| 157 return; |
| 158 |
| 150 int last_version = prefs_->GetInteger(prefs::kAppShortcutsVersion); | 159 int last_version = prefs_->GetInteger(prefs::kAppShortcutsVersion); |
| 151 if (last_version >= kCurrentAppShortcutsVersion) | 160 if (last_version >= kCurrentAppShortcutsVersion) |
| 152 return; | 161 return; |
| 153 | 162 |
| 154 content::BrowserThread::PostDelayedTask( | 163 content::BrowserThread::PostDelayedTask( |
| 155 content::BrowserThread::UI, | 164 content::BrowserThread::UI, |
| 156 FROM_HERE, | 165 FROM_HERE, |
| 157 base::Bind(&web_app::UpdateShortcutsForAllApps, | 166 base::Bind(&web_app::UpdateShortcutsForAllApps, |
| 158 profile_, | 167 profile_, |
| 159 base::Bind(&SetCurrentAppShortcutsVersion, prefs_)), | 168 base::Bind(&SetCurrentAppShortcutsVersion, prefs_)), |
| 160 base::TimeDelta::FromSeconds(kUpdateShortcutsForAllAppsDelay)); | 169 base::TimeDelta::FromSeconds(kUpdateShortcutsForAllAppsDelay)); |
| 161 } | 170 } |
| OLD | NEW |