| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/chromeos/policy/policy_oauth2_token_fetcher.h" | 5 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 void PolicyOAuth2TokenFetcher::OnGetTokenFailure( | 96 void PolicyOAuth2TokenFetcher::OnGetTokenFailure( |
| 97 const GoogleServiceAuthError& error) { | 97 const GoogleServiceAuthError& error) { |
| 98 LOG(ERROR) << "OAuth2 access token (device management) fetching failed!"; | 98 LOG(ERROR) << "OAuth2 access token (device management) fetching failed!"; |
| 99 RetryOnError(error, | 99 RetryOnError(error, |
| 100 base::Bind(&PolicyOAuth2TokenFetcher::StartFetchingAccessToken, | 100 base::Bind(&PolicyOAuth2TokenFetcher::StartFetchingAccessToken, |
| 101 AsWeakPtr())); | 101 AsWeakPtr())); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void PolicyOAuth2TokenFetcher::RetryOnError(const GoogleServiceAuthError& error, | 104 void PolicyOAuth2TokenFetcher::RetryOnError(const GoogleServiceAuthError& error, |
| 105 const base::Closure& task) { | 105 const base::Closure& task) { |
| 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 106 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 107 if ((error.state() == GoogleServiceAuthError::CONNECTION_FAILED || | 107 if ((error.state() == GoogleServiceAuthError::CONNECTION_FAILED || |
| 108 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE || | 108 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE || |
| 109 error.state() == GoogleServiceAuthError::REQUEST_CANCELED) && | 109 error.state() == GoogleServiceAuthError::REQUEST_CANCELED) && |
| 110 retry_count_ < kMaxRequestAttemptCount) { | 110 retry_count_ < kMaxRequestAttemptCount) { |
| 111 retry_count_++; | 111 retry_count_++; |
| 112 BrowserThread::PostDelayedTask( | 112 BrowserThread::PostDelayedTask( |
| 113 BrowserThread::UI, FROM_HERE, task, | 113 BrowserThread::UI, FROM_HERE, task, |
| 114 base::TimeDelta::FromMilliseconds(kRequestRestartDelay)); | 114 base::TimeDelta::FromMilliseconds(kRequestRestartDelay)); |
| 115 return; | 115 return; |
| 116 } | 116 } |
| 117 LOG(ERROR) << "Unrecoverable error or retry count max reached."; | 117 LOG(ERROR) << "Unrecoverable error or retry count max reached."; |
| 118 failed_ = true; | 118 failed_ = true; |
| 119 // Invoking the |callback_| signals to the owner of this object that it has | 119 // Invoking the |callback_| signals to the owner of this object that it has |
| 120 // completed, and the owner may delete this object on the callback method. | 120 // completed, and the owner may delete this object on the callback method. |
| 121 // So don't rely on |this| still being valid after ForwardPolicyToken() | 121 // So don't rely on |this| still being valid after ForwardPolicyToken() |
| 122 // returns i.e. don't write to |failed_| or other fields. | 122 // returns i.e. don't write to |failed_| or other fields. |
| 123 ForwardPolicyToken(std::string(), error); | 123 ForwardPolicyToken(std::string(), error); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void PolicyOAuth2TokenFetcher::ForwardPolicyToken( | 126 void PolicyOAuth2TokenFetcher::ForwardPolicyToken( |
| 127 const std::string& token, | 127 const std::string& token, |
| 128 const GoogleServiceAuthError& error) { | 128 const GoogleServiceAuthError& error) { |
| 129 if (!callback_.is_null()) | 129 if (!callback_.is_null()) |
| 130 callback_.Run(token, error); | 130 callback_.Run(token, error); |
| 131 } | 131 } |
| 132 | 132 |
| 133 } // namespace policy | 133 } // namespace policy |
| OLD | NEW |