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_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 Loading... |
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. Parameters may |
117 bool GetDesktopShortcutsDirectory(FilePath* directory) { | 117 // be NULL if a directory type is not needed. Returns true on success. |
118 const bool result = | 118 bool GetDesktopShortcutsDirectories(FilePath* user_shortcuts_directory, |
119 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, | 119 FilePath* system_shortcuts_directory) { |
120 BrowserDistribution::GetDistribution(), | 120 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
121 ShellUtil::CURRENT_USER, directory); | 121 if (user_shortcuts_directory && |
122 DCHECK(result); | 122 !ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
123 return result; | 123 distribution, ShellUtil::CURRENT_USER, |
| 124 user_shortcuts_directory)) { |
| 125 NOTREACHED(); |
| 126 return false; |
| 127 } |
| 128 if (system_shortcuts_directory && |
| 129 !ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
| 130 distribution, ShellUtil::SYSTEM_LEVEL, |
| 131 system_shortcuts_directory)) { |
| 132 NOTREACHED(); |
| 133 return false; |
| 134 } |
| 135 return true; |
124 } | 136 } |
125 | 137 |
126 // Returns the long form of |path|, which will expand any shortened components | 138 // Returns the long form of |path|, which will expand any shortened components |
127 // like "foo~2" to their full names. | 139 // like "foo~2" to their full names. |
128 FilePath ConvertToLongPath(const FilePath& path) { | 140 FilePath ConvertToLongPath(const FilePath& path) { |
129 const size_t length = GetLongPathName(path.value().c_str(), NULL, 0); | 141 const size_t length = GetLongPathName(path.value().c_str(), NULL, 0); |
130 if (length != 0 && length != path.value().length()) { | 142 if (length != 0 && length != path.value().length()) { |
131 std::vector<wchar_t> long_path(length); | 143 std::vector<wchar_t> long_path(length); |
132 if (GetLongPathName(path.value().c_str(), &long_path[0], length) != 0) | 144 if (GetLongPathName(path.value().c_str(), &long_path[0], length) != 0) |
133 return FilePath(&long_path[0]); | 145 return FilePath(&long_path[0]); |
(...skipping 19 matching lines...) Expand all Loading... |
153 return ConvertToLongPath(target_path) == ConvertToLongPath(chrome_exe); | 165 return ConvertToLongPath(target_path) == ConvertToLongPath(chrome_exe); |
154 } | 166 } |
155 | 167 |
156 // Populates |paths| with the file paths of Chrome desktop shortcuts that have | 168 // Populates |paths| with the file paths of Chrome desktop shortcuts that have |
157 // the specified |command_line|. If |include_empty_command_lines| is true, | 169 // the specified |command_line|. If |include_empty_command_lines| is true, |
158 // Chrome desktop shortcuts with empty command lines will also be included. | 170 // Chrome desktop shortcuts with empty command lines will also be included. |
159 void ListDesktopShortcutsWithCommandLine(const FilePath& chrome_exe, | 171 void ListDesktopShortcutsWithCommandLine(const FilePath& chrome_exe, |
160 const string16& command_line, | 172 const string16& command_line, |
161 bool include_empty_command_lines, | 173 bool include_empty_command_lines, |
162 std::vector<FilePath>* paths) { | 174 std::vector<FilePath>* paths) { |
163 FilePath shortcuts_directory; | 175 FilePath user_shortcuts_directory; |
164 if (!GetDesktopShortcutsDirectory(&shortcuts_directory)) | 176 if (!GetDesktopShortcutsDirectories(&user_shortcuts_directory, NULL)) |
165 return; | 177 return; |
166 | 178 |
167 file_util::FileEnumerator enumerator(shortcuts_directory, false, | 179 file_util::FileEnumerator enumerator(user_shortcuts_directory, false, |
168 file_util::FileEnumerator::FILES); | 180 file_util::FileEnumerator::FILES); |
169 for (FilePath path = enumerator.Next(); !path.empty(); | 181 for (FilePath path = enumerator.Next(); !path.empty(); |
170 path = enumerator.Next()) { | 182 path = enumerator.Next()) { |
171 string16 shortcut_command_line; | 183 string16 shortcut_command_line; |
172 if (!IsChromeShortcut(path, chrome_exe, &shortcut_command_line)) | 184 if (!IsChromeShortcut(path, chrome_exe, &shortcut_command_line)) |
173 continue; | 185 continue; |
174 | 186 |
175 // TODO(asvitkine): Change this to build a CommandLine object and ensure all | 187 // 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 | 188 // args from |command_line| are present in the shortcut's CommandLine. This |
177 // will be more robust when |command_line| contains multiple args. | 189 // will be more robust when |command_line| contains multiple args. |
178 if ((shortcut_command_line.empty() && include_empty_command_lines) || | 190 if ((shortcut_command_line.empty() && include_empty_command_lines) || |
179 (shortcut_command_line.find(command_line) != string16::npos)) { | 191 (shortcut_command_line.find(command_line) != string16::npos)) { |
180 paths->push_back(path); | 192 paths->push_back(path); |
181 } | 193 } |
182 } | 194 } |
183 } | 195 } |
184 | 196 |
185 // Renames an existing Chrome desktop profile shortcut. Must be called on the | 197 // Renames an existing Chrome desktop profile shortcut. Must be called on the |
186 // FILE thread. | 198 // FILE thread. |
187 void RenameChromeDesktopShortcutForProfile( | 199 void RenameChromeDesktopShortcutForProfile( |
188 const string16& old_shortcut_file, | 200 const string16& old_shortcut_filename, |
189 const string16& new_shortcut_file) { | 201 const string16& new_shortcut_filename) { |
190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
191 | 203 |
192 FilePath shortcuts_directory; | 204 FilePath user_shortcuts_directory; |
193 if (!GetDesktopShortcutsDirectory(&shortcuts_directory)) | 205 FilePath system_shortcuts_directory; |
| 206 if (!GetDesktopShortcutsDirectories(&user_shortcuts_directory, |
| 207 &system_shortcuts_directory)) { |
194 return; | 208 return; |
| 209 } |
195 | 210 |
196 FilePath old_shortcut_path = shortcuts_directory.Append(old_shortcut_file); | 211 const FilePath old_shortcut_path = |
197 // If the shortcut does not exist, it may have been renamed by the user. In | 212 user_shortcuts_directory.Append(old_shortcut_filename); |
198 // that case, its name should not be changed. | 213 const FilePath new_shortcut_path = |
199 if (!file_util::PathExists(old_shortcut_path)) | 214 user_shortcuts_directory.Append(new_shortcut_filename); |
200 return; | |
201 | 215 |
202 FilePath new_shortcut_path = shortcuts_directory.Append(new_shortcut_file); | 216 if (file_util::PathExists(old_shortcut_path)) { |
203 if (!file_util::Move(old_shortcut_path, new_shortcut_path)) | 217 // Rename the old shortcut unless a system-level shortcut exists at the |
204 LOG(ERROR) << "Could not rename Windows profile desktop shortcut."; | 218 // destination, in which case the old shortcut is simply deleted. |
| 219 const FilePath possible_new_system_shortcut = |
| 220 system_shortcuts_directory.Append(new_shortcut_filename); |
| 221 if (file_util::PathExists(possible_new_system_shortcut)) |
| 222 file_util::Delete(old_shortcut_path, false); |
| 223 else if (!file_util::Move(old_shortcut_path, new_shortcut_path)) |
| 224 DLOG(ERROR) << "Could not rename Windows profile desktop shortcut."; |
| 225 } else { |
| 226 // If the shortcut does not exist, it may have been renamed by the user. In |
| 227 // that case, its name should not be changed. |
| 228 // It's also possible that a system-level shortcut exists instead - this |
| 229 // should only be the case for the original Chrome shortcut from an |
| 230 // installation. If that's the case, copy that one over - it will get its |
| 231 // properties updated by |CreateOrUpdateDesktopShortcutsForProfile()|. |
| 232 const FilePath possible_old_system_shortcut = |
| 233 system_shortcuts_directory.Append(old_shortcut_filename); |
| 234 if (file_util::PathExists(possible_old_system_shortcut)) |
| 235 file_util::CopyFile(possible_old_system_shortcut, new_shortcut_path); |
| 236 } |
205 } | 237 } |
206 | 238 |
207 // Updates all desktop shortcuts for the given profile to have the specified | 239 // 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 | 240 // 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 | 241 // 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. | 242 // be updated is specified by |action|. Must be called on the FILE thread. |
211 void CreateOrUpdateDesktopShortcutsForProfile( | 243 void CreateOrUpdateDesktopShortcutsForProfile( |
212 const FilePath& profile_path, | 244 const FilePath& profile_path, |
| 245 const string16& old_profile_name, |
213 const string16& profile_name, | 246 const string16& profile_name, |
214 const SkBitmap& avatar_image, | 247 const SkBitmap& avatar_image, |
215 ProfileShortcutManagerWin::CreateOrUpdateMode create_mode, | 248 ProfileShortcutManagerWin::CreateOrUpdateMode create_mode, |
216 ProfileShortcutManagerWin::NonProfileShortcutAction action) { | 249 ProfileShortcutManagerWin::NonProfileShortcutAction action) { |
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
218 | 251 |
219 FilePath chrome_exe; | 252 FilePath chrome_exe; |
220 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 253 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
221 NOTREACHED(); | 254 NOTREACHED(); |
222 return; | 255 return; |
223 } | 256 } |
224 | 257 |
225 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 258 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
226 // Ensure that the distribution supports creating shortcuts. If it doesn't, | 259 // Ensure that the distribution supports creating shortcuts. If it doesn't, |
227 // the following code may result in NOTREACHED() being hit. | 260 // the following code may result in NOTREACHED() being hit. |
228 DCHECK(distribution->CanCreateDesktopShortcuts()); | 261 DCHECK(distribution->CanCreateDesktopShortcuts()); |
229 installer::Product product(distribution); | 262 |
| 263 if (old_profile_name != profile_name) { |
| 264 const string16 old_shortcut_filename = |
| 265 profiles::internal::GetShortcutFilenameForProfile(old_profile_name, |
| 266 distribution); |
| 267 const string16 new_shortcut_filename = |
| 268 profiles::internal::GetShortcutFilenameForProfile(profile_name, |
| 269 distribution); |
| 270 RenameChromeDesktopShortcutForProfile(old_shortcut_filename, |
| 271 new_shortcut_filename); |
| 272 } |
230 | 273 |
231 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); | 274 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); |
| 275 installer::Product product(distribution); |
232 product.AddDefaultShortcutProperties(chrome_exe, &properties); | 276 product.AddDefaultShortcutProperties(chrome_exe, &properties); |
233 | 277 |
234 const string16 command_line = | 278 const string16 command_line = |
235 profiles::internal::CreateProfileShortcutFlags(profile_path); | 279 profiles::internal::CreateProfileShortcutFlags(profile_path); |
236 | 280 |
237 // Only set the profile-specific properties when |profile_name| is non empty. | 281 // 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, | 282 // If it is empty, it means the shortcut being created should be a regular, |
239 // non-profile Chrome shortcut. | 283 // non-profile Chrome shortcut. |
240 if (!profile_name.empty()) { | 284 if (!profile_name.empty()) { |
241 const FilePath shortcut_icon = | 285 const FilePath shortcut_icon = |
(...skipping 13 matching lines...) Expand all Loading... |
255 std::vector<FilePath> shortcuts; | 299 std::vector<FilePath> shortcuts; |
256 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, | 300 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, |
257 action == ProfileShortcutManagerWin::UPDATE_NON_PROFILE_SHORTCUTS, | 301 action == ProfileShortcutManagerWin::UPDATE_NON_PROFILE_SHORTCUTS, |
258 &shortcuts); | 302 &shortcuts); |
259 if (create_mode == ProfileShortcutManagerWin::CREATE_WHEN_NONE_FOUND && | 303 if (create_mode == ProfileShortcutManagerWin::CREATE_WHEN_NONE_FOUND && |
260 shortcuts.empty()) { | 304 shortcuts.empty()) { |
261 const string16 shortcut_name = | 305 const string16 shortcut_name = |
262 profiles::internal::GetShortcutFilenameForProfile(profile_name, | 306 profiles::internal::GetShortcutFilenameForProfile(profile_name, |
263 distribution); | 307 distribution); |
264 shortcuts.push_back(FilePath(shortcut_name)); | 308 shortcuts.push_back(FilePath(shortcut_name)); |
265 operation = ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS; | 309 operation = ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL; |
266 } | 310 } |
267 | 311 |
268 for (size_t i = 0; i < shortcuts.size(); ++i) { | 312 for (size_t i = 0; i < shortcuts.size(); ++i) { |
269 const FilePath shortcut_name = shortcuts[i].BaseName().RemoveExtension(); | 313 const FilePath shortcut_name = shortcuts[i].BaseName().RemoveExtension(); |
270 properties.set_shortcut_name(shortcut_name.value()); | 314 properties.set_shortcut_name(shortcut_name.value()); |
271 ShellUtil::CreateOrUpdateShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, | 315 ShellUtil::CreateOrUpdateShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
272 distribution, properties, operation); | 316 distribution, properties, operation); |
273 } | 317 } |
274 } | 318 } |
275 | 319 |
276 // Returns true if any desktop shortcuts exist with target |chrome_exe|, | 320 // Returns true if any desktop shortcuts exist with target |chrome_exe|, |
277 // regardless of their command line arguments. | 321 // regardless of their command line arguments. |
278 bool ChromeDesktopShortcutsExist(const FilePath& chrome_exe) { | 322 bool ChromeDesktopShortcutsExist(const FilePath& chrome_exe) { |
279 FilePath shortcuts_directory; | 323 FilePath user_shortcuts_directory; |
280 if (!GetDesktopShortcutsDirectory(&shortcuts_directory)) | 324 if (!GetDesktopShortcutsDirectories(&user_shortcuts_directory, NULL)) |
281 return false; | 325 return false; |
282 | 326 |
283 file_util::FileEnumerator enumerator(shortcuts_directory, false, | 327 file_util::FileEnumerator enumerator(user_shortcuts_directory, false, |
284 file_util::FileEnumerator::FILES); | 328 file_util::FileEnumerator::FILES); |
285 for (FilePath path = enumerator.Next(); !path.empty(); | 329 for (FilePath path = enumerator.Next(); !path.empty(); |
286 path = enumerator.Next()) { | 330 path = enumerator.Next()) { |
287 if (IsChromeShortcut(path, chrome_exe, NULL)) | 331 if (IsChromeShortcut(path, chrome_exe, NULL)) |
288 return true; | 332 return true; |
289 } | 333 } |
290 | 334 |
291 return false; | 335 return false; |
292 } | 336 } |
293 | 337 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 // Ensure that the distribution supports creating shortcuts. If it doesn't, | 377 // Ensure that the distribution supports creating shortcuts. If it doesn't, |
334 // the following code may result in NOTREACHED() being hit. | 378 // the following code may result in NOTREACHED() being hit. |
335 DCHECK(distribution->CanCreateDesktopShortcuts()); | 379 DCHECK(distribution->CanCreateDesktopShortcuts()); |
336 installer::Product product(distribution); | 380 installer::Product product(distribution); |
337 | 381 |
338 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); | 382 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); |
339 product.AddDefaultShortcutProperties(chrome_exe, &properties); | 383 product.AddDefaultShortcutProperties(chrome_exe, &properties); |
340 properties.set_shortcut_name( | 384 properties.set_shortcut_name( |
341 profiles::internal::GetShortcutFilenameForProfile(string16(), | 385 profiles::internal::GetShortcutFilenameForProfile(string16(), |
342 distribution)); | 386 distribution)); |
343 ShellUtil::CreateOrUpdateShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, | 387 ShellUtil::CreateOrUpdateShortcut( |
344 distribution, properties, | 388 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution, properties, |
345 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS); | 389 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); |
346 } | 390 } |
347 } | 391 } |
348 | 392 |
349 // Returns true if profile at |profile_path| has any shortcuts. Does not | 393 // Returns true if profile at |profile_path| has any shortcuts. Does not |
350 // consider non-profile shortcuts. Must be called on the FILE thread. | 394 // consider non-profile shortcuts. Must be called on the FILE thread. |
351 bool HasAnyProfileShortcuts(const FilePath& profile_path) { | 395 bool HasAnyProfileShortcuts(const FilePath& profile_path) { |
352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
353 | 397 |
354 FilePath chrome_exe; | 398 FilePath chrome_exe; |
355 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 399 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, | 542 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, |
499 IGNORE_NON_PROFILE_SHORTCUTS); | 543 IGNORE_NON_PROFILE_SHORTCUTS); |
500 } | 544 } |
501 | 545 |
502 void ProfileShortcutManagerWin::OnProfileAvatarChanged( | 546 void ProfileShortcutManagerWin::OnProfileAvatarChanged( |
503 const FilePath& profile_path) { | 547 const FilePath& profile_path) { |
504 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, | 548 CreateOrUpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY, |
505 IGNORE_NON_PROFILE_SHORTCUTS); | 549 IGNORE_NON_PROFILE_SHORTCUTS); |
506 } | 550 } |
507 | 551 |
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( | 552 FilePath ProfileShortcutManagerWin::GetOtherProfilePath( |
535 const FilePath& profile_path) { | 553 const FilePath& profile_path) { |
536 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 554 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); |
537 DCHECK_EQ(2U, cache.GetNumberOfProfiles()); | 555 DCHECK_EQ(2U, cache.GetNumberOfProfiles()); |
538 // Get the index of the current profile, in order to find the index of the | 556 // Get the index of the current profile, in order to find the index of the |
539 // other profile. | 557 // other profile. |
540 size_t current_profile_index = cache.GetIndexOfProfileWithPath(profile_path); | 558 size_t current_profile_index = cache.GetIndexOfProfileWithPath(profile_path); |
541 size_t other_profile_index = (current_profile_index == 0) ? 1 : 0; | 559 size_t other_profile_index = (current_profile_index == 0) ? 1 : 0; |
542 return cache.GetPathOfProfileAtIndex(other_profile_index); | 560 return cache.GetPathOfProfileAtIndex(other_profile_index); |
543 } | 561 } |
544 | 562 |
545 void ProfileShortcutManagerWin::CreateOrUpdateShortcutsForProfileAtPath( | 563 void ProfileShortcutManagerWin::CreateOrUpdateShortcutsForProfileAtPath( |
546 const FilePath& profile_path, | 564 const FilePath& profile_path, |
547 CreateOrUpdateMode create_mode, | 565 CreateOrUpdateMode create_mode, |
548 NonProfileShortcutAction action) { | 566 NonProfileShortcutAction action) { |
549 ProfileInfoCache* cache = &profile_manager_->GetProfileInfoCache(); | 567 ProfileInfoCache* cache = &profile_manager_->GetProfileInfoCache(); |
550 size_t profile_index = cache->GetIndexOfProfileWithPath(profile_path); | 568 size_t profile_index = cache->GetIndexOfProfileWithPath(profile_path); |
551 if (profile_index == std::string::npos) | 569 if (profile_index == std::string::npos) |
552 return; | 570 return; |
553 bool remove_badging = cache->GetNumberOfProfiles() == 1; | 571 bool remove_badging = cache->GetNumberOfProfiles() == 1; |
554 | 572 |
555 string16 old_shortcut_appended_name = | 573 string16 old_shortcut_appended_name = |
556 cache->GetShortcutNameOfProfileAtIndex(profile_index); | 574 cache->GetShortcutNameOfProfileAtIndex(profile_index); |
557 | 575 |
558 string16 new_shortcut_appended_name; | 576 string16 new_shortcut_appended_name; |
559 if (!remove_badging) | 577 if (!remove_badging) |
560 new_shortcut_appended_name = cache->GetNameOfProfileAtIndex(profile_index); | 578 new_shortcut_appended_name = cache->GetNameOfProfileAtIndex(profile_index); |
561 | 579 |
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; | 580 SkBitmap profile_avatar_bitmap_copy; |
569 if (!remove_badging) { | 581 if (!remove_badging) { |
570 size_t profile_icon_index = | 582 size_t profile_icon_index = |
571 cache->GetAvatarIconIndexOfProfileAtIndex(profile_index); | 583 cache->GetAvatarIconIndexOfProfileAtIndex(profile_index); |
572 gfx::Image profile_avatar_image = ResourceBundle::GetSharedInstance(). | 584 gfx::Image profile_avatar_image = ResourceBundle::GetSharedInstance(). |
573 GetNativeImageNamed( | 585 GetNativeImageNamed( |
574 cache->GetDefaultAvatarIconResourceIDAtIndex(profile_icon_index)); | 586 cache->GetDefaultAvatarIconResourceIDAtIndex(profile_icon_index)); |
575 | 587 |
576 DCHECK(!profile_avatar_image.IsEmpty()); | 588 DCHECK(!profile_avatar_image.IsEmpty()); |
577 const SkBitmap* profile_avatar_bitmap = profile_avatar_image.ToSkBitmap(); | 589 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 | 590 // Make a copy of the SkBitmap to ensure that we can safely use the image |
579 // data on the FILE thread. | 591 // data on the FILE thread. |
580 profile_avatar_bitmap->deepCopyTo(&profile_avatar_bitmap_copy, | 592 profile_avatar_bitmap->deepCopyTo(&profile_avatar_bitmap_copy, |
581 profile_avatar_bitmap->getConfig()); | 593 profile_avatar_bitmap->getConfig()); |
582 } | 594 } |
583 BrowserThread::PostTask( | 595 BrowserThread::PostTask( |
584 BrowserThread::FILE, FROM_HERE, | 596 BrowserThread::FILE, FROM_HERE, |
585 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, | 597 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, |
586 profile_path, new_shortcut_appended_name, | 598 profile_path, old_shortcut_appended_name, |
587 profile_avatar_bitmap_copy, create_mode, action)); | 599 new_shortcut_appended_name, profile_avatar_bitmap_copy, |
| 600 create_mode, action)); |
588 | 601 |
589 cache->SetShortcutNameOfProfileAtIndex(profile_index, | 602 cache->SetShortcutNameOfProfileAtIndex(profile_index, |
590 new_shortcut_appended_name); | 603 new_shortcut_appended_name); |
591 } | 604 } |
OLD | NEW |