Index: chrome/browser/history/web_history_service.cc |
diff --git a/components/history/core/browser/web_history_service.cc b/chrome/browser/history/web_history_service.cc |
similarity index 89% |
rename from components/history/core/browser/web_history_service.cc |
rename to chrome/browser/history/web_history_service.cc |
index ae0071dfaac837c6267500b6be85475f06e17d90..58c42d60622ac79c9bc8b6010eb73d2e73e6671c 100644 |
--- a/components/history/core/browser/web_history_service.cc |
+++ b/chrome/browser/history/web_history_service.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "components/history/core/browser/web_history_service.h" |
+#include "chrome/browser/history/web_history_service.h" |
#include "base/bind.h" |
#include "base/json/json_reader.h" |
@@ -12,6 +12,9 @@ |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/values.h" |
+#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
+#include "chrome/browser/signin/signin_manager_factory.h" |
+#include "components/signin/core/browser/profile_oauth2_token_service.h" |
#include "components/signin/core/browser/signin_manager.h" |
#include "google_apis/gaia/gaia_urls.h" |
#include "google_apis/gaia/google_service_auth_error.h" |
@@ -22,7 +25,6 @@ |
#include "net/http/http_util.h" |
#include "net/url_request/url_fetcher.h" |
#include "net/url_request/url_fetcher_delegate.h" |
-#include "net/url_request/url_request_context_getter.h" |
#include "url/gurl.h" |
namespace history { |
@@ -67,28 +69,29 @@ class RequestImpl : public WebHistoryService::Request, |
private: |
friend class history::WebHistoryService; |
- RequestImpl( |
- OAuth2TokenService* token_service, |
- SigninManagerBase* signin_manager, |
- const scoped_refptr<net::URLRequestContextGetter>& request_context, |
- const GURL& url, |
- const WebHistoryService::CompletionCallback& callback) |
+ RequestImpl(Profile* profile, |
+ const GURL& url, |
+ const WebHistoryService::CompletionCallback& callback) |
: OAuth2TokenService::Consumer("web_history"), |
- token_service_(token_service), |
- signin_manager_(signin_manager), |
+ profile_(profile), |
url_(url), |
response_code_(0), |
auth_retry_count_(0), |
callback_(callback), |
- is_pending_(false) {} |
+ is_pending_(false) { |
+ } |
// Tells the request to do its thang. |
void Start() override { |
OAuth2TokenService::ScopeSet oauth_scopes; |
oauth_scopes.insert(kHistoryOAuthScope); |
- token_request_ = token_service_->StartRequest( |
- signin_manager_->GetAuthenticatedAccountId(), oauth_scopes, this); |
+ ProfileOAuth2TokenService* token_service = |
+ ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
+ SigninManagerBase* signin_manager = |
+ SigninManagerFactory::GetForProfile(profile_); |
+ token_request_ = token_service->StartRequest( |
+ signin_manager->GetAuthenticatedAccountId(), oauth_scopes, this); |
is_pending_ = true; |
} |
@@ -106,8 +109,12 @@ class RequestImpl : public WebHistoryService::Request, |
if (response_code_ == net::HTTP_UNAUTHORIZED && ++auth_retry_count_ <= 1) { |
OAuth2TokenService::ScopeSet oauth_scopes; |
oauth_scopes.insert(kHistoryOAuthScope); |
- token_service_->InvalidateToken( |
- signin_manager_->GetAuthenticatedAccountId(), |
+ ProfileOAuth2TokenService* token_service = |
+ ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
+ SigninManagerBase* signin_manager = |
+ SigninManagerFactory::GetForProfile(profile_); |
+ token_service->InvalidateToken( |
+ signin_manager->GetAuthenticatedAccountId(), |
oauth_scopes, |
access_token_); |
@@ -156,7 +163,7 @@ class RequestImpl : public WebHistoryService::Request, |
net::URLFetcher::GET : net::URLFetcher::POST; |
net::URLFetcher* fetcher = net::URLFetcher::Create( |
url_, request_type, this); |
- fetcher->SetRequestContext(request_context_.get()); |
+ fetcher->SetRequestContext(profile_->GetRequestContext()); |
fetcher->SetMaxRetriesOn5xx(kMaxRetries); |
fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
net::LOAD_DO_NOT_SAVE_COOKIES); |
@@ -172,9 +179,7 @@ class RequestImpl : public WebHistoryService::Request, |
post_data_ = post_data; |
} |
- OAuth2TokenService* token_service_; |
- SigninManagerBase* signin_manager_; |
- scoped_refptr<net::URLRequestContextGetter> request_context_; |
+ Profile* profile_; |
// The URL of the API endpoint. |
GURL url_; |
@@ -280,13 +285,8 @@ WebHistoryService::Request::Request() { |
WebHistoryService::Request::~Request() { |
} |
-WebHistoryService::WebHistoryService( |
- OAuth2TokenService* token_service, |
- SigninManagerBase* signin_manager, |
- const scoped_refptr<net::URLRequestContextGetter>& request_context) |
- : token_service_(token_service), |
- signin_manager_(signin_manager), |
- request_context_(request_context), |
+WebHistoryService::WebHistoryService(Profile* profile) |
+ : profile_(profile), |
weak_ptr_factory_(this) { |
} |
@@ -298,8 +298,7 @@ WebHistoryService::~WebHistoryService() { |
WebHistoryService::Request* WebHistoryService::CreateRequest( |
const GURL& url, |
const CompletionCallback& callback) { |
- return new RequestImpl(token_service_, signin_manager_, request_context_, url, |
- callback); |
+ return new RequestImpl(profile_, url, callback); |
} |
// static |
@@ -337,21 +336,23 @@ void WebHistoryService::ExpireHistory( |
scoped_ptr<base::ListValue> deletions(new base::ListValue); |
base::Time now = base::Time::Now(); |
- for (const auto& expire : expire_list) { |
+ for (std::vector<ExpireHistoryArgs>::const_iterator it = expire_list.begin(); |
+ it != expire_list.end(); ++it) { |
// Convert the times to server timestamps. |
- std::string min_timestamp = ServerTimeString(expire.begin_time); |
+ std::string min_timestamp = ServerTimeString(it->begin_time); |
// TODO(dubroy): Use sane time (crbug.com/146090) here when it's available. |
- base::Time end_time = expire.end_time; |
+ base::Time end_time = it->end_time; |
if (end_time.is_null() || end_time > now) |
end_time = now; |
std::string max_timestamp = ServerTimeString(end_time); |
- for (const auto& url : expire.urls) { |
+ for (std::set<GURL>::const_iterator url_iterator = it->urls.begin(); |
+ url_iterator != it->urls.end(); ++url_iterator) { |
deletions->Append( |
- CreateDeletion(min_timestamp, max_timestamp, url)); |
+ CreateDeletion(min_timestamp, max_timestamp, *url_iterator)); |
} |
// If no URLs were specified, delete everything in the time range. |
- if (expire.urls.empty()) |
+ if (it->urls.empty()) |
deletions->Append(CreateDeletion(min_timestamp, max_timestamp, GURL())); |
} |
delete_request.Set("del", deletions.release()); |