Commit 620e7244 authored by Gayane Petrosyan's avatar Gayane Petrosyan Committed by Commit Bot

Revert "[Profile creation] Show sync confirmation and finish the flow"

This reverts commit b8368dd1.

Reason for revert: CreateSignedInProfile test causes failures on multiple bots
Bug: 1132882

Original change's description:
> [Profile creation] Show sync confirmation and finish the flow
>
> This CL proceeds with the happy path of the signed-in profile creation
> flow:
>  1) After a successful sign-in, the current WebUI for sync confirmation
>     gets displayed;
>  2) After choosing whether to sync, the flow is finished by opening a
>     browser window for the new profile.
>
> Error handling and restyling the confirmation page is left for follow-up
> CLs.
>
> Bug: 1126913
> Change-Id: I17b43fe4ec0c0e0f2f9725b1df8e8e59d2c35f3d
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2421592
> Commit-Queue: Jan Krcal <jkrcal@chromium.org>
> Reviewed-by: David Roger <droger@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#811140}

TBR=droger@chromium.org,jkrcal@chromium.org

Change-Id: I89cf0130e744a1feee9649df1895839e0fe4b314
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1126913
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2435330
Commit-Queue: Gayane Petrosyan <gayane@chromium.org>
Reviewed-by: default avatarGayane Petrosyan <gayane@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811252}
parent fea6d3ed
......@@ -274,20 +274,6 @@ bool ArePublicSessionRestrictionsEnabled() {
#endif
return false;
}
#if !defined(OS_CHROMEOS)
base::string16 GetDefaultNameForNewSignedInProfile(
const AccountInfo& account_info) {
DCHECK(account_info.IsValid());
bool is_consumer = account_info.hosted_domain.empty() ||
account_info.hosted_domain == kNoHostedDomainFound;
if (is_consumer)
return base::UTF8ToUTF16(account_info.given_name);
return l10n_util::GetStringUTF16(
IDS_SIGNIN_DICE_WEB_INTERCEPT_ENTERPRISE_PROFILE_NAME);
}
#endif // !defined(OS_CHROMEOS)
#endif // !defined(OS_ANDROID)
} // namespace profiles
......@@ -16,7 +16,6 @@
#include "chrome/browser/profiles/avatar_menu.h"
#endif
struct AccountInfo;
class Browser;
class PrefRegistrySimple;
class Profile;
......@@ -109,14 +108,6 @@ bool IsPublicSession();
// Returns whether public session restrictions are enabled.
bool ArePublicSessionRestrictionsEnabled();
#if !defined(OS_CHROMEOS)
// Returns the default name for a new signed-in profile, based on
// `account_info`.
base::string16 GetDefaultNameForNewSignedInProfile(
const AccountInfo& account_info);
#endif // !defined(OS_CHROMEOS)
#endif // !defined(OS_ANDROID)
} // namespace profiles
......
......@@ -19,7 +19,6 @@
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/dice_intercepted_session_startup_helper.h"
#include "chrome/browser/signin/dice_signed_in_profile_creator.h"
#include "chrome/browser/signin/dice_web_signin_interceptor_factory.h"
......@@ -31,6 +30,7 @@
#include "chrome/browser/ui/signin/profile_colors_util.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/themes/autogenerated_theme_util.h"
#include "chrome/grit/generated_resources.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -333,7 +333,12 @@ void DiceWebSigninInterceptor::OnProfileCreationChoice(SkColor profile_color,
->FindExtendedAccountInfoForAccountWithRefreshTokenByAccountId(
account_id_);
if (account_info) {
profile_name = profiles::GetDefaultNameForNewSignedInProfile(*account_info);
bool is_managed = !account_info->hosted_domain.empty() &&
account_info->hosted_domain != kNoHostedDomainFound;
profile_name =
is_managed ? l10n_util::GetStringUTF16(
IDS_SIGNIN_DICE_WEB_INTERCEPT_ENTERPRISE_PROFILE_NAME)
: base::UTF8ToUTF16(account_info->given_name);
}
DCHECK(!dice_signed_in_profile_creator_);
......
......@@ -2774,8 +2774,6 @@ static_library("ui") {
"views/profiles/badged_profile_photo.h",
"views/profiles/profile_picker_view.cc",
"views/profiles/profile_picker_view.h",
"views/profiles/profile_picker_view_sync_delegate.cc",
"views/profiles/profile_picker_view_sync_delegate.h",
"views/profiles/user_manager_view.cc",
"views/profiles/user_manager_view.h",
"webui/app_launcher_page_ui.cc",
......
......@@ -7,10 +7,6 @@
#include "third_party/skia/include/core/SkColor.h"
namespace views {
class WebView;
}
class ProfilePicker {
public:
// An entry point that triggers the profile picker window to open.
......@@ -30,25 +26,18 @@ class ProfilePicker {
// Starts the sign-in flow. The layout of the window gets updated for the
// sign-in flow. At the same time, the new profile is created (with
// `profile_color`) and the sign-in page is rendered using the new profile.
// If the creation of the new profile fails, `switch_failure_callback` gets
// |profile_color|) and the sign-in page is rendered using the new profile.
// If the creation of the new profile fails, |switch_failure_callback| gets
// called.
static void SwitchToSignIn(SkColor profile_color,
base::OnceClosure switch_failure_callback);
// Finishes the sign-in flow by moving to the sync confirmation screen. It
// uses the same new profile created by `SwitchToSignIn()`.
static void SwitchToSyncConfirmation();
// Hides the profile picker.
static void Hide();
// Returns whether the profile picker is currently open.
static bool IsOpen();
// Returns the global profile picker instance for testing.
static views::WebView* GetWebViewForTesting();
private:
DISALLOW_COPY_AND_ASSIGN(ProfilePicker);
};
......
......@@ -8,7 +8,6 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
......@@ -17,21 +16,13 @@
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/views/profiles/profile_picker_view_sync_delegate.h"
#include "chrome/browser/ui/webui/signin/dice_turn_sync_on_helper.h"
#include "chrome/browser/ui/webui/signin/profile_picker_ui.h"
#include "chrome/browser/ui/webui/signin/signin_web_dialog_ui.h"
#include "chrome/browser/ui/webui/signin/sync_confirmation_ui.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/google_chrome_strings.h"
#include "components/keep_alive_registry/keep_alive_types.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/startup_metric_utils/browser/startup_metric_utils.h"
#include "content/public/browser/context_menu_params.h"
#include "content/public/browser/render_frame_host.h"
......@@ -90,13 +81,6 @@ void ProfilePicker::SwitchToSignIn(SkColor profile_color,
}
}
// static
void ProfilePicker::SwitchToSyncConfirmation() {
if (g_profile_picker_view) {
g_profile_picker_view->SwitchToSyncConfirmation();
}
}
// static
void ProfilePicker::Hide() {
if (g_profile_picker_view)
......@@ -108,11 +92,6 @@ bool ProfilePicker::IsOpen() {
return g_profile_picker_view;
}
// static
views::WebView* ProfilePicker::GetWebViewForTesting() {
return g_profile_picker_view->web_view_;
}
ProfilePickerView::ProfilePickerView()
: keep_alive_(KeepAliveOrigin::USER_MANAGER_VIEW,
KeepAliveRestartOption::DISABLED) {
......@@ -242,7 +221,7 @@ void ProfilePickerView::OnProfileForSigninCreated(
DCHECK(profile);
ProfileAttributesEntry* entry = nullptr;
ProfileAttributesEntry* entry;
if (!g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(profile->GetPath(), &entry)) {
......@@ -258,25 +237,6 @@ void ProfilePickerView::OnProfileForSigninCreated(
auto* theme_service = ThemeServiceFactory::GetForProfile(profile);
theme_service->BuildAutogeneratedThemeFromColor(profile_color);
// TODO(crbug.com/1126913): Record also that we show the sign-in promo
// (it has to be plumbed from js to profile_picker_handler.cc):
// signin_metrics::RecordSigninImpressionUserActionForAccessPoint(
// signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER);
// Record that the sign in process starts (its end is recorded automatically
// by the instance of DiceTurnSyncOnHelper constructed later on).
signin_metrics::RecordSigninUserActionForAccessPoint(
signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER,
signin_metrics::PromoAction::PROMO_ACTION_NO_SIGNIN_PROMO);
signin_metrics::LogSigninAccessPointStarted(
signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER,
signin_metrics::PromoAction::PROMO_ACTION_NO_SIGNIN_PROMO);
// Listen for sign-in getting completed.
identity_manager_observer_.Add(
IdentityManagerFactory::GetForProfile(profile));
profile_being_created_ = profile;
// Rebuild the view.
// TODO(crbug.com/1126913): Add the simple toolbar with the back button.
RemoveAllChildViews(true);
......@@ -288,18 +248,6 @@ void ProfilePickerView::OnProfileForSigninCreated(
web_view_->RequestFocus();
}
void ProfilePickerView::SwitchToSyncConfirmation() {
// TODO(crbug.com/1126913): Remove the simple toolbar with the back button
// (once it is added for the GAIA part).
web_view_->LoadInitialURL(GURL(chrome::kChromeUISyncConfirmationURL));
web_view_->RequestFocus();
SyncConfirmationUI* sync_confirmation_ui = static_cast<SyncConfirmationUI*>(
web_view_->GetWebContents()->GetWebUI()->GetController());
sync_confirmation_ui->InitializeMessageHandlerWithProfile(
profile_being_created_);
}
gfx::Size ProfilePickerView::CalculatePreferredSize() const {
gfx::Size preferred_size = gfx::Size(kWindowWidth, kWindowHeight);
gfx::Size work_area_size = GetWidget()->GetWorkAreaBoundsInScreen().size();
......@@ -333,114 +281,3 @@ bool ProfilePickerView::HandleContextMenu(
// Ignores context menu.
return true;
}
void ProfilePickerView::OnRefreshTokenUpdatedForAccount(
const CoreAccountInfo& account_info) {
DCHECK(!account_info.IsEmpty());
base::OnceClosure sync_consent_completed_closure =
base::BindOnce(&ProfilePickerView::FinishSignedInCreationFlow,
weak_ptr_factory_.GetWeakPtr(), profile_being_created_,
BrowserOpenedCallback());
// DiceTurnSyncOnHelper deletes itself once done.
new DiceTurnSyncOnHelper(
profile_being_created_,
signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER,
signin_metrics::PromoAction::PROMO_ACTION_NO_SIGNIN_PROMO,
signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT,
account_info.account_id,
DiceTurnSyncOnHelper::SigninAbortedMode::KEEP_ACCOUNT,
std::make_unique<ProfilePickerViewSyncDelegate>(
profile_being_created_,
base::BindOnce(&ProfilePickerView::FinishSignedInCreationFlow,
weak_ptr_factory_.GetWeakPtr())),
std::move(sync_consent_completed_closure));
}
void ProfilePickerView::OnExtendedAccountInfoUpdated(
const AccountInfo& account_info) {
if (!account_info.IsValid())
return;
account_info_ = account_info;
// Stop listening to further changes.
identity_manager_observer_.Remove(
IdentityManagerFactory::GetForProfile(profile_being_created_));
if (on_account_info_available_)
std::move(on_account_info_available_).Run();
}
void ProfilePickerView::FinishSignedInCreationFlow(
Profile* profile,
BrowserOpenedCallback callback) {
// This can get called first time from a special case handling (such as the
// Settings link) and than second time when the consent flow finishes. We need
// to make sure only the first call gets handled.
if (!profile_being_created_)
return;
profile_being_created_ = nullptr;
if (!account_info_.IsValid()) {
// TODO(crbug.com/1126913): Add a timeout so that Chrome deals with cases
// when the extended info is never available (firewall, etc).
on_account_info_available_ = base::BindOnce(
&ProfilePickerView::FinishSignedInCreationFlowImpl,
weak_ptr_factory_.GetWeakPtr(), profile, std::move(callback));
return;
}
FinishSignedInCreationFlowImpl(profile, std::move(callback));
}
void ProfilePickerView::FinishSignedInCreationFlowImpl(
Profile* profile,
BrowserOpenedCallback callback) {
DCHECK(account_info_.IsValid());
ProfileAttributesEntry* entry = nullptr;
if (!g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(profile->GetPath(), &entry)) {
NOTREACHED();
return;
}
// Unmark this profile ephemeral so that it is not deleted upon next startup.
entry->SetIsEphemeral(false);
// Set the profile name
entry->SetLocalProfileName(
profiles::GetDefaultNameForNewSignedInProfile(account_info_));
// TODO(crbug.com/1126913): Change the callback of
// profiles::OpenBrowserWindowForProfile() to be a OnceCallback as it is only
// called once.
profiles::OpenBrowserWindowForProfile(
base::AdaptCallbackForRepeating(
base::BindOnce(&ProfilePickerView::OnBrowserOpened,
weak_ptr_factory_.GetWeakPtr(), std::move(callback))),
/*always_create=*/false, // Don't create a window if one already exists.
/*is_new_profile=*/false, // Don't create a first run window.
/*unblock_extensions=*/false, // There is no need to unblock all
// extensions because we only open browser
// window if the Profile is not locked.
// Hence there is no extension blocked.
profile, Profile::CREATE_STATUS_INITIALIZED);
}
void ProfilePickerView::OnBrowserOpened(
BrowserOpenedCallback finish_flow_callback,
Profile* profile,
Profile::CreateStatus profile_create_status) {
// Hide the picker view.
Clear();
if (!finish_flow_callback)
return;
Browser* browser = chrome::FindLastActiveWithProfile(profile);
DCHECK(browser);
std::move(finish_flow_callback).Run(browser);
}
......@@ -9,14 +9,10 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/profile_picker.h"
#include "components/keep_alive_registry/scoped_keep_alive.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "content/public/browser/web_contents_delegate.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/window/dialog_delegate.h"
struct AccountInfo;
class Browser;
namespace content {
struct ContextMenuParams;
class RenderFrameHost;
......@@ -24,11 +20,7 @@ class RenderFrameHost;
// Dialog widget that contains the Desktop Profile picker webui.
class ProfilePickerView : public views::DialogDelegateView,
public content::WebContentsDelegate,
public signin::IdentityManager::Observer {
public:
using BrowserOpenedCallback = base::OnceCallback<void(Browser*)>;
public content::WebContentsDelegate {
private:
friend class ProfilePicker;
......@@ -62,8 +54,6 @@ class ProfilePickerView : public views::DialogDelegateView,
void OnProfileForSigninCreated(SkColor profile_color,
Profile* new_profile,
Profile::CreateStatus status);
// Switches the layout to the sync confirmation screen.
void SwitchToSyncConfirmation();
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
......@@ -76,35 +66,12 @@ class ProfilePickerView : public views::DialogDelegateView,
bool HandleContextMenu(content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params) override;
// IdentityManager::Observer:
void OnRefreshTokenUpdatedForAccount(
const CoreAccountInfo& account_info) override;
void OnExtendedAccountInfoUpdated(const AccountInfo& account_info) override;
// Finishes the creation flow by marking `profile` as fully created, opening a
// browser window for `profile` and calling `callback`.
void FinishSignedInCreationFlow(Profile* profile,
BrowserOpenedCallback callback);
void FinishSignedInCreationFlowImpl(Profile* profile,
BrowserOpenedCallback callback);
// Internal callback to finish the last steps of the signed-in creation flow.
void OnBrowserOpened(BrowserOpenedCallback finish_flow_callback,
Profile* profile,
Profile::CreateStatus profile_create_status);
ScopedKeepAlive keep_alive_;
views::WebView* web_view_ = nullptr;
InitState initialized_ = InitState::kNotInitialized;
Profile* profile_being_created_ = nullptr;
AccountInfo account_info_;
base::OnceClosure on_account_info_available_;
// Not null iff switching to sign-in is in progress.
base::OnceClosure switch_failure_callback_;
ScopedObserver<signin::IdentityManager, signin::IdentityManager::Observer>
identity_manager_observer_{this};
// Creation time of the picker, to measure performance on startup. Only set
// when the picker is shown on startup.
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/profiles/profile_picker_view.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/mock_callback.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/policy/cloud/user_policy_signin_service.h"
#include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_manager_observer.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/webui/signin/login_ui_service.h"
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/identity_test_utils.h"
#include "components/sync/driver/sync_driver_switches.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "google_apis/gaia/gaia_urls.h"
#include "third_party/skia/include/core/SkColor.h"
namespace {
AccountInfo FillAccountInfo(const CoreAccountInfo& core_info,
const std::string& given_name) {
AccountInfo account_info;
account_info.email = core_info.email;
account_info.gaia = core_info.gaia;
account_info.account_id = core_info.account_id;
account_info.is_under_advanced_protection =
core_info.is_under_advanced_protection;
account_info.full_name = "Test Full Name";
account_info.given_name = given_name;
account_info.hosted_domain = kNoHostedDomainFound;
account_info.locale = "en";
account_info.picture_url = "https://get-avatar.com/foo";
account_info.is_child_account = false;
return account_info;
}
// Waits until a new profile is created.
class ProfileWaiter : public ProfileManagerObserver {
public:
ProfileWaiter() {
profile_manager_observer_.Add(g_browser_process->profile_manager());
}
~ProfileWaiter() override = default;
Profile* WaitForProfileAdded() {
run_loop_.Run();
return profile_;
}
private:
// ProfileManagerObserver:
void OnProfileAdded(Profile* profile) override {
profile_manager_observer_.RemoveAll();
profile_ = profile;
run_loop_.Quit();
}
Profile* profile_ = nullptr;
ScopedObserver<ProfileManager, ProfileManagerObserver>
profile_manager_observer_{this};
base::RunLoop run_loop_;
};
// Waits until a first non empty paint for given `url`.
class FirstVisuallyNonEmptyPaintObserver : public content::WebContentsObserver {
public:
explicit FirstVisuallyNonEmptyPaintObserver(content::WebContents* contents,
const GURL& url)
: content::WebContentsObserver(contents), url_(url) {}
void DidFirstVisuallyNonEmptyPaint() override {
if (web_contents()->GetVisibleURL() == url_)
run_loop_.Quit();
}
void Wait() { run_loop_.Run(); }
private:
base::RunLoop run_loop_{base::RunLoop::Type::kNestableTasksAllowed};
GURL url_;
};
// Fake user policy signin service immediately invoking the callbacks.
class FakeUserPolicySigninService : public policy::UserPolicySigninService {
public:
static std::unique_ptr<KeyedService> Build(content::BrowserContext* context) {
Profile* profile = Profile::FromBrowserContext(context);
return std::make_unique<FakeUserPolicySigninService>(
profile, IdentityManagerFactory::GetForProfile(profile));
}
FakeUserPolicySigninService(Profile* profile,
signin::IdentityManager* identity_manager)
: UserPolicySigninService(profile,
nullptr,
nullptr,
nullptr,
identity_manager,
nullptr) {}
// policy::UserPolicySigninService:
void RegisterForPolicyWithAccountId(
const std::string& username,
const CoreAccountId& account_id,
PolicyRegistrationCallback callback) override {
std::move(callback).Run(dm_token_, client_id_);
}
// policy::UserPolicySigninServiceBase:
void FetchPolicyForSignedInUser(
const AccountId& account_id,
const std::string& dm_token,
const std::string& client_id,
scoped_refptr<network::SharedURLLoaderFactory> test_shared_loader_factory,
PolicyFetchCallback callback) override {
std::move(callback).Run(true);
}
private:
std::string dm_token_;
std::string client_id_;
};
class ProfilePickerCreationFlowBrowserTest : public InProcessBrowserTest {
public:
ProfilePickerCreationFlowBrowserTest() {
feature_list_.InitWithFeatures(
{features::kProfilesUIRevamp, features::kNewProfilePicker}, {});
}
void SetUpInProcessBrowserTestFixture() override {
InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
create_services_subscription_ =
BrowserContextDependencyManager::GetInstance()
->RegisterCreateServicesCallbackForTesting(
base::Bind(&ProfilePickerCreationFlowBrowserTest::
OnWillCreateBrowserContextServices,
base::Unretained(this)));
// A hack for DiceTurnSyncOnHelper to actually skip talking to SyncService.
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
command_line->AppendSwitch(switches::kDisableSync);
}
void OnWillCreateBrowserContextServices(content::BrowserContext* context) {
policy::UserPolicySigninServiceFactory::GetInstance()->SetTestingFactory(
context, base::BindRepeating(&FakeUserPolicySigninService::Build));
}
content::WebContents* web_contents() {
return ProfilePicker::GetWebViewForTesting()->GetWebContents();
}
private:
std::unique_ptr<
BrowserContextDependencyManager::CreateServicesCallbackList::Subscription>
create_services_subscription_;
base::test::ScopedFeatureList feature_list_;
};
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest, ShowChoice) {
ProfilePicker::Show(ProfilePicker::EntryPoint::kProfileMenuAddNewProfile);
// Wait for web_contents() to get created.
base::RunLoop().RunUntilIdle();
FirstVisuallyNonEmptyPaintObserver(
web_contents(), GURL("chrome://profile-picker/new-profile"))
.Wait();
}
IN_PROC_BROWSER_TEST_F(ProfilePickerCreationFlowBrowserTest,
CreateSignedInProfile) {
const SkColor kProfileColor = SK_ColorRED;
ProfileManager* profile_manager = g_browser_process->profile_manager();
BrowserList* active_browser_list = BrowserList::GetInstance();
ASSERT_EQ(1u, profile_manager->GetNumberOfProfiles());
EXPECT_EQ(1u, active_browser_list->size());
ProfilePicker::Show(ProfilePicker::EntryPoint::kProfileMenuAddNewProfile);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(ProfilePicker::IsOpen());
// Simulate a click on the signin button.
base::MockCallback<base::OnceClosure> switch_failure_callback;
EXPECT_CALL(switch_failure_callback, Run()).Times(0);
ProfilePicker::SwitchToSignIn(kProfileColor, switch_failure_callback.Get());
// Need to wait for the new profile being created before waiting on
// web_contents() because web_contents is reconstructed with the new profile.
Profile* profile_being_created = ProfileWaiter().WaitForProfileAdded();
base::RunLoop().RunUntilIdle();
FirstVisuallyNonEmptyPaintObserver(
web_contents(), GaiaUrls::GetInstance()->signin_chrome_sync_dice())
.Wait();
// Add an account - simulate a successful Gaia sign-in.
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile_being_created);
CoreAccountInfo core_account_info =
signin::MakeAccountAvailable(identity_manager, "joe.consumer@gmail.com");
ASSERT_TRUE(identity_manager->HasAccountWithRefreshToken(
core_account_info.account_id));
AccountInfo account_info = FillAccountInfo(core_account_info, "Joe");
signin::UpdateAccountInfoForAccount(identity_manager, account_info);
FirstVisuallyNonEmptyPaintObserver(web_contents(),
GURL("chrome://sync-confirmation/"))
.Wait();
// Simulate closing the UI with "Yes, I'm in".
LoginUIServiceFactory::GetForProfile(profile_being_created)
->SyncConfirmationUIClosed(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS);
base::RunLoop().RunUntilIdle();
// Check expectations when the profile creation flow is done.
EXPECT_EQ(2u, active_browser_list->size());
EXPECT_FALSE(ProfilePicker::IsOpen());
ProfileAttributesEntry* entry = nullptr;
ASSERT_TRUE(g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(
profile_being_created->GetPath(), &entry));
EXPECT_FALSE(entry->IsEphemeral());
EXPECT_EQ(entry->GetLocalProfileName(), base::UTF8ToUTF16("Joe"));
EXPECT_EQ(ThemeServiceFactory::GetForProfile(profile_being_created)
->GetAutogeneratedThemeColor(),
kProfileColor);
}
} // namespace
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/profiles/profile_picker_view_sync_delegate.h"
#include "base/logging.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/profile_picker.h"
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
#include "chrome/common/webui_url_constants.h"
namespace {
void OpenSettingsInBrowser(Browser* browser) {
chrome::ShowSettingsSubPage(browser, chrome::kSyncSetupSubPage);
}
} // namespace
ProfilePickerViewSyncDelegate::ProfilePickerViewSyncDelegate(
Profile* profile,
OpenBrowserCallback open_browser_callback)
: profile_(profile),
open_browser_callback_(std::move(open_browser_callback)) {}
ProfilePickerViewSyncDelegate::~ProfilePickerViewSyncDelegate() = default;
void ProfilePickerViewSyncDelegate::ShowLoginError(
const std::string& email,
const std::string& error_message) {
// TODO(crbug.com/1126913): Handle the error cases.
NOTIMPLEMENTED();
}
void ProfilePickerViewSyncDelegate::ShowMergeSyncDataConfirmation(
const std::string& previous_email,
const std::string& new_email,
DiceTurnSyncOnHelper::SigninChoiceCallback callback) {
// A brand new profile cannot have a conflict in sync accounts.
NOTREACHED();
}
void ProfilePickerViewSyncDelegate::ShowEnterpriseAccountConfirmation(
const std::string& email,
DiceTurnSyncOnHelper::SigninChoiceCallback callback) {
// TODO(crbug.com/1126913): Handle the error cases.
NOTIMPLEMENTED();
}
void ProfilePickerViewSyncDelegate::ShowSyncConfirmation(
base::OnceCallback<void(LoginUIService::SyncConfirmationUIClosedResult)>
callback) {
DCHECK(callback);
sync_confirmation_callback_ = std::move(callback);
scoped_login_ui_service_observer_.Add(
LoginUIServiceFactory::GetForProfile(profile_));
ProfilePicker::SwitchToSyncConfirmation();
}
void ProfilePickerViewSyncDelegate::ShowSyncSettings() {
// Open the browser and when it's done, open settings in the browser.
std::move(open_browser_callback_)
.Run(profile_, base::BindOnce(&OpenSettingsInBrowser));
}
void ProfilePickerViewSyncDelegate::SwitchToProfile(Profile* new_profile) {
// TODO(crbug.com/1126913): Handle this flow.
NOTIMPLEMENTED();
}
void ProfilePickerViewSyncDelegate::OnSyncConfirmationUIClosed(
LoginUIService::SyncConfirmationUIClosedResult result) {
// No need to listen to further confirmations any more.
scoped_login_ui_service_observer_.Remove(
LoginUIServiceFactory::GetForProfile(profile_));
DCHECK(sync_confirmation_callback_);
std::move(sync_confirmation_callback_).Run(result);
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_PICKER_VIEW_SYNC_DELEGATE_H_
#define CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_PICKER_VIEW_SYNC_DELEGATE_H_
#include "base/scoped_observer.h"
#include "chrome/browser/ui/views/profiles/profile_picker_view.h"
#include "chrome/browser/ui/webui/signin/dice_turn_sync_on_helper.h"
#include "chrome/browser/ui/webui/signin/login_ui_service.h"
class Profile;
// Handles the sync consent screen for creating a signed-in profile from the
// profile picker.
class ProfilePickerViewSyncDelegate : public DiceTurnSyncOnHelper::Delegate,
public LoginUIService::Observer {
public:
using OpenBrowserCallback =
base::OnceCallback<void(Profile*,
ProfilePickerView::BrowserOpenedCallback)>;
ProfilePickerViewSyncDelegate(Profile* profile,
OpenBrowserCallback open_browser_callback);
~ProfilePickerViewSyncDelegate() override;
private:
// DiceTurnSyncOnHelper::Delegate:
void ShowLoginError(const std::string& email,
const std::string& error_message) override;
void ShowMergeSyncDataConfirmation(
const std::string& previous_email,
const std::string& new_email,
DiceTurnSyncOnHelper::SigninChoiceCallback callback) override;
void ShowEnterpriseAccountConfirmation(
const std::string& email,
DiceTurnSyncOnHelper::SigninChoiceCallback callback) override;
void ShowSyncConfirmation(
base::OnceCallback<void(LoginUIService::SyncConfirmationUIClosedResult)>
callback) override;
void ShowSyncSettings() override;
void SwitchToProfile(Profile* new_profile) override;
// LoginUIService::Observer:
void OnSyncConfirmationUIClosed(
LoginUIService::SyncConfirmationUIClosedResult result) override;
Profile* profile_;
OpenBrowserCallback open_browser_callback_;
base::OnceCallback<void(LoginUIService::SyncConfirmationUIClosedResult)>
sync_confirmation_callback_;
ScopedObserver<LoginUIService, LoginUIService::Observer>
scoped_login_ui_service_observer_{this};
DISALLOW_COPY_AND_ASSIGN(ProfilePickerViewSyncDelegate);
};
#endif // CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_PICKER_VIEW_SYNC_DELEGATE_H_
......@@ -37,14 +37,14 @@ const int kProfileImageSize = 128;
} // namespace
SyncConfirmationHandler::SyncConfirmationHandler(
Profile* profile,
const std::unordered_map<std::string, int>& string_to_grd_id_map,
Browser* browser)
: profile_(profile),
string_to_grd_id_map_(string_to_grd_id_map),
Browser* browser,
const std::unordered_map<std::string, int>& string_to_grd_id_map)
: profile_(browser->profile()),
browser_(browser),
string_to_grd_id_map_(string_to_grd_id_map),
identity_manager_(IdentityManagerFactory::GetForProfile(profile_)) {
DCHECK(profile_);
DCHECK(browser_);
BrowserList::AddObserver(this);
}
......@@ -219,6 +219,9 @@ void SyncConfirmationHandler::HandleInitializedWithSize(
const base::ListValue* args) {
AllowJavascript();
if (!browser_)
return;
base::Optional<AccountInfo> primary_account_info =
identity_manager_->FindExtendedAccountInfoForAccountWithRefreshToken(
identity_manager_->GetPrimaryAccountInfo(ConsentLevel::kNotRequired));
......@@ -235,6 +238,5 @@ void SyncConfirmationHandler::HandleInitializedWithSize(
SetUserImageURL(primary_account_info->picture_url);
}
if (browser_)
signin::SetInitializedModalHeight(browser_, web_ui(), args);
signin::SetInitializedModalHeight(browser_, web_ui(), args);
}
......@@ -29,14 +29,12 @@ class SyncConfirmationHandler : public content::WebUIMessageHandler,
public signin::IdentityManager::Observer,
public BrowserListObserver {
public:
// Creates a SyncConfirmationHandler for the |profile|. All strings in the
// Creates a SyncConfirmationHandler for the |browser|. All strings in the
// corresponding Web UI should be represented in |string_to_grd_id_map| and
// mapped to their GRD IDs. If |browser| is provided, its signin view
// controller will be notified of the rendered size of the web page.
// mapped to their GRD IDs.
SyncConfirmationHandler(
Profile* profile,
const std::unordered_map<std::string, int>& string_to_grd_id_map,
Browser* browser = nullptr);
Browser* browser,
const std::unordered_map<std::string, int>& string_to_grd_id_map);
~SyncConfirmationHandler() override;
// content::WebUIMessageHandler:
......@@ -97,6 +95,9 @@ class SyncConfirmationHandler : public content::WebUIMessageHandler,
private:
Profile* profile_;
// Weak reference to the browser that showed the sync confirmation dialog.
Browser* browser_;
// Records whether the user clicked on Undo, Ok, or Settings.
bool did_user_explicitly_interact_ = false;
......@@ -104,10 +105,6 @@ class SyncConfirmationHandler : public content::WebUIMessageHandler,
// and their respective GRD IDs.
std::unordered_map<std::string, int> string_to_grd_id_map_;
// Weak reference to the browser that showed the sync confirmation dialog (if
// such a dialog exists).
Browser* browser_;
signin::IdentityManager* identity_manager_;
DISALLOW_COPY_AND_ASSIGN(SyncConfirmationHandler);
......
......@@ -45,9 +45,7 @@ class TestingSyncConfirmationHandler : public SyncConfirmationHandler {
Browser* browser,
content::WebUI* web_ui,
std::unordered_map<std::string, int> string_to_grd_id_map)
: SyncConfirmationHandler(browser->profile(),
string_to_grd_id_map,
browser) {
: SyncConfirmationHandler(browser, string_to_grd_id_map) {
set_web_ui(web_ui);
}
......
......@@ -12,7 +12,6 @@
#include "chrome/browser/signin/account_consistency_mode_manager.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/webui/signin/sync_confirmation_handler.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/browser_resources.h"
......@@ -121,12 +120,7 @@ SyncConfirmationUI::~SyncConfirmationUI() {}
void SyncConfirmationUI::InitializeMessageHandlerWithBrowser(Browser* browser) {
web_ui()->AddMessageHandler(std::make_unique<SyncConfirmationHandler>(
browser->profile(), js_localized_string_to_ids_map_, browser));
}
void SyncConfirmationUI::InitializeMessageHandlerWithProfile(Profile* profile) {
web_ui()->AddMessageHandler(std::make_unique<SyncConfirmationHandler>(
profile, js_localized_string_to_ids_map_));
browser, js_localized_string_to_ids_map_));
}
void SyncConfirmationUI::AddStringResource(content::WebUIDataSource* source,
......
......@@ -12,9 +12,6 @@
#include "base/macros.h"
#include "chrome/browser/ui/webui/signin/signin_web_dialog_ui.h"
class Browser;
class Profile;
namespace content {
class WebUIDataSource;
}
......@@ -35,10 +32,6 @@ class SyncConfirmationUI : public SigninWebDialogUI {
// SigninWebDialogUI:
void InitializeMessageHandlerWithBrowser(Browser* browser) override;
// Initializes the message handler when there's no browser for `profile`
// available (such as in the profile creation flow).
void InitializeMessageHandlerWithProfile(Profile* profile);
private:
// Adds a string resource with the given GRD |ids| to the WebUI data |source|
// named as |name|. Also stores a reverse mapping from the localized version
......
......@@ -3060,11 +3060,6 @@ if (!is_android) {
[ "../browser/site_isolation/spellcheck_per_process_browsertest.cc" ]
}
if (is_win || is_mac || (is_desktop_linux && !chromeos_is_browser_only)) {
sources +=
[ "../browser/ui/views/profiles/profile_picker_view_browsertest.cc" ]
}
sources += metric_integration_sources
}
}
......
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