diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-01-20 13:40:20 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-01-22 12:41:23 +0000 |
commit | 7961cea6d1041e3e454dae6a1da660b453efd238 (patch) | |
tree | c0eeb4a9ff9ba32986289c1653d9608e53ccb444 /chromium/google_apis | |
parent | b7034d0803538058e5c9d904ef03cf5eab34f6ef (diff) | |
download | qtwebengine-chromium-7961cea6d1041e3e454dae6a1da660b453efd238.tar.gz |
BASELINE: Update Chromium to 78.0.3904.130
Change-Id: If185e0c0061b3437531c97c9c8c78f239352a68b
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/google_apis')
74 files changed, 752 insertions, 313 deletions
diff --git a/chromium/google_apis/BUILD.gn b/chromium/google_apis/BUILD.gn index 9069f08949b..f1c9338ea5b 100644 --- a/chromium/google_apis/BUILD.gn +++ b/chromium/google_apis/BUILD.gn @@ -118,7 +118,6 @@ template("google_apis_tmpl") { "gaia/oauth2_id_token_decoder.h", "gaia/oauth2_mint_token_flow.cc", "gaia/oauth2_mint_token_flow.h", - "gaia/oauth2_token_service_observer.h", "gaia/oauth_multilogin_result.cc", "gaia/oauth_multilogin_result.h", "gaia/oauth_request_signer.cc", @@ -135,6 +134,7 @@ template("google_apis_tmpl") { deps = [ "//base", "//base/third_party/dynamic_annotations", + "//build:branding_buildflags", "//crypto", "//mojo/public/cpp/bindings:struct_traits", "//services/network/public/cpp", @@ -231,6 +231,7 @@ test("google_apis_unittests") { ":test_support", "//base", "//base/test:test_support", + "//build:branding_buildflags", "//testing/gmock", "//testing/gtest", ] diff --git a/chromium/google_apis/OWNERS b/chromium/google_apis/OWNERS index 75d1a794053..e7eac15c7dc 100644 --- a/chromium/google_apis/OWNERS +++ b/chromium/google_apis/OWNERS @@ -1,4 +1,3 @@ -rogerta@chromium.org file://components/signin/OWNERS per-file BUILD.gn=* diff --git a/chromium/google_apis/drive/OWNERS b/chromium/google_apis/drive/OWNERS index c9f39ecc74a..7ed32b30f3e 100644 --- a/chromium/google_apis/drive/OWNERS +++ b/chromium/google_apis/drive/OWNERS @@ -1 +1,2 @@ file://components/drive/OWNERS +# COMPONENT: Platform>Apps>FileManager diff --git a/chromium/google_apis/drive/auth_service.cc b/chromium/google_apis/drive/auth_service.cc index b2fbfdae461..ab73b9264ed 100644 --- a/chromium/google_apis/drive/auth_service.cc +++ b/chromium/google_apis/drive/auth_service.cc @@ -118,8 +118,7 @@ AuthService::AuthService( : identity_manager_(identity_manager), account_id_(account_id), url_loader_factory_(url_loader_factory), - scopes_(scopes), - weak_ptr_factory_(this) { + scopes_(scopes) { DCHECK(identity_manager_); identity_manager_->AddObserver(this); diff --git a/chromium/google_apis/drive/auth_service.h b/chromium/google_apis/drive/auth_service.h index 1a2fc936422..0e49064abf0 100644 --- a/chromium/google_apis/drive/auth_service.h +++ b/chromium/google_apis/drive/auth_service.h @@ -78,7 +78,7 @@ class AuthService : public AuthServiceInterface, // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. - base::WeakPtrFactory<AuthService> weak_ptr_factory_; + base::WeakPtrFactory<AuthService> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(AuthService); }; diff --git a/chromium/google_apis/drive/base_requests.cc b/chromium/google_apis/drive/base_requests.cc index 4c3de77198f..ef79519c100 100644 --- a/chromium/google_apis/drive/base_requests.cc +++ b/chromium/google_apis/drive/base_requests.cc @@ -255,8 +255,7 @@ UrlFetchRequestBase::UrlFetchRequestBase( sender_(sender), upload_progress_callback_(upload_progress_callback), download_progress_callback_(download_progress_callback), - response_content_length_(-1), - weak_ptr_factory_(this) {} + response_content_length_(-1) {} UrlFetchRequestBase::~UrlFetchRequestBase() {} @@ -316,8 +315,8 @@ void UrlFetchRequestBase::StartAfterPrepare( auto request = std::make_unique<network::ResourceRequest>(); request->url = url; request->method = GetRequestType(); - request->load_flags = net::LOAD_DO_NOT_SEND_COOKIES | - net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DISABLE_CACHE; + request->load_flags = net::LOAD_DISABLE_CACHE; + request->credentials_mode = network::mojom::CredentialsMode::kOmit; // Add request headers. // Note that SetHeader clears the current headers and sets it to the passed-in @@ -684,8 +683,7 @@ UploadRangeRequestBase::UploadRangeRequestBase( const GURL& upload_url, const ProgressCallback& progress_callback) : UrlFetchRequestBase(sender, progress_callback, ProgressCallback()), - upload_url_(upload_url), - weak_ptr_factory_(this) {} + upload_url_(upload_url) {} UploadRangeRequestBase::~UploadRangeRequestBase() {} @@ -880,8 +878,7 @@ MultipartUploadRequestBase::MultipartUploadRequestBase( content_type_(content_type), local_path_(local_file_path), callback_(callback), - progress_callback_(progress_callback), - weak_ptr_factory_(this) { + progress_callback_(progress_callback) { DCHECK(!content_type.empty()); DCHECK_GE(content_length, 0); DCHECK(!local_file_path.empty()); diff --git a/chromium/google_apis/drive/base_requests.h b/chromium/google_apis/drive/base_requests.h index 874bd109e99..5d056c2be7f 100644 --- a/chromium/google_apis/drive/base_requests.h +++ b/chromium/google_apis/drive/base_requests.h @@ -281,7 +281,7 @@ class UrlFetchRequestBase : public AuthenticatedRequestInterface, // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. - base::WeakPtrFactory<UrlFetchRequestBase> weak_ptr_factory_; + base::WeakPtrFactory<UrlFetchRequestBase> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(UrlFetchRequestBase); }; @@ -462,7 +462,7 @@ class UploadRangeRequestBase : public UrlFetchRequestBase { // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. - base::WeakPtrFactory<UploadRangeRequestBase> weak_ptr_factory_; + base::WeakPtrFactory<UploadRangeRequestBase> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(UploadRangeRequestBase); }; @@ -609,7 +609,7 @@ class MultipartUploadRequestBase : public BatchableDelegate { // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. - base::WeakPtrFactory<MultipartUploadRequestBase> weak_ptr_factory_; + base::WeakPtrFactory<MultipartUploadRequestBase> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(MultipartUploadRequestBase); }; diff --git a/chromium/google_apis/drive/base_requests_server_unittest.cc b/chromium/google_apis/drive/base_requests_server_unittest.cc index 9794e0c7b20..01aa96d904c 100644 --- a/chromium/google_apis/drive/base_requests_server_unittest.cc +++ b/chromium/google_apis/drive/base_requests_server_unittest.cc @@ -10,7 +10,7 @@ #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" #include "base/run_loop.h" -#include "base/test/scoped_task_environment.h" +#include "base/test/task_environment.h" #include "google_apis/drive/dummy_auth_service.h" #include "google_apis/drive/request_sender.h" #include "google_apis/drive/task_util.h" @@ -70,7 +70,7 @@ class BaseRequestsServerTest : public testing::Test { request_sender_ = std::make_unique<RequestSender>( std::make_unique<DummyAuthService>(), test_shared_loader_factory_, - scoped_task_environment_.GetMainThreadTaskRunner(), kTestUserAgent, + task_environment_.GetMainThreadTaskRunner(), kTestUserAgent, TRAFFIC_ANNOTATION_FOR_TESTS); ASSERT_TRUE(test_server_.InitializeAndListen()); @@ -86,8 +86,8 @@ class BaseRequestsServerTest : public testing::Test { return temp_dir_.GetPath().Append(file_name); } - base::test::ScopedTaskEnvironment scoped_task_environment_{ - base::test::ScopedTaskEnvironment::MainThreadType::IO}; + base::test::TaskEnvironment task_environment_{ + base::test::TaskEnvironment::MainThreadType::IO}; net::EmbeddedTestServer test_server_; std::unique_ptr<RequestSender> request_sender_; std::unique_ptr<network::mojom::NetworkService> network_service_; diff --git a/chromium/google_apis/drive/base_requests_unittest.cc b/chromium/google_apis/drive/base_requests_unittest.cc index 2ff0eb9e10f..f9a08af85d4 100644 --- a/chromium/google_apis/drive/base_requests_unittest.cc +++ b/chromium/google_apis/drive/base_requests_unittest.cc @@ -12,7 +12,7 @@ #include "base/bind.h" #include "base/message_loop/message_loop.h" #include "base/run_loop.h" -#include "base/test/scoped_task_environment.h" +#include "base/test/task_environment.h" #include "base/values.h" #include "google_apis/drive/drive_api_parser.h" #include "google_apis/drive/drive_api_requests.h" @@ -142,11 +142,11 @@ class BaseRequestsTest : public testing::Test { } void SetUp() override { - sender_.reset(new RequestSender( - std::make_unique<DummyAuthService>(), test_shared_loader_factory_, - scoped_task_environment_.GetMainThreadTaskRunner(), - std::string(), /* custom user agent */ - TRAFFIC_ANNOTATION_FOR_TESTS)); + sender_.reset(new RequestSender(std::make_unique<DummyAuthService>(), + test_shared_loader_factory_, + task_environment_.GetMainThreadTaskRunner(), + std::string(), /* custom user agent */ + TRAFFIC_ANNOTATION_FOR_TESTS)); test_server_.RegisterRequestHandler( base::Bind(&BaseRequestsTest::HandleRequest, base::Unretained(this))); @@ -157,7 +157,7 @@ class BaseRequestsTest : public testing::Test { // Deleting the sender here will delete all request objects. sender_.reset(); // Wait for any DeleteSoon tasks to run. - scoped_task_environment_.RunUntilIdle(); + task_environment_.RunUntilIdle(); } std::unique_ptr<net::test_server::HttpResponse> HandleRequest( @@ -170,8 +170,8 @@ class BaseRequestsTest : public testing::Test { return std::move(response); } - base::test::ScopedTaskEnvironment scoped_task_environment_{ - base::test::ScopedTaskEnvironment::MainThreadType::IO}; + base::test::TaskEnvironment task_environment_{ + base::test::TaskEnvironment::MainThreadType::IO}; std::unique_ptr<network::mojom::NetworkService> network_service_; std::unique_ptr<network::mojom::NetworkServiceClient> network_service_client_; network::mojom::NetworkContextPtr network_context_; diff --git a/chromium/google_apis/drive/drive_api_requests.cc b/chromium/google_apis/drive/drive_api_requests.cc index d7aa3818c23..c7805693a1d 100644 --- a/chromium/google_apis/drive/drive_api_requests.cc +++ b/chromium/google_apis/drive/drive_api_requests.cc @@ -1109,8 +1109,7 @@ SingleBatchableDelegateRequest::SingleBatchableDelegateRequest( // class and cannot outlive this instance. base::Unretained(this)), ProgressCallback()), - delegate_(std::move(delegate)), - weak_ptr_factory_(this) {} + delegate_(std::move(delegate)) {} SingleBatchableDelegateRequest::~SingleBatchableDelegateRequest() { } @@ -1181,8 +1180,7 @@ BatchUploadRequest::BatchUploadRequest( sender_(sender), url_generator_(url_generator), committed_(false), - last_progress_value_(0), - weak_ptr_factory_(this) {} + last_progress_value_(0) {} BatchUploadRequest::~BatchUploadRequest() { } diff --git a/chromium/google_apis/drive/drive_api_requests.h b/chromium/google_apis/drive/drive_api_requests.h index 53300571858..4ec8bd9365e 100644 --- a/chromium/google_apis/drive/drive_api_requests.h +++ b/chromium/google_apis/drive/drive_api_requests.h @@ -143,9 +143,7 @@ class DriveApiDataRequest : public DriveApiPartialFieldRequest { // |callback| is called when the request finishes either by success or by // failure. On success, a JSON Value object is passed. It must not be null. DriveApiDataRequest(RequestSender* sender, const Callback& callback) - : DriveApiPartialFieldRequest(sender), - callback_(callback), - weak_ptr_factory_(this) { + : DriveApiPartialFieldRequest(sender), callback_(callback) { DCHECK(!callback_.is_null()); } ~DriveApiDataRequest() override {} @@ -197,7 +195,7 @@ class DriveApiDataRequest : public DriveApiPartialFieldRequest { // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. - base::WeakPtrFactory<DriveApiDataRequest> weak_ptr_factory_; + base::WeakPtrFactory<DriveApiDataRequest> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(DriveApiDataRequest); }; @@ -1169,7 +1167,7 @@ class SingleBatchableDelegateRequest : public UrlFetchRequestBase { // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. - base::WeakPtrFactory<SingleBatchableDelegateRequest> weak_ptr_factory_; + base::WeakPtrFactory<SingleBatchableDelegateRequest> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(SingleBatchableDelegateRequest); }; @@ -1266,7 +1264,7 @@ class BatchUploadRequest : public UrlFetchRequestBase { // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. - base::WeakPtrFactory<BatchUploadRequest> weak_ptr_factory_; + base::WeakPtrFactory<BatchUploadRequest> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(BatchUploadRequest); }; diff --git a/chromium/google_apis/drive/drive_api_requests_unittest.cc b/chromium/google_apis/drive/drive_api_requests_unittest.cc index 30c0b960c1f..24b90d33732 100644 --- a/chromium/google_apis/drive/drive_api_requests_unittest.cc +++ b/chromium/google_apis/drive/drive_api_requests_unittest.cc @@ -20,7 +20,7 @@ #include "base/run_loop.h" #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" -#include "base/test/scoped_task_environment.h" +#include "base/test/task_environment.h" #include "base/values.h" #include "google_apis/drive/drive_api_parser.h" #include "google_apis/drive/drive_api_url_generator.h" @@ -33,6 +33,7 @@ #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" #include "services/network/network_service.h" #include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h" +#include "services/network/test/test_network_context_client.h" #include "services/network/test/test_network_service_client.h" #include "testing/gtest/include/gtest/gtest.h" @@ -140,6 +141,13 @@ class DriveApiRequestsTest : public testing::Test { network_service_ptr->SetClient(std::move(network_service_client_ptr), network::mojom::NetworkServiceParams::New()); + mojo::PendingRemote<network::mojom::NetworkContextClient> + network_context_client_remote; + network_context_client_ = + std::make_unique<network::TestNetworkContextClient>( + network_context_client_remote.InitWithNewPipeAndPassReceiver()); + network_context_->SetClient(std::move(network_context_client_remote)); + network::mojom::URLLoaderFactoryParamsPtr params = network::mojom::URLLoaderFactoryParams::New(); params->process_id = network::mojom::kBrowserProcessId; @@ -154,7 +162,7 @@ class DriveApiRequestsTest : public testing::Test { void SetUp() override { request_sender_ = std::make_unique<RequestSender>( std::make_unique<DummyAuthService>(), test_shared_loader_factory_, - scoped_task_environment_.GetMainThreadTaskRunner(), kTestUserAgent, + task_environment_.GetMainThreadTaskRunner(), kTestUserAgent, TRAFFIC_ANNOTATION_FOR_TESTS); ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); @@ -212,13 +220,14 @@ class DriveApiRequestsTest : public testing::Test { testing_properties_.push_back(public_property); } - base::test::ScopedTaskEnvironment scoped_task_environment_{ - base::test::ScopedTaskEnvironment::MainThreadType::IO}; + base::test::TaskEnvironment task_environment_{ + base::test::TaskEnvironment::MainThreadType::IO}; net::EmbeddedTestServer test_server_; std::unique_ptr<RequestSender> request_sender_; std::unique_ptr<DriveApiUrlGenerator> url_generator_; std::unique_ptr<network::mojom::NetworkService> network_service_; std::unique_ptr<network::mojom::NetworkServiceClient> network_service_client_; + std::unique_ptr<network::mojom::NetworkContextClient> network_context_client_; network::mojom::NetworkContextPtr network_context_; network::mojom::URLLoaderFactoryPtr url_loader_factory_; scoped_refptr<network::WeakWrapperSharedURLLoaderFactory> diff --git a/chromium/google_apis/drive/drive_api_url_generator_unittest.cc b/chromium/google_apis/drive/drive_api_url_generator_unittest.cc index 596929bfdfc..2629141a72b 100644 --- a/chromium/google_apis/drive/drive_api_url_generator_unittest.cc +++ b/chromium/google_apis/drive/drive_api_url_generator_unittest.cc @@ -29,7 +29,7 @@ class DriveApiUrlGeneratorTest : public testing::Test { url::AddStandardScheme("chrome-extension", url::SCHEME_WITH_HOST); } - ~DriveApiUrlGeneratorTest() override { url::Shutdown(); } + ~DriveApiUrlGeneratorTest() override { url::ResetForTests(); } protected: DriveApiUrlGenerator url_generator_; diff --git a/chromium/google_apis/drive/files_list_request_runner.cc b/chromium/google_apis/drive/files_list_request_runner.cc index 8b25e1cd85d..38042b55d61 100644 --- a/chromium/google_apis/drive/files_list_request_runner.cc +++ b/chromium/google_apis/drive/files_list_request_runner.cc @@ -18,10 +18,7 @@ namespace google_apis { FilesListRequestRunner::FilesListRequestRunner( RequestSender* request_sender, const google_apis::DriveApiUrlGenerator& url_generator) - : request_sender_(request_sender), - url_generator_(url_generator), - weak_ptr_factory_(this) { -} + : request_sender_(request_sender), url_generator_(url_generator) {} FilesListRequestRunner::~FilesListRequestRunner() { } diff --git a/chromium/google_apis/drive/files_list_request_runner.h b/chromium/google_apis/drive/files_list_request_runner.h index a4993ceb27b..1e3027b0bdf 100644 --- a/chromium/google_apis/drive/files_list_request_runner.h +++ b/chromium/google_apis/drive/files_list_request_runner.h @@ -66,7 +66,7 @@ class FilesListRequestRunner { // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. - base::WeakPtrFactory<FilesListRequestRunner> weak_ptr_factory_; + base::WeakPtrFactory<FilesListRequestRunner> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(FilesListRequestRunner); }; diff --git a/chromium/google_apis/drive/files_list_request_runner_unittest.cc b/chromium/google_apis/drive/files_list_request_runner_unittest.cc index 50d14ce4e28..4a09612c978 100644 --- a/chromium/google_apis/drive/files_list_request_runner_unittest.cc +++ b/chromium/google_apis/drive/files_list_request_runner_unittest.cc @@ -12,7 +12,7 @@ #include "base/run_loop.h" #include "base/sequenced_task_runner.h" #include "base/strings/string_number_conversions.h" -#include "base/test/scoped_task_environment.h" +#include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "google_apis/drive/base_requests.h" #include "google_apis/drive/dummy_auth_service.h" @@ -101,7 +101,7 @@ class FilesListRequestRunnerTest : public testing::Test { void SetUp() override { request_sender_ = std::make_unique<RequestSender>( std::make_unique<DummyAuthService>(), test_shared_loader_factory_, - scoped_task_environment_.GetMainThreadTaskRunner(), kTestUserAgent, + task_environment_.GetMainThreadTaskRunner(), kTestUserAgent, TRAFFIC_ANNOTATION_FOR_TESTS); test_server_.RegisterRequestHandler( @@ -149,8 +149,8 @@ class FilesListRequestRunnerTest : public testing::Test { return std::move(fake_server_response_); } - base::test::ScopedTaskEnvironment scoped_task_environment_{ - base::test::ScopedTaskEnvironment::MainThreadType::IO}; + base::test::TaskEnvironment task_environment_{ + base::test::TaskEnvironment::MainThreadType::IO}; std::unique_ptr<RequestSender> request_sender_; net::EmbeddedTestServer test_server_; std::unique_ptr<FilesListRequestRunner> runner_; diff --git a/chromium/google_apis/drive/request_sender.cc b/chromium/google_apis/drive/request_sender.cc index 5614632b466..86abc742031 100644 --- a/chromium/google_apis/drive/request_sender.cc +++ b/chromium/google_apis/drive/request_sender.cc @@ -23,8 +23,7 @@ RequestSender::RequestSender( url_loader_factory_(url_loader_factory), blocking_task_runner_(blocking_task_runner), custom_user_agent_(custom_user_agent), - traffic_annotation_(traffic_annotation), - weak_ptr_factory_(this) {} + traffic_annotation_(traffic_annotation) {} RequestSender::~RequestSender() { DCHECK(thread_checker_.CalledOnValidThread()); diff --git a/chromium/google_apis/drive/request_sender.h b/chromium/google_apis/drive/request_sender.h index 44a21ee15d7..5deb974bcf1 100644 --- a/chromium/google_apis/drive/request_sender.h +++ b/chromium/google_apis/drive/request_sender.h @@ -111,7 +111,7 @@ class RequestSender { // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. - base::WeakPtrFactory<RequestSender> weak_ptr_factory_; + base::WeakPtrFactory<RequestSender> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(RequestSender); }; diff --git a/chromium/google_apis/drive/request_sender_unittest.cc b/chromium/google_apis/drive/request_sender_unittest.cc index 67032a3167d..d61444c5e80 100644 --- a/chromium/google_apis/drive/request_sender_unittest.cc +++ b/chromium/google_apis/drive/request_sender_unittest.cc @@ -83,9 +83,7 @@ class TestRequest : public AuthenticatedRequestInterface { FinishReason* finish_reason) : sender_(sender), start_called_(start_called), - finish_reason_(finish_reason), - weak_ptr_factory_(this) { - } + finish_reason_(finish_reason) {} // Test the situation that the request has finished. void FinishRequestWithSuccess() { @@ -133,7 +131,7 @@ class TestRequest : public AuthenticatedRequestInterface { FinishReason* finish_reason_; std::string passed_access_token_; ReAuthenticateCallback passed_reauth_callback_; - base::WeakPtrFactory<TestRequest> weak_ptr_factory_; + base::WeakPtrFactory<TestRequest> weak_ptr_factory_{this}; }; } // namespace diff --git a/chromium/google_apis/gaia/OWNERS b/chromium/google_apis/gaia/OWNERS index 753faeeff6d..a0a9d581027 100644 --- a/chromium/google_apis/gaia/OWNERS +++ b/chromium/google_apis/gaia/OWNERS @@ -1,6 +1,4 @@ -droger@chromium.org -msarda@chromium.org -rogerta@chromium.org +file://components/signin/OWNERS # Solely for the duration of the refactoring of OAuth2TokenService # (https://crbug.com/950159). Do not choose for any other reviews. diff --git a/chromium/google_apis/gaia/fake_oauth2_access_token_manager.cc b/chromium/google_apis/gaia/fake_oauth2_access_token_manager.cc index 4e48c808d5b..252309bf9bf 100644 --- a/chromium/google_apis/gaia/fake_oauth2_access_token_manager.cc +++ b/chromium/google_apis/gaia/fake_oauth2_access_token_manager.cc @@ -22,13 +22,12 @@ FakeOAuth2AccessTokenManager::PendingRequest::~PendingRequest() {} FakeOAuth2AccessTokenManager::FakeOAuth2AccessTokenManager( OAuth2AccessTokenManager::Delegate* delegate) : OAuth2AccessTokenManager(delegate), - auto_post_fetch_response_on_message_loop_(false), - weak_ptr_factory_(this) {} + auto_post_fetch_response_on_message_loop_(false) {} FakeOAuth2AccessTokenManager::~FakeOAuth2AccessTokenManager() {} void FakeOAuth2AccessTokenManager::IssueAllTokensForAccount( - const std::string& account_id, + const CoreAccountId& account_id, const std::string& access_token, const base::Time& expiration) { DCHECK(!auto_post_fetch_response_on_message_loop_); @@ -39,7 +38,7 @@ void FakeOAuth2AccessTokenManager::IssueAllTokensForAccount( } void FakeOAuth2AccessTokenManager::IssueAllTokensForAccount( - const std::string& account_id, + const CoreAccountId& account_id, const OAuth2AccessTokenConsumer::TokenResponse& token_response) { DCHECK(!auto_post_fetch_response_on_message_loop_); CompleteRequests(account_id, true, FakeOAuth2AccessTokenManager::ScopeSet(), @@ -47,7 +46,7 @@ void FakeOAuth2AccessTokenManager::IssueAllTokensForAccount( } void FakeOAuth2AccessTokenManager::IssueErrorForAllPendingRequestsForAccount( - const std::string& account_id, + const CoreAccountId& account_id, const GoogleServiceAuthError& error) { DCHECK(!auto_post_fetch_response_on_message_loop_); CompleteRequests(account_id, true, FakeOAuth2AccessTokenManager::ScopeSet(), @@ -59,7 +58,8 @@ void FakeOAuth2AccessTokenManager::IssueTokenForScope( const std::string& access_token, const base::Time& expiration) { DCHECK(!auto_post_fetch_response_on_message_loop_); - CompleteRequests("", false, scope, GoogleServiceAuthError::AuthErrorNone(), + CompleteRequests(CoreAccountId(), false, scope, + GoogleServiceAuthError::AuthErrorNone(), OAuth2AccessTokenConsumer::TokenResponse( access_token, expiration, std::string() /* id_token */)); } @@ -68,22 +68,23 @@ void FakeOAuth2AccessTokenManager::IssueTokenForScope( const FakeOAuth2AccessTokenManager::ScopeSet& scope, const OAuth2AccessTokenConsumer::TokenResponse& token_response) { DCHECK(!auto_post_fetch_response_on_message_loop_); - CompleteRequests("", false, scope, GoogleServiceAuthError::AuthErrorNone(), - token_response); + CompleteRequests(CoreAccountId(), false, scope, + GoogleServiceAuthError::AuthErrorNone(), token_response); } void FakeOAuth2AccessTokenManager::IssueErrorForScope( const FakeOAuth2AccessTokenManager::ScopeSet& scope, const GoogleServiceAuthError& error) { DCHECK(!auto_post_fetch_response_on_message_loop_); - CompleteRequests("", false, scope, error, + CompleteRequests(CoreAccountId(), false, scope, error, OAuth2AccessTokenConsumer::TokenResponse()); } void FakeOAuth2AccessTokenManager::IssueErrorForAllPendingRequests( const GoogleServiceAuthError& error) { DCHECK(!auto_post_fetch_response_on_message_loop_); - CompleteRequests("", true, FakeOAuth2AccessTokenManager::ScopeSet(), error, + CompleteRequests(CoreAccountId(), true, + FakeOAuth2AccessTokenManager::ScopeSet(), error, OAuth2AccessTokenConsumer::TokenResponse()); } @@ -91,7 +92,8 @@ void FakeOAuth2AccessTokenManager::IssueTokenForAllPendingRequests( const std::string& access_token, const base::Time& expiration) { DCHECK(!auto_post_fetch_response_on_message_loop_); - CompleteRequests("", true, FakeOAuth2AccessTokenManager::ScopeSet(), + CompleteRequests(CoreAccountId(), true, + FakeOAuth2AccessTokenManager::ScopeSet(), GoogleServiceAuthError::AuthErrorNone(), OAuth2AccessTokenConsumer::TokenResponse( access_token, expiration, std::string() /* id_token */)); @@ -100,12 +102,13 @@ void FakeOAuth2AccessTokenManager::IssueTokenForAllPendingRequests( void FakeOAuth2AccessTokenManager::IssueTokenForAllPendingRequests( const OAuth2AccessTokenConsumer::TokenResponse& token_response) { DCHECK(!auto_post_fetch_response_on_message_loop_); - CompleteRequests("", true, FakeOAuth2AccessTokenManager::ScopeSet(), + CompleteRequests(CoreAccountId(), true, + FakeOAuth2AccessTokenManager::ScopeSet(), GoogleServiceAuthError::AuthErrorNone(), token_response); } void FakeOAuth2AccessTokenManager::CompleteRequests( - const std::string& account_id, + const CoreAccountId& account_id, bool all_scopes, const FakeOAuth2AccessTokenManager::ScopeSet& scope, const GoogleServiceAuthError& error, @@ -151,7 +154,7 @@ FakeOAuth2AccessTokenManager::GetPendingRequests() { void FakeOAuth2AccessTokenManager::CancelAllRequests() { CompleteRequests( - "", true, FakeOAuth2AccessTokenManager::ScopeSet(), + CoreAccountId(), true, FakeOAuth2AccessTokenManager::ScopeSet(), GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED), OAuth2AccessTokenConsumer::TokenResponse()); } diff --git a/chromium/google_apis/gaia/fake_oauth2_access_token_manager.h b/chromium/google_apis/gaia/fake_oauth2_access_token_manager.h index d9efa6be2fe..7feeafe632c 100644 --- a/chromium/google_apis/gaia/fake_oauth2_access_token_manager.h +++ b/chromium/google_apis/gaia/fake_oauth2_access_token_manager.h @@ -23,7 +23,7 @@ class FakeOAuth2AccessTokenManager : public OAuth2AccessTokenManager { PendingRequest(const PendingRequest& other); ~PendingRequest(); - std::string account_id; + CoreAccountId account_id; std::string client_id; std::string client_secret; scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory; @@ -40,17 +40,17 @@ class FakeOAuth2AccessTokenManager : public OAuth2AccessTokenManager { std::vector<PendingRequest> GetPendingRequests(); // Helper routines to issue tokens for pending requests. - void IssueAllTokensForAccount(const std::string& account_id, + void IssueAllTokensForAccount(const CoreAccountId& account_id, const std::string& access_token, const base::Time& expiration); // Helper routines to issue token for pending requests based on TokenResponse. void IssueAllTokensForAccount( - const std::string& account_id, + const CoreAccountId& account_id, const OAuth2AccessTokenConsumer::TokenResponse& token_response); void IssueErrorForAllPendingRequestsForAccount( - const std::string& account_id, + const CoreAccountId& account_id, const GoogleServiceAuthError& error); void IssueTokenForScope(const OAuth2AccessTokenManager::ScopeSet& scopes, @@ -102,7 +102,7 @@ class FakeOAuth2AccessTokenManager : public OAuth2AccessTokenManager { // requests for all accounts are completed, otherwise only requests for the // given account. void CompleteRequests( - const std::string& account_id, + const CoreAccountId& account_id, bool all_scopes, const OAuth2AccessTokenManager::ScopeSet& scopes, const GoogleServiceAuthError& error, @@ -115,7 +115,7 @@ class FakeOAuth2AccessTokenManager : public OAuth2AccessTokenManager { // |IssueTokenForScope| in this case. bool auto_post_fetch_response_on_message_loop_; - base::WeakPtrFactory<FakeOAuth2AccessTokenManager> weak_ptr_factory_; + base::WeakPtrFactory<FakeOAuth2AccessTokenManager> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(FakeOAuth2AccessTokenManager); }; diff --git a/chromium/google_apis/gaia/gaia_auth_fetcher.cc b/chromium/google_apis/gaia/gaia_auth_fetcher.cc index e20bb74c360..29f0e2357ba 100644 --- a/chromium/google_apis/gaia/gaia_auth_fetcher.cc +++ b/chromium/google_apis/gaia/gaia_auth_fetcher.cc @@ -16,7 +16,6 @@ #include "base/metrics/histogram_macros.h" #include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics_action.h" -#include "base/process/process.h" #include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" @@ -269,6 +268,12 @@ void GaiaAuthFetcher::CreateAndStartGaiaFetcher( DCHECK_EQ(GaiaUrls::GetInstance()->gaia_url(), gaia_gurl.GetOrigin()) << gaia_gurl; resource_request->site_for_cookies = GaiaUrls::GetInstance()->gaia_url(); + url::Origin origin = + url::Origin::Create(GaiaUrls::GetInstance()->gaia_url()); + resource_request->trusted_params = + network::ResourceRequest::TrustedParams(); + resource_request->trusted_params->network_isolation_key = + net::NetworkIsolationKey(origin, origin); } if (!body.empty()) @@ -701,11 +706,6 @@ void GaiaAuthFetcher::StartOAuthLogin(const std::string& access_token, void GaiaAuthFetcher::StartListAccounts() { DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; - list_accounts_system_uptime_ = base::SysInfo::Uptime(); -#if !defined(OS_IOS) && !defined(OS_ANDROID) - list_accounts_process_uptime_ = - base::Time::Now() - base::Process::Current().CreationTime(); -#endif net::NetworkTrafficAnnotationTag traffic_annotation = net::DefineNetworkTrafficAnnotation("gaia_auth_list_accounts", R"( @@ -949,28 +949,8 @@ void GaiaAuthFetcher::OnOAuth2RevokeTokenFetched(const std::string& data, void GaiaAuthFetcher::OnListAccountsFetched(const std::string& data, net::Error net_error, int response_code) { - // Log error rates and details for ListAccounts, for investigation of - // https://crbug.com/876306. base::UmaHistogramSparse("Gaia.AuthFetcher.ListAccounts.NetErrorCodes", -net_error); - if (net_error == net::OK) { - UMA_HISTOGRAM_LONG_TIMES( - "Gaia.AuthFetcher.ListAccounts.SystemUptime.Success", - list_accounts_system_uptime_); -#if !defined(OS_IOS) && !defined(OS_ANDROID) - UMA_HISTOGRAM_LONG_TIMES( - "Gaia.AuthFetcher.ListAccounts.ProcessUptime.Success", - list_accounts_process_uptime_); -#endif - } else { - UMA_HISTOGRAM_LONG_TIMES("Gaia.AuthFetcher.ListAccounts.SystemUptime.Error", - list_accounts_system_uptime_); -#if !defined(OS_IOS) && !defined(OS_ANDROID) - UMA_HISTOGRAM_LONG_TIMES( - "Gaia.AuthFetcher.ListAccounts.ProcessUptime.Error", - list_accounts_process_uptime_); -#endif - } if (net_error == net::OK && response_code == net::HTTP_OK) consumer_->OnListAccountsSuccess(data); diff --git a/chromium/google_apis/gaia/gaia_auth_fetcher.h b/chromium/google_apis/gaia/gaia_auth_fetcher.h index 79964d2edf6..4dcff58f675 100644 --- a/chromium/google_apis/gaia/gaia_auth_fetcher.h +++ b/chromium/google_apis/gaia/gaia_auth_fetcher.h @@ -13,7 +13,6 @@ #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_refptr.h" -#include "base/time/time.h" #include "build/build_config.h" #include "google_apis/gaia/gaia_auth_consumer.h" #include "google_apis/gaia/google_service_auth_error.h" @@ -364,13 +363,6 @@ class GaiaAuthFetcher { bool fetch_pending_ = false; bool fetch_token_from_auth_code_ = false; - // For investigation of https://crbug.com/876306. - base::TimeDelta list_accounts_system_uptime_; -#if !defined(OS_IOS) && !defined(OS_ANDROID) - // Process creation time is not available on iOS and Android. - base::TimeDelta list_accounts_process_uptime_; -#endif - friend class GaiaAuthFetcherTest; FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CaptchaParse); FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, BadAuthenticationError); diff --git a/chromium/google_apis/gaia/gaia_auth_fetcher_unittest.cc b/chromium/google_apis/gaia/gaia_auth_fetcher_unittest.cc index b0163e74480..9f930333139 100644 --- a/chromium/google_apis/gaia/gaia_auth_fetcher_unittest.cc +++ b/chromium/google_apis/gaia/gaia_auth_fetcher_unittest.cc @@ -15,7 +15,7 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "base/test/bind_test_util.h" -#include "base/test/scoped_task_environment.h" +#include "base/test/task_environment.h" #include "base/values.h" #include "build/build_config.h" #include "google_apis/gaia/gaia_auth_consumer.h" @@ -71,8 +71,7 @@ class GaiaAuthFetcherTest : public testing::Test { GaiaUrls::GetInstance()->oauth1_login_url().Resolve( "?source=&issueuberauth=1")), oauth_login_gurl_(GaiaUrls::GetInstance()->oauth1_login_url()), - scoped_task_environment_( - base::test::ScopedTaskEnvironment::MainThreadType::UI), + task_environment_(base::test::TaskEnvironment::MainThreadType::UI), test_shared_loader_factory_( base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>( &test_url_loader_factory_)) { @@ -123,7 +122,7 @@ class GaiaAuthFetcherTest : public testing::Test { return test_shared_loader_factory_; } - base::test::ScopedTaskEnvironment scoped_task_environment_; + base::test::TaskEnvironment task_environment_; network::TestURLLoaderFactory test_url_loader_factory_; scoped_refptr<network::SharedURLLoaderFactory> test_shared_loader_factory_; std::vector<network::ResourceRequest> received_requests_; diff --git a/chromium/google_apis/gaia/gaia_constants.cc b/chromium/google_apis/gaia/gaia_constants.cc index 63cb6bd0a5e..93cba997fac 100644 --- a/chromium/google_apis/gaia/gaia_constants.cc +++ b/chromium/google_apis/gaia/gaia_constants.cc @@ -64,6 +64,13 @@ const char kPeopleApiReadOnlyOAuth2Scope[] = const char kAccountsReauthOAuth2Scope[] = "https://www.googleapis.com/auth/accounts.reauth"; +// OAuth scope for access to audit recording (ARI). +const char kAuditRecordingOAuth2Scope[] = + "https://www.googleapis.com/auth/auditrecording-pa"; + +// OAuth scope for access to clear cut logs. +const char kClearCutOAuth2Scope[] = "https://www.googleapis.com/auth/cclog"; + // Used to mint uber auth tokens when needed. const char kGaiaSid[] = "sid"; const char kGaiaLsid[] = "lsid"; diff --git a/chromium/google_apis/gaia/gaia_constants.h b/chromium/google_apis/gaia/gaia_constants.h index 5694050ede4..53892094ee4 100644 --- a/chromium/google_apis/gaia/gaia_constants.h +++ b/chromium/google_apis/gaia/gaia_constants.h @@ -35,6 +35,8 @@ extern const char kGoogleUserInfoEmail[]; extern const char kGoogleUserInfoProfile[]; extern const char kPeopleApiReadOnlyOAuth2Scope[]; extern const char kAccountsReauthOAuth2Scope[]; +extern const char kAuditRecordingOAuth2Scope[]; +extern const char kClearCutOAuth2Scope[]; // Used with uber auth tokens when needed. extern const char kGaiaSid[]; diff --git a/chromium/google_apis/gaia/gaia_oauth_client.cc b/chromium/google_apis/gaia/gaia_oauth_client.cc index fb38b4d29fe..4838ad55fd2 100644 --- a/chromium/google_apis/gaia/gaia_oauth_client.cc +++ b/chromium/google_apis/gaia/gaia_oauth_client.cc @@ -43,8 +43,7 @@ class GaiaOAuthClient::Core max_retries_(0), url_loader_factory_(url_loader_factory), delegate_(nullptr), - request_type_(NO_PENDING_REQUEST), - weak_ptr_factory_(this) { + request_type_(NO_PENDING_REQUEST) { backoff_policy_.num_errors_to_ignore = net::URLRequestThrottlerEntry::kDefaultNumErrorsToIgnore; backoff_policy_.initial_delay_ms = @@ -142,7 +141,7 @@ class GaiaOAuthClient::Core std::unique_ptr<network::SimpleURLLoader> request_; RequestType request_type_; - base::WeakPtrFactory<Core> weak_ptr_factory_; + base::WeakPtrFactory<Core> weak_ptr_factory_{this}; }; void GaiaOAuthClient::Core::GetTokensFromAuthCode( @@ -387,8 +386,7 @@ void GaiaOAuthClient::Core::SendRequestImpl() { auto resource_request = std::make_unique<network::ResourceRequest>(); resource_request->url = url_; resource_request->method = post_body_.empty() ? "GET" : "POST"; - resource_request->load_flags = - net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES; + resource_request->credentials_mode = network::mojom::CredentialsMode::kOmit; if (!authorization_header_.empty()) resource_request->headers.SetHeader("Authorization", authorization_header_); diff --git a/chromium/google_apis/gaia/gaia_oauth_client_unittest.cc b/chromium/google_apis/gaia/gaia_oauth_client_unittest.cc index 9a543bdb02c..7102449c6e9 100644 --- a/chromium/google_apis/gaia/gaia_oauth_client_unittest.cc +++ b/chromium/google_apis/gaia/gaia_oauth_client_unittest.cc @@ -11,7 +11,7 @@ #include "base/json/json_reader.h" #include "base/macros.h" #include "base/strings/string_number_conversions.h" -#include "base/test/scoped_task_environment.h" +#include "base/test/task_environment.h" #include "base/time/tick_clock.h" #include "base/values.h" #include "google_apis/gaia/gaia_oauth_client.h" @@ -168,8 +168,7 @@ namespace gaia { class GaiaOAuthClientTest : public testing::Test { protected: GaiaOAuthClientTest() - : scoped_task_environment_( - base::test::ScopedTaskEnvironment::TimeSource::MOCK_TIME) {} + : task_environment_(base::test::TaskEnvironment::TimeSource::MOCK_TIME) {} void SetUp() override { client_info_.client_id = "test_client_id"; @@ -187,11 +186,11 @@ class GaiaOAuthClientTest : public testing::Test { // TestURLLoaderFactory to its clients via mojo pipes. In addition, // some retries may have back off, so may need to advance (mock) time // for them to finish, too. - scoped_task_environment_.FastForwardUntilNoTasksRemain(); + task_environment_.FastForwardUntilNoTasksRemain(); } protected: - base::test::ScopedTaskEnvironment scoped_task_environment_; + base::test::TaskEnvironment task_environment_; network::TestURLLoaderFactory url_loader_factory_; OAuthClientInfo client_info_; @@ -284,8 +283,7 @@ TEST_F(GaiaOAuthClientTest, NetworkFailureRecoverBackoff) { injector.set_max_failure_count(21); injector.set_results(kDummyGetTokensResult); - base::TimeTicks start = - scoped_task_environment_.GetMockTickClock()->NowTicks(); + base::TimeTicks start = task_environment_.GetMockTickClock()->NowTicks(); GaiaOAuthClient auth(GetSharedURLLoaderFactory()); auth.GetTokensFromAuthCode(client_info_, "auth_code", -1, &delegate); @@ -299,7 +297,7 @@ TEST_F(GaiaOAuthClientTest, NetworkFailureRecoverBackoff) { // 0.6 * 700ms * 1.4^(20-2) ~ 179s // // ... so the whole thing should take at least 307s - EXPECT_GE(scoped_task_environment_.GetMockTickClock()->NowTicks() - start, + EXPECT_GE(task_environment_.GetMockTickClock()->NowTicks() - start, base::TimeDelta::FromSeconds(307)); } diff --git a/chromium/google_apis/gaia/oauth2_access_token_fetcher_impl.cc b/chromium/google_apis/gaia/oauth2_access_token_fetcher_impl.cc index 7e0e08534b9..426a186dffe 100644 --- a/chromium/google_apis/gaia/oauth2_access_token_fetcher_impl.cc +++ b/chromium/google_apis/gaia/oauth2_access_token_fetcher_impl.cc @@ -120,8 +120,7 @@ static std::unique_ptr<network::SimpleURLLoader> CreateURLLoader( auto resource_request = std::make_unique<network::ResourceRequest>(); resource_request->url = url; - resource_request->load_flags = - net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES; + resource_request->credentials_mode = network::mojom::CredentialsMode::kOmit; if (!body.empty()) resource_request->method = "POST"; @@ -210,8 +209,6 @@ void OAuth2AccessTokenFetcherImpl::EndGetAccessToken( int histogram_value; if (url_loader_->NetError() == net::OK && url_loader_->ResponseInfo() && url_loader_->ResponseInfo()->headers) { - // Note that the SimpleURLLoader reports net::ERR_FAILED for HTTP codes - // other than 200s. histogram_value = url_loader_->ResponseInfo()->headers->response_code(); } else { histogram_value = url_loader_->NetError(); diff --git a/chromium/google_apis/gaia/oauth2_access_token_fetcher_impl_unittest.cc b/chromium/google_apis/gaia/oauth2_access_token_fetcher_impl_unittest.cc index 848ce5efbfe..4a9ca46280a 100644 --- a/chromium/google_apis/gaia/oauth2_access_token_fetcher_impl_unittest.cc +++ b/chromium/google_apis/gaia/oauth2_access_token_fetcher_impl_unittest.cc @@ -11,7 +11,7 @@ #include "base/bind.h" #include "base/run_loop.h" -#include "base/test/scoped_task_environment.h" +#include "base/test/task_environment.h" #include "google_apis/gaia/gaia_urls.h" #include "google_apis/gaia/google_service_auth_error.h" #include "google_apis/gaia/oauth2_access_token_consumer.h" @@ -115,7 +115,7 @@ class OAuth2AccessTokenFetcherImplTest : public testing::Test { } protected: - base::test::ScopedTaskEnvironment scoped_task_environment_; + base::test::SingleThreadTaskEnvironment task_environment_; MockOAuth2AccessTokenConsumer consumer_; URLLoaderFactoryInterceptor url_loader_factory_interceptor_; network::TestURLLoaderFactory url_loader_factory_; diff --git a/chromium/google_apis/gaia/oauth2_access_token_manager.h b/chromium/google_apis/gaia/oauth2_access_token_manager.h index a7454adcd32..8fd6041e7e6 100644 --- a/chromium/google_apis/gaia/oauth2_access_token_manager.h +++ b/chromium/google_apis/gaia/oauth2_access_token_manager.h @@ -64,7 +64,7 @@ class OAuth2AccessTokenManager { // Called when an access token is invalidated. virtual void OnAccessTokenInvalidated(const CoreAccountId& account_id, const std::string& client_id, - const std::set<std::string>& scopes, + const ScopeSet& scopes, const std::string& access_token) {} // Called when an access token is fetched. @@ -217,7 +217,6 @@ class OAuth2AccessTokenManager { // Fetches an OAuth token for the specified client/scopes. Virtual so it can // be overridden for tests. - // TODO(https://crbug.com/967598): Move this to protected. virtual void FetchOAuth2Token( RequestImpl* request, const CoreAccountId& account_id, @@ -226,13 +225,6 @@ class OAuth2AccessTokenManager { const std::string& client_secret, const ScopeSet& scopes); - // Add a new entry to the cache. - void RegisterTokenResponse( - const std::string& client_id, - const CoreAccountId& account_id, - const ScopeSet& scopes, - const OAuth2AccessTokenConsumer::TokenResponse& token_response); - // Returns a currently valid OAuth2 access token for the given set of scopes, // or NULL if none have been cached. Note the user of this method should // ensure no entry with the same |client_scopes| is added before the usage of @@ -250,12 +242,10 @@ class OAuth2AccessTokenManager { // Cancels all requests that are currently in progress. Virtual so it can be // overridden for tests. - // TODO(https://crbug.com/967598): Move this to protected. virtual void CancelAllRequests(); // Cancels all requests related to a given |account_id|. Virtual so it can be // overridden for tests. - // TODO(https://crbug.com/967598): Move this to protected. virtual void CancelRequestsForAccount(const CoreAccountId& account_id); // Mark an OAuth2 |access_token| issued for |account_id| and |scopes| as @@ -267,14 +257,6 @@ class OAuth2AccessTokenManager { const ScopeSet& scopes, const std::string& access_token); - // Invalidates the |access_token| issued for |account_id|, |client_id| and - // |scopes|. Virtual so it can be overridden for tests. - // TODO(https://crbug.com/967598): Move this to protected. - virtual void InvalidateAccessTokenImpl(const CoreAccountId& account_id, - const std::string& client_id, - const ScopeSet& scopes, - const std::string& access_token); - void set_max_authorization_token_fetch_retries_for_testing(int max_retries); // Returns the current number of pending fetchers matching given params. @@ -286,11 +268,15 @@ class OAuth2AccessTokenManager { const base::ObserverList<DiagnosticsObserver, true>::Unchecked& GetDiagnosticsObserversForTesting(); - private: - // TODO(https://crbug.com/967598): Determine whether ProfileOAuth2TokenService - // needs to have API to access to token_cache(). - friend class ProfileOAuth2TokenService; + protected: + // Invalidates the |access_token| issued for |account_id|, |client_id| and + // |scopes|. Virtual so it can be overridden for tests. + virtual void InvalidateAccessTokenImpl(const CoreAccountId& account_id, + const std::string& client_id, + const ScopeSet& scopes, + const std::string& access_token); + private: class Fetcher; friend class Fetcher; @@ -319,6 +305,13 @@ class OAuth2AccessTokenManager { RequestImpl* request, const RequestParameters& client_scopes); + // Add a new entry to the cache. + void RegisterTokenResponse( + const std::string& client_id, + const CoreAccountId& account_id, + const ScopeSet& scopes, + const OAuth2AccessTokenConsumer::TokenResponse& token_response); + // Removes an access token for the given set of scopes from the cache. // Returns true if the entry was removed, otherwise false. bool RemoveCachedTokenResponse(const RequestParameters& client_scopes, @@ -344,6 +337,10 @@ class OAuth2AccessTokenManager { SEQUENCE_CHECKER(sequence_checker_); + FRIEND_TEST_ALL_PREFIXES(OAuth2AccessTokenManagerTest, ClearCache); + FRIEND_TEST_ALL_PREFIXES(OAuth2AccessTokenManagerTest, ClearCacheForAccount); + FRIEND_TEST_ALL_PREFIXES(OAuth2AccessTokenManagerTest, OnAccessTokenRemoved); + DISALLOW_COPY_AND_ASSIGN(OAuth2AccessTokenManager); }; diff --git a/chromium/google_apis/gaia/oauth2_access_token_manager_unittest.cc b/chromium/google_apis/gaia/oauth2_access_token_manager_unittest.cc index 04bb9ba9b9f..0faaceae8a1 100644 --- a/chromium/google_apis/gaia/oauth2_access_token_manager_unittest.cc +++ b/chromium/google_apis/gaia/oauth2_access_token_manager_unittest.cc @@ -3,8 +3,9 @@ // found in the LICENSE file. #include "google_apis/gaia/oauth2_access_token_manager.h" + #include "base/memory/ref_counted.h" -#include "base/test/scoped_task_environment.h" +#include "base/test/task_environment.h" #include "google_apis/gaia/gaia_constants.h" #include "google_apis/gaia/gaia_urls.h" #include "google_apis/gaia/google_service_auth_error.h" @@ -35,13 +36,16 @@ class FakeOAuth2AccessTokenManagerDelegate const CoreAccountId& account_id, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, OAuth2AccessTokenConsumer* consumer) override { - EXPECT_EQ(CoreAccountId(kTestAccountId), account_id); + EXPECT_NE(account_ids_to_refresh_tokens_.find(account_id), + account_ids_to_refresh_tokens_.end()); return std::make_unique<OAuth2AccessTokenFetcherImpl>( - consumer, url_loader_factory, "fake_refresh_token"); + consumer, url_loader_factory, + account_ids_to_refresh_tokens_[account_id]); } bool HasRefreshToken(const CoreAccountId& account_id) const override { - return CoreAccountId(kTestAccountId) == account_id; + return account_ids_to_refresh_tokens_.find(account_id) != + account_ids_to_refresh_tokens_.end(); } scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() @@ -49,8 +53,86 @@ class FakeOAuth2AccessTokenManagerDelegate return shared_factory_; } + bool HandleAccessTokenFetch( + OAuth2AccessTokenManager::RequestImpl* request, + const CoreAccountId& account_id, + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, + const std::string& client_id, + const std::string& client_secret, + const OAuth2AccessTokenManager::ScopeSet& scopes) override { + if (access_token_fetch_closure_) { + std::move(access_token_fetch_closure_).Run(); + return true; + } + return false; + } + + void OnAccessTokenInvalidated( + const CoreAccountId& account_id, + const std::string& client_id, + const OAuth2AccessTokenManager::ScopeSet& scopes, + const std::string& access_token) override { + if (!on_access_token_invalidated_callback_) + return; + + EXPECT_EQ(access_token_invalidated_account_id_, account_id); + EXPECT_EQ(access_token_invalidated_client_id_, client_id); + EXPECT_EQ(access_token_invalidated_scopes_, scopes); + EXPECT_EQ(access_token_invalidated_access_token_, access_token); + std::move(on_access_token_invalidated_callback_).Run(); + } + + void OnAccessTokenFetched(const CoreAccountId& account_id, + const GoogleServiceAuthError& error) override { + if (!access_token_fetched_callback_) + return; + + EXPECT_EQ(access_token_fetched_account_id_, account_id); + EXPECT_EQ(access_token_fetched_error_, error); + std::move(access_token_fetched_callback_).Run(); + } + + void AddAccount(CoreAccountId id, std::string refresh_token) { + account_ids_to_refresh_tokens_[id] = refresh_token; + } + + void SetAccessTokenHandleClosure(base::OnceClosure closure) { + access_token_fetch_closure_ = std::move(closure); + } + + void SetOnAccessTokenInvalidated( + const CoreAccountId& account_id, + const std::string& client_id, + const OAuth2AccessTokenManager::ScopeSet& scopes, + const std::string& access_token, + base::OnceClosure callback) { + access_token_invalidated_account_id_ = account_id; + access_token_invalidated_client_id_ = client_id; + access_token_invalidated_scopes_ = scopes; + access_token_invalidated_access_token_ = access_token; + on_access_token_invalidated_callback_ = std::move(callback); + } + + void SetOnAccessTokenFetched(const CoreAccountId& account_id, + const GoogleServiceAuthError& error, + base::OnceClosure callback) { + access_token_fetched_account_id_ = account_id; + access_token_fetched_error_ = error; + access_token_fetched_callback_ = std::move(callback); + } + private: scoped_refptr<network::SharedURLLoaderFactory> shared_factory_; + std::map<CoreAccountId, std::string> account_ids_to_refresh_tokens_; + base::OnceClosure access_token_fetch_closure_; + CoreAccountId access_token_invalidated_account_id_; + std::string access_token_invalidated_client_id_; + OAuth2AccessTokenManager::ScopeSet access_token_invalidated_scopes_; + std::string access_token_invalidated_access_token_; + base::OnceClosure on_access_token_invalidated_callback_; + CoreAccountId access_token_fetched_account_id_; + GoogleServiceAuthError access_token_fetched_error_; + base::OnceClosure access_token_fetched_callback_; }; class FakeOAuth2AccessTokenManagerConsumer @@ -84,14 +166,114 @@ class FakeOAuth2AccessTokenManagerConsumer base::OnceClosure closure_; }; +class DiagnosticsObserverForTesting + : public OAuth2AccessTokenManager::DiagnosticsObserver { + public: + // OAuth2AccessTokenManager::DiagnosticsObserver: + void OnAccessTokenRequested( + const CoreAccountId& account_id, + const std::string& consumer_id, + const OAuth2AccessTokenManager::ScopeSet& scopes) override { + if (!access_token_requested_callback_) + return; + EXPECT_EQ(access_token_requested_account_id_, account_id); + EXPECT_EQ(access_token_requested_consumer_id_, consumer_id); + EXPECT_EQ(access_token_requested_scopes_, scopes); + std::move(access_token_requested_callback_).Run(); + } + void OnFetchAccessTokenComplete( + const CoreAccountId& account_id, + const std::string& consumer_id, + const OAuth2AccessTokenManager::ScopeSet& scopes, + GoogleServiceAuthError error, + base::Time expiration_time) override { + if (!fetch_access_token_completed_callback_) + return; + EXPECT_EQ(fetch_access_token_completed_account_id_, account_id); + EXPECT_EQ(fetch_access_token_completed_consumer_id_, consumer_id); + EXPECT_EQ(fetch_access_token_completed_scopes_, scopes); + EXPECT_EQ(fetch_access_token_completed_error_, error); + std::move(fetch_access_token_completed_callback_).Run(); + } + void OnAccessTokenRemoved( + const CoreAccountId& account_id, + const OAuth2AccessTokenManager::ScopeSet& scopes) override { + if (!access_token_removed_callback_) + return; + auto iterator = access_token_removed_account_to_scopes_.find(account_id); + EXPECT_NE(iterator, access_token_removed_account_to_scopes_.end()); + EXPECT_EQ(iterator->second, scopes); + access_token_removed_account_to_scopes_.erase(iterator); + + if (access_token_removed_account_to_scopes_.empty()) + std::move(access_token_removed_callback_).Run(); + } + + void SetOnAccessTokenRequested( + const CoreAccountId& account_id, + const std::string& consumer_id, + const OAuth2AccessTokenManager::ScopeSet& scopes, + base::OnceClosure callback) { + access_token_requested_account_id_ = account_id; + access_token_requested_consumer_id_ = consumer_id; + access_token_requested_scopes_ = scopes; + access_token_requested_callback_ = std::move(callback); + } + void SetOnFetchAccessTokenComplete( + const CoreAccountId& account_id, + const std::string& consumer_id, + const OAuth2AccessTokenManager::ScopeSet& scopes, + GoogleServiceAuthError error, + base::OnceClosure callback) { + fetch_access_token_completed_account_id_ = account_id; + fetch_access_token_completed_consumer_id_ = consumer_id; + fetch_access_token_completed_scopes_ = scopes; + fetch_access_token_completed_error_ = error; + fetch_access_token_completed_callback_ = std::move(callback); + } + + typedef std::map<CoreAccountId, OAuth2AccessTokenManager::ScopeSet> + AccountToScopeSet; + // OnAccessTokenRemoved() can be invoked multiple times as part of a given + // test expectation (e.g., when clearing the cache of multiple tokens). To + // support this, this method takes in a map of account IDs to scopesets, and + // OnAccessTokenRemoved() invokes |callback| only once invocations of it have + // occurred for all of the (account_id, scopeset) pairs in + // |account_to_scopeset|. + void SetOnAccessTokenRemoved(const AccountToScopeSet& account_to_scopeset, + base::OnceClosure callback) { + access_token_removed_account_to_scopes_ = account_to_scopeset; + access_token_removed_callback_ = std::move(callback); + } + + private: + CoreAccountId access_token_requested_account_id_; + std::string access_token_requested_consumer_id_; + OAuth2AccessTokenManager::ScopeSet access_token_requested_scopes_; + base::OnceClosure access_token_requested_callback_; + CoreAccountId fetch_access_token_completed_account_id_; + std::string fetch_access_token_completed_consumer_id_; + OAuth2AccessTokenManager::ScopeSet fetch_access_token_completed_scopes_; + GoogleServiceAuthError fetch_access_token_completed_error_; + base::OnceClosure fetch_access_token_completed_callback_; + AccountToScopeSet access_token_removed_account_to_scopes_; + base::OnceClosure access_token_removed_callback_; +}; + } // namespace +// Any public API surfaces that are wrapped by ProfileOAuth2TokenService are +// unittested as part of the unittests of that class. + class OAuth2AccessTokenManagerTest : public testing::Test { public: OAuth2AccessTokenManagerTest() : delegate_(&test_url_loader_factory_), token_manager_(&delegate_) {} - void SetUp() override { account_id_ = CoreAccountId(kTestAccountId); } + void SetUp() override { + account_id_ = CoreAccountId(kTestAccountId); + delegate_.AddAccount(account_id_, "fake_refresh_token"); + } void TearDown() override { // Makes sure that all the clean up tasks are run. It's required because of @@ -106,8 +288,18 @@ class OAuth2AccessTokenManagerTest : public testing::Test { GaiaUrls::GetInstance()->oauth2_token_url().spec(), token, status); } + void CreateRequestAndBlockUntilComplete( + const CoreAccountId& account, + const OAuth2AccessTokenManager::ScopeSet& scopeset) { + base::RunLoop run_loop; + consumer_.SetResponseCompletedClosure(run_loop.QuitClosure()); + std::unique_ptr<OAuth2AccessTokenManager::Request> request( + token_manager_.StartRequest(account, scopeset, &consumer_)); + run_loop.Run(); + } + protected: - base::test::ScopedTaskEnvironment scoped_task_environment_; + base::test::TaskEnvironment task_environment_; CoreAccountId account_id_; network::TestURLLoaderFactory test_url_loader_factory_; FakeOAuth2AccessTokenManagerDelegate delegate_; @@ -115,7 +307,7 @@ class OAuth2AccessTokenManagerTest : public testing::Test { FakeOAuth2AccessTokenManagerConsumer consumer_; }; -// Test if StartRequest gets a response properly. +// Test that StartRequest gets a response properly. TEST_F(OAuth2AccessTokenManagerTest, StartRequest) { base::RunLoop run_loop; consumer_.SetResponseCompletedClosure(run_loop.QuitClosure()); @@ -128,3 +320,332 @@ TEST_F(OAuth2AccessTokenManagerTest, StartRequest) { EXPECT_EQ(1, consumer_.number_of_successful_tokens_); EXPECT_EQ(0, consumer_.number_of_errors_); } + +// Test that CancelAllRequests triggers OnGetTokenFailure. +TEST_F(OAuth2AccessTokenManagerTest, CancelAllRequests) { + std::unique_ptr<OAuth2AccessTokenManager::Request> request( + token_manager_.StartRequest( + account_id_, OAuth2AccessTokenManager::ScopeSet(), &consumer_)); + const CoreAccountId account_id_2("account_id_2"); + delegate_.AddAccount(account_id_2, "refreshToken2"); + std::unique_ptr<OAuth2AccessTokenManager::Request> request2( + token_manager_.StartRequest( + account_id_2, OAuth2AccessTokenManager::ScopeSet(), &consumer_)); + + EXPECT_EQ(0, consumer_.number_of_successful_tokens_); + EXPECT_EQ(0, consumer_.number_of_errors_); + + token_manager_.CancelAllRequests(); + + EXPECT_EQ(0, consumer_.number_of_successful_tokens_); + EXPECT_EQ(2, consumer_.number_of_errors_); +} + +// Test that CancelRequestsForAccount cancels requests for the specific account. +TEST_F(OAuth2AccessTokenManagerTest, CancelRequestsForAccount) { + OAuth2AccessTokenManager::ScopeSet scope_set_1; + scope_set_1.insert("scope1"); + scope_set_1.insert("scope2"); + OAuth2AccessTokenManager::ScopeSet scope_set_2(scope_set_1.begin(), + scope_set_1.end()); + scope_set_2.insert("scope3"); + + std::unique_ptr<OAuth2AccessTokenManager::Request> request1( + token_manager_.StartRequest(account_id_, scope_set_1, &consumer_)); + std::unique_ptr<OAuth2AccessTokenManager::Request> request2( + token_manager_.StartRequest(account_id_, scope_set_2, &consumer_)); + + const CoreAccountId account_id_2("account_id_2"); + delegate_.AddAccount(account_id_2, "refreshToken2"); + std::unique_ptr<OAuth2AccessTokenManager::Request> request3( + token_manager_.StartRequest(account_id_2, scope_set_1, &consumer_)); + + EXPECT_EQ(0, consumer_.number_of_successful_tokens_); + EXPECT_EQ(0, consumer_.number_of_errors_); + + token_manager_.CancelRequestsForAccount(account_id_); + + EXPECT_EQ(0, consumer_.number_of_successful_tokens_); + EXPECT_EQ(2, consumer_.number_of_errors_); + + token_manager_.CancelRequestsForAccount(account_id_2); + + EXPECT_EQ(0, consumer_.number_of_successful_tokens_); + EXPECT_EQ(3, consumer_.number_of_errors_); +} + +// Test that StartRequest fetches a network request after ClearCache. +TEST_F(OAuth2AccessTokenManagerTest, ClearCache) { + base::RunLoop run_loop1; + consumer_.SetResponseCompletedClosure(run_loop1.QuitClosure()); + + std::set<std::string> scope_list; + scope_list.insert("scope"); + std::unique_ptr<OAuth2AccessTokenManager::Request> request( + token_manager_.StartRequest(account_id_, scope_list, &consumer_)); + SimulateOAuthTokenResponse(GetValidTokenResponse("token", 3600)); + run_loop1.Run(); + + EXPECT_EQ(1, consumer_.number_of_successful_tokens_); + EXPECT_EQ(0, consumer_.number_of_errors_); + EXPECT_EQ("token", consumer_.last_token_); + EXPECT_EQ(1U, token_manager_.token_cache().size()); + + token_manager_.ClearCache(); + + EXPECT_EQ(0U, token_manager_.token_cache().size()); + base::RunLoop run_loop2; + consumer_.SetResponseCompletedClosure(run_loop2.QuitClosure()); + + SimulateOAuthTokenResponse(GetValidTokenResponse("another token", 3600)); + request = token_manager_.StartRequest(account_id_, scope_list, &consumer_); + run_loop2.Run(); + EXPECT_EQ(2, consumer_.number_of_successful_tokens_); + EXPECT_EQ(0, consumer_.number_of_errors_); + EXPECT_EQ("another token", consumer_.last_token_); + EXPECT_EQ(1U, token_manager_.token_cache().size()); +} + +// Test that ClearCacheForAccount clears caches for the specific account. +TEST_F(OAuth2AccessTokenManagerTest, ClearCacheForAccount) { + base::RunLoop run_loop1; + consumer_.SetResponseCompletedClosure(run_loop1.QuitClosure()); + + std::unique_ptr<OAuth2AccessTokenManager::Request> request1( + token_manager_.StartRequest( + account_id_, OAuth2AccessTokenManager::ScopeSet(), &consumer_)); + SimulateOAuthTokenResponse(GetValidTokenResponse("token", 3600)); + run_loop1.Run(); + + EXPECT_EQ(1, consumer_.number_of_successful_tokens_); + EXPECT_EQ(0, consumer_.number_of_errors_); + EXPECT_EQ("token", consumer_.last_token_); + EXPECT_EQ(1U, token_manager_.token_cache().size()); + + base::RunLoop run_loop2; + consumer_.SetResponseCompletedClosure(run_loop2.QuitClosure()); + const CoreAccountId account_id_2("account_id_2"); + delegate_.AddAccount(account_id_2, "refreshToken2"); + // Makes a request for |account_id_2|. + std::unique_ptr<OAuth2AccessTokenManager::Request> request2( + token_manager_.StartRequest( + account_id_2, OAuth2AccessTokenManager::ScopeSet(), &consumer_)); + run_loop2.Run(); + + EXPECT_EQ(2, consumer_.number_of_successful_tokens_); + EXPECT_EQ(0, consumer_.number_of_errors_); + EXPECT_EQ("token", consumer_.last_token_); + EXPECT_EQ(2U, token_manager_.token_cache().size()); + + // Clears caches for |account_id_|. + token_manager_.ClearCacheForAccount(account_id_); + EXPECT_EQ(1U, token_manager_.token_cache().size()); + + base::RunLoop run_loop3; + consumer_.SetResponseCompletedClosure(run_loop3.QuitClosure()); + SimulateOAuthTokenResponse(GetValidTokenResponse("another token", 3600)); + // Makes a request for |account_id_| again. + std::unique_ptr<OAuth2AccessTokenManager::Request> request3( + token_manager_.StartRequest( + account_id_, OAuth2AccessTokenManager::ScopeSet(), &consumer_)); + run_loop3.Run(); + + EXPECT_EQ(3, consumer_.number_of_successful_tokens_); + EXPECT_EQ(0, consumer_.number_of_errors_); + EXPECT_EQ("another token", consumer_.last_token_); + EXPECT_EQ(2U, token_manager_.token_cache().size()); + + // Clears caches for |account_id_|. + token_manager_.ClearCacheForAccount(account_id_); + EXPECT_EQ(1U, token_manager_.token_cache().size()); + + // Clears caches for |account_id_2|. + token_manager_.ClearCacheForAccount(account_id_2); + EXPECT_EQ(0U, token_manager_.token_cache().size()); +} + +// Test that StartRequest checks HandleAccessTokenFetch() from |delegate_| +// before FetchOAuth2Token. +TEST_F(OAuth2AccessTokenManagerTest, HandleAccessTokenFetch) { + base::RunLoop run_loop; + delegate_.SetAccessTokenHandleClosure(run_loop.QuitClosure()); + std::unique_ptr<OAuth2AccessTokenManager::Request> request( + token_manager_.StartRequest( + account_id_, OAuth2AccessTokenManager::ScopeSet(), &consumer_)); + SimulateOAuthTokenResponse(GetValidTokenResponse("token", 3600)); + run_loop.Run(); + + EXPECT_EQ(0, consumer_.number_of_successful_tokens_); + EXPECT_EQ(0, consumer_.number_of_errors_); + EXPECT_EQ(0U, token_manager_.GetNumPendingRequestsForTesting( + GaiaUrls::GetInstance()->oauth2_chrome_client_id(), + account_id_, OAuth2AccessTokenManager::ScopeSet())); +} + +// Test that InvalidateAccessToken triggers OnAccessTokenInvalidated. +TEST_F(OAuth2AccessTokenManagerTest, OnAccessTokenInvalidated) { + base::RunLoop run_loop; + OAuth2AccessTokenManager::ScopeSet scope_set; + scope_set.insert("scope"); + std::string access_token("access_token"); + delegate_.SetOnAccessTokenInvalidated( + account_id_, GaiaUrls::GetInstance()->oauth2_chrome_client_id(), + scope_set, access_token, run_loop.QuitClosure()); + token_manager_.InvalidateAccessToken(account_id_, scope_set, access_token); + run_loop.Run(); +} + +// Test that OnAccessTokenFetched is invoked when a request is canceled. +TEST_F(OAuth2AccessTokenManagerTest, OnAccessTokenFetchedOnRequestCanceled) { + base::RunLoop run_loop; + GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); + delegate_.SetOnAccessTokenFetched(account_id_, error, run_loop.QuitClosure()); + std::unique_ptr<OAuth2AccessTokenManager::Request> request( + token_manager_.StartRequest( + account_id_, OAuth2AccessTokenManager::ScopeSet(), &consumer_)); + token_manager_.CancelAllRequests(); + run_loop.Run(); +} + +// Test that OnAccessTokenFetched is invoked when a request is completed. +TEST_F(OAuth2AccessTokenManagerTest, OnAccessTokenFetchedOnRequestCompleted) { + base::RunLoop run_loop; + GoogleServiceAuthError error(GoogleServiceAuthError::NONE); + delegate_.SetOnAccessTokenFetched(account_id_, error, run_loop.QuitClosure()); + std::unique_ptr<OAuth2AccessTokenManager::Request> request( + token_manager_.StartRequest( + account_id_, OAuth2AccessTokenManager::ScopeSet(), &consumer_)); + SimulateOAuthTokenResponse(GetValidTokenResponse("token", 3600)); + run_loop.Run(); +} + +// Test that StartRequest triggers DiagnosticsObserver::OnAccessTokenRequested. +TEST_F(OAuth2AccessTokenManagerTest, OnAccessTokenRequested) { + DiagnosticsObserverForTesting observer; + OAuth2AccessTokenManager::ScopeSet scopeset; + scopeset.insert("scope"); + base::RunLoop run_loop; + observer.SetOnAccessTokenRequested(account_id_, consumer_.id(), scopeset, + run_loop.QuitClosure()); + token_manager_.AddDiagnosticsObserver(&observer); + + std::unique_ptr<OAuth2AccessTokenManager::Request> request( + token_manager_.StartRequest(account_id_, scopeset, &consumer_)); + run_loop.Run(); + token_manager_.RemoveDiagnosticsObserver(&observer); +} + +// Test that DiagnosticsObserver::OnFetchAccessTokenComplete is invoked when a +// request is completed. +TEST_F(OAuth2AccessTokenManagerTest, + OnFetchAccessTokenCompleteOnRequestCompleted) { + DiagnosticsObserverForTesting observer; + OAuth2AccessTokenManager::ScopeSet scopeset; + scopeset.insert("scope"); + base::RunLoop run_loop; + GoogleServiceAuthError error(GoogleServiceAuthError::NONE); + observer.SetOnFetchAccessTokenComplete(account_id_, consumer_.id(), scopeset, + error, run_loop.QuitClosure()); + token_manager_.AddDiagnosticsObserver(&observer); + SimulateOAuthTokenResponse(GetValidTokenResponse("token", 3600)); + + std::unique_ptr<OAuth2AccessTokenManager::Request> request( + token_manager_.StartRequest(account_id_, scopeset, &consumer_)); + run_loop.Run(); + token_manager_.RemoveDiagnosticsObserver(&observer); +} + +// Test that DiagnosticsObserver::OnFetchAccessTokenComplete is invoked when +// StartRequest is called for an account without a refresh token. +TEST_F(OAuth2AccessTokenManagerTest, + OnFetchAccessTokenCompleteOnRequestWithoutRefreshToken) { + DiagnosticsObserverForTesting observer; + OAuth2AccessTokenManager::ScopeSet scopeset; + scopeset.insert("scope"); + base::RunLoop run_loop; + // |account_id| doesn't have a refresh token, OnFetchAccessTokenComplete + // should report GoogleServiceAuthError::USER_NOT_SIGNED_UP. + GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); + const CoreAccountId account_id("new_account_id"); + observer.SetOnFetchAccessTokenComplete(account_id, consumer_.id(), scopeset, + error, run_loop.QuitClosure()); + token_manager_.AddDiagnosticsObserver(&observer); + + std::unique_ptr<OAuth2AccessTokenManager::Request> request( + token_manager_.StartRequest(account_id, scopeset, &consumer_)); + run_loop.Run(); + token_manager_.RemoveDiagnosticsObserver(&observer); +} + +// Test that DiagnosticsObserver::OnAccessTokenRemoved is called when a token is +// removed from the token cache. +TEST_F(OAuth2AccessTokenManagerTest, OnAccessTokenRemoved) { + const std::string access_token("token"); + SimulateOAuthTokenResponse(GetValidTokenResponse(access_token, 3600)); + + // First populate the cache with access tokens for four accounts. + OAuth2AccessTokenManager::ScopeSet scopeset1; + scopeset1.insert("scope1"); + CreateRequestAndBlockUntilComplete(account_id_, scopeset1); + + OAuth2AccessTokenManager::ScopeSet scopeset2; + scopeset2.insert("scope2"); + CoreAccountId account_id_2("account_id_2"); + delegate_.AddAccount(account_id_2, "refreshToken2"); + CreateRequestAndBlockUntilComplete(account_id_2, scopeset2); + + OAuth2AccessTokenManager::ScopeSet scopeset3; + scopeset3.insert("scope3"); + CoreAccountId account_id_3("account_id_3"); + delegate_.AddAccount(account_id_3, "refreshToken3"); + CreateRequestAndBlockUntilComplete(account_id_3, scopeset3); + + OAuth2AccessTokenManager::ScopeSet scopeset4; + scopeset4.insert("scope4"); + CoreAccountId account_id_4("account_id_4"); + delegate_.AddAccount(account_id_4, "refreshToken4"); + CreateRequestAndBlockUntilComplete(account_id_4, scopeset4); + + EXPECT_EQ(4, consumer_.number_of_successful_tokens_); + EXPECT_EQ(0, consumer_.number_of_errors_); + EXPECT_EQ("token", consumer_.last_token_); + EXPECT_EQ(4U, token_manager_.token_cache().size()); + + DiagnosticsObserverForTesting observer; + token_manager_.AddDiagnosticsObserver(&observer); + + DiagnosticsObserverForTesting::AccountToScopeSet account_to_scopeset; + + // ClearCacheForAccount should call OnAccessTokenRemoved. + base::RunLoop run_loop1; + account_to_scopeset[account_id_] = scopeset1; + observer.SetOnAccessTokenRemoved(account_to_scopeset, + run_loop1.QuitClosure()); + token_manager_.ClearCacheForAccount(account_id_); + run_loop1.Run(); + EXPECT_EQ(3U, token_manager_.token_cache().size()); + + // InvalidateAccessToken should call OnAccessTokenRemoved for the cached + // token. + base::RunLoop run_loop2; + account_to_scopeset.clear(); + account_to_scopeset[account_id_2] = scopeset2; + observer.SetOnAccessTokenRemoved(account_to_scopeset, + run_loop2.QuitClosure()); + token_manager_.InvalidateAccessToken(account_id_2, scopeset2, access_token); + run_loop2.Run(); + EXPECT_EQ(2U, token_manager_.token_cache().size()); + + // ClearCache should call OnAccessTokenRemoved for all of the cached tokens. + base::RunLoop run_loop3; + account_to_scopeset.clear(); + account_to_scopeset[account_id_3] = scopeset3; + account_to_scopeset[account_id_4] = scopeset4; + observer.SetOnAccessTokenRemoved(account_to_scopeset, + run_loop3.QuitClosure()); + token_manager_.ClearCache(); + run_loop3.Run(); + EXPECT_EQ(0U, token_manager_.token_cache().size()); + + token_manager_.RemoveDiagnosticsObserver(&observer); +} diff --git a/chromium/google_apis/gaia/oauth2_api_call_flow.cc b/chromium/google_apis/gaia/oauth2_api_call_flow.cc index 14c637d27b1..7ef2fdda4d1 100644 --- a/chromium/google_apis/gaia/oauth2_api_call_flow.cc +++ b/chromium/google_apis/gaia/oauth2_api_call_flow.cc @@ -89,8 +89,7 @@ std::unique_ptr<network::SimpleURLLoader> OAuth2ApiCallFlow::CreateURLLoader( auto request = std::make_unique<network::ResourceRequest>(); request->url = CreateApiCallUrl(); request->method = request_type; - request->load_flags = - net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES; + request->credentials_mode = network::mojom::CredentialsMode::kOmit; request->headers.SetHeader("Authorization", MakeAuthorizationValue(access_token)); std::unique_ptr<network::SimpleURLLoader> result = diff --git a/chromium/google_apis/gaia/oauth2_api_call_flow_unittest.cc b/chromium/google_apis/gaia/oauth2_api_call_flow_unittest.cc index 1a9ba7911b3..4d1c16a6b4d 100644 --- a/chromium/google_apis/gaia/oauth2_api_call_flow_unittest.cc +++ b/chromium/google_apis/gaia/oauth2_api_call_flow_unittest.cc @@ -11,7 +11,7 @@ #include <utility> #include "base/run_loop.h" -#include "base/test/scoped_task_environment.h" +#include "base/test/task_environment.h" #include "base/time/time.h" #include "google_apis/gaia/gaia_urls.h" #include "google_apis/gaia/google_service_auth_error.h" @@ -100,7 +100,7 @@ class OAuth2ApiCallFlowTest : public testing::Test { AddFetchResult(url, succeeds, status, std::string()); } - base::test::ScopedTaskEnvironment scoped_task_environment_; + base::test::SingleThreadTaskEnvironment task_environment_; network::TestURLLoaderFactory test_url_loader_factory_; scoped_refptr<network::SharedURLLoaderFactory> shared_factory_; StrictMock<MockApiCallFlow> flow_; diff --git a/chromium/google_apis/gaia/oauth2_mint_token_flow.cc b/chromium/google_apis/gaia/oauth2_mint_token_flow.cc index 216afac40b3..98d8da5fd56 100644 --- a/chromium/google_apis/gaia/oauth2_mint_token_flow.cc +++ b/chromium/google_apis/gaia/oauth2_mint_token_flow.cc @@ -128,8 +128,7 @@ OAuth2MintTokenFlow::Parameters::~Parameters() {} OAuth2MintTokenFlow::OAuth2MintTokenFlow(Delegate* delegate, const Parameters& parameters) - : delegate_(delegate), parameters_(parameters), weak_factory_(this) { -} + : delegate_(delegate), parameters_(parameters) {} OAuth2MintTokenFlow::~OAuth2MintTokenFlow() { } diff --git a/chromium/google_apis/gaia/oauth2_mint_token_flow.h b/chromium/google_apis/gaia/oauth2_mint_token_flow.h index 4a50391d8be..caed408fb46 100644 --- a/chromium/google_apis/gaia/oauth2_mint_token_flow.h +++ b/chromium/google_apis/gaia/oauth2_mint_token_flow.h @@ -131,7 +131,7 @@ class OAuth2MintTokenFlow : public OAuth2ApiCallFlow { Delegate* delegate_; Parameters parameters_; - base::WeakPtrFactory<OAuth2MintTokenFlow> weak_factory_; + base::WeakPtrFactory<OAuth2MintTokenFlow> weak_factory_{this}; DISALLOW_COPY_AND_ASSIGN(OAuth2MintTokenFlow); }; diff --git a/chromium/google_apis/gaia/oauth2_token_service_observer.h b/chromium/google_apis/gaia/oauth2_token_service_observer.h deleted file mode 100644 index bbbd1968244..00000000000 --- a/chromium/google_apis/gaia/oauth2_token_service_observer.h +++ /dev/null @@ -1,43 +0,0 @@ -// 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 GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_OBSERVER_H_ -#define GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_OBSERVER_H_ - -#include "google_apis/gaia/core_account_id.h" -#include "google_apis/gaia/google_service_auth_error.h" - -// Classes that want to listen for refresh token availability should -// implement this interface and register with the OAuth2TokenService:: -// AddObserver() call. -class OAuth2TokenServiceObserver { - public: - // Called whenever a new login-scoped refresh token is available for - // account |account_id|. Once available, access tokens can be retrieved for - // this account. This is called during initial startup for each token - // loaded (and any time later when, e.g., credentials change). When called, - // any pending token request is cancelled and needs to be retried. Such a - // pending request can easily occur on Android, where refresh tokens are - // held by the OS and are thus often available on startup even before - // OnRefreshTokenAvailable() is called. - virtual void OnRefreshTokenAvailable(const CoreAccountId& account_id) {} - // Called whenever the login-scoped refresh token becomes unavailable for - // account |account_id|. - virtual void OnRefreshTokenRevoked(const CoreAccountId& account_id) {} - // Called after all refresh tokens are loaded during OAuth2TokenService - // startup. - virtual void OnRefreshTokensLoaded() {} - // Sent after a batch of refresh token changes is done. - virtual void OnEndBatchChanges() {} - // Called when the authentication error state for |account_id| has changed. - // Note: It is always called after |OnRefreshTokenAvailable| when refresh - // token is updated. It is not called when the refresh token is revoked. - virtual void OnAuthErrorChanged(const CoreAccountId& account_id, - const GoogleServiceAuthError& auth_error) {} - - protected: - virtual ~OAuth2TokenServiceObserver() {} -}; - -#endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_OBSERVER_H_ diff --git a/chromium/google_apis/gcm/BUILD.gn b/chromium/google_apis/gcm/BUILD.gn index fc9fe079349..5c865139e91 100644 --- a/chromium/google_apis/gcm/BUILD.gn +++ b/chromium/google_apis/gcm/BUILD.gn @@ -62,6 +62,7 @@ component("gcm") { public_deps = [ ":proto", + "//google_apis", ] deps = [ "//base", @@ -165,6 +166,7 @@ test("gcm_unit_tests") { ":test_support", "//base", "//base/test:test_support", + "//google_apis", "//google_apis:run_all_unittests", "//mojo/public/cpp/system:system", "//net", diff --git a/chromium/google_apis/gcm/OWNERS b/chromium/google_apis/gcm/OWNERS index f81b5f54052..1ef66754b90 100644 --- a/chromium/google_apis/gcm/OWNERS +++ b/chromium/google_apis/gcm/OWNERS @@ -3,3 +3,4 @@ peter@chromium.org zea@chromium.org # COMPONENT: Services>CloudMessaging +# TEAM: platform-capabilities@chromium.org diff --git a/chromium/google_apis/gcm/base/socket_stream.cc b/chromium/google_apis/gcm/base/socket_stream.cc index 8038dc0ed05..d9759e76777 100644 --- a/chromium/google_apis/gcm/base/socket_stream.cc +++ b/chromium/google_apis/gcm/base/socket_stream.cc @@ -30,8 +30,7 @@ SocketInputStream::SocketInputStream(mojo::ScopedDataPipeConsumerHandle stream) base::MakeRefCounted<net::DrainableIOBuffer>(io_buffer_, kDefaultBufferSize)), next_pos_(0), - last_error_(net::OK), - weak_ptr_factory_(this) { + last_error_(net::OK) { stream_watcher_.Watch( stream_.get(), MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, @@ -226,8 +225,7 @@ SocketOutputStream::SocketOutputStream( io_buffer_( base::MakeRefCounted<net::IOBufferWithSize>(kDefaultBufferSize)), next_pos_(0), - last_error_(net::OK), - weak_ptr_factory_(this) { + last_error_(net::OK) { stream_watcher_.Watch( stream_.get(), MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, diff --git a/chromium/google_apis/gcm/base/socket_stream.h b/chromium/google_apis/gcm/base/socket_stream.h index 63556b292e3..109f4168d9e 100644 --- a/chromium/google_apis/gcm/base/socket_stream.h +++ b/chromium/google_apis/gcm/base/socket_stream.h @@ -128,7 +128,7 @@ class GCM_EXPORT SocketInputStream // Note: last_error_ == net::ERR_IO_PENDING implies GetState() == READING. net::Error last_error_; - base::WeakPtrFactory<SocketInputStream> weak_ptr_factory_; + base::WeakPtrFactory<SocketInputStream> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(SocketInputStream); }; @@ -201,7 +201,7 @@ class GCM_EXPORT SocketOutputStream // Note: last_error_ == net::ERR_IO_PENDING implies GetState() == FLUSHING. net::Error last_error_; - base::WeakPtrFactory<SocketOutputStream> weak_ptr_factory_; + base::WeakPtrFactory<SocketOutputStream> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(SocketOutputStream); }; diff --git a/chromium/google_apis/gcm/base/socket_stream_unittest.cc b/chromium/google_apis/gcm/base/socket_stream_unittest.cc index 0c7000072f9..e1d4f90d648 100644 --- a/chromium/google_apis/gcm/base/socket_stream_unittest.cc +++ b/chromium/google_apis/gcm/base/socket_stream_unittest.cc @@ -17,7 +17,7 @@ #include "base/stl_util.h" #include "base/strings/string_piece.h" #include "base/test/bind_test_util.h" -#include "base/test/scoped_task_environment.h" +#include "base/test/task_environment.h" #include "net/base/ip_address.h" #include "net/log/net_log_source.h" #include "net/socket/socket_test_util.h" @@ -79,7 +79,7 @@ class GCMSocketStreamTest : public testing::Test { void ResetInputStream(); void ResetOutputStream(); - base::test::ScopedTaskEnvironment scoped_task_environment_; + base::test::TaskEnvironment task_environment_; // SocketStreams and their data providers. ReadList mock_reads_; @@ -103,8 +103,7 @@ class GCMSocketStreamTest : public testing::Test { }; GCMSocketStreamTest::GCMSocketStreamTest() - : scoped_task_environment_( - base::test::ScopedTaskEnvironment::MainThreadType::IO), + : task_environment_(base::test::TaskEnvironment::MainThreadType::IO), network_change_notifier_(net::NetworkChangeNotifier::CreateMock()), network_service_(network::NetworkService::CreateForTesting()), url_request_context_(true /* delay_initialization */) { diff --git a/chromium/google_apis/gcm/engine/account_mapping.h b/chromium/google_apis/gcm/engine/account_mapping.h index bfd25a70212..b64425b9c8e 100644 --- a/chromium/google_apis/gcm/engine/account_mapping.h +++ b/chromium/google_apis/gcm/engine/account_mapping.h @@ -8,6 +8,7 @@ #include <string> #include "base/time/time.h" +#include "google_apis/gaia/core_account_id.h" #include "google_apis/gcm/base/gcm_export.h" namespace gcm { @@ -37,8 +38,8 @@ struct GCM_EXPORT AccountMapping { // |status| is infered. bool ParseFromString(const std::string& value); - // Gaia ID of the account. (Acts as key for persistence.) - std::string account_id; + // Account Id of the account. (Acts as key for persistence.) + CoreAccountId account_id; // Email address of the tracked account. std::string email; // OAuth2 access token used to authenticate mappings (not persisted). diff --git a/chromium/google_apis/gcm/engine/checkin_request.cc b/chromium/google_apis/gcm/engine/checkin_request.cc index 031a05fe1ea..a0999b69cf3 100644 --- a/chromium/google_apis/gcm/engine/checkin_request.cc +++ b/chromium/google_apis/gcm/engine/checkin_request.cc @@ -110,8 +110,7 @@ CheckinRequest::CheckinRequest( checkin_url_(checkin_url), request_info_(request_info), io_task_runner_(std::move(io_task_runner)), - recorder_(recorder), - weak_ptr_factory_(this) { + recorder_(recorder) { DCHECK(io_task_runner_); } @@ -184,8 +183,7 @@ void CheckinRequest::Start() { auto resource_request = std::make_unique<network::ResourceRequest>(); resource_request->url = checkin_url_; resource_request->method = "POST"; - resource_request->load_flags = - net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES; + resource_request->credentials_mode = network::mojom::CredentialsMode::kOmit; url_loader_ = network::SimpleURLLoader::Create(std::move(resource_request), traffic_annotation); url_loader_->AttachStringForUpload(upload_data, kRequestContentType); diff --git a/chromium/google_apis/gcm/engine/checkin_request.h b/chromium/google_apis/gcm/engine/checkin_request.h index eb00a26cc6e..bd1b2853c37 100644 --- a/chromium/google_apis/gcm/engine/checkin_request.h +++ b/chromium/google_apis/gcm/engine/checkin_request.h @@ -98,7 +98,7 @@ class GCM_EXPORT CheckinRequest { // Recorder that records GCM activities for debugging purpose. Not owned. GCMStatsRecorder* recorder_; - base::WeakPtrFactory<CheckinRequest> weak_ptr_factory_; + base::WeakPtrFactory<CheckinRequest> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(CheckinRequest); }; diff --git a/chromium/google_apis/gcm/engine/connection_factory_impl.cc b/chromium/google_apis/gcm/engine/connection_factory_impl.cc index 790b9a88b0b..98ef194babb 100644 --- a/chromium/google_apis/gcm/engine/connection_factory_impl.cc +++ b/chromium/google_apis/gcm/engine/connection_factory_impl.cc @@ -68,8 +68,7 @@ ConnectionFactoryImpl::ConnectionFactoryImpl( io_task_runner_(std::move(io_task_runner)), recorder_(recorder), network_connection_tracker_(network_connection_tracker), - listener_(nullptr), - weak_ptr_factory_(this) { + listener_(nullptr) { DCHECK_GE(mcs_endpoints_.size(), 1U); DCHECK(io_task_runner_); } diff --git a/chromium/google_apis/gcm/engine/connection_factory_impl.h b/chromium/google_apis/gcm/engine/connection_factory_impl.h index bbce25fee1c..2dbcbc1af64 100644 --- a/chromium/google_apis/gcm/engine/connection_factory_impl.h +++ b/chromium/google_apis/gcm/engine/connection_factory_impl.h @@ -194,7 +194,7 @@ class GCM_EXPORT ConnectionFactoryImpl // The currently registered listener to notify of connection changes. ConnectionListener* listener_; - base::WeakPtrFactory<ConnectionFactoryImpl> weak_ptr_factory_; + base::WeakPtrFactory<ConnectionFactoryImpl> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(ConnectionFactoryImpl); }; diff --git a/chromium/google_apis/gcm/engine/connection_factory_impl_unittest.cc b/chromium/google_apis/gcm/engine/connection_factory_impl_unittest.cc index 22e09f985a3..6d10cfd8cd8 100644 --- a/chromium/google_apis/gcm/engine/connection_factory_impl_unittest.cc +++ b/chromium/google_apis/gcm/engine/connection_factory_impl_unittest.cc @@ -12,8 +12,8 @@ #include "base/message_loop/message_loop.h" #include "base/optional.h" #include "base/run_loop.h" -#include "base/test/scoped_task_environment.h" #include "base/test/simple_test_tick_clock.h" +#include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "google_apis/gcm/base/mcs_util.h" #include "google_apis/gcm/engine/fake_connection_handler.h" @@ -301,7 +301,7 @@ class ConnectionFactoryImplTest std::unique_ptr<network::TestNetworkConnectionTracker> network_connection_tracker_; - base::test::ScopedTaskEnvironment scoped_task_environment_; + base::test::TaskEnvironment task_environment_; TestConnectionFactoryImpl factory_; std::unique_ptr<base::RunLoop> run_loop_; @@ -315,8 +315,7 @@ class ConnectionFactoryImplTest ConnectionFactoryImplTest::ConnectionFactoryImplTest() : network_connection_tracker_( network::TestNetworkConnectionTracker::CreateInstance()), - scoped_task_environment_( - base::test::ScopedTaskEnvironment::MainThreadType::IO), + task_environment_(base::test::TaskEnvironment::MainThreadType::IO), factory_(base::BindRepeating( &ConnectionFactoryImplTest::GetProxyResolvingSocketFactory, base::Unretained(this)), diff --git a/chromium/google_apis/gcm/engine/connection_handler_impl.cc b/chromium/google_apis/gcm/engine/connection_handler_impl.cc index b5e04813201..e80aff5545f 100644 --- a/chromium/google_apis/gcm/engine/connection_handler_impl.cc +++ b/chromium/google_apis/gcm/engine/connection_handler_impl.cc @@ -58,8 +58,7 @@ ConnectionHandlerImpl::ConnectionHandlerImpl( read_callback_(read_callback), write_callback_(write_callback), connection_callback_(connection_callback), - size_packet_so_far_(0), - weak_ptr_factory_(this) { + size_packet_so_far_(0) { DCHECK(io_task_runner_); DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); } diff --git a/chromium/google_apis/gcm/engine/connection_handler_impl.h b/chromium/google_apis/gcm/engine/connection_handler_impl.h index 13a482cd97d..251063785b6 100644 --- a/chromium/google_apis/gcm/engine/connection_handler_impl.h +++ b/chromium/google_apis/gcm/engine/connection_handler_impl.h @@ -135,7 +135,7 @@ class GCM_EXPORT ConnectionHandlerImpl : public ConnectionHandler { // will be empty otherwise). std::vector<uint8_t> payload_input_buffer_; - base::WeakPtrFactory<ConnectionHandlerImpl> weak_ptr_factory_; + base::WeakPtrFactory<ConnectionHandlerImpl> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(ConnectionHandlerImpl); }; diff --git a/chromium/google_apis/gcm/engine/connection_handler_impl_unittest.cc b/chromium/google_apis/gcm/engine/connection_handler_impl_unittest.cc index 09774809095..90533605a44 100644 --- a/chromium/google_apis/gcm/engine/connection_handler_impl_unittest.cc +++ b/chromium/google_apis/gcm/engine/connection_handler_impl_unittest.cc @@ -15,7 +15,7 @@ #include "base/run_loop.h" #include "base/strings/string_number_conversions.h" #include "base/test/bind_test_util.h" -#include "base/test/scoped_task_environment.h" +#include "base/test/task_environment.h" #include "base/test/test_timeouts.h" #include "base/threading/thread_task_runner_handle.h" #include "build/build_config.h" @@ -190,7 +190,7 @@ class GCMConnectionHandlerImplTest : public testing::Test { int last_error_; net::AddressList address_list_; - base::test::ScopedTaskEnvironment scoped_task_environment_; + base::test::TaskEnvironment task_environment_; std::unique_ptr<base::RunLoop> run_loop_; std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_; std::unique_ptr<network::NetworkService> network_service_; @@ -205,8 +205,7 @@ class GCMConnectionHandlerImplTest : public testing::Test { GCMConnectionHandlerImplTest::GCMConnectionHandlerImplTest() : last_error_(0), - scoped_task_environment_( - base::test::ScopedTaskEnvironment::MainThreadType::IO), + task_environment_(base::test::TaskEnvironment::MainThreadType::IO), network_change_notifier_(net::NetworkChangeNotifier::CreateMock()), network_service_(network::NetworkService::CreateForTesting()), url_request_context_(true /* delay_initialization */) { diff --git a/chromium/google_apis/gcm/engine/gcm_request_test_base.cc b/chromium/google_apis/gcm/engine/gcm_request_test_base.cc index 327ad9740a1..2bd18a59d02 100644 --- a/chromium/google_apis/gcm/engine/gcm_request_test_base.cc +++ b/chromium/google_apis/gcm/engine/gcm_request_test_base.cc @@ -129,7 +129,7 @@ void GCMRequestTestBase::FastForwardToTriggerNextRetry() { int next_retry_delay_ms = kDefaultBackoffPolicy.initial_delay_ms; next_retry_delay_ms *= pow(kDefaultBackoffPolicy.multiply_factor, retry_count_); - scoped_task_environment_.FastForwardBy( + task_environment_.FastForwardBy( base::TimeDelta::FromMilliseconds(next_retry_delay_ms)); } diff --git a/chromium/google_apis/gcm/engine/gcm_request_test_base.h b/chromium/google_apis/gcm/engine/gcm_request_test_base.h index a076e4d9338..4fe9ba2f0e2 100644 --- a/chromium/google_apis/gcm/engine/gcm_request_test_base.h +++ b/chromium/google_apis/gcm/engine/gcm_request_test_base.h @@ -7,7 +7,7 @@ #include "base/macros.h" #include "base/memory/ref_counted.h" -#include "base/test/scoped_task_environment.h" +#include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "net/base/backoff_entry.h" #include "services/network/test/test_url_loader_factory.h" @@ -61,8 +61,8 @@ class GCMRequestTestBase : public testing::Test { // Fast forward the timer used in the test to retry the request immediately. void FastForwardToTriggerNextRetry(); - base::test::ScopedTaskEnvironment scoped_task_environment_{ - base::test::ScopedTaskEnvironment::TimeSource::MOCK_TIME}; + base::test::TaskEnvironment task_environment_{ + base::test::TaskEnvironment::TimeSource::MOCK_TIME}; network::TestURLLoaderFactory test_url_loader_factory_; scoped_refptr<network::SharedURLLoaderFactory> shared_factory_; diff --git a/chromium/google_apis/gcm/engine/gcm_store.h b/chromium/google_apis/gcm/engine/gcm_store.h index d9d0595b69f..d48c22acfe6 100644 --- a/chromium/google_apis/gcm/engine/gcm_store.h +++ b/chromium/google_apis/gcm/engine/gcm_store.h @@ -18,6 +18,7 @@ #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/time/time.h" +#include "google_apis/gaia/core_account_id.h" #include "google_apis/gcm/base/gcm_export.h" #include "google_apis/gcm/engine/account_mapping.h" @@ -137,7 +138,7 @@ class GCM_EXPORT GCMStore { // Sets the account information related to device to account mapping. virtual void AddAccountMapping(const AccountMapping& account_mapping, const UpdateCallback& callback) = 0; - virtual void RemoveAccountMapping(const std::string& account_id, + virtual void RemoveAccountMapping(const CoreAccountId& account_id, const UpdateCallback& callback) = 0; // Sets last token fetch time. diff --git a/chromium/google_apis/gcm/engine/gcm_store_impl.cc b/chromium/google_apis/gcm/engine/gcm_store_impl.cc index cc333cdc0ba..07bba2b22cc 100644 --- a/chromium/google_apis/gcm/engine/gcm_store_impl.cc +++ b/chromium/google_apis/gcm/engine/gcm_store_impl.cc @@ -146,12 +146,12 @@ std::string ParseGServiceSettingKey(const std::string& key) { return key.substr(base::size(kGServiceSettingKeyStart) - 1); } -std::string MakeAccountKey(const std::string& account_id) { - return kAccountKeyStart + account_id; +std::string MakeAccountKey(const CoreAccountId& account_id) { + return kAccountKeyStart + account_id.id; } -std::string ParseAccountKey(const std::string& key) { - return key.substr(base::size(kAccountKeyStart) - 1); +CoreAccountId ParseAccountKey(const std::string& key) { + return CoreAccountId(key.substr(base::size(kAccountKeyStart) - 1)); } std::string MakeHeartbeatKey(const std::string& scope) { @@ -223,7 +223,7 @@ class GCMStoreImpl::Backend const UpdateCallback& callback); void AddAccountMapping(const AccountMapping& account_mapping, const UpdateCallback& callback); - void RemoveAccountMapping(const std::string& account_id, + void RemoveAccountMapping(const CoreAccountId& account_id, const UpdateCallback& callback); void SetLastTokenFetchTime(const base::Time& time, const UpdateCallback& callback); @@ -745,7 +745,7 @@ void GCMStoreImpl::Backend::AddAccountMapping( } void GCMStoreImpl::Backend::RemoveAccountMapping( - const std::string& account_id, + const CoreAccountId& account_id, const UpdateCallback& callback) { if (!db_.get()) { LOG(ERROR) << "GCMStore db doesn't exist."; @@ -1181,8 +1181,7 @@ GCMStoreImpl::GCMStoreImpl( : backend_(new Backend(path, base::ThreadTaskRunnerHandle::Get(), std::move(encryptor))), - blocking_task_runner_(blocking_task_runner), - weak_ptr_factory_(this) {} + blocking_task_runner_(blocking_task_runner) {} GCMStoreImpl::~GCMStoreImpl() {} @@ -1342,7 +1341,7 @@ void GCMStoreImpl::AddAccountMapping(const AccountMapping& account_mapping, backend_, account_mapping, callback)); } -void GCMStoreImpl::RemoveAccountMapping(const std::string& account_id, +void GCMStoreImpl::RemoveAccountMapping(const CoreAccountId& account_id, const UpdateCallback& callback) { blocking_task_runner_->PostTask( FROM_HERE, base::BindOnce(&GCMStoreImpl::Backend::RemoveAccountMapping, diff --git a/chromium/google_apis/gcm/engine/gcm_store_impl.h b/chromium/google_apis/gcm/engine/gcm_store_impl.h index 764772c9be1..95a4d673cee 100644 --- a/chromium/google_apis/gcm/engine/gcm_store_impl.h +++ b/chromium/google_apis/gcm/engine/gcm_store_impl.h @@ -90,7 +90,7 @@ class GCM_EXPORT GCMStoreImpl : public GCMStore { // Sets the account information related to device to account mapping. void AddAccountMapping(const AccountMapping& account_mapping, const UpdateCallback& callback) override; - void RemoveAccountMapping(const std::string& account_id, + void RemoveAccountMapping(const CoreAccountId& account_id, const UpdateCallback& callback) override; // Sets last token fetch time. @@ -146,7 +146,7 @@ class GCM_EXPORT GCMStoreImpl : public GCMStore { scoped_refptr<Backend> backend_; scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; - base::WeakPtrFactory<GCMStoreImpl> weak_ptr_factory_; + base::WeakPtrFactory<GCMStoreImpl> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(GCMStoreImpl); }; diff --git a/chromium/google_apis/gcm/engine/gservices_settings.cc b/chromium/google_apis/gcm/engine/gservices_settings.cc index 6de0e1cb6cb..1d53f9f2308 100644 --- a/chromium/google_apis/gcm/engine/gservices_settings.cc +++ b/chromium/google_apis/gcm/engine/gservices_settings.cc @@ -200,7 +200,7 @@ std::string GServicesSettings::CalculateDigest(const SettingsMap& settings) { return digest; } -GServicesSettings::GServicesSettings() : weak_ptr_factory_(this) { +GServicesSettings::GServicesSettings() { digest_ = CalculateDigest(settings_); } diff --git a/chromium/google_apis/gcm/engine/gservices_settings.h b/chromium/google_apis/gcm/engine/gservices_settings.h index 663b8b24b0d..92a96c12d6b 100644 --- a/chromium/google_apis/gcm/engine/gservices_settings.h +++ b/chromium/google_apis/gcm/engine/gservices_settings.h @@ -70,7 +70,7 @@ class GCM_EXPORT GServicesSettings { SettingsMap settings_; // Factory for creating references in callbacks. - base::WeakPtrFactory<GServicesSettings> weak_ptr_factory_; + base::WeakPtrFactory<GServicesSettings> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(GServicesSettings); }; diff --git a/chromium/google_apis/gcm/engine/heartbeat_manager.cc b/chromium/google_apis/gcm/engine/heartbeat_manager.cc index 71e3f0227a6..6da83360aac 100644 --- a/chromium/google_apis/gcm/engine/heartbeat_manager.cc +++ b/chromium/google_apis/gcm/engine/heartbeat_manager.cc @@ -49,8 +49,7 @@ HeartbeatManager::HeartbeatManager( server_interval_ms_(0), client_interval_ms_(0), io_task_runner_(std::move(io_task_runner)), - heartbeat_timer_(new base::RetainingOneShotTimer()), - weak_ptr_factory_(this) { + heartbeat_timer_(new base::RetainingOneShotTimer()) { DCHECK(io_task_runner_); DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); // Set the heartbeat timer task runner to |maybe_power_wrapped_io_task_runner| diff --git a/chromium/google_apis/gcm/engine/heartbeat_manager.h b/chromium/google_apis/gcm/engine/heartbeat_manager.h index a5171141f5b..cdfde43565e 100644 --- a/chromium/google_apis/gcm/engine/heartbeat_manager.h +++ b/chromium/google_apis/gcm/engine/heartbeat_manager.h @@ -137,7 +137,7 @@ class GCM_EXPORT HeartbeatManager : public base::PowerObserver { base::Closure send_heartbeat_callback_; ReconnectCallback trigger_reconnect_callback_; - base::WeakPtrFactory<HeartbeatManager> weak_ptr_factory_; + base::WeakPtrFactory<HeartbeatManager> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(HeartbeatManager); }; diff --git a/chromium/google_apis/gcm/engine/mcs_client.cc b/chromium/google_apis/gcm/engine/mcs_client.cc index 16d98e60542..5597933a765 100644 --- a/chromium/google_apis/gcm/engine/mcs_client.cc +++ b/chromium/google_apis/gcm/engine/mcs_client.cc @@ -181,8 +181,7 @@ MCSClient::MCSClient(const std::string& version_string, io_task_runner_(io_task_runner), heartbeat_manager_(std::move(base::ThreadTaskRunnerHandle::Get()), std::move(io_task_runner)), - recorder_(recorder), - weak_ptr_factory_(this) { + recorder_(recorder) { DCHECK(io_task_runner_); } diff --git a/chromium/google_apis/gcm/engine/mcs_client.h b/chromium/google_apis/gcm/engine/mcs_client.h index 344855ae54c..163b6ead3df 100644 --- a/chromium/google_apis/gcm/engine/mcs_client.h +++ b/chromium/google_apis/gcm/engine/mcs_client.h @@ -309,7 +309,7 @@ class GCM_EXPORT MCSClient { // Recorder that records GCM activities for debugging purpose. Not owned. GCMStatsRecorder* recorder_; - base::WeakPtrFactory<MCSClient> weak_ptr_factory_; + base::WeakPtrFactory<MCSClient> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(MCSClient); }; diff --git a/chromium/google_apis/gcm/engine/mcs_client_unittest.cc b/chromium/google_apis/gcm/engine/mcs_client_unittest.cc index 39c7fd150f9..0d2c1e278b0 100644 --- a/chromium/google_apis/gcm/engine/mcs_client_unittest.cc +++ b/chromium/google_apis/gcm/engine/mcs_client_unittest.cc @@ -17,8 +17,8 @@ #include "base/memory/ptr_util.h" #include "base/run_loop.h" #include "base/strings/string_number_conversions.h" -#include "base/test/scoped_task_environment.h" #include "base/test/simple_test_clock.h" +#include "base/test/task_environment.h" #include "base/timer/timer.h" #include "google_apis/gcm/base/fake_encryptor.h" #include "google_apis/gcm/base/mcs_util.h" @@ -173,7 +173,7 @@ class MCSClientTest : public testing::Test { base::SimpleTestClock clock_; base::ScopedTempDir temp_directory_; - base::test::ScopedTaskEnvironment scoped_task_environment_; + base::test::TaskEnvironment task_environment_; std::unique_ptr<base::RunLoop> run_loop_; std::unique_ptr<GCMStore> gcm_store_; @@ -209,10 +209,9 @@ void MCSClientTest::SetUp() { } void MCSClientTest::BuildMCSClient() { - gcm_store_.reset( - new GCMStoreImpl(temp_directory_.GetPath(), - scoped_task_environment_.GetMainThreadTaskRunner(), - base::WrapUnique<Encryptor>(new FakeEncryptor))); + gcm_store_.reset(new GCMStoreImpl( + temp_directory_.GetPath(), task_environment_.GetMainThreadTaskRunner(), + base::WrapUnique<Encryptor>(new FakeEncryptor))); mcs_client_.reset( new TestMCSClient(&clock_, &connection_factory_, gcm_store_.get(), base::ThreadTaskRunnerHandle::Get(), &recorder_)); diff --git a/chromium/google_apis/gcm/engine/registration_request.cc b/chromium/google_apis/gcm/engine/registration_request.cc index 620e11551fb..1332d87806e 100644 --- a/chromium/google_apis/gcm/engine/registration_request.cc +++ b/chromium/google_apis/gcm/engine/registration_request.cc @@ -135,8 +135,7 @@ RegistrationRequest::RegistrationRequest( retries_left_(max_retry_count), io_task_runner_(io_task_runner), recorder_(recorder), - source_to_record_(source_to_record), - weak_ptr_factory_(this) { + source_to_record_(source_to_record) { DCHECK(io_task_runner_); DCHECK_GE(max_retry_count, 0); } @@ -178,8 +177,7 @@ void RegistrationRequest::Start() { auto request = std::make_unique<network::ResourceRequest>(); request->url = registration_url_; request->method = "POST"; - request->load_flags = - net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES; + request->credentials_mode = network::mojom::CredentialsMode::kOmit; BuildRequestHeaders(&request->headers); std::string body; diff --git a/chromium/google_apis/gcm/engine/registration_request.h b/chromium/google_apis/gcm/engine/registration_request.h index 650290c8898..50afce82e88 100644 --- a/chromium/google_apis/gcm/engine/registration_request.h +++ b/chromium/google_apis/gcm/engine/registration_request.h @@ -158,7 +158,7 @@ class GCM_EXPORT RegistrationRequest { GCMStatsRecorder* recorder_; std::string source_to_record_; - base::WeakPtrFactory<RegistrationRequest> weak_ptr_factory_; + base::WeakPtrFactory<RegistrationRequest> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(RegistrationRequest); }; diff --git a/chromium/google_apis/gcm/engine/registration_request_unittest.cc b/chromium/google_apis/gcm/engine/registration_request_unittest.cc index d325019a275..4df9c22789d 100644 --- a/chromium/google_apis/gcm/engine/registration_request_unittest.cc +++ b/chromium/google_apis/gcm/engine/registration_request_unittest.cc @@ -462,8 +462,8 @@ TEST_F(InstanceIDGetTokenRequestTest, RequestDataAndURL) { const network::ResourceRequest* pending_request; ASSERT_TRUE( test_url_loader_factory()->IsPending(kRegistrationURL, &pending_request)); - EXPECT_TRUE(pending_request->load_flags & net::LOAD_DO_NOT_SEND_COOKIES); - EXPECT_TRUE(pending_request->load_flags & net::LOAD_DO_NOT_SAVE_COOKIES); + EXPECT_EQ(network::mojom::CredentialsMode::kOmit, + pending_request->credentials_mode); // Verify that authorization header was put together properly. const net::HttpRequestHeaders* headers = diff --git a/chromium/google_apis/gcm/engine/unregistration_request.cc b/chromium/google_apis/gcm/engine/unregistration_request.cc index 6bfa4ff697b..e20991b590a 100644 --- a/chromium/google_apis/gcm/engine/unregistration_request.cc +++ b/chromium/google_apis/gcm/engine/unregistration_request.cc @@ -120,8 +120,7 @@ UnregistrationRequest::UnregistrationRequest( retries_left_(max_retry_count), io_task_runner_(io_task_runner), recorder_(recorder), - source_to_record_(source_to_record), - weak_ptr_factory_(this) { + source_to_record_(source_to_record) { DCHECK(io_task_runner_); DCHECK_GE(max_retry_count, 0); } @@ -163,8 +162,7 @@ void UnregistrationRequest::Start() { auto request = std::make_unique<network::ResourceRequest>(); request->url = registration_url_; request->method = "POST"; - request->load_flags = - net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES; + request->credentials_mode = network::mojom::CredentialsMode::kOmit; BuildRequestHeaders(&request->headers); std::string body; diff --git a/chromium/google_apis/gcm/engine/unregistration_request.h b/chromium/google_apis/gcm/engine/unregistration_request.h index eb3ae4242f5..3317a619917 100644 --- a/chromium/google_apis/gcm/engine/unregistration_request.h +++ b/chromium/google_apis/gcm/engine/unregistration_request.h @@ -153,7 +153,7 @@ class GCM_EXPORT UnregistrationRequest { GCMStatsRecorder* recorder_; std::string source_to_record_; - base::WeakPtrFactory<UnregistrationRequest> weak_ptr_factory_; + base::WeakPtrFactory<UnregistrationRequest> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(UnregistrationRequest); }; diff --git a/chromium/google_apis/gcm/engine/unregistration_request_unittest.cc b/chromium/google_apis/gcm/engine/unregistration_request_unittest.cc index 16a354330ee..228fee9f006 100644 --- a/chromium/google_apis/gcm/engine/unregistration_request_unittest.cc +++ b/chromium/google_apis/gcm/engine/unregistration_request_unittest.cc @@ -115,8 +115,8 @@ TEST_F(GCMUnregistrationRequestTest, RequestDataPassedToFetcher) { const network::ResourceRequest* pending_request; ASSERT_TRUE( test_url_loader_factory()->IsPending(kRegistrationURL, &pending_request)); - EXPECT_TRUE(pending_request->load_flags & net::LOAD_DO_NOT_SEND_COOKIES); - EXPECT_TRUE(pending_request->load_flags & net::LOAD_DO_NOT_SAVE_COOKIES); + EXPECT_EQ(network::mojom::CredentialsMode::kOmit, + pending_request->credentials_mode); // Verify that authorization header was put together properly. const net::HttpRequestHeaders* headers = diff --git a/chromium/google_apis/gcm/tools/mcs_probe.cc b/chromium/google_apis/gcm/tools/mcs_probe.cc index 85853170edb..0a8aebc47a5 100644 --- a/chromium/google_apis/gcm/tools/mcs_probe.cc +++ b/chromium/google_apis/gcm/tools/mcs_probe.cc @@ -22,10 +22,11 @@ #include "base/logging.h" #include "base/memory/ptr_util.h" #include "base/memory/ref_counted.h" +#include "base/message_loop/message_pump_type.h" #include "base/run_loop.h" #include "base/strings/string_number_conversions.h" #include "base/task/single_thread_task_executor.h" -#include "base/task/thread_pool/thread_pool.h" +#include "base/task/thread_pool/thread_pool_instance.h" #include "base/threading/thread.h" #include "base/threading/thread_task_runner_handle.h" #include "base/time/default_clock.h" @@ -213,7 +214,6 @@ class MCSProbe { net::NetLog net_log_; std::unique_ptr<net::FileNetLogObserver> logger_; MCSProbeAuthPreferences http_auth_preferences_; - std::unique_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory_; FakeGCMStatsRecorder recorder_; std::unique_ptr<GCMStore> gcm_store_; @@ -339,15 +339,13 @@ void MCSProbe::InitializeNetworkState() { logger_->StartObserving(&net_log_, capture_mode); } - http_auth_handler_factory_ = net::HttpAuthHandlerRegistryFactory::Create( - &http_auth_preferences_, std::vector<std::string>{net::kBasicAuthScheme}); - net::URLRequestContextBuilder builder; builder.set_net_log(&net_log_); builder.set_host_resolver( net::HostResolver::CreateStandaloneResolver(&net_log_)); - builder.set_shared_http_auth_handler_factory( - http_auth_handler_factory_.get()); + builder.SetHttpAuthHandlerFactory(net::HttpAuthHandlerRegistryFactory::Create( + &http_auth_preferences_, + std::vector<std::string>{net::kBasicAuthScheme})); builder.set_proxy_resolution_service( net::ProxyResolutionService::CreateDirect()); @@ -446,7 +444,7 @@ int MCSProbeMain(int argc, char* argv[]) { mojo::core::Init(); - base::SingleThreadTaskExecutor io_task_executor(base::MessagePump::Type::IO); + base::SingleThreadTaskExecutor io_task_executor(base::MessagePumpType::IO); base::ThreadPoolInstance::CreateAndStartWithDefaultParams("MCSProbe"); const base::CommandLine& command_line = diff --git a/chromium/google_apis/google_api_keys.cc b/chromium/google_apis/google_api_keys.cc index 85ae25ec9f0..d01ef89f6a8 100644 --- a/chromium/google_apis/google_api_keys.cc +++ b/chromium/google_apis/google_api_keys.cc @@ -16,13 +16,14 @@ #include "base/lazy_instance.h" #include "base/logging.h" #include "base/strings/stringize_macros.h" +#include "build/branding_buildflags.h" #include "google_apis/gaia/gaia_switches.h" #if defined(OS_MACOSX) #include "google_apis/google_api_keys_mac.h" #endif -#if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) +#if BUILDFLAG(GOOGLE_CHROME_BRANDING) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) #include "google_apis/internal/google_chrome_api_keys.h" #include "google_apis/internal/metrics_signing_key.h" #endif @@ -252,7 +253,7 @@ class APIKeyCache { } #endif -#if !defined(GOOGLE_CHROME_BUILD) +#if !BUILDFLAG(GOOGLE_CHROME_BRANDING) // Don't allow using the environment to override API keys for official // Google Chrome builds. There have been reports of mangled environments // affecting users (crbug.com/710575). @@ -270,7 +271,7 @@ class APIKeyCache { } if (key_value == DUMMY_API_TOKEN) { -#if defined(GOOGLE_CHROME_BUILD) +#if BUILDFLAG(GOOGLE_CHROME_BRANDING) // No key should be unset in an official build except the // GOOGLE_DEFAULT_* keys. The default keys don't trigger this // check as their "unset" value is not DUMMY_API_TOKEN. @@ -362,7 +363,7 @@ std::string GetSpdyProxyAuthValue() { } bool IsGoogleChromeAPIKeyUsed() { -#if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) +#if BUILDFLAG(GOOGLE_CHROME_BRANDING) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) return true; #else return false; diff --git a/chromium/google_apis/google_api_keys_mac_unittest.mm b/chromium/google_apis/google_api_keys_mac_unittest.mm index ae0d4c13e31..dc1a3ae4db8 100644 --- a/chromium/google_apis/google_api_keys_mac_unittest.mm +++ b/chromium/google_apis/google_api_keys_mac_unittest.mm @@ -14,6 +14,7 @@ #include "base/mac/bundle_locations.h" #include "base/macros.h" +#include "build/branding_buildflags.h" #include "build/build_config.h" #include "google_apis/gaia/gaia_switches.h" #include "testing/gtest/include/gtest/gtest.h" @@ -37,7 +38,10 @@ // After this test, for the remainder of this compilation unit, we // need official keys to not be used. -#undef GOOGLE_CHROME_BUILD +#undef BUILDFLAG_INTERNAL_CHROMIUM_BRANDING +#undef BUILDFLAG_INTERNAL_GOOGLE_CHROME_BRANDING +#define BUILDFLAG_INTERNAL_CHROMIUM_BRANDING() (1) +#define BUILDFLAG_INTERNAL_GOOGLE_CHROME_BRANDING() (0) #undef USE_OFFICIAL_GOOGLE_API_KEYS // Override some keys using both preprocessor defines and Info.plist entries. diff --git a/chromium/google_apis/google_api_keys_unittest.cc b/chromium/google_apis/google_api_keys_unittest.cc index 77c3c84674f..669be144d6d 100644 --- a/chromium/google_apis/google_api_keys_unittest.cc +++ b/chromium/google_apis/google_api_keys_unittest.cc @@ -13,6 +13,7 @@ #include "google_apis/google_api_keys_unittest.h" #include "base/stl_util.h" +#include "build/branding_buildflags.h" #include "build/build_config.h" #include "google_apis/gaia/gaia_switches.h" @@ -88,7 +89,7 @@ void GoogleAPIKeysTest::TearDown() { // This is the default baked-in value for OAuth IDs and secrets. static const char kDummyToken[] = "dummytoken"; -#if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) +#if BUILDFLAG(GOOGLE_CHROME_BRANDING) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) // Test official build behavior, since we are in a checkout where this // is possible. namespace official_build { @@ -186,11 +187,15 @@ TEST_F(GoogleAPIKeysTest, OfficialKeys) { EXPECT_NE(DUMMY_API_TOKEN, secret_remoting_host); EXPECT_NE(kDummyToken, secret_remoting_host); } -#endif // defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) +#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING) || + // defined(USE_OFFICIAL_GOOGLE_API_KEYS) // After this test, for the remainder of this compilation unit, we // need official keys to not be used. -#undef GOOGLE_CHROME_BUILD +#undef BUILDFLAG_INTERNAL_CHROMIUM_BRANDING +#undef BUILDFLAG_INTERNAL_GOOGLE_CHROME_BRANDING +#define BUILDFLAG_INTERNAL_CHROMIUM_BRANDING() (1) +#define BUILDFLAG_INTERNAL_GOOGLE_CHROME_BRANDING() (0) #undef USE_OFFICIAL_GOOGLE_API_KEYS // Test the set of keys temporarily baked into Chromium by default. @@ -398,7 +403,7 @@ TEST_F(GoogleAPIKeysTest, OverrideAllKeys) { EXPECT_EQ("SECRET_REMOTING_HOST", secret_remoting_host); } -#if !defined(GOOGLE_CHROME_BUILD) +#if !BUILDFLAG(GOOGLE_CHROME_BRANDING) // Override all keys using both preprocessor defines and environment // variables. The environment variables should win. @@ -488,7 +493,7 @@ TEST_F(GoogleAPIKeysTest, OverrideAllKeysUsingEnvironment) { EXPECT_EQ("env-SECRET_REMOTING_HOST", secret_remoting_host); } -#endif // !defined(GOOGLE_CHROME_BUILD) +#endif // !BUILDFLAG(GOOGLE_CHROME_BRANDING) #if defined(OS_IOS) // Override all keys using both preprocessor defines and setters. |