Commit 34fc4379 authored by David Roger's avatar David Roger Committed by Commit Bot

[signin] New profiles get generic avatar

This CL changes new profiles created by signin interception to use the
generic avatar instead of a random avatar.

Bug: 1076880
Change-Id: I54a9481db74e9672250e1e4c3436fb723be130de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2353338
Commit-Queue: David Roger <droger@chromium.org>
Reviewed-by: default avatarMonica Basta <msalama@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799109}
parent 3765fb4e
......@@ -132,20 +132,20 @@ DiceSignedInProfileCreator::DiceSignedInProfileCreator(
Profile* source_profile,
CoreAccountId account_id,
const std::string& local_profile_name,
base::Optional<size_t> icon_index,
base::OnceCallback<void(Profile*)> callback)
: source_profile_(source_profile),
account_id_(account_id),
callback_(std::move(callback)) {
ProfileAttributesStorage& storage =
g_browser_process->profile_manager()->GetProfileAttributesStorage();
size_t icon_index = storage.ChooseAvatarIconIndexForNewProfile();
if (!icon_index.has_value())
icon_index = storage.ChooseAvatarIconIndexForNewProfile();
base::string16 name = local_profile_name.empty()
? storage.ChooseNameForNewProfile(icon_index)
? storage.ChooseNameForNewProfile(*icon_index)
: base::UTF8ToUTF16(local_profile_name);
ProfileManager::CreateMultiProfileAsync(
name, profiles::GetDefaultAvatarIconUrl(icon_index),
name, profiles::GetDefaultAvatarIconUrl(*icon_index),
base::BindRepeating(&DiceSignedInProfileCreator::OnNewProfileCreated,
weak_pointer_factory_.GetWeakPtr()));
}
......
......@@ -9,6 +9,7 @@
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "chrome/browser/profiles/profile.h"
#include "google_apis/gaia/core_account_id.h"
......@@ -22,9 +23,11 @@ class DiceSignedInProfileCreator {
// failure. The callback is never called synchronously.
// If |local_profile_name| is not empty, it will be set as local name for the
// new profile.
// If |icon_index| is nullopt, a random icon will be selected.
DiceSignedInProfileCreator(Profile* source_profile,
CoreAccountId account_id,
const std::string& local_profile_name,
base::Optional<size_t> icon_index,
base::OnceCallback<void(Profile*)> callback);
~DiceSignedInProfileCreator();
......
......@@ -14,6 +14,7 @@
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_manager_observer.h"
#include "chrome/browser/signin/identity_manager_factory.h"
......@@ -159,11 +160,12 @@ class DiceSignedInProfileCreatorTest : public testing::Test,
TEST_F(DiceSignedInProfileCreatorTest, CreateWithTokensLoaded) {
AccountInfo account_info =
identity_test_env()->MakeAccountAvailable("bob@example.com");
size_t kTestIcon = profiles::GetModernAvatarIconStartIndex();
base::RunLoop loop;
std::unique_ptr<DiceSignedInProfileCreator> creator =
std::make_unique<DiceSignedInProfileCreator>(
profile(), account_info.account_id, kProfileTestName,
profile(), account_info.account_id, kProfileTestName, kTestIcon,
base::BindOnce(&DiceSignedInProfileCreatorTest::OnProfileCreated,
base::Unretained(this), loop.QuitClosure()));
loop.Run();
......@@ -181,7 +183,7 @@ TEST_F(DiceSignedInProfileCreatorTest, CreateWithTokensLoaded) {
EXPECT_TRUE(IdentityManagerFactory::GetForProfile(signed_in_profile())
->HasAccountWithRefreshToken(account_info.account_id));
// Check the profile name.
// Check the profile name and icon.
ProfileAttributesEntry* entry = nullptr;
ProfileAttributesStorage& storage =
profile_manager()->GetProfileAttributesStorage();
......@@ -189,6 +191,7 @@ TEST_F(DiceSignedInProfileCreatorTest, CreateWithTokensLoaded) {
signed_in_profile()->GetPath(), &entry));
ASSERT_TRUE(entry);
EXPECT_EQ(base::UTF8ToUTF16(kProfileTestName), entry->GetLocalProfileName());
EXPECT_EQ(kTestIcon, entry->GetAvatarIconIndex());
}
TEST_F(DiceSignedInProfileCreatorTest, CreateWithTokensNotLoaded) {
......@@ -201,7 +204,7 @@ TEST_F(DiceSignedInProfileCreatorTest, CreateWithTokensNotLoaded) {
set_profile_added_closure(profile_added_loop.QuitClosure());
std::unique_ptr<DiceSignedInProfileCreator> creator =
std::make_unique<DiceSignedInProfileCreator>(
profile(), account_info.account_id, kProfileTestName,
profile(), account_info.account_id, kProfileTestName, base::nullopt,
base::BindOnce(&DiceSignedInProfileCreatorTest::OnProfileCreated,
base::Unretained(this), creator_loop.QuitClosure()));
profile_added_loop.Run();
......@@ -236,7 +239,7 @@ TEST_F(DiceSignedInProfileCreatorTest, DeleteWhileCreating) {
identity_test_env()->MakeAccountAvailable("bob@example.com");
std::unique_ptr<DiceSignedInProfileCreator> creator =
std::make_unique<DiceSignedInProfileCreator>(
profile(), account_info.account_id, kProfileTestName,
profile(), account_info.account_id, kProfileTestName, base::nullopt,
base::BindOnce(&DiceSignedInProfileCreatorTest::OnProfileCreated,
base::Unretained(this), base::OnceClosure()));
EXPECT_FALSE(creator_callback_called());
......@@ -255,7 +258,7 @@ TEST_F(DiceSignedInProfileCreatorTest, DeleteProfile) {
set_profile_added_closure(profile_added_loop.QuitClosure());
std::unique_ptr<DiceSignedInProfileCreator> creator =
std::make_unique<DiceSignedInProfileCreator>(
profile(), account_info.account_id, kProfileTestName,
profile(), account_info.account_id, kProfileTestName, base::nullopt,
base::BindOnce(&DiceSignedInProfileCreatorTest::OnProfileCreated,
base::Unretained(this), creator_loop.QuitClosure()));
profile_added_loop.Run();
......
......@@ -15,6 +15,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/dice_intercepted_session_startup_helper.h"
#include "chrome/browser/signin/dice_signed_in_profile_creator.h"
......@@ -285,6 +286,7 @@ void DiceWebSigninInterceptor::OnProfileCreationChoice(bool create) {
dice_signed_in_profile_creator_ =
std::make_unique<DiceSignedInProfileCreator>(
profile_, account_id_, profile_name,
profiles::GetPlaceholderAvatarIndex(),
base::BindOnce(&DiceWebSigninInterceptor::OnNewSignedInProfileCreated,
base::Unretained(this)));
}
......
......@@ -371,7 +371,7 @@ void DiceTurnSyncOnHelper::CreateNewSignedInProfile() {
dice_signed_in_profile_creator_ =
std::make_unique<DiceSignedInProfileCreator>(
profile_, account_info_.account_id,
/*local_profile_name=*/std::string(),
/*local_profile_name=*/std::string(), /*icon_index=*/base::nullopt,
base::BindOnce(&DiceTurnSyncOnHelper::OnNewSignedInProfileCreated,
base::Unretained(this)));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment