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

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

Issue 11299160: Find shortcuts that don't have a profile command line set when creating 2nd profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 offscreen_canvas->getDevice()->accessBitmap(false); 91 offscreen_canvas->getDevice()->accessBitmap(false);
92 92
93 // Finally, write the .ico file containing this new bitmap. 93 // Finally, write the .ico file containing this new bitmap.
94 FilePath icon_path = profile_path.AppendASCII(kProfileIconFileName); 94 FilePath icon_path = profile_path.AppendASCII(kProfileIconFileName);
95 if (!IconUtil::CreateIconFileFromSkBitmap(final_bitmap, icon_path)) 95 if (!IconUtil::CreateIconFileFromSkBitmap(final_bitmap, icon_path))
96 return FilePath(); 96 return FilePath();
97 97
98 return icon_path; 98 return icon_path;
99 } 99 }
100 100
101 // Returns the command-line flags to launch Chrome with the given profile.
102 string16 CreateProfileShortcutFlags(const FilePath& profile_path) {
103 return base::StringPrintf(L"--%ls=\"%ls\"",
104 ASCIIToUTF16(switches::kProfileDirectory).c_str(),
105 profile_path.BaseName().value().c_str());
106 }
107
108 // Gets the directory where to create desktop shortcuts. 101 // Gets the directory where to create desktop shortcuts.
109 bool GetDesktopShortcutsDirectory(FilePath* directory) { 102 bool GetDesktopShortcutsDirectory(FilePath* directory) {
110 const bool result = 103 const bool result =
111 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, 104 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP,
112 BrowserDistribution::GetDistribution(), 105 BrowserDistribution::GetDistribution(),
113 ShellUtil::CURRENT_USER, directory); 106 ShellUtil::CURRENT_USER, directory);
114 DCHECK(result); 107 DCHECK(result);
115 return result; 108 return result;
116 } 109 }
117 110
118 // Returns true if the file at |path| is a Chrome shortcut with the given 111 // Returns true if the file at |path| is a Chrome shortcut and returns its
119 // |command_line|. 112 // command line in output parameter |command_line|.
120 bool IsChromeShortcutWithCommandLine(const FilePath& path, 113 bool IsChromeShortcut(const FilePath& path,
121 const FilePath& chrome_exe, 114 const FilePath& chrome_exe,
122 const string16& command_line) { 115 string16* command_line) {
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
124 117
125 if (path.Extension() != installer::kLnkExt) 118 if (path.Extension() != installer::kLnkExt)
126 return false; 119 return false;
127 120
128 FilePath target_path; 121 FilePath target_path;
129 string16 command_line_args; 122 if (!base::win::ResolveShortcut(path, &target_path, command_line))
130 if (!base::win::ResolveShortcut(path, &target_path, &command_line_args))
131 return false; 123 return false;
132 124 return target_path == chrome_exe;
133 // TODO(asvitkine): Change this to build a CommandLine object and ensure all
134 // args from |command_line| are present in the shortcut's CommandLine. This
135 // will be more robust when |command_line| contains multiple args.
136 return target_path == chrome_exe &&
137 command_line_args.find(command_line) != string16::npos;
138 } 125 }
139 126
140 // Populates |paths| with the file paths of Chrome desktop shortcuts that have 127 // Populates |paths| with the file paths of Chrome desktop shortcuts that have
141 // the specified |command_line|. 128 // the specified |command_line|.
142 void ListDesktopShortcutsWithCommandLine(const FilePath& chrome_exe, 129 void ListDesktopShortcutsWithCommandLine(const FilePath& chrome_exe,
143 const string16& command_line, 130 const string16& command_line,
131 bool include_empty_command_lines,
sail 2012/11/28 05:12:31 Yea, I think plumbing the enums here would be grea
Alexei Svitkine (slow) 2012/11/28 21:27:12 I've plumbed them through to CreateOrUpdateDesktop
144 std::vector<FilePath>* paths) { 132 std::vector<FilePath>* paths) {
145 FilePath shortcuts_directory; 133 FilePath shortcuts_directory;
146 if (!GetDesktopShortcutsDirectory(&shortcuts_directory)) 134 if (!GetDesktopShortcutsDirectory(&shortcuts_directory))
147 return; 135 return;
148 136
149 file_util::FileEnumerator enumerator(shortcuts_directory, false, 137 file_util::FileEnumerator enumerator(shortcuts_directory, false,
150 file_util::FileEnumerator::FILES); 138 file_util::FileEnumerator::FILES);
151 for (FilePath path = enumerator.Next(); !path.empty(); 139 for (FilePath path = enumerator.Next(); !path.empty();
152 path = enumerator.Next()) { 140 path = enumerator.Next()) {
153 if (IsChromeShortcutWithCommandLine(path, chrome_exe, command_line)) 141 string16 shortcut_command_line;
142 if (!IsChromeShortcut(path, chrome_exe, &shortcut_command_line))
143 continue;
144
145 // TODO(asvitkine): Change this to build a CommandLine object and ensure all
146 // args from |command_line| are present in the shortcut's CommandLine. This
147 // will be more robust when |command_line| contains multiple args.
148 if ((shortcut_command_line.empty() && include_empty_command_lines) ||
149 (shortcut_command_line.find(command_line) != string16::npos)) {
154 paths->push_back(path); 150 paths->push_back(path);
151 }
155 } 152 }
156 } 153 }
157 154
158 // Renames an existing Chrome desktop profile shortcut. Must be called on the 155 // Renames an existing Chrome desktop profile shortcut. Must be called on the
159 // FILE thread. 156 // FILE thread.
160 void RenameChromeDesktopShortcutForProfile( 157 void RenameChromeDesktopShortcutForProfile(
161 const string16& old_shortcut_file, 158 const string16& old_shortcut_file,
162 const string16& new_shortcut_file) { 159 const string16& new_shortcut_file) {
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
164 161
(...skipping 11 matching lines...) Expand all
176 if (!file_util::Move(old_shortcut_path, new_shortcut_path)) 173 if (!file_util::Move(old_shortcut_path, new_shortcut_path))
177 LOG(ERROR) << "Could not rename Windows profile desktop shortcut."; 174 LOG(ERROR) << "Could not rename Windows profile desktop shortcut.";
178 } 175 }
179 176
180 // Updates all desktop shortcuts for the given profile to have the specified 177 // Updates all desktop shortcuts for the given profile to have the specified
181 // parameters. If |create| is true, a new desktop shortcut is created if no 178 // parameters. If |create| is true, a new desktop shortcut is created if no
182 // existing ones were found. Must be called on the FILE thread. 179 // existing ones were found. Must be called on the FILE thread.
183 void CreateOrUpdateDesktopShortcutsForProfile(const FilePath& profile_path, 180 void CreateOrUpdateDesktopShortcutsForProfile(const FilePath& profile_path,
184 const string16& profile_name, 181 const string16& profile_name,
185 const SkBitmap& avatar_image, 182 const SkBitmap& avatar_image,
183 bool include_empty_command_lines,
186 bool create) { 184 bool create) {
187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
188 186
189 FilePath chrome_exe; 187 FilePath chrome_exe;
190 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 188 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
191 NOTREACHED(); 189 NOTREACHED();
192 return; 190 return;
193 } 191 }
194 192
195 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); 193 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
196 installer::Product product(distribution); 194 installer::Product product(distribution);
197 195
198 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); 196 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER);
199 product.AddDefaultShortcutProperties(chrome_exe, &properties); 197 product.AddDefaultShortcutProperties(chrome_exe, &properties);
200 const FilePath shortcut_icon = 198 const FilePath shortcut_icon =
201 CreateChromeDesktopShortcutIconForProfile(profile_path, avatar_image); 199 CreateChromeDesktopShortcutIconForProfile(profile_path, avatar_image);
202 if (!shortcut_icon.empty()) 200 if (!shortcut_icon.empty())
203 properties.set_icon(shortcut_icon, 0); 201 properties.set_icon(shortcut_icon, 0);
204 202
205 const string16 command_line = CreateProfileShortcutFlags(profile_path); 203 const string16 command_line =
204 profiles::internal::CreateProfileShortcutFlags(profile_path);
206 properties.set_arguments(command_line); 205 properties.set_arguments(command_line);
207 206
208 ShellUtil::ShortcutOperation operation = 207 ShellUtil::ShortcutOperation operation =
209 ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING; 208 ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING;
210 209
211 std::vector<FilePath> shortcuts; 210 std::vector<FilePath> shortcuts;
212 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, &shortcuts); 211 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line,
212 include_empty_command_lines, &shortcuts);
213 if (create && shortcuts.empty()) { 213 if (create && shortcuts.empty()) {
214 const string16 shortcut_name = 214 const string16 shortcut_name =
215 profiles::internal::GetShortcutFilenameForProfile(profile_name, 215 profiles::internal::GetShortcutFilenameForProfile(profile_name,
216 distribution); 216 distribution);
217 shortcuts.push_back(FilePath(shortcut_name)); 217 shortcuts.push_back(FilePath(shortcut_name));
218 operation = ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS; 218 operation = ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS;
219 } 219 }
220 220
221 for (size_t i = 0; i < shortcuts.size(); ++i) { 221 for (size_t i = 0; i < shortcuts.size(); ++i) {
222 const FilePath shortcut_name = shortcuts[i].BaseName().RemoveExtension(); 222 const FilePath shortcut_name = shortcuts[i].BaseName().RemoveExtension();
223 properties.set_shortcut_name(shortcut_name.value()); 223 properties.set_shortcut_name(shortcut_name.value());
224 ShellUtil::CreateOrUpdateShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, 224 ShellUtil::CreateOrUpdateShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP,
225 distribution, properties, operation); 225 distribution, properties, operation);
226 } 226 }
227 } 227 }
228 228
229 // Deletes all desktop shortcuts for the specified profile and also removes the 229 // Deletes all desktop shortcuts for the specified profile and also removes the
230 // corresponding icon file. Must be called on the FILE thread. 230 // corresponding icon file. Must be called on the FILE thread.
231 void DeleteDesktopShortcutsAndIconFile(const FilePath& profile_path, 231 void DeleteDesktopShortcutsAndIconFile(const FilePath& profile_path,
232 const FilePath& icon_path) { 232 const FilePath& icon_path) {
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
234 234
235 FilePath chrome_exe; 235 FilePath chrome_exe;
236 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 236 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
237 NOTREACHED(); 237 NOTREACHED();
238 return; 238 return;
239 } 239 }
240 240
241 const string16 command_line = CreateProfileShortcutFlags(profile_path); 241 const string16 command_line =
242 profiles::internal::CreateProfileShortcutFlags(profile_path);
242 std::vector<FilePath> shortcuts; 243 std::vector<FilePath> shortcuts;
243 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, &shortcuts); 244 ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, false,
245 &shortcuts);
244 246
245 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); 247 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
246 for (size_t i = 0; i < shortcuts.size(); ++i) { 248 for (size_t i = 0; i < shortcuts.size(); ++i) {
247 const string16 shortcut_name = 249 const string16 shortcut_name =
248 shortcuts[i].BaseName().RemoveExtension().value(); 250 shortcuts[i].BaseName().RemoveExtension().value();
249 ShellUtil::RemoveShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, 251 ShellUtil::RemoveShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP,
250 distribution, chrome_exe.value(), 252 distribution, chrome_exe.value(),
251 ShellUtil::CURRENT_USER, 253 ShellUtil::CURRENT_USER,
252 &shortcut_name); 254 &shortcut_name);
253 } 255 }
(...skipping 10 matching lines...) Expand all
264 BrowserDistribution* distribution) { 266 BrowserDistribution* distribution) {
265 string16 shortcut_name; 267 string16 shortcut_name;
266 if (!profile_name.empty()) { 268 if (!profile_name.empty()) {
267 shortcut_name.append(profile_name); 269 shortcut_name.append(profile_name);
268 shortcut_name.append(L" - "); 270 shortcut_name.append(L" - ");
269 } 271 }
270 shortcut_name.append(distribution->GetAppShortCutName()); 272 shortcut_name.append(distribution->GetAppShortCutName());
271 return shortcut_name + installer::kLnkExt; 273 return shortcut_name + installer::kLnkExt;
272 } 274 }
273 275
276 string16 CreateProfileShortcutFlags(const FilePath& profile_path) {
277 return base::StringPrintf(L"--%ls=\"%ls\"",
278 ASCIIToUTF16(switches::kProfileDirectory).c_str(),
279 profile_path.BaseName().value().c_str());
280 }
281
274 } // namespace internal 282 } // namespace internal
275 } // namespace profiles 283 } // namespace profiles
276 284
277 // static 285 // static
278 bool ProfileShortcutManager::IsFeatureEnabled() { 286 bool ProfileShortcutManager::IsFeatureEnabled() {
279 return false; 287 return false;
280 } 288 }
281 289
282 // static 290 // static
283 ProfileShortcutManager* ProfileShortcutManager::Create( 291 ProfileShortcutManager* ProfileShortcutManager::Create(
284 ProfileManager* manager) { 292 ProfileManager* manager) {
285 return new ProfileShortcutManagerWin(manager); 293 return new ProfileShortcutManagerWin(manager);
286 } 294 }
287 295
288 ProfileShortcutManagerWin::ProfileShortcutManagerWin(ProfileManager* manager) 296 ProfileShortcutManagerWin::ProfileShortcutManagerWin(ProfileManager* manager)
289 : profile_manager_(manager) { 297 : profile_manager_(manager) {
290 profile_manager_->GetProfileInfoCache().AddObserver(this); 298 profile_manager_->GetProfileInfoCache().AddObserver(this);
291 } 299 }
292 300
293 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() { 301 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() {
294 profile_manager_->GetProfileInfoCache().RemoveObserver(this); 302 profile_manager_->GetProfileInfoCache().RemoveObserver(this);
295 } 303 }
296 304
297 void ProfileShortcutManagerWin::CreateProfileShortcut( 305 void ProfileShortcutManagerWin::CreateProfileShortcut(
298 const FilePath& profile_path) { 306 const FilePath& profile_path) {
299 UpdateShortcutsForProfileAtPath(profile_path, true); 307 UpdateShortcutsForProfileAtPath(profile_path, CREATE_WHEN_NONE_FOUND,
308 IGNORE_NON_PROFILE_SHORTCUTS);
300 } 309 }
301 310
302 void ProfileShortcutManagerWin::OnProfileAdded(const FilePath& profile_path) { 311 void ProfileShortcutManagerWin::OnProfileAdded(const FilePath& profile_path) {
303 const size_t profile_count = 312 const size_t profile_count =
304 profile_manager_->GetProfileInfoCache().GetNumberOfProfiles(); 313 profile_manager_->GetProfileInfoCache().GetNumberOfProfiles();
305 if (profile_count == 1) { 314 if (profile_count == 1) {
306 UpdateShortcutsForProfileAtPath(profile_path, true); 315 UpdateShortcutsForProfileAtPath(profile_path,
316 CREATE_WHEN_NONE_FOUND,
317 UPDATE_NON_PROFILE_SHORTCUTS);
307 } else if (profile_count == 2) { 318 } else if (profile_count == 2) {
308 UpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path), false); 319 UpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path),
320 UPDATE_EXISTING_ONLY,
321 UPDATE_NON_PROFILE_SHORTCUTS);
309 } 322 }
310 } 323 }
311 324
312 void ProfileShortcutManagerWin::OnProfileWillBeRemoved( 325 void ProfileShortcutManagerWin::OnProfileWillBeRemoved(
313 const FilePath& profile_path) { 326 const FilePath& profile_path) {
314 } 327 }
315 328
316 void ProfileShortcutManagerWin::OnProfileWasRemoved( 329 void ProfileShortcutManagerWin::OnProfileWasRemoved(
317 const FilePath& profile_path, 330 const FilePath& profile_path,
318 const string16& profile_name) { 331 const string16& profile_name) {
319 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); 332 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
320 // If there is only one profile remaining, remove the badging information 333 // If there is only one profile remaining, remove the badging information
321 // from an existing shortcut. 334 // from an existing shortcut.
322 if (cache.GetNumberOfProfiles() == 1) 335 if (cache.GetNumberOfProfiles() == 1) {
323 UpdateShortcutsForProfileAtPath(cache.GetPathOfProfileAtIndex(0), false); 336 UpdateShortcutsForProfileAtPath(cache.GetPathOfProfileAtIndex(0),
337 UPDATE_EXISTING_ONLY,
338 IGNORE_NON_PROFILE_SHORTCUTS);
339 }
324 340
325 const FilePath icon_path = profile_path.AppendASCII(kProfileIconFileName); 341 const FilePath icon_path = profile_path.AppendASCII(kProfileIconFileName);
326 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 342 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
327 base::Bind(&DeleteDesktopShortcutsAndIconFile, 343 base::Bind(&DeleteDesktopShortcutsAndIconFile,
328 profile_path, icon_path)); 344 profile_path, icon_path));
329 } 345 }
330 346
331 void ProfileShortcutManagerWin::OnProfileNameChanged( 347 void ProfileShortcutManagerWin::OnProfileNameChanged(
332 const FilePath& profile_path, 348 const FilePath& profile_path,
333 const string16& old_profile_name) { 349 const string16& old_profile_name) {
334 UpdateShortcutsForProfileAtPath(profile_path, false); 350 UpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY,
351 IGNORE_NON_PROFILE_SHORTCUTS);
335 } 352 }
336 353
337 void ProfileShortcutManagerWin::OnProfileAvatarChanged( 354 void ProfileShortcutManagerWin::OnProfileAvatarChanged(
338 const FilePath& profile_path) { 355 const FilePath& profile_path) {
339 UpdateShortcutsForProfileAtPath(profile_path, false); 356 UpdateShortcutsForProfileAtPath(profile_path, UPDATE_EXISTING_ONLY,
357 IGNORE_NON_PROFILE_SHORTCUTS);
340 } 358 }
341 359
342 void ProfileShortcutManagerWin::StartProfileShortcutNameChange( 360 void ProfileShortcutManagerWin::StartProfileShortcutNameChange(
343 const FilePath& profile_path, 361 const FilePath& profile_path,
344 const string16& old_profile_name) { 362 const string16& old_profile_name) {
345 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); 363 const ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
346 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_path); 364 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_path);
347 if (profile_index == std::string::npos) 365 if (profile_index == std::string::npos)
348 return; 366 return;
349 // If the shortcut will have an appended name, get the profile name. 367 // If the shortcut will have an appended name, get the profile name.
(...skipping 22 matching lines...) Expand all
372 // Get the index of the current profile, in order to find the index of the 390 // Get the index of the current profile, in order to find the index of the
373 // other profile. 391 // other profile.
374 size_t current_profile_index = cache.GetIndexOfProfileWithPath(profile_path); 392 size_t current_profile_index = cache.GetIndexOfProfileWithPath(profile_path);
375 size_t other_profile_index = (current_profile_index == 0) ? 1 : 0; 393 size_t other_profile_index = (current_profile_index == 0) ? 1 : 0;
376 return profile_manager_->GetProfileInfoCache(). 394 return profile_manager_->GetProfileInfoCache().
377 GetPathOfProfileAtIndex(other_profile_index); 395 GetPathOfProfileAtIndex(other_profile_index);
378 } 396 }
379 397
380 void ProfileShortcutManagerWin::UpdateShortcutsForProfileAtPath( 398 void ProfileShortcutManagerWin::UpdateShortcutsForProfileAtPath(
381 const FilePath& profile_path, 399 const FilePath& profile_path,
382 bool create_always) { 400 CreateOrUpdateMode create_mode,
401 NonProfileShortcutAction action) {
383 ProfileInfoCache* cache = &profile_manager_->GetProfileInfoCache(); 402 ProfileInfoCache* cache = &profile_manager_->GetProfileInfoCache();
384 size_t profile_index = cache->GetIndexOfProfileWithPath(profile_path); 403 size_t profile_index = cache->GetIndexOfProfileWithPath(profile_path);
385 if (profile_index == std::string::npos) 404 if (profile_index == std::string::npos)
386 return; 405 return;
387 bool remove_badging = cache->GetNumberOfProfiles() == 1; 406 bool remove_badging = cache->GetNumberOfProfiles() == 1;
388 407
389 string16 old_shortcut_appended_name = 408 string16 old_shortcut_appended_name =
390 cache->GetShortcutNameOfProfileAtIndex(profile_index); 409 cache->GetShortcutNameOfProfileAtIndex(profile_index);
391 410
392 string16 new_shortcut_appended_name; 411 string16 new_shortcut_appended_name;
393 if (!remove_badging) 412 if (!remove_badging)
394 new_shortcut_appended_name = cache->GetNameOfProfileAtIndex(profile_index); 413 new_shortcut_appended_name = cache->GetNameOfProfileAtIndex(profile_index);
395 414
396 if (!create_always && 415 if (create_mode == UPDATE_EXISTING_ONLY &&
397 new_shortcut_appended_name != old_shortcut_appended_name) { 416 new_shortcut_appended_name != old_shortcut_appended_name) {
398 // TODO(asvitkine): Fold this into |UpdateDesktopShortcutsForProfile()|. 417 // TODO(asvitkine): Fold this into |UpdateDesktopShortcutsForProfile()|.
399 StartProfileShortcutNameChange(profile_path, old_shortcut_appended_name); 418 StartProfileShortcutNameChange(profile_path, old_shortcut_appended_name);
400 } 419 }
401 420
402 SkBitmap profile_avatar_bitmap_copy; 421 SkBitmap profile_avatar_bitmap_copy;
403 if (!remove_badging) { 422 if (!remove_badging) {
404 size_t profile_icon_index = 423 size_t profile_icon_index =
405 cache->GetAvatarIconIndexOfProfileAtIndex(profile_index); 424 cache->GetAvatarIconIndexOfProfileAtIndex(profile_index);
406 gfx::Image profile_avatar_image = ResourceBundle::GetSharedInstance(). 425 gfx::Image profile_avatar_image = ResourceBundle::GetSharedInstance().
407 GetNativeImageNamed( 426 GetNativeImageNamed(
408 cache->GetDefaultAvatarIconResourceIDAtIndex(profile_icon_index)); 427 cache->GetDefaultAvatarIconResourceIDAtIndex(profile_icon_index));
409 428
410 DCHECK(!profile_avatar_image.IsEmpty()); 429 DCHECK(!profile_avatar_image.IsEmpty());
411 const SkBitmap* profile_avatar_bitmap = profile_avatar_image.ToSkBitmap(); 430 const SkBitmap* profile_avatar_bitmap = profile_avatar_image.ToSkBitmap();
412 // Make a copy of the SkBitmap to ensure that we can safely use the image 431 // Make a copy of the SkBitmap to ensure that we can safely use the image
413 // data on the FILE thread. 432 // data on the FILE thread.
414 profile_avatar_bitmap->deepCopyTo(&profile_avatar_bitmap_copy, 433 profile_avatar_bitmap->deepCopyTo(&profile_avatar_bitmap_copy,
415 profile_avatar_bitmap->getConfig()); 434 profile_avatar_bitmap->getConfig());
416 } 435 }
417 BrowserThread::PostTask( 436 BrowserThread::PostTask(
418 BrowserThread::FILE, FROM_HERE, 437 BrowserThread::FILE, FROM_HERE,
419 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile, 438 base::Bind(&CreateOrUpdateDesktopShortcutsForProfile,
420 profile_path, new_shortcut_appended_name, 439 profile_path, new_shortcut_appended_name,
421 profile_avatar_bitmap_copy, create_always)); 440 profile_avatar_bitmap_copy,
441 action == UPDATE_NON_PROFILE_SHORTCUTS,
442 create_mode == CREATE_WHEN_NONE_FOUND));
422 443
423 cache->SetShortcutNameOfProfileAtIndex(profile_index, 444 cache->SetShortcutNameOfProfileAtIndex(profile_index,
424 new_shortcut_appended_name); 445 new_shortcut_appended_name);
425 } 446 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698