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