| 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/history/web_history_service.h" | 5 #include "chrome/browser/history/web_history_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 14 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 16 #include "chrome/browser/signin/signin_manager.h" | |
| 17 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 18 #include "google_apis/gaia/gaia_urls.h" | 16 #include "google_apis/gaia/gaia_urls.h" |
| 19 #include "google_apis/gaia/google_service_auth_error.h" | 17 #include "google_apis/gaia/google_service_auth_error.h" |
| 20 #include "google_apis/gaia/oauth2_token_service.h" | 18 #include "google_apis/gaia/oauth2_token_service.h" |
| 21 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
| 22 #include "net/base/url_util.h" | 20 #include "net/base/url_util.h" |
| 23 #include "net/http/http_status_code.h" | 21 #include "net/http/http_status_code.h" |
| 24 #include "net/http/http_util.h" | 22 #include "net/http/http_util.h" |
| 25 #include "net/url_request/url_fetcher.h" | 23 #include "net/url_request/url_fetcher.h" |
| 26 #include "net/url_request/url_fetcher_delegate.h" | 24 #include "net/url_request/url_fetcher_delegate.h" |
| 27 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 is_pending_(false) { | 75 is_pending_(false) { |
| 78 } | 76 } |
| 79 | 77 |
| 80 // Tells the request to do its thang. | 78 // Tells the request to do its thang. |
| 81 void Start() { | 79 void Start() { |
| 82 OAuth2TokenService::ScopeSet oauth_scopes; | 80 OAuth2TokenService::ScopeSet oauth_scopes; |
| 83 oauth_scopes.insert(kHistoryOAuthScope); | 81 oauth_scopes.insert(kHistoryOAuthScope); |
| 84 | 82 |
| 85 ProfileOAuth2TokenService* token_service = | 83 ProfileOAuth2TokenService* token_service = |
| 86 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 84 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 87 SigninManagerBase* signin_manager = | |
| 88 SigninManagerFactory::GetForProfile(profile_); | |
| 89 token_request_ = token_service->StartRequest( | 85 token_request_ = token_service->StartRequest( |
| 90 signin_manager->GetAuthenticatedAccountId(), oauth_scopes, this); | 86 token_service->GetPrimaryAccountId(), oauth_scopes, this); |
| 91 is_pending_ = true; | 87 is_pending_ = true; |
| 92 } | 88 } |
| 93 | 89 |
| 94 // content::URLFetcherDelegate interface. | 90 // content::URLFetcherDelegate interface. |
| 95 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE { | 91 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE { |
| 96 DCHECK_EQ(source, url_fetcher_.get()); | 92 DCHECK_EQ(source, url_fetcher_.get()); |
| 97 response_code_ = url_fetcher_->GetResponseCode(); | 93 response_code_ = url_fetcher_->GetResponseCode(); |
| 98 | 94 |
| 99 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebHistory.OAuthTokenResponseCode", | 95 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebHistory.OAuthTokenResponseCode", |
| 100 net::HttpUtil::MapStatusCodeForHistogram(response_code_), | 96 net::HttpUtil::MapStatusCodeForHistogram(response_code_), |
| 101 net::HttpUtil::GetStatusCodesForHistogram()); | 97 net::HttpUtil::GetStatusCodesForHistogram()); |
| 102 | 98 |
| 103 // If the response code indicates that the token might not be valid, | 99 // If the response code indicates that the token might not be valid, |
| 104 // invalidate the token and try again. | 100 // invalidate the token and try again. |
| 105 if (response_code_ == net::HTTP_UNAUTHORIZED && ++auth_retry_count_ <= 1) { | 101 if (response_code_ == net::HTTP_UNAUTHORIZED && ++auth_retry_count_ <= 1) { |
| 106 OAuth2TokenService::ScopeSet oauth_scopes; | 102 OAuth2TokenService::ScopeSet oauth_scopes; |
| 107 oauth_scopes.insert(kHistoryOAuthScope); | 103 oauth_scopes.insert(kHistoryOAuthScope); |
| 108 ProfileOAuth2TokenService* token_service = | 104 ProfileOAuth2TokenService* token_service = |
| 109 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 105 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 110 SigninManagerBase* signin_manager = | 106 token_service->InvalidateToken(token_service->GetPrimaryAccountId(), |
| 111 SigninManagerFactory::GetForProfile(profile_); | 107 oauth_scopes, |
| 112 token_service->InvalidateToken( | 108 access_token_); |
| 113 signin_manager->GetAuthenticatedAccountId(), | |
| 114 oauth_scopes, | |
| 115 access_token_); | |
| 116 | 109 |
| 117 access_token_.clear(); | 110 access_token_.clear(); |
| 118 Start(); | 111 Start(); |
| 119 return; | 112 return; |
| 120 } | 113 } |
| 121 url_fetcher_->GetResponseAsString(&response_body_); | 114 url_fetcher_->GetResponseAsString(&response_body_); |
| 122 url_fetcher_.reset(); | 115 url_fetcher_.reset(); |
| 123 is_pending_ = false; | 116 is_pending_ = false; |
| 124 callback_.Run(this, true); | 117 callback_.Run(this, true); |
| 125 // It is valid for the callback to delete |this|, so do not access any | 118 // It is valid for the callback to delete |this|, so do not access any |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 scoped_ptr<base::DictionaryValue> response_value; | 394 scoped_ptr<base::DictionaryValue> response_value; |
| 402 if (success) { | 395 if (success) { |
| 403 response_value = ReadResponse(static_cast<RequestImpl*>(request)); | 396 response_value = ReadResponse(static_cast<RequestImpl*>(request)); |
| 404 if (response_value) | 397 if (response_value) |
| 405 response_value->GetString("version_info", &server_version_info_); | 398 response_value->GetString("version_info", &server_version_info_); |
| 406 } | 399 } |
| 407 callback.Run(request, response_value.get() && success); | 400 callback.Run(request, response_value.get() && success); |
| 408 } | 401 } |
| 409 | 402 |
| 410 } // namespace history | 403 } // namespace history |
| OLD | NEW |