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" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 is_pending_(false) { | 74 is_pending_(false) { |
75 } | 75 } |
76 | 76 |
77 // Tells the request to do its thang. | 77 // Tells the request to do its thang. |
78 void Start() { | 78 void Start() { |
79 OAuth2TokenService::ScopeSet oauth_scopes; | 79 OAuth2TokenService::ScopeSet oauth_scopes; |
80 oauth_scopes.insert(kHistoryOAuthScope); | 80 oauth_scopes.insert(kHistoryOAuthScope); |
81 | 81 |
82 ProfileOAuth2TokenService* token_service = | 82 ProfileOAuth2TokenService* token_service = |
83 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 83 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
84 token_request_ = token_service->StartRequest(oauth_scopes, this); | 84 token_request_ = token_service->StartRequest( |
| 85 token_service->GetPrimaryAccountId(), oauth_scopes, this); |
85 is_pending_ = true; | 86 is_pending_ = true; |
86 } | 87 } |
87 | 88 |
88 // content::URLFetcherDelegate interface. | 89 // content::URLFetcherDelegate interface. |
89 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE { | 90 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE { |
90 DCHECK_EQ(source, url_fetcher_.get()); | 91 DCHECK_EQ(source, url_fetcher_.get()); |
91 response_code_ = url_fetcher_->GetResponseCode(); | 92 response_code_ = url_fetcher_->GetResponseCode(); |
92 | 93 |
93 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebHistory.OAuthTokenResponseCode", | 94 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebHistory.OAuthTokenResponseCode", |
94 net::HttpUtil::MapStatusCodeForHistogram(response_code_), | 95 net::HttpUtil::MapStatusCodeForHistogram(response_code_), |
95 net::HttpUtil::GetStatusCodesForHistogram()); | 96 net::HttpUtil::GetStatusCodesForHistogram()); |
96 | 97 |
97 // If the response code indicates that the token might not be valid, | 98 // If the response code indicates that the token might not be valid, |
98 // invalidate the token and try again. | 99 // invalidate the token and try again. |
99 if (response_code_ == net::HTTP_UNAUTHORIZED && ++auth_retry_count_ <= 1) { | 100 if (response_code_ == net::HTTP_UNAUTHORIZED && ++auth_retry_count_ <= 1) { |
100 OAuth2TokenService::ScopeSet oauth_scopes; | 101 OAuth2TokenService::ScopeSet oauth_scopes; |
101 oauth_scopes.insert(kHistoryOAuthScope); | 102 oauth_scopes.insert(kHistoryOAuthScope); |
102 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) | 103 ProfileOAuth2TokenService* token_service = |
103 ->InvalidateToken(oauth_scopes, access_token_); | 104 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 105 token_service->InvalidateToken(token_service->GetPrimaryAccountId(), |
| 106 oauth_scopes, |
| 107 access_token_); |
104 | 108 |
105 access_token_ = std::string(); | 109 access_token_.clear(); |
106 Start(); | 110 Start(); |
107 return; | 111 return; |
108 } | 112 } |
109 url_fetcher_->GetResponseAsString(&response_body_); | 113 url_fetcher_->GetResponseAsString(&response_body_); |
110 url_fetcher_.reset(); | 114 url_fetcher_.reset(); |
111 is_pending_ = false; | 115 is_pending_ = false; |
112 callback_.Run(this, true); | 116 callback_.Run(this, true); |
113 // It is valid for the callback to delete |this|, so do not access any | 117 // It is valid for the callback to delete |this|, so do not access any |
114 // members below here. | 118 // members below here. |
115 } | 119 } |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 scoped_ptr<DictionaryValue> response_value; | 393 scoped_ptr<DictionaryValue> response_value; |
390 if (success) { | 394 if (success) { |
391 response_value = ReadResponse(static_cast<RequestImpl*>(request)); | 395 response_value = ReadResponse(static_cast<RequestImpl*>(request)); |
392 if (response_value) | 396 if (response_value) |
393 response_value->GetString("version_info", &server_version_info_); | 397 response_value->GetString("version_info", &server_version_info_); |
394 } | 398 } |
395 callback.Run(request, response_value.get() && success); | 399 callback.Run(request, response_value.get() && success); |
396 } | 400 } |
397 | 401 |
398 } // namespace history | 402 } // namespace history |
OLD | NEW |