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/command_line.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/extensions/extension_ui_util.h" | 15 #include "chrome/browser/extensions/extension_ui_util.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/profiles/profile_info_cache.h" | 17 #include "chrome/browser/profiles/profile_info_cache.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/browser/shell_integration.h" | 19 #include "chrome/browser/shell_integration.h" |
20 #include "chrome/browser/web_applications/web_app.h" | 20 #include "chrome/browser/web_applications/web_app.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "components/pref_registry/pref_registry_syncable.h" | 23 #include "components/pref_registry/pref_registry_syncable.h" |
24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
25 #include "extensions/browser/extension_registry.h" | 25 #include "extensions/browser/extension_registry.h" |
26 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
| 27 #include "extensions/browser/extension_util.h" |
27 #include "extensions/common/extension_set.h" | 28 #include "extensions/common/extension_set.h" |
28 #include "extensions/common/one_shot_event.h" | 29 #include "extensions/common/one_shot_event.h" |
29 | 30 |
30 using extensions::Extension; | 31 using extensions::Extension; |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 // 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 |
35 // 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 |
36 // shortcuts like command-line flags or associated icons, binaries, etc. | 37 // shortcuts like command-line flags or associated icons, binaries, etc. |
37 const int kCurrentAppShortcutsVersion = 0; | 38 const int kCurrentAppShortcutsVersion = 0; |
38 | 39 |
39 // Delay in seconds before running UpdateShortcutsForAllApps. | 40 // Delay in seconds before running UpdateShortcutsForAllApps. |
40 const int kUpdateShortcutsForAllAppsDelay = 10; | 41 const int kUpdateShortcutsForAllAppsDelay = 10; |
41 | 42 |
42 // Creates a shortcut for an application in the applications menu, if there is | 43 void CreateShortcutsForApp(Profile* profile, const Extension* app) { |
43 // not already one present. | |
44 void CreateShortcutsInApplicationsMenu(Profile* profile, | |
45 const Extension* app) { | |
46 web_app::ShortcutLocations creation_locations; | 44 web_app::ShortcutLocations creation_locations; |
47 // Create the shortcut in the Chrome Apps subdir. | 45 |
48 creation_locations.applications_menu_location = | 46 if (extensions::util::IsEphemeralApp(app->id(), profile)) { |
49 web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS; | 47 // Ephemeral apps should not have visible shortcuts, but may still require |
| 48 // platform-specific handling. |
| 49 creation_locations.applications_menu_location = |
| 50 web_app::APP_MENU_LOCATION_HIDDEN; |
| 51 } else { |
| 52 // Creates a shortcut for an app in the Chrome Apps subdir of the |
| 53 // applications menu, if there is not already one present. |
| 54 creation_locations.applications_menu_location = |
| 55 web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS; |
| 56 } |
| 57 |
50 web_app::CreateShortcuts( | 58 web_app::CreateShortcuts( |
51 web_app::SHORTCUT_CREATION_AUTOMATED, creation_locations, profile, app); | 59 web_app::SHORTCUT_CREATION_AUTOMATED, creation_locations, profile, app); |
52 } | 60 } |
53 | 61 |
54 void SetCurrentAppShortcutsVersion(PrefService* prefs) { | 62 void SetCurrentAppShortcutsVersion(PrefService* prefs) { |
55 prefs->SetInteger(prefs::kAppShortcutsVersion, kCurrentAppShortcutsVersion); | 63 prefs->SetInteger(prefs::kAppShortcutsVersion, kCurrentAppShortcutsVersion); |
56 } | 64 } |
57 | 65 |
58 } // namespace | 66 } // namespace |
59 | 67 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 if (!extension->is_app()) | 121 if (!extension->is_app()) |
114 return; | 122 return; |
115 | 123 |
116 // If the app is being updated, update any existing shortcuts but do not | 124 // If the app is being updated, update any existing shortcuts but do not |
117 // create new ones. If it is being installed, automatically create a | 125 // create new ones. If it is being installed, automatically create a |
118 // shortcut in the applications menu (e.g., Start Menu). | 126 // shortcut in the applications menu (e.g., Start Menu). |
119 if (is_update && !from_ephemeral) { | 127 if (is_update && !from_ephemeral) { |
120 web_app::UpdateAllShortcuts( | 128 web_app::UpdateAllShortcuts( |
121 base::UTF8ToUTF16(old_name), profile_, extension); | 129 base::UTF8ToUTF16(old_name), profile_, extension); |
122 } else { | 130 } else { |
123 CreateShortcutsInApplicationsMenu(profile_, extension); | 131 CreateShortcutsForApp(profile_, extension); |
124 } | 132 } |
125 } | 133 } |
126 | 134 |
127 void AppShortcutManager::OnExtensionUninstalled( | 135 void AppShortcutManager::OnExtensionUninstalled( |
128 content::BrowserContext* browser_context, | 136 content::BrowserContext* browser_context, |
129 const Extension* extension) { | 137 const Extension* extension) { |
130 web_app::DeleteAllShortcuts(profile_, extension); | 138 web_app::DeleteAllShortcuts(profile_, extension); |
131 } | 139 } |
132 | 140 |
133 void AppShortcutManager::OnProfileWillBeRemoved( | 141 void AppShortcutManager::OnProfileWillBeRemoved( |
(...skipping 12 matching lines...) Expand all Loading... |
146 return; | 154 return; |
147 | 155 |
148 content::BrowserThread::PostDelayedTask( | 156 content::BrowserThread::PostDelayedTask( |
149 content::BrowserThread::UI, | 157 content::BrowserThread::UI, |
150 FROM_HERE, | 158 FROM_HERE, |
151 base::Bind(&web_app::UpdateShortcutsForAllApps, | 159 base::Bind(&web_app::UpdateShortcutsForAllApps, |
152 profile_, | 160 profile_, |
153 base::Bind(&SetCurrentAppShortcutsVersion, prefs_)), | 161 base::Bind(&SetCurrentAppShortcutsVersion, prefs_)), |
154 base::TimeDelta::FromSeconds(kUpdateShortcutsForAllAppsDelay)); | 162 base::TimeDelta::FromSeconds(kUpdateShortcutsForAllAppsDelay)); |
155 } | 163 } |
OLD | NEW |