| 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 "chrome/browser/google_apis/auth_service.h" | 5 #include "chrome/browser/google_apis/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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } else { | 130 } else { |
| 131 // Permanent auth error. | 131 // Permanent auth error. |
| 132 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", | 132 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", |
| 133 kSuccessRatioHistogramFailure, | 133 kSuccessRatioHistogramFailure, |
| 134 kSuccessRatioHistogramMaxValue); | 134 kSuccessRatioHistogramMaxValue); |
| 135 callback_.Run(HTTP_UNAUTHORIZED, std::string()); | 135 callback_.Run(HTTP_UNAUTHORIZED, std::string()); |
| 136 } | 136 } |
| 137 delete this; | 137 delete this; |
| 138 } | 138 } |
| 139 | 139 |
| 140 void AuthService::Initialize(Profile* profile) { | 140 AuthService::AuthService( |
| 141 profile_ = profile; | 141 Profile* profile, |
| 142 net::URLRequestContextGetter* url_request_context_getter, |
| 143 const std::vector<std::string>& scopes) |
| 144 : profile_(profile), |
| 145 url_request_context_getter_(url_request_context_getter), |
| 146 scopes_(scopes), |
| 147 weak_ptr_factory_(this) { |
| 148 DCHECK(thread_checker_.CalledOnValidThread()); |
| 149 |
| 142 // Get OAuth2 refresh token (if we have any) and register for its updates. | 150 // Get OAuth2 refresh token (if we have any) and register for its updates. |
| 143 TokenService* service = TokenServiceFactory::GetForProfile(profile_); | 151 TokenService* service = TokenServiceFactory::GetForProfile(profile_); |
| 144 refresh_token_ = service->GetOAuth2LoginRefreshToken(); | 152 refresh_token_ = service->GetOAuth2LoginRefreshToken(); |
| 145 registrar_.Add(this, | 153 registrar_.Add(this, |
| 146 chrome::NOTIFICATION_TOKEN_AVAILABLE, | 154 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
| 147 content::Source<TokenService>(service)); | 155 content::Source<TokenService>(service)); |
| 148 registrar_.Add(this, | 156 registrar_.Add(this, |
| 149 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, | 157 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, |
| 150 content::Source<TokenService>(service)); | 158 content::Source<TokenService>(service)); |
| 151 | |
| 152 if (!refresh_token_.empty()) | |
| 153 FOR_EACH_OBSERVER(AuthServiceObserver, | |
| 154 observers_, | |
| 155 OnOAuth2RefreshTokenChanged()); | |
| 156 } | |
| 157 | |
| 158 AuthService::AuthService( | |
| 159 net::URLRequestContextGetter* url_request_context_getter, | |
| 160 const std::vector<std::string>& scopes) | |
| 161 : profile_(NULL), | |
| 162 url_request_context_getter_(url_request_context_getter), | |
| 163 scopes_(scopes), | |
| 164 weak_ptr_factory_(this) { | |
| 165 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 166 } | 159 } |
| 167 | 160 |
| 168 AuthService::~AuthService() { | 161 AuthService::~AuthService() { |
| 169 } | 162 } |
| 170 | 163 |
| 171 void AuthService::StartAuthentication(const AuthStatusCallback& callback) { | 164 void AuthService::StartAuthentication(const AuthStatusCallback& callback) { |
| 172 DCHECK(thread_checker_.CalledOnValidThread()); | 165 DCHECK(thread_checker_.CalledOnValidThread()); |
| 173 scoped_refptr<base::MessageLoopProxy> relay_proxy( | 166 scoped_refptr<base::MessageLoopProxy> relay_proxy( |
| 174 base::MessageLoopProxy::current()); | 167 base::MessageLoopProxy::current()); |
| 175 | 168 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 #endif // OS_CHROMEOS | 272 #endif // OS_CHROMEOS |
| 280 | 273 |
| 281 // Authentication cannot be done with the incognito mode profile. | 274 // Authentication cannot be done with the incognito mode profile. |
| 282 if (profile->IsOffTheRecord()) | 275 if (profile->IsOffTheRecord()) |
| 283 return false; | 276 return false; |
| 284 | 277 |
| 285 return true; | 278 return true; |
| 286 } | 279 } |
| 287 | 280 |
| 288 } // namespace google_apis | 281 } // namespace google_apis |
| OLD | NEW |