Commit f53a075d authored by David Roger's avatar David Roger Committed by Commit Bot

[signin] Use AccountConsistencyModeManager

This CL converts almost all the remaining code to use
AccountConsistencyModeManager. There are a few calls left in tests and
debugging code, which will be converted in a follow-up CL.

TBR=stevenjb

Bug: 777774
Change-Id: Ic2da79f6b332880e2143425c91ab50322b9d542f
Reviewed-on: https://chromium-review.googlesource.com/1099069
Commit-Queue: David Roger <droger@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568000}
parent fdd303ce
...@@ -117,9 +117,6 @@ class DiceURLRequestUserData : public base::SupportsUserData::Data { ...@@ -117,9 +117,6 @@ class DiceURLRequestUserData : public base::SupportsUserData::Data {
// Attaches a DiceURLRequestUserData to the request if it needs to block the // Attaches a DiceURLRequestUserData to the request if it needs to block the
// AccountReconcilor. // AccountReconcilor.
static void AttachToRequest(net::URLRequest* request) { static void AttachToRequest(net::URLRequest* request) {
if (!IsDicePrepareMigrationEnabled())
return;
if (ShouldBlockReconcilorForRequest(request) && if (ShouldBlockReconcilorForRequest(request) &&
!request->GetUserData(kDiceURLRequestUserDataKey)) { !request->GetUserData(kDiceURLRequestUserDataKey)) {
const content::ResourceRequestInfo* info = const content::ResourceRequestInfo* info =
...@@ -165,7 +162,6 @@ class DiceURLRequestUserData : public base::SupportsUserData::Data { ...@@ -165,7 +162,6 @@ class DiceURLRequestUserData : public base::SupportsUserData::Data {
// * Main frame requests. // * Main frame requests.
// * XHR requests having Gaia URL as referrer. // * XHR requests having Gaia URL as referrer.
static bool ShouldBlockReconcilorForRequest(net::URLRequest* request) { static bool ShouldBlockReconcilorForRequest(net::URLRequest* request) {
DCHECK(IsDicePrepareMigrationEnabled());
const content::ResourceRequestInfo* info = const content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request); content::ResourceRequestInfo::ForRequest(request);
content::ResourceType resource_type = info->GetResourceType(); content::ResourceType resource_type = info->GetResourceType();
...@@ -296,7 +292,6 @@ void ProcessDiceHeaderUIThread( ...@@ -296,7 +292,6 @@ void ProcessDiceHeaderUIThread(
const content::ResourceRequestInfo::WebContentsGetter& const content::ResourceRequestInfo::WebContentsGetter&
web_contents_getter) { web_contents_getter) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(IsDiceFixAuthErrorsEnabled());
content::WebContents* web_contents = web_contents_getter.Run(); content::WebContents* web_contents = web_contents_getter.Run();
if (!web_contents) if (!web_contents)
...@@ -306,6 +301,14 @@ void ProcessDiceHeaderUIThread( ...@@ -306,6 +301,14 @@ void ProcessDiceHeaderUIThread(
Profile::FromBrowserContext(web_contents->GetBrowserContext()); Profile::FromBrowserContext(web_contents->GetBrowserContext());
DCHECK(!profile->IsOffTheRecord()); DCHECK(!profile->IsOffTheRecord());
AccountConsistencyMethod account_consistency =
AccountConsistencyModeManager::GetMethodForProfile(profile);
if (account_consistency == AccountConsistencyMethod::kMirror ||
account_consistency == AccountConsistencyMethod::kDisabled) {
// Ignore Dice response headers if Dice is not enabled at all.
return;
}
signin_metrics::AccessPoint access_point = signin_metrics::AccessPoint access_point =
signin_metrics::AccessPoint::ACCESS_POINT_UNKNOWN; signin_metrics::AccessPoint::ACCESS_POINT_UNKNOWN;
signin_metrics::PromoAction promo_action = signin_metrics::PromoAction promo_action =
...@@ -314,7 +317,7 @@ void ProcessDiceHeaderUIThread( ...@@ -314,7 +317,7 @@ void ProcessDiceHeaderUIThread(
bool is_sync_signin_tab = false; bool is_sync_signin_tab = false;
DiceTabHelper* tab_helper = DiceTabHelper::FromWebContents(web_contents); DiceTabHelper* tab_helper = DiceTabHelper::FromWebContents(web_contents);
if (signin::IsDicePrepareMigrationEnabled() && tab_helper) { if (tab_helper) {
is_sync_signin_tab = true; is_sync_signin_tab = true;
access_point = tab_helper->signin_access_point(); access_point = tab_helper->signin_access_point();
promo_action = tab_helper->signin_promo_action(); promo_action = tab_helper->signin_promo_action();
...@@ -326,7 +329,7 @@ void ProcessDiceHeaderUIThread( ...@@ -326,7 +329,7 @@ void ProcessDiceHeaderUIThread(
dice_response_handler->ProcessDiceHeader( dice_response_handler->ProcessDiceHeader(
dice_params, dice_params,
std::make_unique<ProcessDiceHeaderDelegateImpl>( std::make_unique<ProcessDiceHeaderDelegateImpl>(
web_contents, profile->GetPrefs(), web_contents, account_consistency,
SigninManagerFactory::GetForProfile(profile), is_sync_signin_tab, SigninManagerFactory::GetForProfile(profile), is_sync_signin_tab,
base::BindOnce(&CreateDiceTurnOnSyncHelper, base::Unretained(profile), base::BindOnce(&CreateDiceTurnOnSyncHelper, base::Unretained(profile),
access_point, promo_action, reason), access_point, promo_action, reason),
...@@ -385,16 +388,9 @@ void ProcessDiceResponseHeaderIfExists(net::URLRequest* request, ...@@ -385,16 +388,9 @@ void ProcessDiceResponseHeaderIfExists(net::URLRequest* request,
if (is_off_the_record) if (is_off_the_record)
return; return;
const content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request);
if (!gaia::IsGaiaSignonRealm(request->url().GetOrigin())) if (!gaia::IsGaiaSignonRealm(request->url().GetOrigin()))
return; return;
if (!IsDiceFixAuthErrorsEnabled()) {
return;
}
net::HttpResponseHeaders* response_headers = request->response_headers(); net::HttpResponseHeaders* response_headers = request->response_headers();
if (!response_headers) if (!response_headers)
return; return;
...@@ -417,6 +413,8 @@ void ProcessDiceResponseHeaderIfExists(net::URLRequest* request, ...@@ -417,6 +413,8 @@ void ProcessDiceResponseHeaderIfExists(net::URLRequest* request,
if (params.user_intention == DiceAction::NONE) if (params.user_intention == DiceAction::NONE)
return; return;
const content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request);
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE, content::BrowserThread::UI, FROM_HERE,
base::Bind(ProcessDiceHeaderUIThread, base::Passed(std::move(params)), base::Bind(ProcessDiceHeaderUIThread, base::Passed(std::move(params)),
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_consistency_mode_manager.h"
#include "chrome/browser/signin/account_reconcilor_factory.h" #include "chrome/browser/signin/account_reconcilor_factory.h"
#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/chrome_signin_helper.h" #include "chrome/browser/signin/chrome_signin_helper.h"
...@@ -151,11 +152,13 @@ std::unique_ptr<HttpResponse> HandleSigninURL( ...@@ -151,11 +152,13 @@ std::unique_ptr<HttpResponse> HandleSigninURL(
// Add the SIGNIN dice header. // Add the SIGNIN dice header.
std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse);
if (header_value != kNoDiceRequestHeader) {
http_response->AddCustomHeader( http_response->AddCustomHeader(
kDiceResponseHeader, kDiceResponseHeader,
base::StringPrintf( base::StringPrintf(
"action=SIGNIN,authuser=1,id=%s,email=%s,authorization_code=%s", "action=SIGNIN,authuser=1,id=%s,email=%s,authorization_code=%s",
kMainGaiaID, kMainEmail, kAuthorizationCode)); kMainGaiaID, kMainEmail, kAuthorizationCode));
}
// When hitting the Chrome Sync endpoint, redirect to kEnableSyncURL, which // When hitting the Chrome Sync endpoint, redirect to kEnableSyncURL, which
// adds the ENABLE_SYNC dice header. // adds the ENABLE_SYNC dice header.
...@@ -392,7 +395,12 @@ class DiceBrowserTestBase : public InProcessBrowserTest, ...@@ -392,7 +395,12 @@ class DiceBrowserTestBase : public InProcessBrowserTest,
// Navigate to a Gaia URL setting the Google-Accounts-SignOut header. // Navigate to a Gaia URL setting the Google-Accounts-SignOut header.
void SignOutWithDice(SignoutType signout_type) { void SignOutWithDice(SignoutType signout_type) {
NavigateToURL(base::StringPrintf("%s?%i", kSignoutURL, signout_type)); NavigateToURL(base::StringPrintf("%s?%i", kSignoutURL, signout_type));
if (signin::IsDicePrepareMigrationEnabled()) { signin::AccountConsistencyMethod account_consistency =
AccountConsistencyModeManager::GetMethodForProfile(
browser()->profile());
if (signin::DiceMethodGreaterOrEqual(
account_consistency,
signin::AccountConsistencyMethod::kDicePrepareMigration)) {
EXPECT_EQ(1, reconcilor_blocked_count_); EXPECT_EQ(1, reconcilor_blocked_count_);
WaitForReconcilorUnblockedCount(1); WaitForReconcilorUnblockedCount(1);
} else { } else {
...@@ -474,7 +482,8 @@ class DiceBrowserTestBase : public InProcessBrowserTest, ...@@ -474,7 +482,8 @@ class DiceBrowserTestBase : public InProcessBrowserTest,
// FakeGaia callbacks: // FakeGaia callbacks:
void OnSigninRequest(const std::string& dice_request_header) { void OnSigninRequest(const std::string& dice_request_header) {
EXPECT_EQ(signin::IsDicePrepareMigrationEnabled(), IsReconcilorBlocked()); EXPECT_EQ(dice_request_header != kNoDiceRequestHeader,
IsReconcilorBlocked());
dice_request_header_ = dice_request_header; dice_request_header_ = dice_request_header;
} }
...@@ -484,7 +493,7 @@ class DiceBrowserTestBase : public InProcessBrowserTest, ...@@ -484,7 +493,7 @@ class DiceBrowserTestBase : public InProcessBrowserTest,
} }
void OnEnableSyncRequest(base::OnceClosure unblock_response_closure) { void OnEnableSyncRequest(base::OnceClosure unblock_response_closure) {
EXPECT_EQ(signin::IsDicePrepareMigrationEnabled(), IsReconcilorBlocked()); EXPECT_TRUE(IsReconcilorBlocked());
enable_sync_requested_ = true; enable_sync_requested_ = true;
RunClosureIfValid(std::move(enable_sync_requested_quit_closure_)); RunClosureIfValid(std::move(enable_sync_requested_quit_closure_));
unblock_enable_sync_response_closure_ = std::move(unblock_response_closure); unblock_enable_sync_response_closure_ = std::move(unblock_response_closure);
...@@ -493,7 +502,7 @@ class DiceBrowserTestBase : public InProcessBrowserTest, ...@@ -493,7 +502,7 @@ class DiceBrowserTestBase : public InProcessBrowserTest,
void OnTokenExchangeRequest(base::OnceClosure unblock_response_closure) { void OnTokenExchangeRequest(base::OnceClosure unblock_response_closure) {
// The token must be exchanged only once. // The token must be exchanged only once.
EXPECT_FALSE(token_requested_); EXPECT_FALSE(token_requested_);
EXPECT_EQ(signin::IsDicePrepareMigrationEnabled(), IsReconcilorBlocked()); EXPECT_TRUE(IsReconcilorBlocked());
token_requested_ = true; token_requested_ = true;
RunClosureIfValid(std::move(token_requested_quit_closure_)); RunClosureIfValid(std::move(token_requested_quit_closure_));
unblock_token_exchange_response_closure_ = unblock_token_exchange_response_closure_ =
...@@ -845,8 +854,8 @@ IN_PROC_BROWSER_TEST_F(DiceFixAuthErrorsBrowserTest, SigninAccountMismatch) { ...@@ -845,8 +854,8 @@ IN_PROC_BROWSER_TEST_F(DiceFixAuthErrorsBrowserTest, SigninAccountMismatch) {
EXPECT_FALSE(refresh_token_available_); EXPECT_FALSE(refresh_token_available_);
EXPECT_EQ(GetSecondaryAccountID(), EXPECT_EQ(GetSecondaryAccountID(),
GetSigninManager()->GetAuthenticatedAccountId()); GetSigninManager()->GetAuthenticatedAccountId());
EXPECT_EQ(0, reconcilor_blocked_count_); EXPECT_EQ(1, reconcilor_blocked_count_);
WaitForReconcilorUnblockedCount(0); WaitForReconcilorUnblockedCount(1);
} }
// Checks that signin on Gaia triggers the fetch for a refresh token when there // Checks that signin on Gaia triggers the fetch for a refresh token when there
...@@ -877,8 +886,8 @@ IN_PROC_BROWSER_TEST_F(DiceFixAuthErrorsBrowserTest, ReauthFixAuthError) { ...@@ -877,8 +886,8 @@ IN_PROC_BROWSER_TEST_F(DiceFixAuthErrorsBrowserTest, ReauthFixAuthError) {
// Old token must be revoked silently. // Old token must be revoked silently.
EXPECT_EQ(0, token_revoked_notification_count_); EXPECT_EQ(0, token_revoked_notification_count_);
WaitForTokenRevokedCount(1); WaitForTokenRevokedCount(1);
EXPECT_EQ(0, reconcilor_blocked_count_); EXPECT_EQ(1, reconcilor_blocked_count_);
WaitForReconcilorUnblockedCount(0); WaitForReconcilorUnblockedCount(1);
} }
// Checks that the Dice signout flow is disabled. // Checks that the Dice signout flow is disabled.
......
...@@ -170,8 +170,7 @@ DiceResponseHandler::DiceTokenFetcher::DiceTokenFetcher( ...@@ -170,8 +170,7 @@ DiceResponseHandler::DiceTokenFetcher::DiceTokenFetcher(
SigninClient* signin_client, SigninClient* signin_client,
AccountReconcilor* account_reconcilor, AccountReconcilor* account_reconcilor,
std::unique_ptr<ProcessDiceHeaderDelegate> delegate, std::unique_ptr<ProcessDiceHeaderDelegate> delegate,
DiceResponseHandler* dice_response_handler, DiceResponseHandler* dice_response_handler)
signin::AccountConsistencyMethod account_consistency)
: gaia_id_(gaia_id), : gaia_id_(gaia_id),
email_(email), email_(email),
authorization_code_(authorization_code), authorization_code_(authorization_code),
...@@ -182,12 +181,8 @@ DiceResponseHandler::DiceTokenFetcher::DiceTokenFetcher( ...@@ -182,12 +181,8 @@ DiceResponseHandler::DiceTokenFetcher::DiceTokenFetcher(
base::Unretained(this))), base::Unretained(this))),
should_enable_sync_(false) { should_enable_sync_(false) {
DCHECK(dice_response_handler_); DCHECK(dice_response_handler_);
if (signin::DiceMethodGreaterOrEqual(
account_consistency,
signin::AccountConsistencyMethod::kDicePrepareMigration)) {
account_reconcilor_lock_ = account_reconcilor_lock_ =
std::make_unique<AccountReconcilor::Lock>(account_reconcilor); std::make_unique<AccountReconcilor::Lock>(account_reconcilor);
}
gaia_auth_fetcher_ = signin_client->CreateGaiaAuthFetcher( gaia_auth_fetcher_ = signin_client->CreateGaiaAuthFetcher(
this, GaiaConstants::kChromeSource, this, GaiaConstants::kChromeSource,
signin_client->GetURLRequestContext()); signin_client->GetURLRequestContext());
...@@ -346,7 +341,7 @@ void DiceResponseHandler::ProcessDiceSigninHeader( ...@@ -346,7 +341,7 @@ void DiceResponseHandler::ProcessDiceSigninHeader(
} }
token_fetchers_.push_back(std::make_unique<DiceTokenFetcher>( token_fetchers_.push_back(std::make_unique<DiceTokenFetcher>(
gaia_id, email, authorization_code, signin_client_, account_reconcilor_, gaia_id, email, authorization_code, signin_client_, account_reconcilor_,
std::move(delegate), this, account_consistency_)); std::move(delegate), this));
} }
void DiceResponseHandler::ProcessEnableSyncHeader( void DiceResponseHandler::ProcessEnableSyncHeader(
......
...@@ -80,8 +80,7 @@ class DiceResponseHandler : public KeyedService { ...@@ -80,8 +80,7 @@ class DiceResponseHandler : public KeyedService {
SigninClient* signin_client, SigninClient* signin_client,
AccountReconcilor* account_reconcilor, AccountReconcilor* account_reconcilor,
std::unique_ptr<ProcessDiceHeaderDelegate> delegate, std::unique_ptr<ProcessDiceHeaderDelegate> delegate,
DiceResponseHandler* dice_response_handler, DiceResponseHandler* dice_response_handler);
signin::AccountConsistencyMethod account_consistency);
~DiceTokenFetcher() override; ~DiceTokenFetcher() override;
const std::string& gaia_id() const { return gaia_id_; } const std::string& gaia_id() const { return gaia_id_; }
......
...@@ -752,10 +752,9 @@ TEST_F(DiceResponseHandlerTest, FixAuthError) { ...@@ -752,10 +752,9 @@ TEST_F(DiceResponseHandlerTest, FixAuthError) {
// Check that the token has not been inserted in the token service. // Check that the token has not been inserted in the token service.
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id));
EXPECT_TRUE(token_service_observer->token_received()); EXPECT_TRUE(token_service_observer->token_received());
// Check that the reconcilor was not blocked or unblocked when fixing auth // Check that the reconcilor was blocked and unblocked.
// errors. EXPECT_EQ(1, reconcilor_blocked_count_);
EXPECT_EQ(0, reconcilor_blocked_count_); EXPECT_EQ(1, reconcilor_unblocked_count_);
EXPECT_EQ(0, reconcilor_unblocked_count_);
} }
// Tests that the Dice Signout response is ignored when kDiceFixAuthErrors is // Tests that the Dice Signout response is ignored when kDiceFixAuthErrors is
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/logging.h" #include "base/logging.h"
#include "chrome/common/webui_url_constants.h" #include "chrome/common/webui_url_constants.h"
#include "components/signin/core/browser/profile_management_switches.h"
#include "components/signin/core/browser/signin_manager.h" #include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -28,26 +27,28 @@ void RedirectToNtp(content::WebContents* contents) { ...@@ -28,26 +27,28 @@ void RedirectToNtp(content::WebContents* contents) {
ProcessDiceHeaderDelegateImpl::ProcessDiceHeaderDelegateImpl( ProcessDiceHeaderDelegateImpl::ProcessDiceHeaderDelegateImpl(
content::WebContents* web_contents, content::WebContents* web_contents,
PrefService* user_prefs, signin::AccountConsistencyMethod account_consistency,
SigninManager* signin_manager, SigninManager* signin_manager,
bool is_sync_signin_tab, bool is_sync_signin_tab,
EnableSyncCallback enable_sync_callback, EnableSyncCallback enable_sync_callback,
ShowSigninErrorCallback show_signin_error_callback) ShowSigninErrorCallback show_signin_error_callback)
: content::WebContentsObserver(web_contents), : content::WebContentsObserver(web_contents),
user_prefs_(user_prefs), account_consistency_(account_consistency),
signin_manager_(signin_manager), signin_manager_(signin_manager),
enable_sync_callback_(std::move(enable_sync_callback)), enable_sync_callback_(std::move(enable_sync_callback)),
show_signin_error_callback_(std::move(show_signin_error_callback)), show_signin_error_callback_(std::move(show_signin_error_callback)),
is_sync_signin_tab_(is_sync_signin_tab) { is_sync_signin_tab_(is_sync_signin_tab) {
DCHECK(web_contents); DCHECK(web_contents);
DCHECK(user_prefs_);
DCHECK(signin_manager_); DCHECK(signin_manager_);
} }
ProcessDiceHeaderDelegateImpl::~ProcessDiceHeaderDelegateImpl() = default; ProcessDiceHeaderDelegateImpl::~ProcessDiceHeaderDelegateImpl() = default;
bool ProcessDiceHeaderDelegateImpl::ShouldEnableSync() { bool ProcessDiceHeaderDelegateImpl::ShouldEnableSync() {
if (!signin::IsDicePrepareMigrationEnabled()) { if (!signin::DiceMethodGreaterOrEqual(
account_consistency_,
signin::AccountConsistencyMethod::kDicePrepareMigration)) {
// Dice prepare migration not enabled.
VLOG(1) << "Do not start sync after web sign-in [DICE prepare migration " VLOG(1) << "Do not start sync after web sign-in [DICE prepare migration "
"not enabled]."; "not enabled].";
return false; return false;
...@@ -89,7 +90,8 @@ void ProcessDiceHeaderDelegateImpl::HandleTokenExchangeFailure( ...@@ -89,7 +90,8 @@ void ProcessDiceHeaderDelegateImpl::HandleTokenExchangeFailure(
const GoogleServiceAuthError& error) { const GoogleServiceAuthError& error) {
DCHECK_NE(GoogleServiceAuthError::NONE, error.state()); DCHECK_NE(GoogleServiceAuthError::NONE, error.state());
bool should_enable_sync = ShouldEnableSync(); bool should_enable_sync = ShouldEnableSync();
if (!should_enable_sync && !signin::IsDiceEnabledForProfile(user_prefs_)) if (!should_enable_sync &&
account_consistency_ != signin::AccountConsistencyMethod::kDice)
return; return;
content::WebContents* web_contents = this->web_contents(); content::WebContents* web_contents = this->web_contents();
......
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/macros.h" #include "base/macros.h"
#include "components/signin/core/browser/profile_management_switches.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
namespace content { namespace content {
class WebContents; class WebContents;
} }
class PrefService;
class SigninManager; class SigninManager;
class ProcessDiceHeaderDelegateImpl : public ProcessDiceHeaderDelegate, class ProcessDiceHeaderDelegateImpl : public ProcessDiceHeaderDelegate,
...@@ -39,7 +39,7 @@ class ProcessDiceHeaderDelegateImpl : public ProcessDiceHeaderDelegate, ...@@ -39,7 +39,7 @@ class ProcessDiceHeaderDelegateImpl : public ProcessDiceHeaderDelegate,
// tab. // tab.
ProcessDiceHeaderDelegateImpl( ProcessDiceHeaderDelegateImpl(
content::WebContents* web_contents, content::WebContents* web_contents,
PrefService* user_prefs, signin::AccountConsistencyMethod account_consistency,
SigninManager* signin_manager, SigninManager* signin_manager,
bool is_sync_signin_tab, bool is_sync_signin_tab,
EnableSyncCallback enable_sync_callback, EnableSyncCallback enable_sync_callback,
...@@ -55,7 +55,7 @@ class ProcessDiceHeaderDelegateImpl : public ProcessDiceHeaderDelegate, ...@@ -55,7 +55,7 @@ class ProcessDiceHeaderDelegateImpl : public ProcessDiceHeaderDelegate,
// Returns true if sync should be enabled after the user signs in. // Returns true if sync should be enabled after the user signs in.
bool ShouldEnableSync(); bool ShouldEnableSync();
PrefService* user_prefs_; signin::AccountConsistencyMethod account_consistency_;
SigninManager* signin_manager_; SigninManager* signin_manager_;
EnableSyncCallback enable_sync_callback_; EnableSyncCallback enable_sync_callback_;
ShowSigninErrorCallback show_signin_error_callback_; ShowSigninErrorCallback show_signin_error_callback_;
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "components/signin/core/browser/fake_profile_oauth2_token_service.h" #include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
#include "components/signin/core/browser/fake_signin_manager.h" #include "components/signin/core/browser/fake_signin_manager.h"
#include "components/signin/core/browser/profile_management_switches.h" #include "components/signin/core/browser/profile_management_switches.h"
#include "components/signin/core/browser/scoped_account_consistency.h"
#include "components/signin/core/browser/test_signin_client.h" #include "components/signin/core/browser/test_signin_client.h"
#include "components/sync_preferences/testing_pref_service_syncable.h" #include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -61,9 +60,11 @@ class ProcessDiceHeaderDelegateImplTest ...@@ -61,9 +60,11 @@ class ProcessDiceHeaderDelegateImplTest
// Creates a ProcessDiceHeaderDelegateImpl instance. // Creates a ProcessDiceHeaderDelegateImpl instance.
std::unique_ptr<ProcessDiceHeaderDelegateImpl> CreateDelegate( std::unique_ptr<ProcessDiceHeaderDelegateImpl> CreateDelegate(
bool is_sync_signin_tab) { bool is_sync_signin_tab,
signin::AccountConsistencyMethod account_consistency) {
return std::make_unique<ProcessDiceHeaderDelegateImpl>( return std::make_unique<ProcessDiceHeaderDelegateImpl>(
web_contents(), &pref_service_, &signin_manager_, is_sync_signin_tab, web_contents(), account_consistency, &signin_manager_,
is_sync_signin_tab,
base::BindOnce(&ProcessDiceHeaderDelegateImplTest::StartSyncCallback, base::BindOnce(&ProcessDiceHeaderDelegateImplTest::StartSyncCallback,
base::Unretained(this)), base::Unretained(this)),
base::BindOnce( base::BindOnce(
...@@ -105,12 +106,11 @@ class ProcessDiceHeaderDelegateImplTest ...@@ -105,12 +106,11 @@ class ProcessDiceHeaderDelegateImplTest
// Check that sync is enabled if the tab is closed during signin. // Check that sync is enabled if the tab is closed during signin.
TEST_F(ProcessDiceHeaderDelegateImplTest, CloseTabWhileStartingSync) { TEST_F(ProcessDiceHeaderDelegateImplTest, CloseTabWhileStartingSync) {
// Setup the test. // Setup the test.
signin::ScopedAccountConsistencyDice account_consistency;
GURL kSigninURL = GURL("https://accounts.google.com"); GURL kSigninURL = GURL("https://accounts.google.com");
NavigateAndCommit(kSigninURL); NavigateAndCommit(kSigninURL);
ASSERT_EQ(kSigninURL, web_contents()->GetVisibleURL()); ASSERT_EQ(kSigninURL, web_contents()->GetVisibleURL());
std::unique_ptr<ProcessDiceHeaderDelegateImpl> delegate = std::unique_ptr<ProcessDiceHeaderDelegateImpl> delegate =
CreateDelegate(true); CreateDelegate(true, signin::AccountConsistencyMethod::kDice);
// Close the tab. // Close the tab.
DeleteContents(); DeleteContents();
...@@ -125,12 +125,11 @@ TEST_F(ProcessDiceHeaderDelegateImplTest, CloseTabWhileStartingSync) { ...@@ -125,12 +125,11 @@ TEST_F(ProcessDiceHeaderDelegateImplTest, CloseTabWhileStartingSync) {
// received. // received.
TEST_F(ProcessDiceHeaderDelegateImplTest, CloseTabWhileFailingSignin) { TEST_F(ProcessDiceHeaderDelegateImplTest, CloseTabWhileFailingSignin) {
// Setup the test. // Setup the test.
signin::ScopedAccountConsistencyDice account_consistency;
GURL kSigninURL = GURL("https://accounts.google.com"); GURL kSigninURL = GURL("https://accounts.google.com");
NavigateAndCommit(kSigninURL); NavigateAndCommit(kSigninURL);
ASSERT_EQ(kSigninURL, web_contents()->GetVisibleURL()); ASSERT_EQ(kSigninURL, web_contents()->GetVisibleURL());
std::unique_ptr<ProcessDiceHeaderDelegateImpl> delegate = std::unique_ptr<ProcessDiceHeaderDelegateImpl> delegate =
CreateDelegate(true); CreateDelegate(true, signin::AccountConsistencyMethod::kDice);
// Close the tab. // Close the tab.
DeleteContents(); DeleteContents();
...@@ -178,15 +177,13 @@ class ProcessDiceHeaderDelegateImplTestEnableSync ...@@ -178,15 +177,13 @@ class ProcessDiceHeaderDelegateImplTestEnableSync
// Test the EnableSync() method in all configurations. // Test the EnableSync() method in all configurations.
TEST_P(ProcessDiceHeaderDelegateImplTestEnableSync, EnableSync) { TEST_P(ProcessDiceHeaderDelegateImplTestEnableSync, EnableSync) {
// Setup the test. // Setup the test.
signin::ScopedAccountConsistency account_consistency(
GetParam().account_consistency);
GURL kSigninURL = GURL("https://accounts.google.com"); GURL kSigninURL = GURL("https://accounts.google.com");
NavigateAndCommit(kSigninURL); NavigateAndCommit(kSigninURL);
ASSERT_EQ(kSigninURL, web_contents()->GetVisibleURL()); ASSERT_EQ(kSigninURL, web_contents()->GetVisibleURL());
if (GetParam().signed_in) if (GetParam().signed_in)
signin_manager_.SignIn("gaia_id", "user", "pass"); signin_manager_.SignIn("gaia_id", "user", "pass");
std::unique_ptr<ProcessDiceHeaderDelegateImpl> delegate = std::unique_ptr<ProcessDiceHeaderDelegateImpl> delegate =
CreateDelegate(GetParam().signin_tab); CreateDelegate(GetParam().signin_tab, GetParam().account_consistency);
// Check expectations. // Check expectations.
delegate->EnableSync(account_id_); delegate->EnableSync(account_id_);
...@@ -228,15 +225,13 @@ class ProcessDiceHeaderDelegateImplTestHandleTokenExchangeFailure ...@@ -228,15 +225,13 @@ class ProcessDiceHeaderDelegateImplTestHandleTokenExchangeFailure
TEST_P(ProcessDiceHeaderDelegateImplTestHandleTokenExchangeFailure, TEST_P(ProcessDiceHeaderDelegateImplTestHandleTokenExchangeFailure,
HandleTokenExchangeFailure) { HandleTokenExchangeFailure) {
// Setup the test. // Setup the test.
signin::ScopedAccountConsistency account_consistency(
GetParam().account_consistency);
GURL kSigninURL = GURL("https://accounts.google.com"); GURL kSigninURL = GURL("https://accounts.google.com");
NavigateAndCommit(kSigninURL); NavigateAndCommit(kSigninURL);
ASSERT_EQ(kSigninURL, web_contents()->GetVisibleURL()); ASSERT_EQ(kSigninURL, web_contents()->GetVisibleURL());
if (GetParam().signed_in) if (GetParam().signed_in)
signin_manager_.SignIn("gaia_id", "user", "pass"); signin_manager_.SignIn("gaia_id", "user", "pass");
std::unique_ptr<ProcessDiceHeaderDelegateImpl> delegate = std::unique_ptr<ProcessDiceHeaderDelegateImpl> delegate =
CreateDelegate(GetParam().signin_tab); CreateDelegate(GetParam().signin_tab, GetParam().account_consistency);
// Check expectations. // Check expectations.
delegate->HandleTokenExchangeFailure(email_, auth_error_); delegate->HandleTokenExchangeFailure(email_, auth_error_);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/search_engines/ui_thread_search_terms_data.h" #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
#include "chrome/browser/signin/account_consistency_mode_manager.h"
#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/signin_error_controller_factory.h" #include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/signin_manager_factory.h"
...@@ -275,7 +276,9 @@ GURL GetReauthURLWithEmailForDialog(signin_metrics::AccessPoint access_point, ...@@ -275,7 +276,9 @@ GURL GetReauthURLWithEmailForDialog(signin_metrics::AccessPoint access_point,
} }
GURL GetSigninURLForDice(Profile* profile, const std::string& email) { GURL GetSigninURLForDice(Profile* profile, const std::string& email) {
DCHECK(signin::IsDicePrepareMigrationEnabled()); DCHECK(signin::DiceMethodGreaterOrEqual(
AccountConsistencyModeManager::GetMethodForProfile(profile),
signin::AccountConsistencyMethod::kDicePrepareMigration));
GURL url = GaiaUrls::GetInstance()->signin_chrome_sync_dice(); GURL url = GaiaUrls::GetInstance()->signin_chrome_sync_dice();
if (!email.empty()) if (!email.empty())
url = net::AppendQueryParameter(url, "email_hint", email); url = net::AppendQueryParameter(url, "email_hint", email);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <utility> #include <utility>
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_consistency_mode_manager.h"
#include "chrome/browser/signin/dice_tab_helper.h" #include "chrome/browser/signin/dice_tab_helper.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/signin_promo.h" #include "chrome/browser/signin/signin_promo.h"
...@@ -66,12 +67,14 @@ void SigninViewController::ShowSignin( ...@@ -66,12 +67,14 @@ void SigninViewController::ShowSignin(
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
ShowModalSigninDialog(mode, browser, access_point); ShowModalSigninDialog(mode, browser, access_point);
#else // defined(OS_CHROMEOS) #else // defined(OS_CHROMEOS)
if (signin::IsDicePrepareMigrationEnabled()) { Profile* profile = browser->profile();
if (signin::DiceMethodGreaterOrEqual(
AccountConsistencyModeManager::GetMethodForProfile(profile),
signin::AccountConsistencyMethod::kDicePrepareMigration)) {
std::string email; std::string email;
if (GetSigninReasonFromMode(mode) == if (GetSigninReasonFromMode(mode) ==
signin_metrics::Reason::REASON_REAUTHENTICATION) { signin_metrics::Reason::REASON_REAUTHENTICATION) {
SigninManagerBase* manager = SigninManagerBase* manager = SigninManagerFactory::GetForProfile(profile);
SigninManagerFactory::GetForProfile(browser->profile());
email = manager->GetAuthenticatedAccountInfo().email; email = manager->GetAuthenticatedAccountInfo().email;
} }
ShowDiceSigninTab(mode, browser, access_point, ShowDiceSigninTab(mode, browser, access_point,
......
...@@ -99,10 +99,10 @@ ...@@ -99,10 +99,10 @@
#include "chromeos/chromeos_switches.h" #include "chromeos/chromeos_switches.h"
#include "components/arc/arc_util.h" #include "components/arc/arc_util.h"
#else // !defined(OS_CHROMEOS) #else // !defined(OS_CHROMEOS)
#include "chrome/browser/signin/account_consistency_mode_manager.h"
#include "chrome/browser/ui/webui/settings/settings_default_browser_handler.h" #include "chrome/browser/ui/webui/settings/settings_default_browser_handler.h"
#include "chrome/browser/ui/webui/settings/settings_manage_profile_handler.h" #include "chrome/browser/ui/webui/settings/settings_manage_profile_handler.h"
#include "chrome/browser/ui/webui/settings/system_handler.h" #include "chrome/browser/ui/webui/settings/system_handler.h"
#include "components/signin/core/browser/profile_management_switches.h"
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#if defined(USE_NSS_CERTS) #if defined(USE_NSS_CERTS)
...@@ -315,8 +315,9 @@ MdSettingsUI::MdSettingsUI(content::WebUI* web_ui) ...@@ -315,8 +315,9 @@ MdSettingsUI::MdSettingsUI(content::WebUI* web_ui)
profile->GetPrefs())); profile->GetPrefs()));
} }
#else // !defined(OS_CHROMEOS) #else // !defined(OS_CHROMEOS)
html_source->AddBoolean("diceEnabled", html_source->AddBoolean(
signin::IsDiceEnabledForProfile(profile->GetPrefs())); "diceEnabled",
AccountConsistencyModeManager::IsDiceEnabledForProfile(profile));
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
html_source->AddBoolean("unifiedConsentEnabled", html_source->AddBoolean("unifiedConsentEnabled",
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_consistency_mode_manager.h"
#include "chrome/browser/ui/webui/welcome_handler.h" #include "chrome/browser/ui/webui/welcome_handler.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/grit/browser_resources.h" #include "chrome/grit/browser_resources.h"
...@@ -14,7 +15,6 @@ ...@@ -14,7 +15,6 @@
#include "chrome/grit/chromium_strings.h" #include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/signin/core/browser/profile_management_switches.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
#include "net/base/url_util.h" #include "net/base/url_util.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -47,7 +47,8 @@ WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url) ...@@ -47,7 +47,8 @@ WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
content::WebUIDataSource* html_source = content::WebUIDataSource* html_source =
content::WebUIDataSource::Create(url.host()); content::WebUIDataSource::Create(url.host());
bool is_dice = signin::IsDiceEnabledForProfile(profile->GetPrefs()); bool is_dice =
AccountConsistencyModeManager::IsDiceEnabledForProfile(profile);
// There are multiple possible configurations that affects the layout, but // There are multiple possible configurations that affects the layout, but
// first add resources that are shared across all layouts. // first add resources that are shared across all layouts.
......
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