diff --git a/google_apis/drive/drive_api_requests_unittest.cc b/google_apis/drive/drive_api_requests_unittest.cc index 0d6831b6e3ef45..61013778f9aa43 100644 --- a/google_apis/drive/drive_api_requests_unittest.cc +++ b/google_apis/drive/drive_api_requests_unittest.cc @@ -11,6 +11,7 @@ #include #include +#include "base/containers/contains.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" @@ -277,7 +278,7 @@ class DriveApiRequestsTest : public testing::Test { std::unique_ptr HandleChildrenDeleteRequest( const net::test_server::HttpRequest& request) { if (request.method != net::test_server::METHOD_DELETE || - request.relative_url.find("/children/") == std::string::npos) { + !base::Contains(request.relative_url, "/children/")) { // The request is not the "Children: delete" request. Delegate the // processing to the next handler. return nullptr; @@ -315,7 +316,7 @@ class DriveApiRequestsTest : public testing::Test { std::unique_ptr HandleDeleteRequest( const net::test_server::HttpRequest& request) { if (request.method != net::test_server::METHOD_DELETE || - request.relative_url.find("/files/") == std::string::npos) { + !base::Contains(request.relative_url, "/files/")) { // The file is not file deletion request. Delegate the processing to the // next handler. return nullptr; diff --git a/google_apis/drive/drive_base_requests.cc b/google_apis/drive/drive_base_requests.cc index ad5934a9b72763..865057b26d1039 100644 --- a/google_apis/drive/drive_base_requests.cc +++ b/google_apis/drive/drive_base_requests.cc @@ -10,6 +10,7 @@ #include #include +#include "base/containers/contains.h" #include "base/files/file_util.h" #include "base/functional/bind.h" #include "base/json/json_reader.h" @@ -127,8 +128,8 @@ void GenerateMultipartBody(MultipartType multipart_type, while (true) { boundary = net::GenerateMimeMultipartBoundary(); bool conflict_with_content = false; - for (auto& part : parts) { - if (part.data.find(boundary, 0) != std::string::npos) { + for (const auto& part : parts) { + if (base::Contains(part.data, boundary)) { conflict_with_content = true; break; } @@ -152,7 +153,7 @@ void GenerateMultipartBody(MultipartType multipart_type, output->data.clear(); if (data_offset) data_offset->clear(); - for (auto& part : parts) { + for (const auto& part : parts) { output->data.append(base::StringPrintf( kMultipartItemHeaderFormat, boundary.c_str(), part.type.c_str())); if (data_offset) diff --git a/google_apis/gaia/core_account_id.cc b/google_apis/gaia/core_account_id.cc index 4dad7936aa3e0a..51fbecea39bb47 100644 --- a/google_apis/gaia/core_account_id.cc +++ b/google_apis/gaia/core_account_id.cc @@ -5,13 +5,14 @@ #include "google_apis/gaia/core_account_id.h" #include "base/check.h" +#include "base/containers/contains.h" #include "google_apis/gaia/gaia_auth_util.h" namespace { // Returns whether the string looks like an email (the test is // crude an only checks whether it includes an '@'). bool IsEmailString(const std::string& string) { - return string.find('@') != std::string::npos; + return base::Contains(string, '@'); } } // anonymous namespace @@ -99,4 +100,4 @@ std::vector ToStringList( for (const auto& account_id : account_ids) account_ids_string.push_back(account_id.ToString()); return account_ids_string; -} \ No newline at end of file +} diff --git a/google_apis/gaia/fake_gaia.cc b/google_apis/gaia/fake_gaia.cc index f75abf20d34619..d36880f4799588 100644 --- a/google_apis/gaia/fake_gaia.cc +++ b/google_apis/gaia/fake_gaia.cc @@ -659,7 +659,7 @@ void FakeGaia::HandleEmbeddedLookupAccountLookup( std::string email; const bool is_saml = GetQueryParameter(request.content, "identifier", &email) && - saml_account_idp_map_.find(email) != saml_account_idp_map_.end(); + base::Contains(saml_account_idp_map_, email); if (!is_saml) return; diff --git a/google_apis/gaia/gaia_auth_fetcher_unittest.cc b/google_apis/gaia/gaia_auth_fetcher_unittest.cc index a051dd766c3eff..81a03aead774f1 100644 --- a/google_apis/gaia/gaia_auth_fetcher_unittest.cc +++ b/google_apis/gaia/gaia_auth_fetcher_unittest.cc @@ -9,6 +9,7 @@ #include #include +#include "base/containers/contains.h" #include "base/functional/bind.h" #include "base/json/json_reader.h" #include "base/memory/ref_counted.h" @@ -270,7 +271,7 @@ TEST_F(GaiaAuthFetcherTest, StartAuthCodeForOAuth2TokenExchangeSuccess) { EXPECT_EQ(google_apis::GetOmitCredentialsModeForGaiaRequests(), received_requests_.at(0).credentials_mode); std::string body = GetRequestBodyAsString(&received_requests_.at(0)); - EXPECT_EQ(std::string::npos, body.find("device_type=chrome")); + EXPECT_FALSE(base::Contains(body, "device_type=chrome")); EXPECT_TRUE(auth.HasPendingFetch()); auth.TestOnURLLoadCompleteInternal(net::OK, net::HTTP_OK, @@ -289,8 +290,8 @@ TEST_F(GaiaAuthFetcherTest, StartAuthCodeForOAuth2TokenExchangeDeviceId) { EXPECT_EQ(google_apis::GetOmitCredentialsModeForGaiaRequests(), received_requests_.at(0).credentials_mode); std::string body = GetRequestBodyAsString(&received_requests_.at(0)); - EXPECT_NE(std::string::npos, body.find("device_type=chrome")); - EXPECT_NE(std::string::npos, body.find("device_id=device_ABCDE_1")); + EXPECT_TRUE(base::Contains(body, "device_type=chrome")); + EXPECT_TRUE(base::Contains(body, "device_id=device_ABCDE_1")); } TEST_F(GaiaAuthFetcherTest, @@ -308,8 +309,8 @@ TEST_F(GaiaAuthFetcherTest, EXPECT_EQ(google_apis::GetOmitCredentialsModeForGaiaRequests(), received_requests_.at(0).credentials_mode); std::string body = GetRequestBodyAsString(&received_requests_.at(0)); - EXPECT_NE(std::string::npos, - body.find("bound_token_registration_jwt=registration_jwt")); + EXPECT_TRUE( + base::Contains(body, "bound_token_registration_jwt=registration_jwt")); EXPECT_TRUE(auth.HasPendingFetch()); auth.TestOnURLLoadCompleteInternal(net::OK, net::HTTP_OK, diff --git a/google_apis/gaia/gaia_auth_util.cc b/google_apis/gaia/gaia_auth_util.cc index a942ada781b46f..ae6e2c464fa065 100644 --- a/google_apis/gaia/gaia_auth_util.cc +++ b/google_apis/gaia/gaia_auth_util.cc @@ -9,6 +9,7 @@ #include #include "base/base64url.h" +#include "base/containers/contains.h" #include "base/functional/bind.h" #include "base/json/json_reader.h" #include "base/logging.h" @@ -76,7 +77,7 @@ std::string SanitizeEmail(base::StringPiece email_address) { std::string sanitized(email_address); // Apply a default domain if necessary. - if (sanitized.find('@') == std::string::npos) { + if (!base::Contains(sanitized, '@')) { sanitized += '@'; sanitized += kGmailDomain; } diff --git a/google_apis/gaia/oauth2_access_token_manager_unittest.cc b/google_apis/gaia/oauth2_access_token_manager_unittest.cc index 2c90db57177951..089220139bcff5 100644 --- a/google_apis/gaia/oauth2_access_token_manager_unittest.cc +++ b/google_apis/gaia/oauth2_access_token_manager_unittest.cc @@ -4,6 +4,7 @@ #include "google_apis/gaia/oauth2_access_token_manager.h" +#include "base/containers/contains.h" #include "base/memory/ref_counted.h" #include "base/test/bind.h" #include "base/test/task_environment.h" @@ -38,8 +39,7 @@ class FakeOAuth2AccessTokenManagerDelegate const CoreAccountId& account_id, scoped_refptr url_loader_factory, OAuth2AccessTokenConsumer* consumer) override { - EXPECT_NE(account_ids_to_refresh_tokens_.find(account_id), - account_ids_to_refresh_tokens_.end()); + EXPECT_TRUE(base::Contains(account_ids_to_refresh_tokens_, account_id)); return GaiaAccessTokenFetcher:: CreateExchangeRefreshTokenForAccessTokenInstance( consumer, url_loader_factory, @@ -47,8 +47,7 @@ class FakeOAuth2AccessTokenManagerDelegate } bool HasRefreshToken(const CoreAccountId& account_id) const override { - return account_ids_to_refresh_tokens_.find(account_id) != - account_ids_to_refresh_tokens_.end(); + return base::Contains(account_ids_to_refresh_tokens_, account_id); } scoped_refptr GetURLLoaderFactory() diff --git a/google_apis/gcm/engine/gcm_store_impl_unittest.cc b/google_apis/gcm/engine/gcm_store_impl_unittest.cc index 80b11aebccb1a7..c4f0c969a37af3 100644 --- a/google_apis/gcm/engine/gcm_store_impl_unittest.cc +++ b/google_apis/gcm/engine/gcm_store_impl_unittest.cc @@ -12,6 +12,7 @@ #include #include "base/command_line.h" +#include "base/containers/contains.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" @@ -297,11 +298,9 @@ TEST_F(GCMStoreImplTest, Registrations) { LoadGCMStore(gcm_store.get(), &load_result); ASSERT_EQ(2u, load_result->registrations.size()); - ASSERT_TRUE(load_result->registrations.find(kAppName) != - load_result->registrations.end()); + EXPECT_TRUE(base::Contains(load_result->registrations, kAppName)); EXPECT_EQ(registration, load_result->registrations[kAppName]); - ASSERT_TRUE(load_result->registrations.find(kAppName2) != - load_result->registrations.end()); + EXPECT_TRUE(base::Contains(load_result->registrations, kAppName2)); EXPECT_EQ(registration2, load_result->registrations[kAppName2]); gcm_store->RemoveRegistration( @@ -313,8 +312,7 @@ TEST_F(GCMStoreImplTest, Registrations) { LoadGCMStore(gcm_store.get(), &load_result); ASSERT_EQ(1u, load_result->registrations.size()); - ASSERT_TRUE(load_result->registrations.find(kAppName) != - load_result->registrations.end()); + EXPECT_TRUE(base::Contains(load_result->registrations, kAppName)); EXPECT_EQ(registration, load_result->registrations[kAppName]); } @@ -660,11 +658,9 @@ TEST_F(GCMStoreImplTest, HeartbeatInterval) { LoadGCMStore(gcm_store.get(), &load_result); EXPECT_EQ(2UL, load_result->heartbeat_intervals.size()); - ASSERT_TRUE(load_result->heartbeat_intervals.find(scope1) != - load_result->heartbeat_intervals.end()); + EXPECT_TRUE(base::Contains(load_result->heartbeat_intervals, scope1)); EXPECT_EQ(heartbeat1, load_result->heartbeat_intervals[scope1]); - ASSERT_TRUE(load_result->heartbeat_intervals.find(scope2) != - load_result->heartbeat_intervals.end()); + EXPECT_TRUE(base::Contains(load_result->heartbeat_intervals, scope2)); EXPECT_EQ(heartbeat2, load_result->heartbeat_intervals[scope2]); gcm_store->RemoveHeartbeatInterval( @@ -676,8 +672,7 @@ TEST_F(GCMStoreImplTest, HeartbeatInterval) { LoadGCMStore(gcm_store.get(), &load_result); EXPECT_EQ(1UL, load_result->heartbeat_intervals.size()); - ASSERT_TRUE(load_result->heartbeat_intervals.find(scope1) != - load_result->heartbeat_intervals.end()); + EXPECT_TRUE(base::Contains(load_result->heartbeat_intervals, scope1)); EXPECT_EQ(heartbeat1, load_result->heartbeat_intervals[scope1]); } @@ -766,10 +761,8 @@ TEST_F(GCMStoreImplTest, InstanceIDData) { LoadGCMStore(gcm_store.get(), &load_result); ASSERT_EQ(2u, load_result->instance_id_data.size()); - ASSERT_TRUE(load_result->instance_id_data.find(kAppName) != - load_result->instance_id_data.end()); - ASSERT_TRUE(load_result->instance_id_data.find(kAppName2) != - load_result->instance_id_data.end()); + EXPECT_TRUE(base::Contains(load_result->instance_id_data, kAppName)); + EXPECT_TRUE(base::Contains(load_result->instance_id_data, kAppName2)); EXPECT_EQ(instance_id_data, load_result->instance_id_data[kAppName]); EXPECT_EQ(instance_id_data2, load_result->instance_id_data[kAppName2]); @@ -782,8 +775,7 @@ TEST_F(GCMStoreImplTest, InstanceIDData) { LoadGCMStore(gcm_store.get(), &load_result); ASSERT_EQ(1u, load_result->instance_id_data.size()); - ASSERT_TRUE(load_result->instance_id_data.find(kAppName2) != - load_result->instance_id_data.end()); + EXPECT_TRUE(base::Contains(load_result->instance_id_data, kAppName2)); EXPECT_EQ(instance_id_data2, load_result->instance_id_data[kAppName2]); } diff --git a/google_apis/gcm/engine/instance_id_delete_token_request_handler.cc b/google_apis/gcm/engine/instance_id_delete_token_request_handler.cc index 8783ef24ef7f00..2913fc6e859540 100644 --- a/google_apis/gcm/engine/instance_id_delete_token_request_handler.cc +++ b/google_apis/gcm/engine/instance_id_delete_token_request_handler.cc @@ -5,6 +5,7 @@ #include "google_apis/gcm/engine/instance_id_delete_token_request_handler.h" #include "base/check.h" +#include "base/containers/contains.h" #include "base/metrics/histogram_macros.h" #include "base/strings/string_number_conversions.h" #include "google_apis/gcm/base/gcm_util.h" @@ -52,8 +53,9 @@ void InstanceIDDeleteTokenRequestHandler::BuildRequestBody(std::string* body){ UnregistrationRequest::Status InstanceIDDeleteTokenRequestHandler::ParseResponse( const std::string& response) { - if (response.find(kTokenPrefix) == std::string::npos) + if (!base::Contains(response, kTokenPrefix)) { return UnregistrationRequest::RESPONSE_PARSING_FAILED; + } return UnregistrationRequest::SUCCESS; } diff --git a/google_apis/gcm/engine/registration_request.cc b/google_apis/gcm/engine/registration_request.cc index 36adf30acbb6f5..3ea57da31dffaf 100644 --- a/google_apis/gcm/engine/registration_request.cc +++ b/google_apis/gcm/engine/registration_request.cc @@ -8,6 +8,7 @@ #include +#include "base/containers/contains.h" #include "base/functional/bind.h" #include "base/location.h" #include "base/metrics/histogram.h" @@ -53,20 +54,27 @@ const char kTooManyRegistrations[] = "TOO_MANY_REGISTRATIONS"; // Gets correct status from the error message. RegistrationRequest::Status GetStatusFromError(const std::string& error) { - if (error.find(kDeviceRegistrationError) != std::string::npos) + if (base::Contains(error, kDeviceRegistrationError)) { return RegistrationRequest::DEVICE_REGISTRATION_ERROR; - if (error.find(kAuthenticationFailed) != std::string::npos) + } + if (base::Contains(error, kAuthenticationFailed)) { return RegistrationRequest::AUTHENTICATION_FAILED; - if (error.find(kInvalidSender) != std::string::npos) + } + if (base::Contains(error, kInvalidSender)) { return RegistrationRequest::INVALID_SENDER; - if (error.find(kInvalidParameters) != std::string::npos) + } + if (base::Contains(error, kInvalidParameters)) { return RegistrationRequest::INVALID_PARAMETERS; - if (error.find(kInternalServerError) != std::string::npos) + } + if (base::Contains(error, kInternalServerError)) { return RegistrationRequest::INTERNAL_SERVER_ERROR; - if (error.find(kQuotaExceeded) != std::string::npos) + } + if (base::Contains(error, kQuotaExceeded)) { return RegistrationRequest::QUOTA_EXCEEDED; - if (error.find(kTooManyRegistrations) != std::string::npos) + } + if (base::Contains(error, kTooManyRegistrations)) { return RegistrationRequest::TOO_MANY_REGISTRATIONS; + } // Should not be reached, unless the server adds new error types. return RegistrationRequest::UNKNOWN_ERROR; } diff --git a/google_apis/gcm/engine/unregistration_request.cc b/google_apis/gcm/engine/unregistration_request.cc index 195f5a97f37ef7..cdda15d082bac5 100644 --- a/google_apis/gcm/engine/unregistration_request.cc +++ b/google_apis/gcm/engine/unregistration_request.cc @@ -6,6 +6,7 @@ #include +#include "base/containers/contains.h" #include "base/functional/bind.h" #include "base/location.h" #include "base/strings/escape.h" @@ -47,12 +48,15 @@ const char kDeviceRegistrationError[] = "PHONE_REGISTRATION_ERROR"; // Gets correct status from the error message. UnregistrationRequest::Status GetStatusFromError(const std::string& error) { - if (error.find(kInvalidParameters) != std::string::npos) + if (base::Contains(error, kInvalidParameters)) { return UnregistrationRequest::INVALID_PARAMETERS; - if (error.find(kInternalServerError) != std::string::npos) + } + if (base::Contains(error, kInternalServerError)) { return UnregistrationRequest::INTERNAL_SERVER_ERROR; - if (error.find(kDeviceRegistrationError) != std::string::npos) + } + if (base::Contains(error, kDeviceRegistrationError)) { return UnregistrationRequest::DEVICE_REGISTRATION_ERROR; + } // Should not be reached, unless the server adds new error types. return UnregistrationRequest::UNKNOWN_ERROR; }