OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/mutable_profile_oauth2_token_service_delegate.h" | 5 #include "chrome/browser/signin/mutable_profile_oauth2_token_service_delegate.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/profiler/scoped_tracker.h" | 11 #include "base/profiler/scoped_tracker.h" |
11 #include "components/signin/core/browser/signin_client.h" | 12 #include "components/signin/core/browser/signin_client.h" |
12 #include "components/signin/core/browser/signin_metrics.h" | 13 #include "components/signin/core/browser/signin_metrics.h" |
13 #include "components/signin/core/browser/webdata/token_web_data.h" | 14 #include "components/signin/core/browser/webdata/token_web_data.h" |
14 #include "components/signin/core/common/profile_management_switches.h" | 15 #include "components/signin/core/common/profile_management_switches.h" |
15 #include "components/webdata/common/web_data_service_base.h" | 16 #include "components/webdata/common/web_data_service_base.h" |
16 #include "google_apis/gaia/gaia_auth_fetcher.h" | 17 #include "google_apis/gaia/gaia_auth_fetcher.h" |
17 #include "google_apis/gaia/gaia_auth_util.h" | 18 #include "google_apis/gaia/gaia_auth_util.h" |
18 #include "google_apis/gaia/gaia_constants.h" | 19 #include "google_apis/gaia/gaia_constants.h" |
19 #include "google_apis/gaia/oauth2_access_token_fetcher_immediate_error.h" | 20 #include "google_apis/gaia/oauth2_access_token_fetcher_immediate_error.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 94 } |
94 | 95 |
95 MutableProfileOAuth2TokenServiceDelegate::RevokeServerRefreshToken:: | 96 MutableProfileOAuth2TokenServiceDelegate::RevokeServerRefreshToken:: |
96 ~RevokeServerRefreshToken() { | 97 ~RevokeServerRefreshToken() { |
97 } | 98 } |
98 | 99 |
99 void MutableProfileOAuth2TokenServiceDelegate::RevokeServerRefreshToken:: | 100 void MutableProfileOAuth2TokenServiceDelegate::RevokeServerRefreshToken:: |
100 OnOAuth2RevokeTokenCompleted() { | 101 OnOAuth2RevokeTokenCompleted() { |
101 // |this| pointer will be deleted when removed from the vector, so don't | 102 // |this| pointer will be deleted when removed from the vector, so don't |
102 // access any members after call to erase(). | 103 // access any members after call to erase(). |
103 token_service_delegate_->server_revokes_.erase( | 104 token_service_delegate_->server_revokes_.erase(std::find_if( |
104 std::find(token_service_delegate_->server_revokes_.begin(), | 105 token_service_delegate_->server_revokes_.begin(), |
105 token_service_delegate_->server_revokes_.end(), this)); | 106 token_service_delegate_->server_revokes_.end(), |
| 107 [this](const std::unique_ptr<MutableProfileOAuth2TokenServiceDelegate:: |
| 108 RevokeServerRefreshToken>& item) { |
| 109 return item.get() == this; |
| 110 })); |
106 } | 111 } |
107 | 112 |
108 MutableProfileOAuth2TokenServiceDelegate::AccountStatus::AccountStatus( | 113 MutableProfileOAuth2TokenServiceDelegate::AccountStatus::AccountStatus( |
109 SigninErrorController* signin_error_controller, | 114 SigninErrorController* signin_error_controller, |
110 const std::string& account_id, | 115 const std::string& account_id, |
111 const std::string& refresh_token) | 116 const std::string& refresh_token) |
112 : signin_error_controller_(signin_error_controller), | 117 : signin_error_controller_(signin_error_controller), |
113 account_id_(account_id), | 118 account_id_(account_id), |
114 refresh_token_(refresh_token), | 119 refresh_token_(refresh_token), |
115 last_auth_error_(GoogleServiceAuthError::NONE) { | 120 last_auth_error_(GoogleServiceAuthError::NONE) { |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 VLOG(1) << "MutablePO2TS::ClearPersistedCredentials for account_id=" | 540 VLOG(1) << "MutablePO2TS::ClearPersistedCredentials for account_id=" |
536 << account_id; | 541 << account_id; |
537 token_web_data->RemoveTokenForService(ApplyAccountIdPrefix(account_id)); | 542 token_web_data->RemoveTokenForService(ApplyAccountIdPrefix(account_id)); |
538 } | 543 } |
539 } | 544 } |
540 | 545 |
541 void MutableProfileOAuth2TokenServiceDelegate::RevokeCredentialsOnServer( | 546 void MutableProfileOAuth2TokenServiceDelegate::RevokeCredentialsOnServer( |
542 const std::string& refresh_token) { | 547 const std::string& refresh_token) { |
543 // Keep track or all server revoke requests. This way they can be deleted | 548 // Keep track or all server revoke requests. This way they can be deleted |
544 // before the token service is shutdown and won't outlive the profile. | 549 // before the token service is shutdown and won't outlive the profile. |
545 server_revokes_.push_back(new RevokeServerRefreshToken(this, refresh_token)); | 550 server_revokes_.push_back( |
| 551 base::MakeUnique<RevokeServerRefreshToken>(this, refresh_token)); |
546 } | 552 } |
547 | 553 |
548 void MutableProfileOAuth2TokenServiceDelegate::CancelWebTokenFetch() { | 554 void MutableProfileOAuth2TokenServiceDelegate::CancelWebTokenFetch() { |
549 if (web_data_service_request_ != 0) { | 555 if (web_data_service_request_ != 0) { |
550 scoped_refptr<TokenWebData> token_web_data = client_->GetDatabase(); | 556 scoped_refptr<TokenWebData> token_web_data = client_->GetDatabase(); |
551 DCHECK(token_web_data.get()); | 557 DCHECK(token_web_data.get()); |
552 token_web_data->CancelRequest(web_data_service_request_); | 558 token_web_data->CancelRequest(web_data_service_request_); |
553 web_data_service_request_ = 0; | 559 web_data_service_request_ = 0; |
554 } | 560 } |
555 } | 561 } |
556 | 562 |
557 void MutableProfileOAuth2TokenServiceDelegate::Shutdown() { | 563 void MutableProfileOAuth2TokenServiceDelegate::Shutdown() { |
558 VLOG(1) << "MutablePO2TS::Shutdown"; | 564 VLOG(1) << "MutablePO2TS::Shutdown"; |
559 server_revokes_.clear(); | 565 server_revokes_.clear(); |
560 CancelWebTokenFetch(); | 566 CancelWebTokenFetch(); |
561 refresh_tokens_.clear(); | 567 refresh_tokens_.clear(); |
562 } | 568 } |
563 | 569 |
564 void MutableProfileOAuth2TokenServiceDelegate::OnNetworkChanged( | 570 void MutableProfileOAuth2TokenServiceDelegate::OnNetworkChanged( |
565 net::NetworkChangeNotifier::ConnectionType type) { | 571 net::NetworkChangeNotifier::ConnectionType type) { |
566 // If our network has changed, reset the backoff timer so that errors caused | 572 // If our network has changed, reset the backoff timer so that errors caused |
567 // by a previous lack of network connectivity don't prevent new requests. | 573 // by a previous lack of network connectivity don't prevent new requests. |
568 backoff_entry_.Reset(); | 574 backoff_entry_.Reset(); |
569 } | 575 } |
570 | 576 |
571 const net::BackoffEntry* | 577 const net::BackoffEntry* |
572 MutableProfileOAuth2TokenServiceDelegate::BackoffEntry() const { | 578 MutableProfileOAuth2TokenServiceDelegate::BackoffEntry() const { |
573 return &backoff_entry_; | 579 return &backoff_entry_; |
574 } | 580 } |
OLD | NEW |