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.hidden = true; | |
benwells
2014/06/05 09:27:43
I think this will have some effect on Linux; it mi
tmdiep
2014/06/06 02:49:55
I thought the purpose of adding NoDisplay=true in
Matt Giuca
2014/06/06 05:50:17
Yeah, NoDisplay=true is what you want if you want
| |
50 } else { | |
51 // Creates a shortcut for an app in the Chrome Apps subdir of the | |
52 // applications menu, if there is not already one present. | |
53 creation_locations.applications_menu_location = | |
54 web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS; | |
55 } | |
56 | |
50 web_app::CreateShortcuts( | 57 web_app::CreateShortcuts( |
51 web_app::SHORTCUT_CREATION_AUTOMATED, creation_locations, profile, app); | 58 web_app::SHORTCUT_CREATION_AUTOMATED, creation_locations, profile, app); |
52 } | 59 } |
53 | 60 |
54 void SetCurrentAppShortcutsVersion(PrefService* prefs) { | 61 void SetCurrentAppShortcutsVersion(PrefService* prefs) { |
55 prefs->SetInteger(prefs::kAppShortcutsVersion, kCurrentAppShortcutsVersion); | 62 prefs->SetInteger(prefs::kAppShortcutsVersion, kCurrentAppShortcutsVersion); |
56 } | 63 } |
57 | 64 |
58 } // namespace | 65 } // namespace |
59 | 66 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 if (!extension->is_app()) | 120 if (!extension->is_app()) |
114 return; | 121 return; |
115 | 122 |
116 // If the app is being updated, update any existing shortcuts but do not | 123 // 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 | 124 // create new ones. If it is being installed, automatically create a |
118 // shortcut in the applications menu (e.g., Start Menu). | 125 // shortcut in the applications menu (e.g., Start Menu). |
119 if (is_update && !from_ephemeral) { | 126 if (is_update && !from_ephemeral) { |
120 web_app::UpdateAllShortcuts( | 127 web_app::UpdateAllShortcuts( |
121 base::UTF8ToUTF16(old_name), profile_, extension); | 128 base::UTF8ToUTF16(old_name), profile_, extension); |
122 } else { | 129 } else { |
123 CreateShortcutsInApplicationsMenu(profile_, extension); | 130 CreateShortcutsForApp(profile_, extension); |
124 } | 131 } |
125 } | 132 } |
126 | 133 |
127 void AppShortcutManager::OnExtensionUninstalled( | 134 void AppShortcutManager::OnExtensionUninstalled( |
128 content::BrowserContext* browser_context, | 135 content::BrowserContext* browser_context, |
129 const Extension* extension) { | 136 const Extension* extension) { |
130 web_app::DeleteAllShortcuts(profile_, extension); | 137 web_app::DeleteAllShortcuts(profile_, extension); |
131 } | 138 } |
132 | 139 |
133 void AppShortcutManager::OnProfileWillBeRemoved( | 140 void AppShortcutManager::OnProfileWillBeRemoved( |
(...skipping 12 matching lines...) Expand all Loading... | |
146 return; | 153 return; |
147 | 154 |
148 content::BrowserThread::PostDelayedTask( | 155 content::BrowserThread::PostDelayedTask( |
149 content::BrowserThread::UI, | 156 content::BrowserThread::UI, |
150 FROM_HERE, | 157 FROM_HERE, |
151 base::Bind(&web_app::UpdateShortcutsForAllApps, | 158 base::Bind(&web_app::UpdateShortcutsForAllApps, |
152 profile_, | 159 profile_, |
153 base::Bind(&SetCurrentAppShortcutsVersion, prefs_)), | 160 base::Bind(&SetCurrentAppShortcutsVersion, prefs_)), |
154 base::TimeDelta::FromSeconds(kUpdateShortcutsForAllAppsDelay)); | 161 base::TimeDelta::FromSeconds(kUpdateShortcutsForAllAppsDelay)); |
155 } | 162 } |
OLD | NEW |