OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/profiles/profile_shortcut_manager.h" | 5 #include "chrome/browser/profiles/profile_shortcut_manager.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include "chrome/installer/util/auto_launch_util.h" | 25 #include "chrome/installer/util/auto_launch_util.h" |
26 #include "chrome/installer/util/browser_distribution.h" | 26 #include "chrome/installer/util/browser_distribution.h" |
27 #include "chrome/installer/util/shell_util.h" | 27 #include "chrome/installer/util/shell_util.h" |
28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
29 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
30 #include "skia/ext/image_operations.h" | 30 #include "skia/ext/image_operations.h" |
31 #include "skia/ext/platform_canvas.h" | 31 #include "skia/ext/platform_canvas.h" |
32 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
33 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
34 #include "ui/gfx/icon_util.h" | 34 #include "ui/gfx/icon_util.h" |
35 #include "ui/gfx/image/image.h" | |
35 | 36 |
36 using content::BrowserThread; | 37 using content::BrowserThread; |
37 | 38 |
38 namespace { | 39 namespace { |
39 | 40 |
40 const char kProfileIconFileName[] = "Google Profile.ico"; | 41 const char kProfileIconFileName[] = "Google Profile.ico"; |
41 const int kProfileAvatarShortcutBadgeWidth = 28; | 42 const int kProfileAvatarShortcutBadgeWidth = 28; |
42 const int kProfileAvatarShortcutBadgeHeight = 28; | 43 const int kProfileAvatarShortcutBadgeHeight = 28; |
43 const int kShortcutIconSize = 48; | 44 const int kShortcutIconSize = 48; |
44 | 45 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 const base::Callback<bool(void)>& bool_function) { | 114 const base::Callback<bool(void)>& bool_function) { |
114 bool_function.Run(); | 115 bool_function.Run(); |
115 } | 116 } |
116 | 117 |
117 // Renames an existing Chrome desktop profile shortcut. Must be called on the | 118 // Renames an existing Chrome desktop profile shortcut. Must be called on the |
118 // FILE thread. | 119 // FILE thread. |
119 void RenameChromeDesktopShortcutForProfile( | 120 void RenameChromeDesktopShortcutForProfile( |
120 const string16& old_shortcut_file, | 121 const string16& old_shortcut_file, |
121 const string16& new_shortcut_file) { | 122 const string16& new_shortcut_file) { |
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
124 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
123 FilePath shortcut_path; | 125 FilePath shortcut_path; |
124 if (ShellUtil::GetDesktopPath(false, // User's directory instead of system. | 126 if (ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_DESKTOP, dist, false, |
125 &shortcut_path)) { | 127 &shortcut_path)) { |
126 FilePath old_shortcut_path = shortcut_path.Append(old_shortcut_file); | 128 FilePath old_shortcut_path = shortcut_path.Append(old_shortcut_file); |
127 FilePath new_shortcut_path = shortcut_path.Append(new_shortcut_file); | 129 FilePath new_shortcut_path = shortcut_path.Append(new_shortcut_file); |
128 if (!file_util::Move(old_shortcut_path, new_shortcut_path)) | 130 if (!file_util::Move(old_shortcut_path, new_shortcut_path)) |
129 LOG(ERROR) << "Could not rename Windows profile desktop shortcut."; | 131 LOG(ERROR) << "Could not rename Windows profile desktop shortcut."; |
130 } | 132 } |
131 } | 133 } |
132 | 134 |
133 // Create or update a profile desktop shortcut. Must be called on the FILE | 135 // Create or update a profile desktop shortcut. Must be called on the FILE |
134 // thread. | 136 // thread. |
135 void CreateOrUpdateProfileDesktopShortcut( | 137 void CreateOrUpdateProfileDesktopShortcut( |
136 const FilePath& profile_path, | 138 const FilePath& profile_path, |
137 const string16& profile_name, | 139 const string16& profile_name, |
138 const SkBitmap& avatar_image, | 140 const SkBitmap& avatar_image, |
139 bool create) { | 141 bool create) { |
140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
141 FilePath shortcut_icon = | 143 FilePath shortcut_icon = |
142 CreateChromeDesktopShortcutIconForProfile(profile_path, avatar_image); | 144 CreateChromeDesktopShortcutIconForProfile(profile_path, avatar_image); |
143 | 145 |
144 FilePath chrome_exe; | 146 FilePath chrome_exe; |
145 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) | 147 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
148 NOTREACHED(); | |
146 return; | 149 return; |
150 } | |
147 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 151 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
148 if (!dist) | 152 if (!dist) { |
153 NOTREACHED(); | |
robertshield
2012/10/02 13:08:04
we don't check the return value of GetDistribution
gab
2012/10/03 15:14:59
True, removed!
| |
149 return; | 154 return; |
150 string16 description(dist->GetAppDescription()); | 155 } |
151 | 156 |
152 uint32 options = create ? ShellUtil::SHORTCUT_CREATE_ALWAYS : | 157 ShellUtil::ChromeShortcutProperties properties; |
153 ShellUtil::SHORTCUT_NO_OPTIONS; | 158 properties.set_target(chrome_exe); |
154 ShellUtil::CreateChromeDesktopShortcut( | 159 properties.set_arguments(CreateProfileShortcutFlags(profile_path)); |
155 dist, | 160 if (!shortcut_icon.empty()) |
156 chrome_exe.value(), | 161 properties.set_icon(shortcut_icon); |
157 description, | 162 properties.set_shortcut_name( |
158 profile_name, | 163 ProfileShortcutManager::GetShortcutNameForProfile(profile_name)); |
159 CreateProfileShortcutFlags(profile_path), | 164 ShellUtil::ChromeShortcutOperation operation = |
160 shortcut_icon.empty() ? chrome_exe.value() : shortcut_icon.value(), | 165 create ? ShellUtil::SHORTCUT_CREATE_ALWAYS : |
161 shortcut_icon.empty() ? dist->GetIconIndex() : 0, | 166 ShellUtil::SHORTCUT_REPLACE_EXISTING; |
162 ShellUtil::CURRENT_USER, | 167 ShellUtil::CreateOrUpdateChromeShortcut( |
163 options); | 168 ShellUtil::SHORTCUT_DESKTOP, dist, properties, operation); |
164 } | 169 } |
165 | 170 |
166 } // namespace | 171 } // namespace |
167 | 172 |
168 class ProfileShortcutManagerWin : public ProfileShortcutManager, | 173 class ProfileShortcutManagerWin : public ProfileShortcutManager, |
169 public ProfileInfoCacheObserver { | 174 public ProfileInfoCacheObserver { |
170 public: | 175 public: |
171 explicit ProfileShortcutManagerWin(ProfileManager* manager); | 176 explicit ProfileShortcutManagerWin(ProfileManager* manager); |
172 virtual ~ProfileShortcutManagerWin(); | 177 virtual ~ProfileShortcutManagerWin(); |
173 | 178 |
(...skipping 26 matching lines...) Expand all Loading... | |
200 bool ProfileShortcutManager::IsFeatureEnabled() { | 205 bool ProfileShortcutManager::IsFeatureEnabled() { |
201 return false; | 206 return false; |
202 } | 207 } |
203 | 208 |
204 // static | 209 // static |
205 ProfileShortcutManager* ProfileShortcutManager::Create( | 210 ProfileShortcutManager* ProfileShortcutManager::Create( |
206 ProfileManager* manager) { | 211 ProfileManager* manager) { |
207 return new ProfileShortcutManagerWin(manager); | 212 return new ProfileShortcutManagerWin(manager); |
208 } | 213 } |
209 | 214 |
215 // static | |
216 string16 ProfileShortcutManager::GetShortcutNameForProfile( | |
217 const string16& profile_name) { | |
218 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
219 string16 shortcut_name(dist->GetAppShortCutName()); | |
220 shortcut_name.append(L" ("); | |
221 shortcut_name.append(profile_name); | |
222 shortcut_name.append(L")"); | |
223 return shortcut_name; | |
224 } | |
225 | |
210 ProfileShortcutManagerWin::ProfileShortcutManagerWin(ProfileManager* manager) | 226 ProfileShortcutManagerWin::ProfileShortcutManagerWin(ProfileManager* manager) |
211 : profile_manager_(manager) { | 227 : profile_manager_(manager) { |
212 profile_manager_->GetProfileInfoCache().AddObserver(this); | 228 profile_manager_->GetProfileInfoCache().AddObserver(this); |
213 } | 229 } |
214 | 230 |
215 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() { | 231 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() { |
216 profile_manager_->GetProfileInfoCache().RemoveObserver(this); | 232 profile_manager_->GetProfileInfoCache().RemoveObserver(this); |
217 } | 233 } |
218 | 234 |
219 void ProfileShortcutManagerWin::CreateProfileShortcut( | 235 void ProfileShortcutManagerWin::CreateProfileShortcut( |
(...skipping 24 matching lines...) Expand all Loading... | |
244 UpdateShortcutForProfileAtPath( | 260 UpdateShortcutForProfileAtPath( |
245 profile_manager_->GetProfileInfoCache().GetPathOfProfileAtIndex(0), | 261 profile_manager_->GetProfileInfoCache().GetPathOfProfileAtIndex(0), |
246 false); | 262 false); |
247 } | 263 } |
248 | 264 |
249 string16 profile_name_updated; | 265 string16 profile_name_updated; |
250 if (profile_manager_->GetProfileInfoCache().GetNumberOfProfiles() != 0) | 266 if (profile_manager_->GetProfileInfoCache().GetNumberOfProfiles() != 0) |
251 profile_name_updated = profile_name; | 267 profile_name_updated = profile_name; |
252 | 268 |
253 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 269 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
254 string16 shortcut; | 270 ShellUtil::ChromeShortcutProperties shortcut_properties; |
255 // If we can find the shortcut, delete it | 271 shortcut_properties.set_shortcut_name( |
256 if (ShellUtil::GetChromeShortcutName(dist, false, | 272 GetShortcutNameForProfile(profile_name_updated)); |
257 profile_name_updated, &shortcut)) { | 273 BrowserThread::PostTask( |
258 std::vector<string16> appended_names(1, shortcut); | 274 BrowserThread::FILE, FROM_HERE, |
259 BrowserThread::PostTask( | 275 base::Bind(&CallBoolFunction, base::Bind( |
260 BrowserThread::FILE, FROM_HERE, | 276 &ShellUtil::RemoveChromeShortcut, ShellUtil::SHORTCUT_DESKTOP, |
261 base::Bind(&CallBoolFunction, base::Bind( | 277 dist, shortcut_properties))); |
262 &ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames, | 278 |
263 appended_names))); | |
264 } | |
265 FilePath icon_path = profile_path.AppendASCII(kProfileIconFileName); | 279 FilePath icon_path = profile_path.AppendASCII(kProfileIconFileName); |
266 BrowserThread::PostTask( | 280 BrowserThread::PostTask( |
267 BrowserThread::FILE, FROM_HERE, | 281 BrowserThread::FILE, FROM_HERE, |
268 base::Bind(&CallBoolFunction, base::Bind( | 282 base::Bind(&CallBoolFunction, base::Bind( |
269 &file_util::Delete, icon_path, false))); | 283 &file_util::Delete, icon_path, false))); |
270 } | 284 } |
271 | 285 |
272 void ProfileShortcutManagerWin::OnProfileNameChanged( | 286 void ProfileShortcutManagerWin::OnProfileNameChanged( |
273 const FilePath& profile_path, | 287 const FilePath& profile_path, |
274 const string16& old_profile_name) { | 288 const string16& old_profile_name) { |
(...skipping 12 matching lines...) Expand all Loading... | |
287 GetIndexOfProfileWithPath(profile_path); | 301 GetIndexOfProfileWithPath(profile_path); |
288 if (profile_index == std::string::npos) | 302 if (profile_index == std::string::npos) |
289 return; | 303 return; |
290 // If the shortcut will have an appended name, get the profile name. | 304 // If the shortcut will have an appended name, get the profile name. |
291 string16 new_profile_name = | 305 string16 new_profile_name = |
292 (profile_manager_->GetProfileInfoCache().GetNumberOfProfiles() == 1) ? | 306 (profile_manager_->GetProfileInfoCache().GetNumberOfProfiles() == 1) ? |
293 string16() : | 307 string16() : |
294 profile_manager_->GetProfileInfoCache(). | 308 profile_manager_->GetProfileInfoCache(). |
295 GetNameOfProfileAtIndex(profile_index); | 309 GetNameOfProfileAtIndex(profile_index); |
296 | 310 |
297 string16 old_shortcut_file; | |
298 string16 new_shortcut_file; | |
299 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 311 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
300 if (ShellUtil::GetChromeShortcutName( | 312 string16 old_shortcut_file(GetShortcutNameForProfile(old_profile_name)); |
301 dist, false, old_profile_name, &old_shortcut_file) && | 313 string16 new_shortcut_file(GetShortcutNameForProfile(new_profile_name)); |
302 ShellUtil::GetChromeShortcutName( | 314 BrowserThread::PostTask( |
303 dist, false, new_profile_name, &new_shortcut_file)) { | 315 BrowserThread::FILE, FROM_HERE, |
304 BrowserThread::PostTask( | 316 base::Bind(&RenameChromeDesktopShortcutForProfile, |
305 BrowserThread::FILE, FROM_HERE, | 317 old_shortcut_file, |
306 base::Bind(&RenameChromeDesktopShortcutForProfile, | 318 new_shortcut_file)); |
307 old_shortcut_file, | |
308 new_shortcut_file)); | |
309 } | |
310 } | 319 } |
311 | 320 |
312 FilePath ProfileShortcutManagerWin::GetOtherProfilePath( | 321 FilePath ProfileShortcutManagerWin::GetOtherProfilePath( |
313 const FilePath& profile_path) { | 322 const FilePath& profile_path) { |
314 DCHECK_EQ(2U, profile_manager_->GetProfileInfoCache().GetNumberOfProfiles()); | 323 DCHECK_EQ(2U, profile_manager_->GetProfileInfoCache().GetNumberOfProfiles()); |
315 // Get the index of the current profile, in order to find the index of the | 324 // Get the index of the current profile, in order to find the index of the |
316 // other profile. | 325 // other profile. |
317 size_t current_profile_index = profile_manager_->GetProfileInfoCache(). | 326 size_t current_profile_index = profile_manager_->GetProfileInfoCache(). |
318 GetIndexOfProfileWithPath(profile_path); | 327 GetIndexOfProfileWithPath(profile_path); |
319 size_t other_profile_index = (current_profile_index == 0) ? 1 : 0; | 328 size_t other_profile_index = (current_profile_index == 0) ? 1 : 0; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 } | 374 } |
366 BrowserThread::PostTask( | 375 BrowserThread::PostTask( |
367 BrowserThread::FILE, FROM_HERE, | 376 BrowserThread::FILE, FROM_HERE, |
368 base::Bind(&CreateOrUpdateProfileDesktopShortcut, | 377 base::Bind(&CreateOrUpdateProfileDesktopShortcut, |
369 profile_path, new_shortcut_appended_name, | 378 profile_path, new_shortcut_appended_name, |
370 profile_avatar_bitmap_copy, create_always)); | 379 profile_avatar_bitmap_copy, create_always)); |
371 | 380 |
372 profile_manager_->GetProfileInfoCache().SetShortcutNameOfProfileAtIndex( | 381 profile_manager_->GetProfileInfoCache().SetShortcutNameOfProfileAtIndex( |
373 profile_index, new_shortcut_appended_name); | 382 profile_index, new_shortcut_appended_name); |
374 } | 383 } |
OLD | NEW |