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

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

Issue 9271018: Merge 115621 - Refactor ProfileInfoCacheObserver interface and usage thereof. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/963/src/
Patch Set: Created 8 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
« no previous file with comments | « chrome/browser/profiles/profile_shortcut_manager_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 208
209 } // namespace 209 } // namespace
210 210
211 ProfileShortcutManagerWin::ProfileShortcutManagerWin() { 211 ProfileShortcutManagerWin::ProfileShortcutManagerWin() {
212 } 212 }
213 213
214 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() { 214 ProfileShortcutManagerWin::~ProfileShortcutManagerWin() {
215 } 215 }
216 216
217 void ProfileShortcutManagerWin::OnProfileAdded( 217 void ProfileShortcutManagerWin::OnProfileAdded(
218 const string16& profile_name, 218 const FilePath& profile_path) {
219 const string16& profile_base_dir, 219 ProfileInfoCache& cache =
220 const FilePath& profile_path, 220 g_browser_process->profile_manager()->GetProfileInfoCache();
221 const gfx::Image* avatar_image) { 221 size_t index = cache.GetIndexOfProfileWithPath(profile_path);
222
222 // Launch task to add shortcut to desktop on Windows. If this is the very 223 // Launch task to add shortcut to desktop on Windows. If this is the very
223 // first profile created, don't add the user name to the shortcut. 224 // first profile created, don't add the user name to the shortcut.
224 // TODO(mirandac): respect master_preferences choice to create no shortcuts 225 // TODO(mirandac): respect master_preferences choice to create no shortcuts
225 // (see http://crbug.com/104463) 226 // (see http://crbug.com/104463)
226 if (g_browser_process->profile_manager()->GetNumberOfProfiles() > 1) { 227 if (g_browser_process->profile_manager()->GetNumberOfProfiles() > 1) {
227 { 228 {
228 // We make a copy of the Image to ensure that the underlying image data is 229 // We make a copy of the Image to ensure that the underlying image data is
229 // AddRef'd, in case the original copy gets deleted. 230 // AddRef'd, in case the original copy gets deleted.
230 gfx::Image* avatar_copy = avatar_image ? 231 gfx::Image* avatar_copy =
231 new gfx::Image(*avatar_image) : NULL; 232 new gfx::Image(cache.GetAvatarIconOfProfileAtIndex(index));
233 string16 profile_name = cache.GetNameOfProfileAtIndex(index);
234 string16 profile_base_dir = profile_path.BaseName().value();
232 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 235 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
233 base::Bind(&CreateChromeDesktopShortcutForProfile, 236 base::Bind(&CreateChromeDesktopShortcutForProfile,
234 profile_name, profile_base_dir, profile_path, 237 profile_name, profile_base_dir, profile_path,
235 base::Owned(avatar_copy), true)); 238 base::Owned(avatar_copy), true));
236 } 239 }
237 240
238 // If this is the second existing multi-user account created, change the 241 // If this is the second existing multi-user account created, change the
239 // original shortcut use the first profile's details (name, badge, 242 // original shortcut use the first profile's details (name, badge,
240 // argument). 243 // argument).
241 ProfileInfoCache& cache =
242 g_browser_process->profile_manager()->GetProfileInfoCache();
243 if (cache.GetNumberOfProfiles() == 2) { 244 if (cache.GetNumberOfProfiles() == 2) {
244 // Get the index of the first profile, based on the index of the second 245 // Get the index of the first profile, based on the index of the second
245 // profile. It's either 0 or 1, whichever the second profile isn't. 246 // profile. It's either 0 or 1, whichever the second profile isn't.
246 size_t first_index = 0; 247 size_t first_index = 0;
247 if (cache.GetIndexOfProfileWithPath(profile_path) == 0) 248 if (cache.GetIndexOfProfileWithPath(profile_path) == 0)
248 first_index = 1; 249 first_index = 1;
249 string16 first_name = cache.GetNameOfProfileAtIndex(first_index); 250 string16 first_name = cache.GetNameOfProfileAtIndex(first_index);
250 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 251 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
251 252
252 string16 old_shortcut; 253 string16 old_shortcut;
(...skipping 26 matching lines...) Expand all
279 } 280 }
280 } 281 }
281 } else { // Only one profile, so create original shortcut, with no avatar. 282 } else { // Only one profile, so create original shortcut, with no avatar.
282 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 283 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
283 base::Bind(&CreateChromeDesktopShortcutForProfile, 284 base::Bind(&CreateChromeDesktopShortcutForProfile,
284 L"", L"", FilePath(), static_cast<gfx::Image*>(NULL), true)); 285 L"", L"", FilePath(), static_cast<gfx::Image*>(NULL), true));
285 } 286 }
286 } 287 }
287 288
288 void ProfileShortcutManagerWin::OnProfileWillBeRemoved( 289 void ProfileShortcutManagerWin::OnProfileWillBeRemoved(
289 const string16& profile_name) { 290 const FilePath& profile_path) {
291 ProfileInfoCache& cache =
292 g_browser_process->profile_manager()->GetProfileInfoCache();
293 string16 profile_name = cache.GetNameOfProfileAtIndex(
294 cache.GetIndexOfProfileWithPath(profile_path));
290 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 295 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
291 string16 shortcut; 296 string16 shortcut;
292 if (ShellUtil::GetChromeShortcutName(dist, false, profile_name, &shortcut)) { 297 if (ShellUtil::GetChromeShortcutName(dist, false, profile_name, &shortcut)) {
293 std::vector<string16> shortcuts(1, shortcut); 298 std::vector<string16> shortcuts(1, shortcut);
294 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 299 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
295 base::Bind(&CallShellUtilBoolFunction, 300 base::Bind(&CallShellUtilBoolFunction,
296 base::Bind( 301 base::Bind(
297 &ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames, 302 &ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames,
298 shortcuts))); 303 shortcuts)));
299 } 304 }
300 } 305 }
301 306
302 void ProfileShortcutManagerWin::OnProfileWasRemoved( 307 void ProfileShortcutManagerWin::OnProfileWasRemoved(
308 const FilePath& profile_path,
303 const string16& profile_name) { 309 const string16& profile_name) {
304 // If there is one profile left, we want to remove the badge and name from it. 310 // If there is one profile left, we want to remove the badge and name from it.
305 ProfileInfoCache& cache = 311 ProfileInfoCache& cache =
306 g_browser_process->profile_manager()->GetProfileInfoCache(); 312 g_browser_process->profile_manager()->GetProfileInfoCache();
307 if (cache.GetNumberOfProfiles() != 1) 313 if (cache.GetNumberOfProfiles() != 1)
308 return; 314 return;
309 315
310 // TODO(stevet): Now that we've sunk our fangs onto ProfileInfoCache, we 316 FilePath last_profile_path = cache.GetPathOfProfileAtIndex(0);
311 // should clean up the ProfileInfoCacheObserver interface and its users
312 // (including us) to not pass every parameter through and instead query the
313 // cache when needed.
314 FilePath profile_path = cache.GetPathOfProfileAtIndex(0);
315 string16 old_shortcut; 317 string16 old_shortcut;
316 string16 new_shortcut; 318 string16 new_shortcut;
317 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 319 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
318 if (ShellUtil::GetChromeShortcutName( 320 if (ShellUtil::GetChromeShortcutName(
319 dist, false, cache.GetNameOfProfileAtIndex(0), &old_shortcut) && 321 dist, false, cache.GetNameOfProfileAtIndex(0), &old_shortcut) &&
320 ShellUtil::GetChromeShortcutName( 322 ShellUtil::GetChromeShortcutName(
321 dist, false, L"", &new_shortcut)) { 323 dist, false, L"", &new_shortcut)) {
322 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 324 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
323 base::Bind(&RenameChromeDesktopShortcutForProfile, 325 base::Bind(&RenameChromeDesktopShortcutForProfile,
324 old_shortcut, 326 old_shortcut,
325 new_shortcut)); 327 new_shortcut));
326 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 328 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
327 base::Bind(&UpdateChromeDesktopShortcutForProfile, 329 base::Bind(&UpdateChromeDesktopShortcutForProfile,
328 new_shortcut, 330 new_shortcut,
329 CreateProfileShortcutSwitch(UTF8ToUTF16( 331 CreateProfileShortcutSwitch(UTF8ToUTF16(
330 profile_path.BaseName().MaybeAsASCII())), 332 last_profile_path.BaseName().MaybeAsASCII())),
331 profile_path, 333 last_profile_path,
332 static_cast<gfx::Image*>(NULL))); 334 static_cast<gfx::Image*>(NULL)));
333 } 335 }
334 } 336 }
335 337
336 void ProfileShortcutManagerWin::OnProfileNameChanged( 338 void ProfileShortcutManagerWin::OnProfileNameChanged(
337 const string16& old_profile_name, 339 const FilePath& profile_path,
338 const string16& new_profile_name) { 340 const string16& old_profile_name) {
339 // Launch task to change name of desktop shortcut on Windows. 341 // Launch task to change name of desktop shortcut on Windows.
340 // TODO(mirandac): respect master_preferences choice to create no shortcuts 342 // TODO(mirandac): respect master_preferences choice to create no shortcuts
341 // (see http://crbug.com/104463) 343 // (see http://crbug.com/104463)
344 ProfileInfoCache& cache =
345 g_browser_process->profile_manager()->GetProfileInfoCache();
346 string16 new_profile_name = cache.GetNameOfProfileAtIndex(
347 cache.GetIndexOfProfileWithPath(profile_path));
348
342 string16 old_shortcut; 349 string16 old_shortcut;
343 string16 new_shortcut; 350 string16 new_shortcut;
344 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 351 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
345 if (ShellUtil::GetChromeShortcutName( 352 if (ShellUtil::GetChromeShortcutName(
346 dist, false, old_profile_name, &old_shortcut) && 353 dist, false, old_profile_name, &old_shortcut) &&
347 ShellUtil::GetChromeShortcutName( 354 ShellUtil::GetChromeShortcutName(
348 dist, false, new_profile_name, &new_shortcut)) { 355 dist, false, new_profile_name, &new_shortcut)) {
349 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 356 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
350 base::Bind(&RenameChromeDesktopShortcutForProfile, 357 base::Bind(&RenameChromeDesktopShortcutForProfile,
351 old_shortcut, 358 old_shortcut,
352 new_shortcut)); 359 new_shortcut));
353 } 360 }
354 } 361 }
355 362
356 void ProfileShortcutManagerWin::OnProfileAvatarChanged( 363 void ProfileShortcutManagerWin::OnProfileAvatarChanged(
357 const string16& profile_name, 364 const FilePath& profile_path) {
358 const string16& profile_base_dir, 365 ProfileInfoCache& cache =
359 const FilePath& profile_path, 366 g_browser_process->profile_manager()->GetProfileInfoCache();
360 const gfx::Image* avatar_image) { 367 size_t index = cache.GetIndexOfProfileWithPath(profile_path);
368 string16 profile_name = cache.GetNameOfProfileAtIndex(index);
369 string16 profile_base_dir =
370 UTF8ToUTF16(profile_path.BaseName().MaybeAsASCII());
371 const gfx::Image& avatar_image = cache.GetAvatarIconOfProfileAtIndex(index);
372
361 // Launch task to change the icon of the desktop shortcut on windows. 373 // Launch task to change the icon of the desktop shortcut on windows.
362 string16 new_shortcut; 374 string16 new_shortcut;
363 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 375 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
364 if (ShellUtil::GetChromeShortcutName(dist, false, profile_name, 376 if (ShellUtil::GetChromeShortcutName(dist, false, profile_name,
365 &new_shortcut)) { 377 &new_shortcut)) {
366 // We make a copy of the Image to ensure that the underlying image data is 378 // We make a copy of the Image to ensure that the underlying image data is
367 // AddRef'd, in case the original copy gets deleted. 379 // AddRef'd, in case the original copy gets deleted.
368 gfx::Image* avatar_copy = avatar_image ? 380 gfx::Image* avatar_copy = new gfx::Image(avatar_image);
369 new gfx::Image(*avatar_image) : NULL;
370 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 381 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
371 base::Bind(&UpdateChromeDesktopShortcutForProfile, 382 base::Bind(&UpdateChromeDesktopShortcutForProfile,
372 new_shortcut, 383 new_shortcut,
373 CreateProfileShortcutSwitch(profile_base_dir), 384 CreateProfileShortcutSwitch(profile_base_dir),
374 profile_path, 385 profile_path,
375 base::Owned(avatar_copy))); 386 base::Owned(avatar_copy)));
376 } 387 }
377 } 388 }
378 389
379 // static 390 // static
380 std::vector<string16> ProfileShortcutManagerWin::GenerateShortcutsFromProfiles( 391 std::vector<string16> ProfileShortcutManagerWin::GenerateShortcutsFromProfiles(
381 const std::vector<string16>& profile_names) { 392 const std::vector<string16>& profile_names) {
382 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 393 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
383 std::vector<string16> shortcuts; 394 std::vector<string16> shortcuts;
384 shortcuts.reserve(profile_names.size()); 395 shortcuts.reserve(profile_names.size());
385 for (std::vector<string16>::const_iterator it = profile_names.begin(); 396 for (std::vector<string16>::const_iterator it = profile_names.begin();
386 it != profile_names.end(); 397 it != profile_names.end();
387 ++it) { 398 ++it) {
388 string16 shortcut; 399 string16 shortcut;
389 if (ShellUtil::GetChromeShortcutName(dist, false, *it, &shortcut)) 400 if (ShellUtil::GetChromeShortcutName(dist, false, *it, &shortcut))
390 shortcuts.push_back(shortcut); 401 shortcuts.push_back(shortcut);
391 } 402 }
392 return shortcuts; 403 return shortcuts;
393 } 404 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_shortcut_manager_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698