Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(504)

Side by Side Diff: chrome/browser/profiles/profile_shortcut_manager_win.cc

Issue 11876027: ProfileShortcutManagerWin: Don't create user level shortcut when system level one exists. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_win.h" 5 #include "chrome/browser/profiles/profile_shortcut_manager_win.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 const FilePath icon_path = 106 const FilePath icon_path =
107 profile_path.AppendASCII(profiles::internal::kProfileIconFileName); 107 profile_path.AppendASCII(profiles::internal::kProfileIconFileName);
108 // TODO(asvitkine): Create icon with a large 256x256 bitmap. 108 // TODO(asvitkine): Create icon with a large 256x256 bitmap.
109 if (!IconUtil::CreateIconFileFromSkBitmap(final_bitmap, SkBitmap(), 109 if (!IconUtil::CreateIconFileFromSkBitmap(final_bitmap, SkBitmap(),
110 icon_path)) 110 icon_path))
111 return FilePath(); 111 return FilePath();
112 112
113 return icon_path; 113 return icon_path;
114 } 114 }
115 115
116 // Gets the directory where to create desktop shortcuts. 116 // Gets the user and system directories for desktop shortcuts.
gab 2013/01/16 17:44:00 nit: Add comment about return value?
Alexei Svitkine (slow) 2013/01/16 17:59:56 Done.
117 bool GetDesktopShortcutsDirectory(FilePath* directory) { 117 bool GetDesktopShortcutsDirectories(FilePath* user_shortcuts_directory,
118 const bool result = 118 FilePath* system_shortcuts_directory) {
119 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, 119 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
120 BrowserDistribution::GetDistribution(), 120 if (user_shortcuts_directory &&
121 ShellUtil::CURRENT_USER, directory); 121 !ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP,
122 DCHECK(result); 122 distribution, ShellUtil::CURRENT_USER,
123 return result; 123 user_shortcuts_directory)) {
124 NOTREACHED();
125 return false;
126 }
127 if (system_shortcuts_directory &&
128 !ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP,
129 distribution, ShellUtil::SYSTEM_LEVEL,
130 system_shortcuts_directory)) {
131 NOTREACHED();
132 return false;
133 }
134 return true;
124 } 135 }
125 136
126 // Returns the long form of |path|, which will expand any shortened components 137 // Returns the long form of |path|, which will expand any shortened components
127 // like "foo~2" to their full names. 138 // like "foo~2" to their full names.
128 FilePath ConvertToLongPath(const FilePath& path) { 139 FilePath ConvertToLongPath(const FilePath& path) {
129 const size_t length = GetLongPathName(path.value().c_str(), NULL, 0); 140 const size_t length = GetLongPathName(path.value().c_str(), NULL, 0);
130 if (length != 0 && length != path.value().length()) { 141 if (length != 0 && length != path.value().length()) {
131 std::vector<wchar_t> long_path(length); 142 std::vector<wchar_t> long_path(length);
132 if (GetLongPathName(path.value().c_str(), &long_path[0], length) != 0) 143 if (GetLongPathName(path.value().c_str(), &long_path[0], length) != 0)
133 return FilePath(&long_path[0]); 144 return FilePath(&long_path[0]);
(...skipping 20 matching lines...) Expand all
154 } 165 }
155 166
156 // Populates |paths| with the file paths of Chrome desktop shortcuts that have 167 // Populates |paths| with the file paths of Chrome desktop shortcuts that have
157 // the specified |command_line|. If |include_empty_command_lines| is true, 168 // the specified |command_line|. If |include_empty_command_lines| is true,
158 // Chrome desktop shortcuts with empty command lines will also be included. 169 // Chrome desktop shortcuts with empty command lines will also be included.
159 void ListDesktopShortcutsWithCommandLine(const FilePath& chrome_exe, 170 void ListDesktopShortcutsWithCommandLine(const FilePath& chrome_exe,
160 const string16& command_line, 171 const string16& command_line,
161 bool include_empty_command_lines, 172 bool include_empty_command_lines,
162 std::vector<FilePath>* paths) { 173 std::vector<FilePath>* paths) {
163 FilePath shortcuts_directory; 174 FilePath shortcuts_directory;
164 if (!GetDesktopShortcutsDirectory(&shortcuts_directory)) 175 if (!GetDesktopShortcutsDirectories(&shortcuts_directory, NULL))
gab 2013/01/16 17:44:00 nit: perhaps rename all instances of |shortcuts_di
Alexei Svitkine (slow) 2013/01/16 17:59:56 Done.
165 return; 176 return;
166 177
167 file_util::FileEnumerator enumerator(shortcuts_directory, false, 178 file_util::FileEnumerator enumerator(shortcuts_directory, false,
168 file_util::FileEnumerator::FILES); 179 file_util::FileEnumerator::FILES);
169 for (FilePath path = enumerator.Next(); !path.empty(); 180 for (FilePath path = enumerator.Next(); !path.empty();
170 path = enumerator.Next()) { 181 path = enumerator.Next()) {
171 string16 shortcut_command_line; 182 string16 shortcut_command_line;
172 if (!IsChromeShortcut(path, chrome_exe, &shortcut_command_line)) 183 if (!IsChromeShortcut(path, chrome_exe, &shortcut_command_line))
173 continue; 184 continue;
174 185
175 // TODO(asvitkine): Change this to build a CommandLine object and ensure all 186 // TODO(asvitkine): Change this to build a CommandLine object and ensure all
176 // args from |command_line| are present in the shortcut's CommandLine. This 187 // args from |command_line| are present in the shortcut's CommandLine. This
177 // will be more robust when |command_line| contains multiple args. 188 // will be more robust when |command_line| contains multiple args.
178 if ((shortcut_command_line.empty() && include_empty_command_lines) || 189 if ((shortcut_command_line.empty() && include_empty_command_lines) ||
179 (shortcut_command_line.find(command_line) != string16::npos)) { 190 (shortcut_command_line.find(command_line) != string16::npos)) {
180 paths->push_back(path); 191 paths->push_back(path);
181 } 192 }
182 } 193 }
183 } 194 }
184 195
185 // Renames an existing Chrome desktop profile shortcut. Must be called on the 196 // Renames an existing Chrome desktop profile shortcut. Must be called on the
186 // FILE thread. 197 // FILE thread.
187 void RenameChromeDesktopShortcutForProfile( 198 void RenameChromeDesktopShortcutForProfile(
188 const string16& old_shortcut_file, 199 const string16& old_shortcut_filename,
189 const string16& new_shortcut_file) { 200 const string16& new_shortcut_filename) {
190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
191 202
192 FilePath shortcuts_directory; 203 FilePath user_shortcuts_directory;
193 if (!GetDesktopShortcutsDirectory(&shortcuts_directory)) 204 FilePath system_shortcuts_directory;
205 if (!GetDesktopShortcutsDirectories(&user_shortcuts_directory,
206 &system_shortcuts_directory)) {
194 return; 207 return;
208 }
195 209
196 FilePath old_shortcut_path = shortcuts_directory.Append(old_shortcut_file); 210 const FilePath old_shortcut_path =
197 // If the shortcut does not exist, it may have been renamed by the user. In 211 user_shortcuts_directory.Append(old_shortcut_filename);
198 // that case, its name should not be changed. 212 const FilePath new_shortcut_path =
199 if (!file_util::PathExists(old_shortcut_path)) 213 user_shortcuts_directory.Append(new_shortcut_filename);
200 return;
201 214
202 FilePath new_shortcut_path = shortcuts_directory.Append(new_shortcut_file); 215 if (file_util::PathExists(old_shortcut_path)) {
203 if (!file_util::Move(old_shortcut_path, new_shortcut_path)) 216 // Rename the old shortcut unless a system-level shortcut exists at the
204 LOG(ERROR) << "Could not rename Windows profile desktop shortcut."; 217 // destination, in which case the old shortcut is simply deleted.
218 const FilePath possible_new_system_shortcut =
219 system_shortcuts_directory.Append(new_shortcut_filename);
220 if (file_util::PathExists(possible_new_system_shortcut))
221 file_util::Delete(old_shortcut_path, false);
222 else if (!file_util::Move(old_shortcut_path, new_shortcut_path))
223 LOG(ERROR) << "Could not rename Windows profile desktop shortcut.";
gab 2013/01/16 17:44:00 nit: DLOG(ERROR) --> We will never actually get re
Alexei Svitkine (slow) 2013/01/16 17:59:56 Done.
224 } else {
225 // If the shortcut does not exist, it may have been renamed by the user. In
226 // that case, its name should not be changed.
227 // It's also possible that a system-level shortcut exists instead, for
228 // example the original Chrome shortcut from an installation. If that's the
229 // case, copy that one over - it will get its properties updated by the code
230 // in |CreateOrUpdateDesktopShortcutsForProfile()|.
231 const FilePath possible_old_system_shortcut =
232 system_shortcuts_directory.Append(old_shortcut_filename);
233 if (file_util::PathExists(possible_old_system_shortcut))
234 file_util::CopyFile(possible_old_system_shortcut, new_shortcut_path);
gab 2013/01/16 17:44:00 Actually I just realized: if the shortcut has been
gab 2013/01/16 17:44:52 Should probably add a test for this too... shortcu
Alexei Svitkine (slow) 2013/01/16 17:59:56 There shouldn't ever be a system-level *profile* s
gab 2013/01/16 18:17:32 Ah right :) -- perhaps the comment could be clarif
Alexei Svitkine (slow) 2013/01/16 18:40:42 Comment updated.
gab 2013/01/16 18:42:41 Thanks, still lgtm.
235 }
205 } 236 }
206 237
207 // Updates all desktop shortcuts for the given profile to have the specified 238 // Updates all desktop shortcuts for the given profile to have the specified
208 // parameters. If |create_mode| is CREATE_WHEN_NONE_FOUND, a new shortcut is 239 // parameters. If |create_mode| is CREATE_WHEN_NONE_FOUND, a new shortcut is
209 // created if no existing ones were found. Whether non-profile shortcuts should 240 // created if no existing ones were found. Whether non-profile shortcuts should
210 // be updated is specified by |action|. Must be called on the FILE thread. 241 // be updated is specified by |action|. Must be called on the FILE thread.
211 void CreateOrUpdateDesktopShortcutsForProfile( 242 void CreateOrUpdateDesktopShortcutsForProfile(
212 const FilePath& profile_path, 243 const FilePath& profile_path,
244 const string16& old_profile_name,
213 const string16& profile_name, 245 const string16& profile_name,
214 const SkBitmap& avatar_image, 246 const SkBitmap& avatar_image,
215 ProfileShortcutManagerWin::CreateOrUpdateMode create_mode, 247 ProfileShortcutManagerWin::CreateOrUpdateMode create_mode,
216 ProfileShortcutManagerWin::NonProfileShortcutAction action) { 248 ProfileShortcutManagerWin::NonProfileShortcutAction action) {
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
218 250
219 FilePath chrome_exe; 251 FilePath chrome_exe;
220 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 252 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
221 NOTREACHED(); 253 NOTREACHED();
222 return; 254 return;
223 } 255 }
224 256
225 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); 257 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
226 // Ensure that the distribution supports creating shortcuts. If it doesn't, 258 // Ensure that the distribution supports creating shortcuts. If it doesn't,
227 // the following code may result in NOTREACHED() being hit. 259 // the following code may result in NOTREACHED() being hit.
228 DCHECK(distribution->CanCreateDesktopShortcuts()); 260 DCHECK(distribution->CanCreateDesktopShortcuts());
229 installer::Product product(distribution); 261
262 if (old_profile_name != profile_name) {
263 const string16 old_shortcut_filename =
264 profiles::internal::GetShortcutFilenameForProfile(old_profile_name,
265 distribution);
266 const string16 new_shortcut_filename =
267 profiles::internal::GetShortcutFilenameForProfile(profile_name,
268 distribution);
269 RenameChromeDesktopShortcutForProfile(old_shortcut_filename,
270 new_shortcut_filename);
271 }
230 272
231 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); 273 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER);
274 installer::Product product(distribution);
232 product.AddDefaultShortcutProperties(chrome_exe, &properties); 275 product.AddDefaultShortcutProperties(chrome_exe, &properties);
233 276
234 const string16 command_line = 277 const string16 command_line =
235 profiles::internal::CreateProfileShortcutFlags(profile_path); 278 profiles::internal::CreateProfileShortcutFlags(profile_path);
236 279
237 // Only set the profile-specific properties when |profile_name| is non empty. 280 // Only set the profile-specific properties when |profile_name| is non empty.
238 // If it is empty, it means the shortcut being created should be a regular, 281 // If it is empty, it means the shortcut being created should be a regular,
239 // non-profile Chrome shortcut. 282 // non-profile Chrome shortcut.
240 if (!profile_name.empty()) { 283 if (!profile_name.empty()) {
241 const FilePath shortcut_icon = 284 const FilePath shortcut_icon =
(...skipping 13 matching lines...) Expand all
255 std::vector<FilePath> shortcuts; 298 std::vector<FilePath> shortcuts;
256 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, 299 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line,
257 action == ProfileShortcutManagerWin::UPDATE_NON_PROFILE_SHORTCUTS, 300 action == ProfileShortcutManagerWin::UPDATE_NON_PROFILE_SHORTCUTS,
258 &shortcuts); 301 &shortcuts);
259 if (create_mode == ProfileShortcutManagerWin::CREATE_WHEN_NONE_FOUND && 302 if (create_mode == ProfileShortcutManagerWin::CREATE_WHEN_NONE_FOUND &&
260 shortcuts.empty()) { 303 shortcuts.empty()) {
261 const string16 shortcut_name = 304 const string16 shortcut_name =
262 profiles::internal::GetShortcutFilenameForProfile(profile_name, 305 profiles::internal::GetShortcutFilenameForProfile(profile_name,
263 distribution); 306 distribution);
264 shortcuts.push_back(FilePath(shortcut_name)); 307 shortcuts.push_back(FilePath(shortcut_name));
265 operation = ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS; 308 operation = ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL;
266 } 309 }
267 310
268 for (size_t i = 0; i < shortcuts.size(); ++i) { 311 for (size_t i = 0; i < shortcuts.size(); ++i) {
269 const FilePath shortcut_name = shortcuts[i].BaseName().RemoveExtension(); 312 const FilePath shortcut_name = shortcuts[i].BaseName().RemoveExtension();
270 properties.set_shortcut_name(shortcut_name.value()); 313 properties.set_shortcut_name(shortcut_name.value());
271 ShellUtil::CreateOrUpdateShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, 314 ShellUtil::CreateOrUpdateShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP,
272 distribution, properties, operation); 315 distribution, properties, operation);
273 } 316 }
274 } 317 }
275 318
276 // Returns true if any desktop shortcuts exist with target |chrome_exe|, 319 // Returns true if any desktop shortcuts exist with target |chrome_exe|,
277 // regardless of their command line arguments. 320 // regardless of their command line arguments.
278 bool ChromeDesktopShortcutsExist(const FilePath& chrome_exe) { 321 bool ChromeDesktopShortcutsExist(const FilePath& chrome_exe) {
279 FilePath shortcuts_directory; 322 FilePath shortcuts_directory;
280 if (!GetDesktopShortcutsDirectory(&shortcuts_directory)) 323 if (!GetDesktopShortcutsDirectories(&shortcuts_directory, NULL))
281 return false; 324 return false;
282 325
283 file_util::FileEnumerator enumerator(shortcuts_directory, false, 326 file_util::FileEnumerator enumerator(shortcuts_directory, false,
284 file_util::FileEnumerator::FILES); 327 file_util::FileEnumerator::FILES);
285 for (FilePath path = enumerator.Next(); !path.empty(); 328 for (FilePath path = enumerator.Next(); !path.empty();
286 path = enumerator.Next()) { 329 path = enumerator.Next()) {
287 if (IsChromeShortcut(path, chrome_exe, NULL)) 330 if (IsChromeShortcut(path, chrome_exe, NULL))
288 return true; 331 return true;
289 } 332 }
290 333
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // Ensure that the distribution supports creating shortcuts. If it doesn't, 376 // Ensure that the distribution supports creating shortcuts. If it doesn't,
334 // the following code may result in NOTREACHED() being hit. 377 // the following code may result in NOTREACHED() being hit.
335 DCHECK(distribution->CanCreateDesktopShortcuts()); 378 DCHECK(distribution->CanCreateDesktopShortcuts());
336 installer::Product product(distribution); 379 installer::Product product(distribution);
337 380
338 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); 381 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER);
339 product.AddDefaultShortcutProperties(chrome_exe, &properties); 382 product.AddDefaultShortcutProperties(chrome_exe, &properties);
340 properties.set_shortcut_name( 383 properties.set_shortcut_name(
341 profiles::internal::GetShortcutFilenameForProfile(string16(), 384 profiles::internal::GetShortcutFilenameForProfile(string16(),
342 distribution)); 385 distribution));
343 ShellUtil::CreateOrUpdateShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, 386 ShellUtil::CreateOrUpdateShortcut(
344 distribution, properties, 387 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution, properties,
345 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS); 388 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL);
346 } 389 }
347 } 390 }
348 391
349 // Returns true if profile at |profile_path| has any shortcuts. Does not 392 // Returns true if profile at |profile_path| has any shortcuts. Does not
350 // consider non-profile shortcuts. Must be called on the FILE thread. 393 // consider non-profile shortcuts. Must be called on the FILE thread.
351 bool HasAnyProfileShortcuts(const FilePath& profile_path) { 394 bool HasAnyProfileShortcuts(const FilePath& profile_path) {
352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 395 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
353 396
354 FilePath chrome_exe; 397 FilePath chrome_exe;
355 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 398 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, 541 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY,
499 IGNORE_NON_PROFILE_SHORTCUTS); 542 IGNORE_NON_PROFILE_SHORTCUTS);
500 } 543 }
501 544
502 void ProfileShortcutManagerWin::OnProfileAvatarChanged( 545 void ProfileShortcutManagerWin::OnProfileAvatarChanged(
503 const FilePath& profile_path) { 546 const FilePath& profile_path) {
504 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, 547 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY,
505 IGNORE_NON_PROFILE_SHORTCUTS); 548 IGNORE_NON_PROFILE_SHORTCUTS);
506 } 549 }
507 550
508 void ProfileShortcutManagerWin::StartProfileShortcutNameChange(
509 const FilePath& profile_path,
510 const string16& old_profile_name) {
511 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
512 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_path);
513 if (profile_index == std::string::npos)
514 return;
515 // If the shortcut will have an appended name, get the profile name.
516 string16 new_profile_name;
517 if (cache.GetNumberOfProfiles() != 1)
518 new_profile_name = cache.GetNameOfProfileAtIndex(profile_index);
519
520 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
521 const string16 old_shortcut_file =
522 profiles::internal::GetShortcutFilenameForProfile(old_profile_name,
523 distribution);
524 const string16 new_shortcut_file =
525 profiles::internal::GetShortcutFilenameForProfile(new_profile_name,
526 distribution);
527 BrowserThread::PostTask(
528 BrowserThread::FILE, FROM_HERE,
529 base::Bind(&RenameChromeDesktopShortcutForProfile,
530 old_shortcut_file,
531 new_shortcut_file));
532 }
533
534 FilePath ProfileShortcutManagerWin::GetOtherProfilePath( 551 FilePath ProfileShortcutManagerWin::GetOtherProfilePath(
535 const FilePath& profile_path) { 552 const FilePath& profile_path) {
536 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); 553 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
537 DCHECK_EQ(2U, cache.GetNumberOfProfiles()); 554 DCHECK_EQ(2U, cache.GetNumberOfProfiles());
538 // Get the index of the current profile, in order to find the index of the 555 // Get the index of the current profile, in order to find the index of the
539 // other profile. 556 // other profile.
540 size_t current_profile_index = cache.GetIndexOfProfileWithPath(profile_path); 557 size_t current_profile_index = cache.GetIndexOfProfileWithPath(profile_path);
541 size_t other_profile_index = (current_profile_index == 0) ? 1 : 0; 558 size_t other_profile_index = (current_profile_index == 0) ? 1 : 0;
542 return cache.GetPathOfProfileAtIndex(other_profile_index); 559 return cache.GetPathOfProfileAtIndex(other_profile_index);
543 } 560 }
544 561
545 void ProfileShortcutManagerWin::CreateOrUpdateShortcutsForProfileAtPath( 562 void ProfileShortcutManagerWin::CreateOrUpdateShortcutsForProfileAtPath(
546 const FilePath& profile_path, 563 const FilePath& profile_path,
547 CreateOrUpdateMode create_mode, 564 CreateOrUpdateMode create_mode,
548 NonProfileShortcutAction action) { 565 NonProfileShortcutAction action) {
549 ProfileInfoCache* cache = &profile_manager_->GetProfileInfoCache(); 566 ProfileInfoCache* cache = &profile_manager_->GetProfileInfoCache();
550 size_t profile_index = cache->GetIndexOfProfileWithPath(profile_path); 567 size_t profile_index = cache->GetIndexOfProfileWithPath(profile_path);
551 if (profile_index == std::string::npos) 568 if (profile_index == std::string::npos)
552 return; 569 return;
553 bool remove_badging = cache->GetNumberOfProfiles() == 1; 570 bool remove_badging = cache->GetNumberOfProfiles() == 1;
554 571
555 string16 old_shortcut_appended_name = 572 string16 old_shortcut_appended_name =
556 cache->GetShortcutNameOfProfileAtIndex(profile_index); 573 cache->GetShortcutNameOfProfileAtIndex(profile_index);
557 574
558 string16 new_shortcut_appended_name; 575 string16 new_shortcut_appended_name;
559 if (!remove_badging) 576 if (!remove_badging)
560 new_shortcut_appended_name = cache->GetNameOfProfileAtIndex(profile_index); 577 new_shortcut_appended_name = cache->GetNameOfProfileAtIndex(profile_index);
561 578
562 if (create_mode == UPDATE_EXISTING_ONLY &&
563 new_shortcut_appended_name != old_shortcut_appended_name) {
564 // TODO(asvitkine): Fold this into |UpdateDesktopShortcutsForProfile()|.
565 StartProfileShortcutNameChange(profile_path, old_shortcut_appended_name);
566 }
567
568 SkBitmap profile_avatar_bitmap_copy; 579 SkBitmap profile_avatar_bitmap_copy;
569 if (!remove_badging) { 580 if (!remove_badging) {
570 size_t profile_icon_index = 581 size_t profile_icon_index =
571 cache->GetAvatarIconIndexOfProfileAtIndex(profile_index); 582 cache->GetAvatarIconIndexOfProfileAtIndex(profile_index);
572 gfx::Image profile_avatar_image = ResourceBundle::GetSharedInstance(). 583 gfx::Image profile_avatar_image = ResourceBundle::GetSharedInstance().
573 GetNativeImageNamed( 584 GetNativeImageNamed(
574 cache->GetDefaultAvatarIconResourceIDAtIndex(profile_icon_index)); 585 cache->GetDefaultAvatarIconResourceIDAtIndex(profile_icon_index));
575 586
576 DCHECK(!profile_avatar_image.IsEmpty()); 587 DCHECK(!profile_avatar_image.IsEmpty());
577 const SkBitmap* profile_avatar_bitmap = profile_avatar_image.ToSkBitmap(); 588 const SkBitmap* profile_avatar_bitmap = profile_avatar_image.ToSkBitmap();
578 // Make a copy of the SkBitmap to ensure that we can safely use the image 589 // Make a copy of the SkBitmap to ensure that we can safely use the image
579 // data on the FILE thread. 590 // data on the FILE thread.
580 profile_avatar_bitmap->deepCopyTo(&profile_avatar_bitmap_copy, 591 profile_avatar_bitmap->deepCopyTo(&profile_avatar_bitmap_copy,
581 profile_avatar_bitmap->getConfig()); 592 profile_avatar_bitmap->getConfig());
582 } 593 }
583 BrowserThread::PostTask( 594 BrowserThread::PostTask(
584 BrowserThread::FILE, FROM_HERE, 595 BrowserThread::FILE, FROM_HERE,
585 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, 596 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile,
586 profile_path, new_shortcut_appended_name, 597 profile_path, old_shortcut_appended_name,
587 profile_avatar_bitmap_copy, create_mode, action)); 598 new_shortcut_appended_name, profile_avatar_bitmap_copy,
599 create_mode, action));
588 600
589 cache->SetShortcutNameOfProfileAtIndex(profile_index, 601 cache->SetShortcutNameOfProfileAtIndex(profile_index,
590 new_shortcut_appended_name); 602 new_shortcut_appended_name);
591 } 603 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_shortcut_manager_win.h ('k') | chrome/installer/util/shell_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698