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

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: Updated as per latest code Created 4 years, 10 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/stl_util.h"
14 #include "chrome/browser/profiles/profile_android.h" 15 #include "chrome/browser/profiles/profile_android.h"
15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
16 #include "chrome/browser/sync/profile_sync_service_android.h" 17 #include "chrome/browser/sync/profile_sync_service_android.h"
17 #include "components/signin/core/browser/account_info.h" 18 #include "components/signin/core/browser/account_info.h"
18 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
19 #include "google_apis/gaia/gaia_auth_util.h" 20 #include "google_apis/gaia/gaia_auth_util.h"
20 #include "google_apis/gaia/oauth2_access_token_fetcher.h" 21 #include "google_apis/gaia/oauth2_access_token_fetcher.h"
21 #include "jni/OAuth2TokenService_jni.h" 22 #include "jni/OAuth2TokenService_jni.h"
22 23
23 using base::android::AttachCurrentThread; 24 using base::android::AttachCurrentThread;
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 fire_refresh_token_loaded_ = RT_LOADED; 355 fire_refresh_token_loaded_ = RT_LOADED;
355 FireRefreshTokensLoaded(); 356 FireRefreshTokensLoaded();
356 } else if (fire_refresh_token_loaded_ == RT_LOAD_NOT_START) { 357 } else if (fire_refresh_token_loaded_ == RT_LOAD_NOT_START) {
357 fire_refresh_token_loaded_ = RT_HAS_BEEN_VALIDATED; 358 fire_refresh_token_loaded_ = RT_HAS_BEEN_VALIDATED;
358 } 359 }
359 360
360 // Clear accounts no longer exist on device from AccountTrackerService. 361 // Clear accounts no longer exist on device from AccountTrackerService.
361 std::vector<AccountInfo> accounts_info = 362 std::vector<AccountInfo> accounts_info =
362 account_tracker_service_->GetAccounts(); 363 account_tracker_service_->GetAccounts();
363 for (const AccountInfo& info : accounts_info) { 364 for (const AccountInfo& info : accounts_info) {
364 if (std::find(curr_ids.begin(), curr_ids.end(), info.account_id) == 365 if (!ContainsValue(curr_ids, info.account_id))
365 curr_ids.end())
366 account_tracker_service_->RemoveAccount(info.account_id); 366 account_tracker_service_->RemoveAccount(info.account_id);
367 } 367 }
368 368
369 // No need to wait for SigninManager to finish migration if not signed in. 369 // No need to wait for SigninManager to finish migration if not signed in.
370 if (account_tracker_service_->GetMigrationState() == 370 if (account_tracker_service_->GetMigrationState() ==
371 AccountTrackerService::MIGRATION_IN_PROGRESS && 371 AccountTrackerService::MIGRATION_IN_PROGRESS &&
372 signed_in_account_id.empty()) { 372 signed_in_account_id.empty()) {
373 account_tracker_service_->SetMigrationDone(); 373 account_tracker_service_->SetMigrationDone();
374 } 374 }
375 } 375 }
376 376
377 bool OAuth2TokenServiceDelegateAndroid::ValidateAccounts( 377 bool OAuth2TokenServiceDelegateAndroid::ValidateAccounts(
378 const std::string& signed_in_id, 378 const std::string& signed_in_id,
379 const std::vector<std::string>& prev_ids, 379 const std::vector<std::string>& prev_ids,
380 const std::vector<std::string>& curr_ids, 380 const std::vector<std::string>& curr_ids,
381 std::vector<std::string>* refreshed_ids, 381 std::vector<std::string>* refreshed_ids,
382 std::vector<std::string>* revoked_ids, 382 std::vector<std::string>* revoked_ids,
383 bool force_notifications) { 383 bool force_notifications) {
384 bool currently_signed_in = std::find(curr_ids.begin(), curr_ids.end(), 384 bool currently_signed_in = ContainsValue(curr_ids, signed_in_id);
385 signed_in_id) != curr_ids.end();
386 if (currently_signed_in) { 385 if (currently_signed_in) {
387 // Revoke token for ids that have been removed from the device. 386 // Revoke token for ids that have been removed from the device.
388 for (const std::string& prev_id : prev_ids) { 387 for (const std::string& prev_id : prev_ids) {
389 if (prev_id == signed_in_id) 388 if (prev_id == signed_in_id)
390 continue; 389 continue;
391 if (std::find(curr_ids.begin(), curr_ids.end(), prev_id) == 390 if (!ContainsValue(curr_ids, prev_id)) {
392 curr_ids.end()) {
393 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" 391 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:"
394 << "revoked=" << prev_id; 392 << "revoked=" << prev_id;
395 revoked_ids->push_back(prev_id); 393 revoked_ids->push_back(prev_id);
396 } 394 }
397 } 395 }
398 396
399 // Refresh token for new ids or all ids if |force_notifications|. 397 // Refresh token for new ids or all ids if |force_notifications|.
400 if (force_notifications || 398 if (force_notifications ||
401 std::find(prev_ids.begin(), prev_ids.end(), signed_in_id) == 399 !ContainsValue(prev_ids, signed_in_id)) {
402 prev_ids.end()) {
403 // Always fire the primary signed in account first. 400 // Always fire the primary signed in account first.
404 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" 401 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:"
405 << "refreshed=" << signed_in_id; 402 << "refreshed=" << signed_in_id;
406 refreshed_ids->push_back(signed_in_id); 403 refreshed_ids->push_back(signed_in_id);
407 } 404 }
408 for (const std::string& curr_id : curr_ids) { 405 for (const std::string& curr_id : curr_ids) {
409 if (curr_id == signed_in_id) 406 if (curr_id == signed_in_id)
410 continue; 407 continue;
411 if (force_notifications || 408 if (force_notifications ||
412 std::find(prev_ids.begin(), prev_ids.end(), curr_id) == 409 !ContainsValue(prev_ids, curr_id)) {
413 prev_ids.end()) {
414 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" 410 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:"
415 << "refreshed=" << curr_id; 411 << "refreshed=" << curr_id;
416 refreshed_ids->push_back(curr_id); 412 refreshed_ids->push_back(curr_id);
417 } 413 }
418 } 414 }
419 } else { 415 } else {
420 if (std::find(prev_ids.begin(), prev_ids.end(), signed_in_id) != 416 if (ContainsValue(prev_ids, signed_in_id)) {
421 prev_ids.end()) {
422 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" 417 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:"
423 << "revoked=" << signed_in_id; 418 << "revoked=" << signed_in_id;
424 revoked_ids->push_back(signed_in_id); 419 revoked_ids->push_back(signed_in_id);
425 } 420 }
426 for (const std::string& prev_id : prev_ids) { 421 for (const std::string& prev_id : prev_ids) {
427 if (prev_id == signed_in_id) 422 if (prev_id == signed_in_id)
428 continue; 423 continue;
429 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" 424 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:"
430 << "revoked=" << prev_id; 425 << "revoked=" << prev_id;
431 revoked_ids->push_back(prev_id); 426 revoked_ids->push_back(prev_id);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 : isTransientError 562 : isTransientError
568 ? GoogleServiceAuthError::CONNECTION_FAILED 563 ? GoogleServiceAuthError::CONNECTION_FAILED
569 : GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 564 : GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
570 heap_callback->Run(err, token, base::Time()); 565 heap_callback->Run(err, token, base::Time());
571 } 566 }
572 567
573 // static 568 // static
574 bool OAuth2TokenServiceDelegateAndroid::Register(JNIEnv* env) { 569 bool OAuth2TokenServiceDelegateAndroid::Register(JNIEnv* env) {
575 return RegisterNativesImpl(env); 570 return RegisterNativesImpl(env);
576 } 571 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698