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

Side by Side Diff: chrome/browser/ui/webui/options/manage_profile_handler.cc

Issue 476993002: [Profiles] Fix the usage of custom/default names and avatars (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: all rebase all the time Created 6 years, 4 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/ui/webui/options/manage_profile_handler.h" 5 #include "chrome/browser/ui/webui/options/manage_profile_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/prefs/scoped_user_pref_update.h" 10 #include "base/prefs/scoped_user_pref_update.h"
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 "ManageProfileOverlay.showDisconnectManagedProfileDialog", replacements); 333 "ManageProfileOverlay.showDisconnectManagedProfileDialog", replacements);
334 } 334 }
335 335
336 void ManageProfileHandler::SetProfileIconAndName(const base::ListValue* args) { 336 void ManageProfileHandler::SetProfileIconAndName(const base::ListValue* args) {
337 DCHECK(args); 337 DCHECK(args);
338 338
339 base::FilePath profile_file_path; 339 base::FilePath profile_file_path;
340 if (!GetProfilePathFromArgs(args, &profile_file_path)) 340 if (!GetProfilePathFromArgs(args, &profile_file_path))
341 return; 341 return;
342 342
343 ProfileInfoCache& cache =
344 g_browser_process->profile_manager()->GetProfileInfoCache();
345 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
346 if (profile_index == std::string::npos)
347 return;
348
349 Profile* profile = 343 Profile* profile =
350 g_browser_process->profile_manager()->GetProfile(profile_file_path); 344 g_browser_process->profile_manager()->GetProfile(profile_file_path);
351 if (!profile) 345 if (!profile)
352 return; 346 return;
353 347
354 std::string icon_url; 348 std::string icon_url;
355 if (!args->GetString(1, &icon_url)) 349 if (!args->GetString(1, &icon_url))
356 return; 350 return;
357 351
352 PrefService* pref_service = profile->GetPrefs();
353 // Updating the profile preferences will cause the cache to be updated.
354
358 // Metrics logging variable. 355 // Metrics logging variable.
359 bool previously_using_gaia_icon = 356 bool previously_using_gaia_icon =
360 cache.IsUsingGAIAPictureOfProfileAtIndex(profile_index); 357 pref_service->GetBoolean(prefs::kProfileUsingGAIAAvatar);
361 358
362 size_t new_icon_index; 359 size_t new_icon_index;
363 if (icon_url == gaia_picture_url_) { 360 if (icon_url == gaia_picture_url_) {
364 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true); 361 pref_service->SetBoolean(prefs::kProfileUsingDefaultAvatar, false);
362 pref_service->SetBoolean(prefs::kProfileUsingGAIAAvatar, true);
365 if (!previously_using_gaia_icon) { 363 if (!previously_using_gaia_icon) {
366 // Only log if they changed to the GAIA photo. 364 // Only log if they changed to the GAIA photo.
367 // Selection of GAIA photo as avatar is logged as part of the function 365 // Selection of GAIA photo as avatar is logged as part of the function
368 // below. 366 // below.
369 ProfileMetrics::LogProfileSwitchGaia(ProfileMetrics::GAIA_OPT_IN); 367 ProfileMetrics::LogProfileSwitchGaia(ProfileMetrics::GAIA_OPT_IN);
370 } 368 }
371 } else if (profiles::IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) { 369 } else if (profiles::IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) {
372 ProfileMetrics::LogProfileAvatarSelection(new_icon_index); 370 ProfileMetrics::LogProfileAvatarSelection(new_icon_index);
373 PrefService* pref_service = profile->GetPrefs();
374 // Updating the profile preference will cause the cache to be updated for
375 // this preference.
376 pref_service->SetInteger(prefs::kProfileAvatarIndex, new_icon_index); 371 pref_service->SetInteger(prefs::kProfileAvatarIndex, new_icon_index);
377 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, false); 372 pref_service->SetBoolean(prefs::kProfileUsingDefaultAvatar, false);
373 pref_service->SetBoolean(prefs::kProfileUsingGAIAAvatar, false);
378 } 374 }
379 ProfileMetrics::LogProfileUpdate(profile_file_path); 375 ProfileMetrics::LogProfileUpdate(profile_file_path);
380 376
381 if (profile->IsSupervised()) 377 if (profile->IsSupervised())
382 return; 378 return;
383 379
384 base::string16 new_profile_name; 380 base::string16 new_profile_name;
385 if (!args->GetString(2, &new_profile_name)) 381 if (!args->GetString(2, &new_profile_name))
386 return; 382 return;
387 383
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 533
538 // Update the UI buttons. 534 // Update the UI buttons.
539 OnHasProfileShortcuts(false); 535 OnHasProfileShortcuts(false);
540 } 536 }
541 537
542 void ManageProfileHandler::RefreshGaiaPicture(const base::ListValue* args) { 538 void ManageProfileHandler::RefreshGaiaPicture(const base::ListValue* args) {
543 profiles::UpdateGaiaProfilePhotoIfNeeded(Profile::FromWebUI(web_ui())); 539 profiles::UpdateGaiaProfilePhotoIfNeeded(Profile::FromWebUI(web_ui()));
544 } 540 }
545 541
546 } // namespace options 542 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/profiles/avatar_button_controller_unittest.mm ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698