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

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

Issue 9020013: Refactor ProfileInfoCacheObserver interface and usage thereof. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: init Created 9 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) 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,
219 const string16& profile_base_dir,
220 const FilePath& profile_path, 218 const FilePath& profile_path,
221 const gfx::Image* avatar_image) { 219 const string16& profile_base_dir) {
220 ProfileInfoCache& cache =
221 g_browser_process->profile_manager()->GetProfileInfoCache();
222 size_t index = cache.GetIndexOfProfileWithPath(profile_path);
223
222 // Launch task to add shortcut to desktop on Windows. If this is the very 224 // 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. 225 // first profile created, don't add the user name to the shortcut.
224 // TODO(mirandac): respect master_preferences choice to create no shortcuts 226 // TODO(mirandac): respect master_preferences choice to create no shortcuts
225 // (see http://crbug.com/104463) 227 // (see http://crbug.com/104463)
226 if (g_browser_process->profile_manager()->GetNumberOfProfiles() > 1) { 228 if (g_browser_process->profile_manager()->GetNumberOfProfiles() > 1) {
227 { 229 {
228 // We make a copy of the Image to ensure that the underlying image data is 230 // 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. 231 // AddRef'd, in case the original copy gets deleted.
230 gfx::Image* avatar_copy = avatar_image ? 232 gfx::Image* avatar_copy =
231 new gfx::Image(*avatar_image) : NULL; 233 new gfx::Image(cache.GetAvatarIconOfProfileAtIndex(index));
234 string16 profile_name = cache.GetNameOfProfileAtIndex(index);
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 301 }
301 302
302 void ProfileShortcutManagerWin::OnProfileWasRemoved( 303 void ProfileShortcutManagerWin::OnProfileWasRemoved(
303 const string16& profile_name) { 304 const string16& profile_name) {
304 // If there is one profile left, we want to remove the badge and name from it. 305 // If there is one profile left, we want to remove the badge and name from it.
305 ProfileInfoCache& cache = 306 ProfileInfoCache& cache =
306 g_browser_process->profile_manager()->GetProfileInfoCache(); 307 g_browser_process->profile_manager()->GetProfileInfoCache();
307 if (cache.GetNumberOfProfiles() != 1) 308 if (cache.GetNumberOfProfiles() != 1)
308 return; 309 return;
309 310
310 // TODO(stevet): Now that we've sunk our fangs onto ProfileInfoCache, we
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); 311 FilePath profile_path = cache.GetPathOfProfileAtIndex(0);
315 string16 old_shortcut; 312 string16 old_shortcut;
316 string16 new_shortcut; 313 string16 new_shortcut;
317 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 314 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
318 if (ShellUtil::GetChromeShortcutName( 315 if (ShellUtil::GetChromeShortcutName(
319 dist, false, cache.GetNameOfProfileAtIndex(0), &old_shortcut) && 316 dist, false, cache.GetNameOfProfileAtIndex(0), &old_shortcut) &&
320 ShellUtil::GetChromeShortcutName( 317 ShellUtil::GetChromeShortcutName(
321 dist, false, L"", &new_shortcut)) { 318 dist, false, L"", &new_shortcut)) {
322 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 319 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
323 base::Bind(&RenameChromeDesktopShortcutForProfile, 320 base::Bind(&RenameChromeDesktopShortcutForProfile,
(...skipping 23 matching lines...) Expand all
347 ShellUtil::GetChromeShortcutName( 344 ShellUtil::GetChromeShortcutName(
348 dist, false, new_profile_name, &new_shortcut)) { 345 dist, false, new_profile_name, &new_shortcut)) {
349 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 346 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
350 base::Bind(&RenameChromeDesktopShortcutForProfile, 347 base::Bind(&RenameChromeDesktopShortcutForProfile,
351 old_shortcut, 348 old_shortcut,
352 new_shortcut)); 349 new_shortcut));
353 } 350 }
354 } 351 }
355 352
356 void ProfileShortcutManagerWin::OnProfileAvatarChanged( 353 void ProfileShortcutManagerWin::OnProfileAvatarChanged(
357 const string16& profile_name,
358 const string16& profile_base_dir,
359 const FilePath& profile_path, 354 const FilePath& profile_path,
360 const gfx::Image* avatar_image) { 355 const string16& profile_base_dir) {
356 ProfileInfoCache& cache =
357 g_browser_process->profile_manager()->GetProfileInfoCache();
358 size_t index = cache.GetIndexOfProfileWithPath(profile_path);
359 string16 profile_name = cache.GetNameOfProfileAtIndex(index);
360 const gfx::Image& avatar_image = cache.GetAvatarIconOfProfileAtIndex(index);
361
361 // Launch task to change the icon of the desktop shortcut on windows. 362 // Launch task to change the icon of the desktop shortcut on windows.
362 string16 new_shortcut; 363 string16 new_shortcut;
363 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 364 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
364 if (ShellUtil::GetChromeShortcutName(dist, false, profile_name, 365 if (ShellUtil::GetChromeShortcutName(dist, false, profile_name,
365 &new_shortcut)) { 366 &new_shortcut)) {
366 // We make a copy of the Image to ensure that the underlying image data is 367 // 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. 368 // AddRef'd, in case the original copy gets deleted.
368 gfx::Image* avatar_copy = avatar_image ? 369 gfx::Image* avatar_copy = new gfx::Image(avatar_image);
369 new gfx::Image(*avatar_image) : NULL;
370 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 370 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
371 base::Bind(&UpdateChromeDesktopShortcutForProfile, 371 base::Bind(&UpdateChromeDesktopShortcutForProfile,
372 new_shortcut, 372 new_shortcut,
373 CreateProfileShortcutSwitch(profile_base_dir), 373 CreateProfileShortcutSwitch(profile_base_dir),
374 profile_path, 374 profile_path,
375 base::Owned(avatar_copy))); 375 base::Owned(avatar_copy)));
376 } 376 }
377 } 377 }
378 378
379 // static 379 // static
380 std::vector<string16> ProfileShortcutManagerWin::GenerateShortcutsFromProfiles( 380 std::vector<string16> ProfileShortcutManagerWin::GenerateShortcutsFromProfiles(
381 const std::vector<string16>& profile_names) { 381 const std::vector<string16>& profile_names) {
382 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 382 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
383 std::vector<string16> shortcuts; 383 std::vector<string16> shortcuts;
384 shortcuts.reserve(profile_names.size()); 384 shortcuts.reserve(profile_names.size());
385 for (std::vector<string16>::const_iterator it = profile_names.begin(); 385 for (std::vector<string16>::const_iterator it = profile_names.begin();
386 it != profile_names.end(); 386 it != profile_names.end();
387 ++it) { 387 ++it) {
388 string16 shortcut; 388 string16 shortcut;
389 if (ShellUtil::GetChromeShortcutName(dist, false, *it, &shortcut)) 389 if (ShellUtil::GetChromeShortcutName(dist, false, *it, &shortcut))
390 shortcuts.push_back(shortcut); 390 shortcuts.push_back(shortcut);
391 } 391 }
392 return shortcuts; 392 return shortcuts;
393 } 393 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698