| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "google_apis/drive/auth_service.h" | 5 #include "google_apis/drive/auth_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 DCHECK(thread_checker_.CalledOnValidThread()); | 95 DCHECK(thread_checker_.CalledOnValidThread()); |
| 96 | 96 |
| 97 LOG(WARNING) << "AuthRequest: token request using refresh token failed: " | 97 LOG(WARNING) << "AuthRequest: token request using refresh token failed: " |
| 98 << error.ToString(); | 98 << error.ToString(); |
| 99 | 99 |
| 100 // There are many ways to fail, but if the failure is due to connection, | 100 // There are many ways to fail, but if the failure is due to connection, |
| 101 // it's likely that the device is off-line. We treat the error differently | 101 // it's likely that the device is off-line. We treat the error differently |
| 102 // so that the file manager works while off-line. | 102 // so that the file manager works while off-line. |
| 103 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) { | 103 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) { |
| 104 RecordAuthResultHistogram(kSuccessRatioHistogramNoConnection); | 104 RecordAuthResultHistogram(kSuccessRatioHistogramNoConnection); |
| 105 callback_.Run(GDATA_NO_CONNECTION, std::string()); | 105 callback_.Run(DRIVE_NO_CONNECTION, std::string()); |
| 106 } else if (error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { | 106 } else if (error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { |
| 107 RecordAuthResultHistogram(kSuccessRatioHistogramTemporaryFailure); | 107 RecordAuthResultHistogram(kSuccessRatioHistogramTemporaryFailure); |
| 108 callback_.Run(HTTP_FORBIDDEN, std::string()); | 108 callback_.Run(HTTP_FORBIDDEN, std::string()); |
| 109 } else { | 109 } else { |
| 110 // Permanent auth error. | 110 // Permanent auth error. |
| 111 RecordAuthResultHistogram(kSuccessRatioHistogramFailure); | 111 RecordAuthResultHistogram(kSuccessRatioHistogramFailure); |
| 112 callback_.Run(HTTP_UNAUTHORIZED, std::string()); | 112 callback_.Run(HTTP_UNAUTHORIZED, std::string()); |
| 113 } | 113 } |
| 114 delete this; | 114 delete this; |
| 115 } | 115 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // We have refresh token, let's get an access token. | 149 // We have refresh token, let's get an access token. |
| 150 new AuthRequest(oauth2_token_service_, | 150 new AuthRequest(oauth2_token_service_, |
| 151 account_id_, | 151 account_id_, |
| 152 url_request_context_getter_.get(), | 152 url_request_context_getter_.get(), |
| 153 base::Bind(&AuthService::OnAuthCompleted, | 153 base::Bind(&AuthService::OnAuthCompleted, |
| 154 weak_ptr_factory_.GetWeakPtr(), | 154 weak_ptr_factory_.GetWeakPtr(), |
| 155 callback), | 155 callback), |
| 156 scopes_); | 156 scopes_); |
| 157 } else { | 157 } else { |
| 158 base::MessageLoop::current()->PostTask( | 158 base::MessageLoop::current()->PostTask( |
| 159 FROM_HERE, base::Bind(callback, GDATA_NOT_READY, std::string())); | 159 FROM_HERE, base::Bind(callback, DRIVE_NOT_READY, std::string())); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 bool AuthService::HasAccessToken() const { | 163 bool AuthService::HasAccessToken() const { |
| 164 return !access_token_.empty(); | 164 return !access_token_.empty(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 bool AuthService::HasRefreshToken() const { | 167 bool AuthService::HasRefreshToken() const { |
| 168 return has_refresh_token_; | 168 return has_refresh_token_; |
| 169 } | 169 } |
| 170 | 170 |
| 171 const std::string& AuthService::access_token() const { | 171 const std::string& AuthService::access_token() const { |
| 172 return access_token_; | 172 return access_token_; |
| 173 } | 173 } |
| 174 | 174 |
| 175 void AuthService::ClearAccessToken() { | 175 void AuthService::ClearAccessToken() { |
| 176 access_token_.clear(); | 176 access_token_.clear(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void AuthService::ClearRefreshToken() { | 179 void AuthService::ClearRefreshToken() { |
| 180 OnHandleRefreshToken(false); | 180 OnHandleRefreshToken(false); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void AuthService::OnAuthCompleted(const AuthStatusCallback& callback, | 183 void AuthService::OnAuthCompleted(const AuthStatusCallback& callback, |
| 184 GDataErrorCode error, | 184 DriveApiErrorCode error, |
| 185 const std::string& access_token) { | 185 const std::string& access_token) { |
| 186 DCHECK(thread_checker_.CalledOnValidThread()); | 186 DCHECK(thread_checker_.CalledOnValidThread()); |
| 187 DCHECK(!callback.is_null()); | 187 DCHECK(!callback.is_null()); |
| 188 | 188 |
| 189 if (error == HTTP_SUCCESS) { | 189 if (error == HTTP_SUCCESS) { |
| 190 access_token_ = access_token; | 190 access_token_ = access_token; |
| 191 } else if (error == HTTP_UNAUTHORIZED) { | 191 } else if (error == HTTP_UNAUTHORIZED) { |
| 192 // Refreshing access token using the refresh token is failed with 401 error | 192 // Refreshing access token using the refresh token is failed with 401 error |
| 193 // (HTTP_UNAUTHORIZED). This means the current refresh token is invalid for | 193 // (HTTP_UNAUTHORIZED). This means the current refresh token is invalid for |
| 194 // Drive, hence we clear the refresh token here to make HasRefreshToken() | 194 // Drive, hence we clear the refresh token here to make HasRefreshToken() |
| (...skipping 28 matching lines...) Expand all Loading... |
| 223 void AuthService::OnHandleRefreshToken(bool has_refresh_token) { | 223 void AuthService::OnHandleRefreshToken(bool has_refresh_token) { |
| 224 access_token_.clear(); | 224 access_token_.clear(); |
| 225 has_refresh_token_ = has_refresh_token; | 225 has_refresh_token_ = has_refresh_token; |
| 226 | 226 |
| 227 FOR_EACH_OBSERVER(AuthServiceObserver, | 227 FOR_EACH_OBSERVER(AuthServiceObserver, |
| 228 observers_, | 228 observers_, |
| 229 OnOAuth2RefreshTokenChanged()); | 229 OnOAuth2RefreshTokenChanged()); |
| 230 } | 230 } |
| 231 | 231 |
| 232 } // namespace google_apis | 232 } // namespace google_apis |
| OLD | NEW |