[s13n] Add identity::DiagnosticsProvider class
This class will be used to obtain diagnostics about IdentityManager internals. In this CL we're adding a pure interface and an implementation backed by unit tests. It has the following methods and correspondencies: * OAuth2TokenServiceDelegate::LoadCredentialsState GetDetailedStateOfLoadingOfRefreshTokens() corresponds to OAuth2TokenServiceDelegate::load_credentials_state() * GetDelayBeforeMakingAccessTokenRequests() corresponds to ProfileOAuth2TokenService::GetDelegateBackoffEntry()::GetTimeUntilRelease() * GetDelayBeforeMakingCookieRequests() corresponds to GaiaCookieManagerService::GetBackoffEntry()::GetTimeUntilRelease() In order to make the unit test work, BackoffEntry support had to be added to FakeOAuth2TokenServiceDelegate as the current code does not need to modify it (it does not perform retries). A new API to simulate cookie merge session failures had to be added as well to IdentityTestEnvironment. Bug: 926833 Change-Id: I2f1fedccd0c69e6a8de2bd307e6c32b83f76fd84 Reviewed-on: https://chromium-review.googlesource.com/c/1461121 Commit-Queue: Sergio Villar <svillar@igalia.com> Reviewed-by: Mihai Sardarescu <msarda@chromium.org> Reviewed-by: Sylvain Defresne <sdefresne@chromium.org> Cr-Commit-Position: refs/heads/master@{#634311}
This commit is contained in:

committed by
Commit Bot

parent
8784d7259e
commit
fd6d643cde
chrome/browser/signin
google_apis/gaia
ios
chrome
browser
web_view
internal
services/identity/public/cpp
@ -17,6 +17,7 @@
|
|||||||
#include "services/identity/public/cpp/accounts_cookie_mutator.h"
|
#include "services/identity/public/cpp/accounts_cookie_mutator.h"
|
||||||
#include "services/identity/public/cpp/accounts_cookie_mutator_impl.h"
|
#include "services/identity/public/cpp/accounts_cookie_mutator_impl.h"
|
||||||
#include "services/identity/public/cpp/accounts_mutator.h"
|
#include "services/identity/public/cpp/accounts_mutator.h"
|
||||||
|
#include "services/identity/public/cpp/diagnostics_provider_impl.h"
|
||||||
#include "services/identity/public/cpp/identity_manager.h"
|
#include "services/identity/public/cpp/identity_manager.h"
|
||||||
#include "services/identity/public/cpp/primary_account_mutator.h"
|
#include "services/identity/public/cpp/primary_account_mutator.h"
|
||||||
|
|
||||||
@ -80,6 +81,9 @@ class IdentityManagerWrapper : public KeyedService,
|
|||||||
BuildPrimaryAccountMutator(profile),
|
BuildPrimaryAccountMutator(profile),
|
||||||
BuildAccountsMutator(profile),
|
BuildAccountsMutator(profile),
|
||||||
std::make_unique<identity::AccountsCookieMutatorImpl>(
|
std::make_unique<identity::AccountsCookieMutatorImpl>(
|
||||||
|
GaiaCookieManagerServiceFactory::GetForProfile(profile)),
|
||||||
|
std::make_unique<identity::DiagnosticsProviderImpl>(
|
||||||
|
ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
|
||||||
GaiaCookieManagerServiceFactory::GetForProfile(profile))) {}
|
GaiaCookieManagerServiceFactory::GetForProfile(profile))) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,6 +5,25 @@
|
|||||||
#include "google_apis/gaia/fake_oauth2_token_service_delegate.h"
|
#include "google_apis/gaia/fake_oauth2_token_service_delegate.h"
|
||||||
#include "google_apis/gaia/oauth2_access_token_fetcher_impl.h"
|
#include "google_apis/gaia/oauth2_access_token_fetcher_impl.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// Values used from |MutableProfileOAuth2TokenServiceDelegate|.
|
||||||
|
const net::BackoffEntry::Policy kBackoffPolicy = {
|
||||||
|
0 /* int num_errors_to_ignore */,
|
||||||
|
|
||||||
|
1000 /* int initial_delay_ms */,
|
||||||
|
|
||||||
|
2.0 /* double multiply_factor */,
|
||||||
|
|
||||||
|
0.2 /* double jitter_factor */,
|
||||||
|
|
||||||
|
15 * 60 * 1000 /* int64_t maximum_backoff_ms */,
|
||||||
|
|
||||||
|
-1 /* int64_t entry_lifetime_ms */,
|
||||||
|
|
||||||
|
false /* bool always_use_initial_delay */,
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
FakeOAuth2TokenServiceDelegate::AccountInfo::AccountInfo(
|
FakeOAuth2TokenServiceDelegate::AccountInfo::AccountInfo(
|
||||||
const std::string& refresh_token)
|
const std::string& refresh_token)
|
||||||
: refresh_token(refresh_token),
|
: refresh_token(refresh_token),
|
||||||
@ -13,7 +32,8 @@ FakeOAuth2TokenServiceDelegate::AccountInfo::AccountInfo(
|
|||||||
FakeOAuth2TokenServiceDelegate::FakeOAuth2TokenServiceDelegate()
|
FakeOAuth2TokenServiceDelegate::FakeOAuth2TokenServiceDelegate()
|
||||||
: shared_factory_(
|
: shared_factory_(
|
||||||
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
|
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
|
||||||
&test_url_loader_factory_)) {}
|
&test_url_loader_factory_)),
|
||||||
|
backoff_entry_(&kBackoffPolicy) {}
|
||||||
|
|
||||||
FakeOAuth2TokenServiceDelegate::~FakeOAuth2TokenServiceDelegate() {
|
FakeOAuth2TokenServiceDelegate::~FakeOAuth2TokenServiceDelegate() {
|
||||||
}
|
}
|
||||||
@ -49,6 +69,10 @@ std::string FakeOAuth2TokenServiceDelegate::GetRefreshToken(
|
|||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const net::BackoffEntry* FakeOAuth2TokenServiceDelegate::BackoffEntry() const {
|
||||||
|
return &backoff_entry_;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> FakeOAuth2TokenServiceDelegate::GetAccounts() {
|
std::vector<std::string> FakeOAuth2TokenServiceDelegate::GetAccounts() {
|
||||||
std::vector<std::string> account_ids;
|
std::vector<std::string> account_ids;
|
||||||
for (const auto& token : refresh_tokens_)
|
for (const auto& token : refresh_tokens_)
|
||||||
@ -124,6 +148,7 @@ bool FakeOAuth2TokenServiceDelegate::FixRequestErrorIfPossible() {
|
|||||||
void FakeOAuth2TokenServiceDelegate::UpdateAuthError(
|
void FakeOAuth2TokenServiceDelegate::UpdateAuthError(
|
||||||
const std::string& account_id,
|
const std::string& account_id,
|
||||||
const GoogleServiceAuthError& error) {
|
const GoogleServiceAuthError& error) {
|
||||||
|
backoff_entry_.InformOfRequest(!error.IsTransientError());
|
||||||
// Drop transient errors to match OAuth2TokenService's stated contract for
|
// Drop transient errors to match OAuth2TokenService's stated contract for
|
||||||
// GetAuthError() and to allow clients to test proper behavior in the case of
|
// GetAuthError() and to allow clients to test proper behavior in the case of
|
||||||
// transient errors.
|
// transient errors.
|
||||||
|
@ -59,6 +59,8 @@ class FakeOAuth2TokenServiceDelegate : public OAuth2TokenServiceDelegate {
|
|||||||
fix_request_if_possible_ = value;
|
fix_request_if_possible_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const net::BackoffEntry* BackoffEntry() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct AccountInfo {
|
struct AccountInfo {
|
||||||
AccountInfo(const std::string& refresh_token);
|
AccountInfo(const std::string& refresh_token);
|
||||||
@ -77,6 +79,8 @@ class FakeOAuth2TokenServiceDelegate : public OAuth2TokenServiceDelegate {
|
|||||||
scoped_refptr<network::SharedURLLoaderFactory> shared_factory_;
|
scoped_refptr<network::SharedURLLoaderFactory> shared_factory_;
|
||||||
bool fix_request_if_possible_ = false;
|
bool fix_request_if_possible_ = false;
|
||||||
|
|
||||||
|
net::BackoffEntry backoff_entry_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(FakeOAuth2TokenServiceDelegate);
|
DISALLOW_COPY_AND_ASSIGN(FakeOAuth2TokenServiceDelegate);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "ios/chrome/browser/signin/signin_manager_factory.h"
|
#include "ios/chrome/browser/signin/signin_manager_factory.h"
|
||||||
#include "services/identity/public/cpp/accounts_cookie_mutator_impl.h"
|
#include "services/identity/public/cpp/accounts_cookie_mutator_impl.h"
|
||||||
#include "services/identity/public/cpp/accounts_mutator.h"
|
#include "services/identity/public/cpp/accounts_mutator.h"
|
||||||
|
#include "services/identity/public/cpp/diagnostics_provider_impl.h"
|
||||||
#include "services/identity/public/cpp/identity_manager.h"
|
#include "services/identity/public/cpp/identity_manager.h"
|
||||||
#include "services/identity/public/cpp/primary_account_mutator_impl.h"
|
#include "services/identity/public/cpp/primary_account_mutator_impl.h"
|
||||||
|
|
||||||
@ -47,6 +48,11 @@ class IdentityManagerWrapper : public KeyedService,
|
|||||||
ios::SigninManagerFactory::GetForBrowserState(browser_state)),
|
ios::SigninManagerFactory::GetForBrowserState(browser_state)),
|
||||||
nullptr,
|
nullptr,
|
||||||
std::make_unique<identity::AccountsCookieMutatorImpl>(
|
std::make_unique<identity::AccountsCookieMutatorImpl>(
|
||||||
|
ios::GaiaCookieManagerServiceFactory::GetForBrowserState(
|
||||||
|
browser_state)),
|
||||||
|
std::make_unique<identity::DiagnosticsProviderImpl>(
|
||||||
|
ProfileOAuth2TokenServiceFactory::GetForBrowserState(
|
||||||
|
browser_state),
|
||||||
ios::GaiaCookieManagerServiceFactory::GetForBrowserState(
|
ios::GaiaCookieManagerServiceFactory::GetForBrowserState(
|
||||||
browser_state))) {}
|
browser_state))) {}
|
||||||
};
|
};
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "ios/web_view/internal/web_view_browser_state.h"
|
#include "ios/web_view/internal/web_view_browser_state.h"
|
||||||
#include "services/identity/public/cpp/accounts_cookie_mutator_impl.h"
|
#include "services/identity/public/cpp/accounts_cookie_mutator_impl.h"
|
||||||
#include "services/identity/public/cpp/accounts_mutator.h"
|
#include "services/identity/public/cpp/accounts_mutator.h"
|
||||||
|
#include "services/identity/public/cpp/diagnostics_provider_impl.h"
|
||||||
#include "services/identity/public/cpp/identity_manager.h"
|
#include "services/identity/public/cpp/identity_manager.h"
|
||||||
#include "services/identity/public/cpp/primary_account_mutator_impl.h"
|
#include "services/identity/public/cpp/primary_account_mutator_impl.h"
|
||||||
|
|
||||||
@ -51,6 +52,11 @@ class IdentityManagerWrapper : public KeyedService,
|
|||||||
WebViewSigninManagerFactory::GetForBrowserState(browser_state)),
|
WebViewSigninManagerFactory::GetForBrowserState(browser_state)),
|
||||||
nullptr,
|
nullptr,
|
||||||
std::make_unique<identity::AccountsCookieMutatorImpl>(
|
std::make_unique<identity::AccountsCookieMutatorImpl>(
|
||||||
|
WebViewGaiaCookieManagerServiceFactory::GetForBrowserState(
|
||||||
|
browser_state)),
|
||||||
|
std::make_unique<identity::DiagnosticsProviderImpl>(
|
||||||
|
WebViewOAuth2TokenServiceFactory::GetForBrowserState(
|
||||||
|
browser_state),
|
||||||
WebViewGaiaCookieManagerServiceFactory::GetForBrowserState(
|
WebViewGaiaCookieManagerServiceFactory::GetForBrowserState(
|
||||||
browser_state))) {}
|
browser_state))) {}
|
||||||
};
|
};
|
||||||
|
@ -14,6 +14,9 @@ source_set("cpp") {
|
|||||||
"accounts_in_cookie_jar_info.cc",
|
"accounts_in_cookie_jar_info.cc",
|
||||||
"accounts_in_cookie_jar_info.h",
|
"accounts_in_cookie_jar_info.h",
|
||||||
"accounts_mutator.h",
|
"accounts_mutator.h",
|
||||||
|
"diagnostics_provider.h",
|
||||||
|
"diagnostics_provider_impl.cc",
|
||||||
|
"diagnostics_provider_impl.h",
|
||||||
"identity_manager.cc",
|
"identity_manager.cc",
|
||||||
"identity_manager.h",
|
"identity_manager.h",
|
||||||
"primary_account_access_token_fetcher.cc",
|
"primary_account_access_token_fetcher.cc",
|
||||||
@ -77,13 +80,14 @@ source_set("test_support") {
|
|||||||
|
|
||||||
public_deps = [
|
public_deps = [
|
||||||
":cpp",
|
":cpp",
|
||||||
|
"//components/signin/core/browser:internals_test_support",
|
||||||
|
"//components/sync_preferences:test_support",
|
||||||
|
"//google_apis:test_support",
|
||||||
]
|
]
|
||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
"//components/image_fetcher/core:test_support",
|
"//components/image_fetcher/core:test_support",
|
||||||
"//components/signin/core/browser",
|
"//components/signin/core/browser",
|
||||||
"//components/signin/core/browser:internals_test_support",
|
|
||||||
"//components/sync_preferences:test_support",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,6 +96,7 @@ source_set("tests") {
|
|||||||
sources = [
|
sources = [
|
||||||
"accounts_cookie_mutator_unittest.cc",
|
"accounts_cookie_mutator_unittest.cc",
|
||||||
"accounts_mutator_unittest.cc",
|
"accounts_mutator_unittest.cc",
|
||||||
|
"diagnostics_provider_unittest.cc",
|
||||||
"primary_account_mutator_unittest.cc",
|
"primary_account_mutator_unittest.cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -103,6 +108,7 @@ source_set("tests") {
|
|||||||
"//components/signin/core/browser:internals_test_support",
|
"//components/signin/core/browser:internals_test_support",
|
||||||
"//components/sync_preferences:test_support",
|
"//components/sync_preferences:test_support",
|
||||||
"//services/network:test_support",
|
"//services/network:test_support",
|
||||||
|
"//testing/gmock",
|
||||||
"//testing/gtest",
|
"//testing/gtest",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ include_rules = [
|
|||||||
"+google_apis/gaia/google_service_auth_error.h",
|
"+google_apis/gaia/google_service_auth_error.h",
|
||||||
"+google_apis/gaia/oauth2_access_token_consumer.h",
|
"+google_apis/gaia/oauth2_access_token_consumer.h",
|
||||||
"+google_apis/gaia/oauth2_token_service.h",
|
"+google_apis/gaia/oauth2_token_service.h",
|
||||||
|
"+google_apis/gaia/oauth2_token_service_delegate.h",
|
||||||
"+services/network/public/cpp",
|
"+services/network/public/cpp",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -40,4 +41,7 @@ specific_include_rules = {
|
|||||||
"+services/network/test/test_cookie_manager.h",
|
"+services/network/test/test_cookie_manager.h",
|
||||||
"+services/network/test/test_url_loader_factory.h",
|
"+services/network/test/test_url_loader_factory.h",
|
||||||
],
|
],
|
||||||
|
"diagnostics_provider_unittest.cc": [
|
||||||
|
"+google_apis/gaia/fake_oauth2_token_service_delegate.h",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
40
services/identity/public/cpp/diagnostics_provider.h
Normal file
40
services/identity/public/cpp/diagnostics_provider.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// Copyright 2019 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 SERVICES_IDENTITY_PUBLIC_CPP_DIAGNOSTICS_PROVIDER_H_
|
||||||
|
#define SERVICES_IDENTITY_PUBLIC_CPP_DIAGNOSTICS_PROVIDER_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "base/macros.h"
|
||||||
|
#include "google_apis/gaia/oauth2_token_service_delegate.h"
|
||||||
|
|
||||||
|
namespace identity {
|
||||||
|
|
||||||
|
// DiagnosticsProvider is the interface to obtain diagnostics about
|
||||||
|
// IdentityManager internals.
|
||||||
|
class DiagnosticsProvider {
|
||||||
|
public:
|
||||||
|
DiagnosticsProvider() = default;
|
||||||
|
virtual ~DiagnosticsProvider() = default;
|
||||||
|
|
||||||
|
// Returns the state of the load credentials operation.
|
||||||
|
virtual OAuth2TokenServiceDelegate::LoadCredentialsState
|
||||||
|
GetDetailedStateOfLoadingOfRefreshTokens() const = 0;
|
||||||
|
|
||||||
|
// Returns the time until a access token request can be sent (will be zero if
|
||||||
|
// the release time is in the past).
|
||||||
|
virtual base::TimeDelta GetDelayBeforeMakingAccessTokenRequests() const = 0;
|
||||||
|
|
||||||
|
// Returns the time until a cookie request can be sent (will be zero if the
|
||||||
|
// release time is in the past).
|
||||||
|
virtual base::TimeDelta GetDelayBeforeMakingCookieRequests() const = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(DiagnosticsProvider);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace identity
|
||||||
|
|
||||||
|
#endif // SERVICES_IDENTITY_PUBLIC_CPP_DIAGNOSTICS_PROVIDER_H_
|
44
services/identity/public/cpp/diagnostics_provider_impl.cc
Normal file
44
services/identity/public/cpp/diagnostics_provider_impl.cc
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// Copyright 2019 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 "services/identity/public/cpp/diagnostics_provider_impl.h"
|
||||||
|
|
||||||
|
#include "components/signin/core/browser/gaia_cookie_manager_service.h"
|
||||||
|
#include "components/signin/core/browser/profile_oauth2_token_service.h"
|
||||||
|
#include "google_apis/gaia/oauth2_token_service_delegate.h"
|
||||||
|
|
||||||
|
namespace identity {
|
||||||
|
|
||||||
|
DiagnosticsProviderImpl::DiagnosticsProviderImpl(
|
||||||
|
ProfileOAuth2TokenService* profile_oauth2_token_service,
|
||||||
|
GaiaCookieManagerService* gaia_cookie_manager_service)
|
||||||
|
: gaia_cookie_manager_service_(gaia_cookie_manager_service),
|
||||||
|
profile_oauth2_token_service_(profile_oauth2_token_service) {
|
||||||
|
DCHECK(gaia_cookie_manager_service_);
|
||||||
|
DCHECK(profile_oauth2_token_service_);
|
||||||
|
}
|
||||||
|
|
||||||
|
DiagnosticsProviderImpl::~DiagnosticsProviderImpl() {}
|
||||||
|
|
||||||
|
OAuth2TokenServiceDelegate::LoadCredentialsState
|
||||||
|
DiagnosticsProviderImpl::GetDetailedStateOfLoadingOfRefreshTokens() const {
|
||||||
|
DCHECK(profile_oauth2_token_service_->GetDelegate());
|
||||||
|
return profile_oauth2_token_service_->GetDelegate()->load_credentials_state();
|
||||||
|
}
|
||||||
|
|
||||||
|
base::TimeDelta
|
||||||
|
DiagnosticsProviderImpl::GetDelayBeforeMakingAccessTokenRequests() const {
|
||||||
|
const net::BackoffEntry* backoff_entry =
|
||||||
|
profile_oauth2_token_service_->GetDelegateBackoffEntry();
|
||||||
|
return backoff_entry ? backoff_entry->GetTimeUntilRelease()
|
||||||
|
: base::TimeDelta();
|
||||||
|
}
|
||||||
|
|
||||||
|
base::TimeDelta DiagnosticsProviderImpl::GetDelayBeforeMakingCookieRequests()
|
||||||
|
const {
|
||||||
|
DCHECK(gaia_cookie_manager_service_->GetBackoffEntry());
|
||||||
|
return gaia_cookie_manager_service_->GetBackoffEntry()->GetTimeUntilRelease();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace identity
|
45
services/identity/public/cpp/diagnostics_provider_impl.h
Normal file
45
services/identity/public/cpp/diagnostics_provider_impl.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// Copyright 2019 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 SERVICES_IDENTITY_PUBLIC_CPP_DIAGNOSTICS_PROVIDER_IMPL_H_
|
||||||
|
#define SERVICES_IDENTITY_PUBLIC_CPP_DIAGNOSTICS_PROVIDER_IMPL_H_
|
||||||
|
|
||||||
|
#include "base/macros.h"
|
||||||
|
#include "services/identity/public/cpp/diagnostics_provider.h"
|
||||||
|
|
||||||
|
class GaiaCookieManagerService;
|
||||||
|
class ProfileOAuth2TokenService;
|
||||||
|
|
||||||
|
namespace identity {
|
||||||
|
|
||||||
|
// Concrete implementation of the DiagnosticsProvider interface.
|
||||||
|
class DiagnosticsProviderImpl final : public DiagnosticsProvider {
|
||||||
|
public:
|
||||||
|
DiagnosticsProviderImpl(
|
||||||
|
ProfileOAuth2TokenService* profile_oauth2_token_service,
|
||||||
|
GaiaCookieManagerService* gaia_cookie_manager_service);
|
||||||
|
~DiagnosticsProviderImpl() override;
|
||||||
|
|
||||||
|
// Returns the state of the load credentials operation.
|
||||||
|
OAuth2TokenServiceDelegate::LoadCredentialsState
|
||||||
|
GetDetailedStateOfLoadingOfRefreshTokens() const override;
|
||||||
|
|
||||||
|
// Returns the time until a access token request can be sent (will be zero if
|
||||||
|
// the release time is in the past).
|
||||||
|
base::TimeDelta GetDelayBeforeMakingAccessTokenRequests() const override;
|
||||||
|
|
||||||
|
// Returns the time until a cookie request can be sent (will be zero if the
|
||||||
|
// release time is in the past).
|
||||||
|
base::TimeDelta GetDelayBeforeMakingCookieRequests() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
GaiaCookieManagerService* gaia_cookie_manager_service_;
|
||||||
|
ProfileOAuth2TokenService* profile_oauth2_token_service_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(DiagnosticsProviderImpl);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace identity
|
||||||
|
|
||||||
|
#endif // SERVICES_IDENTITY_PUBLIC_CPP_DIAGNOSTICS_PROVIDER_IMPL_H_
|
@ -0,0 +1,77 @@
|
|||||||
|
// Copyright 2019 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 "services/identity/public/cpp/diagnostics_provider_impl.h"
|
||||||
|
|
||||||
|
#include "base/macros.h"
|
||||||
|
#include "base/test/scoped_task_environment.h"
|
||||||
|
#include "services/identity/public/cpp/identity_test_environment.h"
|
||||||
|
#include "testing/gtest/include/gtest/gtest.h"
|
||||||
|
|
||||||
|
const char kAccountId[] = "user@gmail.com";
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class DiagnosticsProviderTest : public testing::Test {
|
||||||
|
public:
|
||||||
|
DiagnosticsProviderTest() = default;
|
||||||
|
|
||||||
|
identity::IdentityTestEnvironment* identity_test_env() {
|
||||||
|
return &identity_test_env_;
|
||||||
|
}
|
||||||
|
|
||||||
|
identity::DiagnosticsProvider* diagnostics_provider() {
|
||||||
|
return identity_test_env_.identity_manager()->GetDiagnosticsProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
base::test::ScopedTaskEnvironment scoped_task_environment_;
|
||||||
|
|
||||||
|
private:
|
||||||
|
identity::IdentityTestEnvironment identity_test_env_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(DiagnosticsProviderTest);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TEST_F(DiagnosticsProviderTest, Basic) {
|
||||||
|
// Accessing the DiagnosticProvider should not crash.
|
||||||
|
ASSERT_TRUE(identity_test_env()->identity_manager());
|
||||||
|
EXPECT_TRUE(
|
||||||
|
identity_test_env()->identity_manager()->GetDiagnosticsProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DiagnosticsProviderTest, GetDetailedStateOfLoadingOfRefreshTokens) {
|
||||||
|
EXPECT_EQ(OAuth2TokenServiceDelegate::LoadCredentialsState::
|
||||||
|
LOAD_CREDENTIALS_FINISHED_WITH_SUCCESS,
|
||||||
|
diagnostics_provider()->GetDetailedStateOfLoadingOfRefreshTokens());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DiagnosticsProviderTest, GetDelayBeforeMakingAccessTokenRequests) {
|
||||||
|
base::TimeDelta zero;
|
||||||
|
EXPECT_EQ(diagnostics_provider()->GetDelayBeforeMakingAccessTokenRequests(),
|
||||||
|
zero);
|
||||||
|
std::string account_id =
|
||||||
|
identity_test_env()->MakeAccountAvailable(kAccountId).account_id;
|
||||||
|
identity_test_env()->UpdatePersistentErrorOfRefreshTokenForAccount(
|
||||||
|
account_id, GoogleServiceAuthError(
|
||||||
|
GoogleServiceAuthError::State::SERVICE_UNAVAILABLE));
|
||||||
|
EXPECT_GT(diagnostics_provider()->GetDelayBeforeMakingAccessTokenRequests(),
|
||||||
|
zero);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DiagnosticsProviderTest, GetDelayBeforeMakingCookieRequests) {
|
||||||
|
base::TimeDelta zero;
|
||||||
|
identity_test_env()
|
||||||
|
->identity_manager()
|
||||||
|
->GetAccountsCookieMutator()
|
||||||
|
->AddAccountToCookie(kAccountId, gaia::GaiaSource::kChrome,
|
||||||
|
base::DoNothing());
|
||||||
|
EXPECT_EQ(diagnostics_provider()->GetDelayBeforeMakingCookieRequests(), zero);
|
||||||
|
|
||||||
|
identity_test_env()->SimulateMergeSessionFailure(
|
||||||
|
GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED));
|
||||||
|
EXPECT_GT(diagnostics_provider()->GetDelayBeforeMakingCookieRequests(), zero);
|
||||||
|
}
|
@ -12,6 +12,7 @@
|
|||||||
#include "google_apis/gaia/gaia_auth_util.h"
|
#include "google_apis/gaia/gaia_auth_util.h"
|
||||||
#include "services/identity/public/cpp/accounts_cookie_mutator.h"
|
#include "services/identity/public/cpp/accounts_cookie_mutator.h"
|
||||||
#include "services/identity/public/cpp/accounts_mutator.h"
|
#include "services/identity/public/cpp/accounts_mutator.h"
|
||||||
|
#include "services/identity/public/cpp/diagnostics_provider.h"
|
||||||
#include "services/identity/public/cpp/primary_account_mutator.h"
|
#include "services/identity/public/cpp/primary_account_mutator.h"
|
||||||
#include "services/network/public/cpp/shared_url_loader_factory.h"
|
#include "services/network/public/cpp/shared_url_loader_factory.h"
|
||||||
|
|
||||||
@ -42,7 +43,8 @@ IdentityManager::IdentityManager(
|
|||||||
GaiaCookieManagerService* gaia_cookie_manager_service,
|
GaiaCookieManagerService* gaia_cookie_manager_service,
|
||||||
std::unique_ptr<PrimaryAccountMutator> primary_account_mutator,
|
std::unique_ptr<PrimaryAccountMutator> primary_account_mutator,
|
||||||
std::unique_ptr<AccountsMutator> accounts_mutator,
|
std::unique_ptr<AccountsMutator> accounts_mutator,
|
||||||
std::unique_ptr<AccountsCookieMutator> accounts_cookie_mutator)
|
std::unique_ptr<AccountsCookieMutator> accounts_cookie_mutator,
|
||||||
|
std::unique_ptr<DiagnosticsProvider> diagnostics_provider)
|
||||||
: signin_manager_(signin_manager),
|
: signin_manager_(signin_manager),
|
||||||
token_service_(token_service),
|
token_service_(token_service),
|
||||||
account_fetcher_service_(account_fetcher_service),
|
account_fetcher_service_(account_fetcher_service),
|
||||||
@ -50,9 +52,11 @@ IdentityManager::IdentityManager(
|
|||||||
gaia_cookie_manager_service_(gaia_cookie_manager_service),
|
gaia_cookie_manager_service_(gaia_cookie_manager_service),
|
||||||
primary_account_mutator_(std::move(primary_account_mutator)),
|
primary_account_mutator_(std::move(primary_account_mutator)),
|
||||||
accounts_mutator_(std::move(accounts_mutator)),
|
accounts_mutator_(std::move(accounts_mutator)),
|
||||||
accounts_cookie_mutator_(std::move(accounts_cookie_mutator)) {
|
accounts_cookie_mutator_(std::move(accounts_cookie_mutator)),
|
||||||
|
diagnostics_provider_(std::move(diagnostics_provider)) {
|
||||||
DCHECK(account_fetcher_service_);
|
DCHECK(account_fetcher_service_);
|
||||||
DCHECK(accounts_cookie_mutator_);
|
DCHECK(accounts_cookie_mutator_);
|
||||||
|
DCHECK(diagnostics_provider_);
|
||||||
signin_manager_->AddObserver(this);
|
signin_manager_->AddObserver(this);
|
||||||
token_service_->AddDiagnosticsObserver(this);
|
token_service_->AddDiagnosticsObserver(this);
|
||||||
token_service_->AddObserver(this);
|
token_service_->AddObserver(this);
|
||||||
@ -287,6 +291,10 @@ void IdentityManager::LegacyLoadCredentialsForSupervisedUser(
|
|||||||
token_service_->LoadCredentials(primary_account_id);
|
token_service_->LoadCredentials(primary_account_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DiagnosticsProvider* IdentityManager::GetDiagnosticsProvider() {
|
||||||
|
return diagnostics_provider_.get();
|
||||||
|
}
|
||||||
|
|
||||||
std::string IdentityManager::LegacySeedAccountInfo(const AccountInfo& info) {
|
std::string IdentityManager::LegacySeedAccountInfo(const AccountInfo& info) {
|
||||||
return account_tracker_service_->SeedAccountInfo(info);
|
return account_tracker_service_->SeedAccountInfo(info);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "components/signin/core/browser/signin_metrics.h"
|
#include "components/signin/core/browser/signin_metrics.h"
|
||||||
#include "components/signin/core/browser/ubertoken_fetcher.h"
|
#include "components/signin/core/browser/ubertoken_fetcher.h"
|
||||||
#include "services/identity/public/cpp/access_token_fetcher.h"
|
#include "services/identity/public/cpp/access_token_fetcher.h"
|
||||||
|
#include "services/identity/public/cpp/accounts_cookie_mutator.h"
|
||||||
#include "services/identity/public/cpp/accounts_in_cookie_jar_info.h"
|
#include "services/identity/public/cpp/accounts_in_cookie_jar_info.h"
|
||||||
#include "services/identity/public/cpp/scope_set.h"
|
#include "services/identity/public/cpp/scope_set.h"
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ namespace identity {
|
|||||||
|
|
||||||
class AccountsMutator;
|
class AccountsMutator;
|
||||||
class AccountsCookieMutator;
|
class AccountsCookieMutator;
|
||||||
|
class DiagnosticsProvider;
|
||||||
class PrimaryAccountMutator;
|
class PrimaryAccountMutator;
|
||||||
enum class ClearPrimaryAccountPolicy;
|
enum class ClearPrimaryAccountPolicy;
|
||||||
struct CookieParams;
|
struct CookieParams;
|
||||||
@ -202,7 +204,8 @@ class IdentityManager : public SigninManagerBase::Observer,
|
|||||||
GaiaCookieManagerService* gaia_cookie_manager_service,
|
GaiaCookieManagerService* gaia_cookie_manager_service,
|
||||||
std::unique_ptr<PrimaryAccountMutator> primary_account_mutator,
|
std::unique_ptr<PrimaryAccountMutator> primary_account_mutator,
|
||||||
std::unique_ptr<AccountsMutator> accounts_mutator,
|
std::unique_ptr<AccountsMutator> accounts_mutator,
|
||||||
std::unique_ptr<AccountsCookieMutator> accounts_cookie_mutator);
|
std::unique_ptr<AccountsCookieMutator> accounts_cookie_mutator,
|
||||||
|
std::unique_ptr<DiagnosticsProvider> diagnostics_provider);
|
||||||
~IdentityManager() override;
|
~IdentityManager() override;
|
||||||
|
|
||||||
// Provides access to the extended information of the user's primary account.
|
// Provides access to the extended information of the user's primary account.
|
||||||
@ -370,6 +373,10 @@ class IdentityManager : public SigninManagerBase::Observer,
|
|||||||
void LegacyLoadCredentialsForSupervisedUser(
|
void LegacyLoadCredentialsForSupervisedUser(
|
||||||
const std::string& primary_account_id);
|
const std::string& primary_account_id);
|
||||||
|
|
||||||
|
// Returns pointer to the object used to obtain diagnostics about the internal
|
||||||
|
// state of IdentityManager.
|
||||||
|
DiagnosticsProvider* GetDiagnosticsProvider();
|
||||||
|
|
||||||
// Picks the correct account_id for the specified account depending on the
|
// Picks the correct account_id for the specified account depending on the
|
||||||
// migration state.
|
// migration state.
|
||||||
// NOTE: This method is added temporarily until when the delegate is moved
|
// NOTE: This method is added temporarily until when the delegate is moved
|
||||||
@ -559,6 +566,9 @@ class IdentityManager : public SigninManagerBase::Observer,
|
|||||||
// functionality is supported on all platforms.
|
// functionality is supported on all platforms.
|
||||||
std::unique_ptr<AccountsCookieMutator> accounts_cookie_mutator_;
|
std::unique_ptr<AccountsCookieMutator> accounts_cookie_mutator_;
|
||||||
|
|
||||||
|
// DiagnosticsProvider instance.
|
||||||
|
std::unique_ptr<DiagnosticsProvider> diagnostics_provider_;
|
||||||
|
|
||||||
// Lists of observers.
|
// Lists of observers.
|
||||||
// Makes sure lists are empty on destruction.
|
// Makes sure lists are empty on destruction.
|
||||||
base::ObserverList<Observer, true>::Unchecked observer_list_;
|
base::ObserverList<Observer, true>::Unchecked observer_list_;
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "services/identity/public/cpp/accounts_cookie_mutator.h"
|
#include "services/identity/public/cpp/accounts_cookie_mutator.h"
|
||||||
#include "services/identity/public/cpp/accounts_cookie_mutator_impl.h"
|
#include "services/identity/public/cpp/accounts_cookie_mutator_impl.h"
|
||||||
#include "services/identity/public/cpp/accounts_mutator.h"
|
#include "services/identity/public/cpp/accounts_mutator.h"
|
||||||
|
#include "services/identity/public/cpp/diagnostics_provider_impl.h"
|
||||||
#include "services/identity/public/cpp/identity_manager.h"
|
#include "services/identity/public/cpp/identity_manager.h"
|
||||||
#include "services/identity/public/cpp/identity_test_utils.h"
|
#include "services/identity/public/cpp/identity_test_utils.h"
|
||||||
#include "services/identity/public/cpp/primary_account_mutator.h"
|
#include "services/identity/public/cpp/primary_account_mutator.h"
|
||||||
@ -399,7 +400,9 @@ class IdentityManagerTest : public testing::Test {
|
|||||||
signin_manager_.get(), &token_service_, &account_fetcher_,
|
signin_manager_.get(), &token_service_, &account_fetcher_,
|
||||||
&account_tracker_, &gaia_cookie_manager_service_, nullptr, nullptr,
|
&account_tracker_, &gaia_cookie_manager_service_, nullptr, nullptr,
|
||||||
std::make_unique<AccountsCookieMutatorImpl>(
|
std::make_unique<AccountsCookieMutatorImpl>(
|
||||||
&gaia_cookie_manager_service_)));
|
&gaia_cookie_manager_service_),
|
||||||
|
std::make_unique<DiagnosticsProviderImpl>(
|
||||||
|
&token_service_, &gaia_cookie_manager_service_)));
|
||||||
identity_manager_observer_.reset(
|
identity_manager_observer_.reset(
|
||||||
new TestIdentityManagerObserver(identity_manager_.get()));
|
new TestIdentityManagerObserver(identity_manager_.get()));
|
||||||
identity_manager_diagnostics_observer_.reset(
|
identity_manager_diagnostics_observer_.reset(
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "services/identity/public/cpp/accounts_cookie_mutator.h"
|
#include "services/identity/public/cpp/accounts_cookie_mutator.h"
|
||||||
#include "services/identity/public/cpp/accounts_cookie_mutator_impl.h"
|
#include "services/identity/public/cpp/accounts_cookie_mutator_impl.h"
|
||||||
#include "services/identity/public/cpp/accounts_mutator.h"
|
#include "services/identity/public/cpp/accounts_mutator.h"
|
||||||
|
#include "services/identity/public/cpp/diagnostics_provider_impl.h"
|
||||||
#include "services/identity/public/cpp/identity_test_utils.h"
|
#include "services/identity/public/cpp/identity_test_utils.h"
|
||||||
#include "services/identity/public/cpp/primary_account_mutator.h"
|
#include "services/identity/public/cpp/primary_account_mutator.h"
|
||||||
#include "services/identity/public/cpp/test_identity_manager_observer.h"
|
#include "services/identity/public/cpp/test_identity_manager_observer.h"
|
||||||
@ -299,6 +300,9 @@ IdentityTestEnvironment::IdentityTestEnvironment(
|
|||||||
token_service_, account_tracker_service_, signin_manager_,
|
token_service_, account_tracker_service_, signin_manager_,
|
||||||
pref_service_);
|
pref_service_);
|
||||||
#endif
|
#endif
|
||||||
|
std::unique_ptr<DiagnosticsProvider> diagnostics_provider =
|
||||||
|
std::make_unique<DiagnosticsProviderImpl>(token_service_,
|
||||||
|
gaia_cookie_manager_service_);
|
||||||
|
|
||||||
std::unique_ptr<AccountsCookieMutator> accounts_cookie_mutator =
|
std::unique_ptr<AccountsCookieMutator> accounts_cookie_mutator =
|
||||||
std::make_unique<AccountsCookieMutatorImpl>(
|
std::make_unique<AccountsCookieMutatorImpl>(
|
||||||
@ -308,7 +312,7 @@ IdentityTestEnvironment::IdentityTestEnvironment(
|
|||||||
signin_manager_, token_service_, account_fetcher_service_,
|
signin_manager_, token_service_, account_fetcher_service_,
|
||||||
account_tracker_service_, gaia_cookie_manager_service_,
|
account_tracker_service_, gaia_cookie_manager_service_,
|
||||||
std::move(primary_account_mutator), std::move(accounts_mutator),
|
std::move(primary_account_mutator), std::move(accounts_mutator),
|
||||||
std::move(accounts_cookie_mutator));
|
std::move(accounts_cookie_mutator), std::move(diagnostics_provider));
|
||||||
}
|
}
|
||||||
|
|
||||||
test_identity_manager_observer_ =
|
test_identity_manager_observer_ =
|
||||||
@ -584,4 +588,13 @@ void IdentityTestEnvironment::SimulateSuccessfulFetchOfAccountInfo(
|
|||||||
picture_url);
|
picture_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IdentityTestEnvironment::SimulateMergeSessionFailure(
|
||||||
|
const GoogleServiceAuthError& auth_error) {
|
||||||
|
// GaiaCookieManagerService changes the visibility of inherited method
|
||||||
|
// OnMergeSessionFailure from public to private. Cast to a base class pointer
|
||||||
|
// to use call the method.
|
||||||
|
static_cast<GaiaAuthConsumer*>(gaia_cookie_manager_service_)
|
||||||
|
->OnMergeSessionFailure(auth_error);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace identity
|
} // namespace identity
|
||||||
|
@ -285,6 +285,9 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver {
|
|||||||
const std::string& locale,
|
const std::string& locale,
|
||||||
const std::string& picture_url);
|
const std::string& picture_url);
|
||||||
|
|
||||||
|
// Simulates a merge session failure with |auth_error| as the error.
|
||||||
|
void SimulateMergeSessionFailure(const GoogleServiceAuthError& auth_error);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class ::IdentityTestEnvironmentChromeBrowserStateAdaptor;
|
friend class ::IdentityTestEnvironmentChromeBrowserStateAdaptor;
|
||||||
friend class ::IdentityTestEnvironmentProfileAdaptor;
|
friend class ::IdentityTestEnvironmentProfileAdaptor;
|
||||||
|
Reference in New Issue
Block a user