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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/signin/oauth2_token_service.h" | 13 #include "chrome/browser/signin/oauth2_token_service.h" |
14 #include "chrome/browser/signin/oauth2_token_service_factory.h" | 14 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
15 #include "google_apis/gaia/gaia_urls.h" | 16 #include "google_apis/gaia/gaia_urls.h" |
16 #include "google_apis/gaia/google_service_auth_error.h" | 17 #include "google_apis/gaia/google_service_auth_error.h" |
17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
18 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
19 #include "net/base/url_util.h" | 20 #include "net/base/url_util.h" |
20 #include "net/http/http_status_code.h" | 21 #include "net/http/http_status_code.h" |
21 #include "net/url_request/url_fetcher.h" | 22 #include "net/url_request/url_fetcher.h" |
22 #include "net/url_request/url_fetcher_delegate.h" | 23 #include "net/url_request/url_fetcher_delegate.h" |
23 | 24 |
24 namespace history { | 25 namespace history { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 response_code_(0), | 67 response_code_(0), |
67 auth_retry_count_(0), | 68 auth_retry_count_(0), |
68 callback_(callback) { | 69 callback_(callback) { |
69 } | 70 } |
70 | 71 |
71 // Tells the request to do its thang. | 72 // Tells the request to do its thang. |
72 void Start() { | 73 void Start() { |
73 OAuth2TokenService::ScopeSet oauth_scopes; | 74 OAuth2TokenService::ScopeSet oauth_scopes; |
74 oauth_scopes.insert(kHistoryOAuthScope); | 75 oauth_scopes.insert(kHistoryOAuthScope); |
75 | 76 |
76 OAuth2TokenService* token_service = | 77 ProfileOAuth2TokenService* token_service = |
77 OAuth2TokenServiceFactory::GetForProfile(profile_); | 78 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
78 token_request_ = token_service->StartRequest(oauth_scopes, this); | 79 token_request_ = token_service->StartRequest(oauth_scopes, this); |
79 } | 80 } |
80 | 81 |
81 // content::URLFetcherDelegate interface. | 82 // content::URLFetcherDelegate interface. |
82 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE { | 83 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE { |
83 DCHECK_EQ(source, url_fetcher_.get()); | 84 DCHECK_EQ(source, url_fetcher_.get()); |
84 response_code_ = url_fetcher_->GetResponseCode(); | 85 response_code_ = url_fetcher_->GetResponseCode(); |
85 | 86 |
86 // If the response code indicates that the token might not be valid, | 87 // If the response code indicates that the token might not be valid, |
87 // invalidate the token and try again. | 88 // invalidate the token and try again. |
88 if (response_code_ == net::HTTP_UNAUTHORIZED && ++auth_retry_count_ <= 1) { | 89 if (response_code_ == net::HTTP_UNAUTHORIZED && ++auth_retry_count_ <= 1) { |
89 OAuth2TokenService::ScopeSet oauth_scopes; | 90 OAuth2TokenService::ScopeSet oauth_scopes; |
90 oauth_scopes.insert(kHistoryOAuthScope); | 91 oauth_scopes.insert(kHistoryOAuthScope); |
91 OAuth2TokenServiceFactory::GetForProfile(profile_)->InvalidateToken( | 92 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) |
92 oauth_scopes, access_token_); | 93 ->InvalidateToken(oauth_scopes, access_token_); |
93 | 94 |
94 access_token_ = std::string(); | 95 access_token_ = std::string(); |
95 Start(); | 96 Start(); |
96 return; | 97 return; |
97 } | 98 } |
98 url_fetcher_->GetResponseAsString(&response_body_); | 99 url_fetcher_->GetResponseAsString(&response_body_); |
99 url_fetcher_.reset(); | 100 url_fetcher_.reset(); |
100 callback_.Run(this, true); | 101 callback_.Run(this, true); |
101 } | 102 } |
102 | 103 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 base::Time end_time, | 319 base::Time end_time, |
319 const ExpireWebHistoryCallback& callback) { | 320 const ExpireWebHistoryCallback& callback) { |
320 std::vector<ExpireHistoryArgs> expire_list(1); | 321 std::vector<ExpireHistoryArgs> expire_list(1); |
321 expire_list.back().urls = restrict_urls; | 322 expire_list.back().urls = restrict_urls; |
322 expire_list.back().begin_time = begin_time; | 323 expire_list.back().begin_time = begin_time; |
323 expire_list.back().end_time = end_time; | 324 expire_list.back().end_time = end_time; |
324 return ExpireHistory(expire_list, callback); | 325 return ExpireHistory(expire_list, callback); |
325 } | 326 } |
326 | 327 |
327 } // namespace history | 328 } // namespace history |
OLD | NEW |