Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: chrome/browser/signin/oauth2_token_service_delegate_android.cc

Issue 1715683002: chrome: Use base's ContainsValue helper function instead of std::find (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing non ContainsValue changes Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/signin/oauth2_token_service_delegate_android.h" 5 #include "chrome/browser/signin/oauth2_token_service_delegate_android.h"
6 6
7 #include "base/android/context_utils.h" 7 #include "base/android/context_utils.h"
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/android/jni_array.h" 9 #include "base/android/jni_array.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/stl_util.h"
15 #include "chrome/browser/profiles/profile_android.h" 16 #include "chrome/browser/profiles/profile_android.h"
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
17 #include "chrome/browser/sync/profile_sync_service_android.h" 18 #include "chrome/browser/sync/profile_sync_service_android.h"
18 #include "components/signin/core/browser/account_info.h" 19 #include "components/signin/core/browser/account_info.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
20 #include "google_apis/gaia/gaia_auth_util.h" 21 #include "google_apis/gaia/gaia_auth_util.h"
21 #include "google_apis/gaia/oauth2_access_token_fetcher.h" 22 #include "google_apis/gaia/oauth2_access_token_fetcher.h"
22 #include "jni/OAuth2TokenService_jni.h" 23 #include "jni/OAuth2TokenService_jni.h"
23 24
24 using base::android::AttachCurrentThread; 25 using base::android::AttachCurrentThread;
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 fire_refresh_token_loaded_ = RT_LOADED; 356 fire_refresh_token_loaded_ = RT_LOADED;
356 FireRefreshTokensLoaded(); 357 FireRefreshTokensLoaded();
357 } else if (fire_refresh_token_loaded_ == RT_LOAD_NOT_START) { 358 } else if (fire_refresh_token_loaded_ == RT_LOAD_NOT_START) {
358 fire_refresh_token_loaded_ = RT_HAS_BEEN_VALIDATED; 359 fire_refresh_token_loaded_ = RT_HAS_BEEN_VALIDATED;
359 } 360 }
360 361
361 // Clear accounts no longer exist on device from AccountTrackerService. 362 // Clear accounts no longer exist on device from AccountTrackerService.
362 std::vector<AccountInfo> accounts_info = 363 std::vector<AccountInfo> accounts_info =
363 account_tracker_service_->GetAccounts(); 364 account_tracker_service_->GetAccounts();
364 for (const AccountInfo& info : accounts_info) { 365 for (const AccountInfo& info : accounts_info) {
365 if (std::find(curr_ids.begin(), curr_ids.end(), info.account_id) == 366 if (!ContainsValue(curr_ids, info.account_id))
366 curr_ids.end())
367 account_tracker_service_->RemoveAccount(info.account_id); 367 account_tracker_service_->RemoveAccount(info.account_id);
368 } 368 }
369 369
370 // No need to wait for SigninManager to finish migration if not signed in. 370 // No need to wait for SigninManager to finish migration if not signed in.
371 if (account_tracker_service_->GetMigrationState() == 371 if (account_tracker_service_->GetMigrationState() ==
372 AccountTrackerService::MIGRATION_IN_PROGRESS && 372 AccountTrackerService::MIGRATION_IN_PROGRESS &&
373 signed_in_account_id.empty()) { 373 signed_in_account_id.empty()) {
374 account_tracker_service_->SetMigrationDone(); 374 account_tracker_service_->SetMigrationDone();
375 } 375 }
376 } 376 }
377 377
378 bool OAuth2TokenServiceDelegateAndroid::ValidateAccounts( 378 bool OAuth2TokenServiceDelegateAndroid::ValidateAccounts(
379 const std::string& signed_in_id, 379 const std::string& signed_in_id,
380 const std::vector<std::string>& prev_ids, 380 const std::vector<std::string>& prev_ids,
381 const std::vector<std::string>& curr_ids, 381 const std::vector<std::string>& curr_ids,
382 std::vector<std::string>* refreshed_ids, 382 std::vector<std::string>* refreshed_ids,
383 std::vector<std::string>* revoked_ids, 383 std::vector<std::string>* revoked_ids,
384 bool force_notifications) { 384 bool force_notifications) {
385 bool currently_signed_in = std::find(curr_ids.begin(), curr_ids.end(), 385 bool currently_signed_in = ContainsValue(curr_ids, signed_in_id);
386 signed_in_id) != curr_ids.end();
387 if (currently_signed_in) { 386 if (currently_signed_in) {
388 // Revoke token for ids that have been removed from the device. 387 // Revoke token for ids that have been removed from the device.
389 for (const std::string& prev_id : prev_ids) { 388 for (const std::string& prev_id : prev_ids) {
390 if (prev_id == signed_in_id) 389 if (prev_id == signed_in_id)
391 continue; 390 continue;
392 if (std::find(curr_ids.begin(), curr_ids.end(), prev_id) == 391 if (!ContainsValue(curr_ids, prev_id)) {
393 curr_ids.end()) {
394 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" 392 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:"
395 << "revoked=" << prev_id; 393 << "revoked=" << prev_id;
396 revoked_ids->push_back(prev_id); 394 revoked_ids->push_back(prev_id);
397 } 395 }
398 } 396 }
399 397
400 // Refresh token for new ids or all ids if |force_notifications|. 398 // Refresh token for new ids or all ids if |force_notifications|.
401 if (force_notifications || 399 if (force_notifications ||
402 std::find(prev_ids.begin(), prev_ids.end(), signed_in_id) == 400 !ContainsValue(prev_ids, signed_in_id)) {
403 prev_ids.end()) {
404 // Always fire the primary signed in account first. 401 // Always fire the primary signed in account first.
405 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" 402 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:"
406 << "refreshed=" << signed_in_id; 403 << "refreshed=" << signed_in_id;
407 refreshed_ids->push_back(signed_in_id); 404 refreshed_ids->push_back(signed_in_id);
408 } 405 }
409 for (const std::string& curr_id : curr_ids) { 406 for (const std::string& curr_id : curr_ids) {
410 if (curr_id == signed_in_id) 407 if (curr_id == signed_in_id)
411 continue; 408 continue;
412 if (force_notifications || 409 if (force_notifications ||
413 std::find(prev_ids.begin(), prev_ids.end(), curr_id) == 410 !ContainsValue(prev_ids, curr_id)) {
414 prev_ids.end()) {
415 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" 411 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:"
416 << "refreshed=" << curr_id; 412 << "refreshed=" << curr_id;
417 refreshed_ids->push_back(curr_id); 413 refreshed_ids->push_back(curr_id);
418 } 414 }
419 } 415 }
420 } else { 416 } else {
421 if (std::find(prev_ids.begin(), prev_ids.end(), signed_in_id) != 417 if (ContainsValue(prev_ids, signed_in_id)) {
422 prev_ids.end()) {
423 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" 418 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:"
424 << "revoked=" << signed_in_id; 419 << "revoked=" << signed_in_id;
425 revoked_ids->push_back(signed_in_id); 420 revoked_ids->push_back(signed_in_id);
426 } 421 }
427 for (const std::string& prev_id : prev_ids) { 422 for (const std::string& prev_id : prev_ids) {
428 if (prev_id == signed_in_id) 423 if (prev_id == signed_in_id)
429 continue; 424 continue;
430 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" 425 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:"
431 << "revoked=" << prev_id; 426 << "revoked=" << prev_id;
432 revoked_ids->push_back(prev_id); 427 revoked_ids->push_back(prev_id);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 : isTransientError 571 : isTransientError
577 ? GoogleServiceAuthError::CONNECTION_FAILED 572 ? GoogleServiceAuthError::CONNECTION_FAILED
578 : GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 573 : GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
579 heap_callback->Run(err, token, base::Time()); 574 heap_callback->Run(err, token, base::Time());
580 } 575 }
581 576
582 // static 577 // static
583 bool OAuth2TokenServiceDelegateAndroid::Register(JNIEnv* env) { 578 bool OAuth2TokenServiceDelegateAndroid::Register(JNIEnv* env) {
584 return RegisterNativesImpl(env); 579 return RegisterNativesImpl(env);
585 } 580 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698