Chromium Code Reviews| Index: components/history/core/browser/web_history_service.cc |
| diff --git a/components/history/core/browser/web_history_service.cc b/components/history/core/browser/web_history_service.cc |
| index 3a0aa2906f0046ed29426bcdec4879e047622163..e90706320c6017fb19cab0b6c4bb784f8ff87bbf 100644 |
| --- a/components/history/core/browser/web_history_service.cc |
| +++ b/components/history/core/browser/web_history_service.cc |
| @@ -5,6 +5,7 @@ |
| #include "components/history/core/browser/web_history_service.h" |
| #include "base/bind.h" |
| +#include "base/command_line.h" |
| #include "base/json/json_reader.h" |
| #include "base/json/json_writer.h" |
| #include "base/metrics/histogram.h" |
| @@ -13,6 +14,7 @@ |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/values.h" |
| #include "components/signin/core/browser/signin_manager.h" |
| +#include "components/sync_driver/sync_util.h" |
| #include "google_apis/gaia/gaia_urls.h" |
| #include "google_apis/gaia/google_service_auth_error.h" |
| #include "google_apis/gaia/oauth2_token_service.h" |
| @@ -23,6 +25,7 @@ |
| #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 "sync/protocol/history_status.pb.h" |
| #include "url/gurl.h" |
| namespace history { |
| @@ -171,6 +174,13 @@ class RequestImpl : public WebHistoryService::Request, |
| fetcher->AddExtraRequestHeader("Authorization: Bearer " + access_token); |
| fetcher->AddExtraRequestHeader("X-Developer-Key: " + |
| GaiaUrls::GetInstance()->oauth2_chrome_client_id()); |
| + |
| + if (user_agent_ != "") { |
|
sdefresne
2016/05/18 14:29:41
if (!user_agent_.empty()) {
msramek
2016/05/18 19:38:37
Done.
|
| + fetcher->AddExtraRequestHeader( |
| + std::string(net::HttpRequestHeaders::kUserAgent) + |
| + ": " + user_agent_); |
| + } |
| + |
| if (request_type == net::URLFetcher::POST) |
| fetcher->SetUploadData(kPostDataMimeType, post_data_); |
| return fetcher; |
| @@ -180,6 +190,10 @@ class RequestImpl : public WebHistoryService::Request, |
| post_data_ = post_data; |
| } |
| + void SetUserAgent(const std::string& user_agent) override { |
| + user_agent_ = user_agent; |
| + } |
| + |
| OAuth2TokenService* token_service_; |
| SigninManagerBase* signin_manager_; |
| scoped_refptr<net::URLRequestContextGetter> request_context_; |
| @@ -190,6 +204,9 @@ class RequestImpl : public WebHistoryService::Request, |
| // POST data to be sent with the request (may be empty). |
| std::string post_data_; |
| + // The user agent header used with this request. |
| + std::string user_agent_; |
| + |
| // The OAuth2 access token request. |
| std::unique_ptr<OAuth2TokenService::Request> token_request_; |
| @@ -441,12 +458,6 @@ size_t WebHistoryService::GetNumberOfPendingAudioHistoryRequests() { |
| return pending_audio_history_requests_.size(); |
| } |
| -bool WebHistoryService::HasOtherFormsOfBrowsingHistory() const { |
| - // TODO(msramek): Query history.google.com for existence of other forms of |
| - // browsing history. In the meantime, assume that there isn't. |
| - return false; |
| -} |
| - |
| void WebHistoryService::QueryWebAndAppActivity( |
| const QueryWebAndAppActivityCallback& callback) { |
| // Wrap the original callback into a generic completion callback. |
| @@ -461,6 +472,25 @@ void WebHistoryService::QueryWebAndAppActivity( |
| request->Start(); |
| } |
| +void WebHistoryService::QueryOtherFormsOfBrowsingHistory( |
| + const version_info::Channel channel, |
| + const std::string& user_agent, |
| + const QueryOtherFormsOfBrowsingHistoryCallback& callback) { |
| + // Wrap the original callback into a generic completion callback. |
| + CompletionCallback completion_callback = base::Bind( |
| + &WebHistoryService::QueryOtherFormsOfBrowsingHistoryCompletionCallback, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + callback); |
| + |
| + GURL url = |
| + GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(), channel); |
|
pavely
2016/05/17 22:56:48
Could you confirm with Kevin that this is correct
msramek
2016/05/18 19:38:37
Fixed. Yes, that would be the very first thing I w
|
| + |
| + Request* request = CreateRequest(url, completion_callback); |
|
pavely
2016/05/17 22:56:48
Looks like request is not owned by any other objec
msramek
2016/05/18 19:38:37
Done. Added the call to the destructor. It would b
|
| + request->SetUserAgent(user_agent); |
| + pending_other_forms_of_browsing_history_requests_.insert(request); |
| + request->Start(); |
| +} |
| + |
| // static |
| void WebHistoryService::QueryHistoryCompletionCallback( |
| const WebHistoryService::QueryWebHistoryCallback& callback, |
| @@ -530,4 +560,22 @@ void WebHistoryService::QueryWebAndAppActivityCompletionCallback( |
| callback.Run(web_and_app_activity_enabled); |
| } |
| +void WebHistoryService::QueryOtherFormsOfBrowsingHistoryCompletionCallback( |
| + const WebHistoryService::QueryOtherFormsOfBrowsingHistoryCallback& callback, |
| + WebHistoryService::Request* request, |
| + bool success) { |
| + pending_other_forms_of_browsing_history_requests_.erase(request); |
| + std::unique_ptr<Request> request_ptr(request); |
| + |
| + bool has_other_forms_of_browsing_history = false; |
| + if (success && request->GetResponseCode() == net::HTTP_OK) { |
| + std::unique_ptr<sync_pb::HistoryStatusResponse> history_status( |
| + new sync_pb::HistoryStatusResponse()); |
| + if (history_status->ParseFromString(request->GetResponseBody())) |
| + has_other_forms_of_browsing_history = history_status->has_derived_data(); |
| + } |
| + |
| + callback.Run(has_other_forms_of_browsing_history); |
| +} |
| + |
| } // namespace history |