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" |
(...skipping 30 matching lines...) Expand all Loading... |
41 #else | 41 #else |
42 const int kCurrentAppShortcutsVersion = 0; | 42 const int kCurrentAppShortcutsVersion = 0; |
43 #endif | 43 #endif |
44 | 44 |
45 // Delay in seconds before running UpdateShortcutsForAllApps. | 45 // Delay in seconds before running UpdateShortcutsForAllApps. |
46 const int kUpdateShortcutsForAllAppsDelay = 10; | 46 const int kUpdateShortcutsForAllAppsDelay = 10; |
47 | 47 |
48 void CreateShortcutsForApp(Profile* profile, const Extension* app) { | 48 void CreateShortcutsForApp(Profile* profile, const Extension* app) { |
49 web_app::ShortcutLocations creation_locations; | 49 web_app::ShortcutLocations creation_locations; |
50 | 50 |
51 if (extensions::util::IsEphemeralApp(app->id(), profile)) { | 51 // Creates a shortcut for an app in the Chrome Apps subdir of the |
52 // Ephemeral apps should not have visible shortcuts, but may still require | 52 // applications menu, if there is not already one present. |
53 // platform-specific handling. | 53 creation_locations.applications_menu_location = |
54 creation_locations.applications_menu_location = | 54 web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS; |
55 web_app::APP_MENU_LOCATION_HIDDEN; | |
56 } else { | |
57 // Creates a shortcut for an app in the Chrome Apps subdir of the | |
58 // applications menu, if there is not already one present. | |
59 creation_locations.applications_menu_location = | |
60 web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS; | |
61 } | |
62 | 55 |
63 web_app::CreateShortcuts( | 56 web_app::CreateShortcuts( |
64 web_app::SHORTCUT_CREATION_AUTOMATED, creation_locations, profile, app); | 57 web_app::SHORTCUT_CREATION_AUTOMATED, creation_locations, profile, app); |
65 } | 58 } |
66 | 59 |
67 void SetCurrentAppShortcutsVersion(PrefService* prefs) { | 60 void SetCurrentAppShortcutsVersion(PrefService* prefs) { |
68 prefs->SetInteger(prefs::kAppShortcutsVersion, kCurrentAppShortcutsVersion); | 61 prefs->SetInteger(prefs::kAppShortcutsVersion, kCurrentAppShortcutsVersion); |
69 } | 62 } |
70 | 63 |
71 } // namespace | 64 } // namespace |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 // profile_manager might be NULL in testing environments or during shutdown. | 105 // profile_manager might be NULL in testing environments or during shutdown. |
113 if (profile_manager) | 106 if (profile_manager) |
114 profile_manager->GetProfileInfoCache().RemoveObserver(this); | 107 profile_manager->GetProfileInfoCache().RemoveObserver(this); |
115 } | 108 } |
116 } | 109 } |
117 | 110 |
118 void AppShortcutManager::OnExtensionWillBeInstalled( | 111 void AppShortcutManager::OnExtensionWillBeInstalled( |
119 content::BrowserContext* browser_context, | 112 content::BrowserContext* browser_context, |
120 const Extension* extension, | 113 const Extension* extension, |
121 bool is_update, | 114 bool is_update, |
122 bool from_ephemeral, | |
123 const std::string& old_name) { | 115 const std::string& old_name) { |
124 if (!extension->is_app()) | 116 if (!extension->is_app()) |
125 return; | 117 return; |
126 | 118 |
127 // If the app is being updated, update any existing shortcuts but do not | 119 // If the app is being updated, update any existing shortcuts but do not |
128 // create new ones. If it is being installed, automatically create a | 120 // create new ones. If it is being installed, automatically create a |
129 // shortcut in the applications menu (e.g., Start Menu). | 121 // shortcut in the applications menu (e.g., Start Menu). |
130 if (is_update && !from_ephemeral) { | 122 if (is_update) { |
131 web_app::UpdateAllShortcuts( | 123 web_app::UpdateAllShortcuts( |
132 base::UTF8ToUTF16(old_name), profile_, extension); | 124 base::UTF8ToUTF16(old_name), profile_, extension); |
133 } else { | 125 } else { |
134 CreateShortcutsForApp(profile_, extension); | 126 CreateShortcutsForApp(profile_, extension); |
135 } | 127 } |
136 } | 128 } |
137 | 129 |
138 void AppShortcutManager::OnExtensionUninstalled( | 130 void AppShortcutManager::OnExtensionUninstalled( |
139 content::BrowserContext* browser_context, | 131 content::BrowserContext* browser_context, |
140 const Extension* extension, | 132 const Extension* extension, |
(...skipping 20 matching lines...) Expand all Loading... |
161 return; | 153 return; |
162 | 154 |
163 content::BrowserThread::PostDelayedTask( | 155 content::BrowserThread::PostDelayedTask( |
164 content::BrowserThread::UI, | 156 content::BrowserThread::UI, |
165 FROM_HERE, | 157 FROM_HERE, |
166 base::Bind(&web_app::UpdateShortcutsForAllApps, | 158 base::Bind(&web_app::UpdateShortcutsForAllApps, |
167 profile_, | 159 profile_, |
168 base::Bind(&SetCurrentAppShortcutsVersion, prefs_)), | 160 base::Bind(&SetCurrentAppShortcutsVersion, prefs_)), |
169 base::TimeDelta::FromSeconds(kUpdateShortcutsForAllAppsDelay)); | 161 base::TimeDelta::FromSeconds(kUpdateShortcutsForAllAppsDelay)); |
170 } | 162 } |
OLD | NEW |