| 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" | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 95       oauth_scopes.insert(kHistoryOAuthScope); | 95       oauth_scopes.insert(kHistoryOAuthScope); | 
| 96       ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) | 96       ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) | 
| 97           ->InvalidateToken(oauth_scopes, access_token_); | 97           ->InvalidateToken(oauth_scopes, access_token_); | 
| 98 | 98 | 
| 99       access_token_ = std::string(); | 99       access_token_ = std::string(); | 
| 100       Start(); | 100       Start(); | 
| 101       return; | 101       return; | 
| 102     } | 102     } | 
| 103     url_fetcher_->GetResponseAsString(&response_body_); | 103     url_fetcher_->GetResponseAsString(&response_body_); | 
| 104     url_fetcher_.reset(); | 104     url_fetcher_.reset(); | 
|  | 105     is_pending_ = false; | 
| 105     callback_.Run(this, true); | 106     callback_.Run(this, true); | 
| 106     is_pending_ = false; | 107     // It is valid for the callback to delete |this|, so do not access any | 
|  | 108     // members below here. | 
| 107   } | 109   } | 
| 108 | 110 | 
| 109   // OAuth2TokenService::Consumer interface. | 111   // OAuth2TokenService::Consumer interface. | 
| 110   virtual void OnGetTokenSuccess( | 112   virtual void OnGetTokenSuccess( | 
| 111       const OAuth2TokenService::Request* request, | 113       const OAuth2TokenService::Request* request, | 
| 112       const std::string& access_token, | 114       const std::string& access_token, | 
| 113       const base::Time& expiration_time) OVERRIDE { | 115       const base::Time& expiration_time) OVERRIDE { | 
| 114     token_request_.reset(); | 116     token_request_.reset(); | 
| 115     DCHECK(!access_token.empty()); | 117     DCHECK(!access_token.empty()); | 
| 116     access_token_ = access_token; | 118     access_token_ = access_token; | 
| 117 | 119 | 
| 118     // Got an access token -- start the actual API request. | 120     // Got an access token -- start the actual API request. | 
| 119     url_fetcher_.reset(CreateUrlFetcher(access_token)); | 121     url_fetcher_.reset(CreateUrlFetcher(access_token)); | 
| 120     url_fetcher_->Start(); | 122     url_fetcher_->Start(); | 
| 121   } | 123   } | 
| 122 | 124 | 
| 123   virtual void OnGetTokenFailure( | 125   virtual void OnGetTokenFailure( | 
| 124       const OAuth2TokenService::Request* request, | 126       const OAuth2TokenService::Request* request, | 
| 125       const GoogleServiceAuthError& error) OVERRIDE { | 127       const GoogleServiceAuthError& error) OVERRIDE { | 
| 126     token_request_.reset(); | 128     token_request_.reset(); | 
| 127     LOG(WARNING) << "Failed to get OAuth token: " << error.ToString(); | 129     is_pending_ = false; | 
| 128     callback_.Run(this, false); | 130     callback_.Run(this, false); | 
| 129     is_pending_ = false; | 131     // It is valid for the callback to delete |this|, so do not access any | 
|  | 132     // members below here. | 
| 130   } | 133   } | 
| 131 | 134 | 
| 132   // Helper for creating a new URLFetcher for the API request. | 135   // Helper for creating a new URLFetcher for the API request. | 
| 133   net::URLFetcher* CreateUrlFetcher(const std::string& access_token) { | 136   net::URLFetcher* CreateUrlFetcher(const std::string& access_token) { | 
| 134     net::URLFetcher::RequestType request_type = post_data_.empty() ? | 137     net::URLFetcher::RequestType request_type = post_data_.empty() ? | 
| 135         net::URLFetcher::GET : net::URLFetcher::POST; | 138         net::URLFetcher::GET : net::URLFetcher::POST; | 
| 136     net::URLFetcher* fetcher = net::URLFetcher::Create( | 139     net::URLFetcher* fetcher = net::URLFetcher::Create( | 
| 137         url_, request_type, this); | 140         url_, request_type, this); | 
| 138     fetcher->SetRequestContext(profile_->GetRequestContext()); | 141     fetcher->SetRequestContext(profile_->GetRequestContext()); | 
| 139     fetcher->SetMaxRetriesOn5xx(kMaxRetries); | 142     fetcher->SetMaxRetriesOn5xx(kMaxRetries); | 
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 367     base::Time end_time, | 370     base::Time end_time, | 
| 368     const ExpireWebHistoryCallback& callback) { | 371     const ExpireWebHistoryCallback& callback) { | 
| 369   std::vector<ExpireHistoryArgs> expire_list(1); | 372   std::vector<ExpireHistoryArgs> expire_list(1); | 
| 370   expire_list.back().urls = restrict_urls; | 373   expire_list.back().urls = restrict_urls; | 
| 371   expire_list.back().begin_time = begin_time; | 374   expire_list.back().begin_time = begin_time; | 
| 372   expire_list.back().end_time = end_time; | 375   expire_list.back().end_time = end_time; | 
| 373   return ExpireHistory(expire_list, callback); | 376   return ExpireHistory(expire_list, callback); | 
| 374 } | 377 } | 
| 375 | 378 | 
| 376 }  // namespace history | 379 }  // namespace history | 
| OLD | NEW | 
|---|