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..8801a9e4b13cca640de8753f68ee3663398c2f76 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 { |
@@ -47,6 +50,8 @@ const char kHistoryAudioHistoryChangeUrl[] = |
const char kQueryWebAndAppActivityUrl[] = |
"https://history.google.com/history/api/lookup?client=web_app"; |
+const char kQueryOtherFormsOfBrowsingHistoryUrlSuffix[] = "/historystatus"; |
+ |
const char kPostDataMimeType[] = "text/plain"; |
// The maximum number of retries for the URLFetcher requests. |
@@ -171,6 +176,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_.empty()) { |
+ fetcher->AddExtraRequestHeader( |
+ std::string(net::HttpRequestHeaders::kUserAgent) + |
+ ": " + user_agent_); |
+ } |
+ |
if (request_type == net::URLFetcher::POST) |
fetcher->SetUploadData(kPostDataMimeType, post_data_); |
return fetcher; |
@@ -180,6 +192,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 +206,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_; |
@@ -302,6 +321,7 @@ WebHistoryService::~WebHistoryService() { |
STLDeleteElements(&pending_expire_requests_); |
STLDeleteElements(&pending_audio_history_requests_); |
STLDeleteElements(&pending_web_and_app_activity_requests_); |
+ STLDeleteElements(&pending_other_forms_of_browsing_history_requests_); |
} |
WebHistoryService::Request* WebHistoryService::CreateRequest( |
@@ -441,12 +461,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 +475,34 @@ void WebHistoryService::QueryWebAndAppActivity( |
request->Start(); |
} |
+void WebHistoryService::QueryOtherFormsOfBrowsingHistory( |
+ 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); |
+ GURL::Replacements replace_path; |
+ std::string new_path = |
+ url.path() + kQueryOtherFormsOfBrowsingHistoryUrlSuffix; |
+ replace_path.SetPathStr(new_path); |
+ url = url.ReplaceComponents(replace_path); |
+ DCHECK(url.is_valid()); |
+ |
+ Request* request = CreateRequest(url, completion_callback); |
+ request->SetUserAgent(user_agent); |
+ pending_other_forms_of_browsing_history_requests_.insert(request); |
+ |
+ // Set post data to a whitespace to force this request to be POST. |
+ request->SetPostData(" "); |
+ request->Start(); |
+} |
+ |
// static |
void WebHistoryService::QueryHistoryCompletionCallback( |
const WebHistoryService::QueryWebHistoryCallback& callback, |
@@ -530,4 +572,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 |