Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Unified Diff: components/history/core/browser/web_history_service.cc

Issue 1983073002: Query the existence other forms of browsing history. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments, re-added protobuf Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..3f4b7557e97b1c350d79fb70aad1afe620ab6138 100644
--- a/components/history/core/browser/web_history_service.cc
+++ b/components/history/core/browser/web_history_service.cc
@@ -4,7 +4,10 @@
#include "components/history/core/browser/web_history_service.h"
+#include <memory>
+
#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 +16,8 @@
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "components/signin/core/browser/signin_manager.h"
+#include "components/sync_driver/local_device_info_provider_impl.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 +28,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,8 +53,12 @@ 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";
+const char kSyncProtoMimeType[] = "application/octet-stream";
+
// The maximum number of retries for the URLFetcher requests.
const size_t kMaxRetries = 1;
@@ -81,6 +91,7 @@ class RequestImpl : public WebHistoryService::Request,
signin_manager_(signin_manager),
request_context_(request_context),
url_(url),
+ post_data_mime_type_(kPostDataMimeType),
response_code_(0),
auth_retry_count_(0),
callback_(callback),
@@ -160,8 +171,8 @@ class RequestImpl : public WebHistoryService::Request,
// Helper for creating a new URLFetcher for the API request.
std::unique_ptr<net::URLFetcher> CreateUrlFetcher(
const std::string& access_token) {
- net::URLFetcher::RequestType request_type = post_data_.empty() ?
- net::URLFetcher::GET : net::URLFetcher::POST;
+ net::URLFetcher::RequestType request_type = post_data_ ?
+ net::URLFetcher::POST : net::URLFetcher::GET;
std::unique_ptr<net::URLFetcher> fetcher =
net::URLFetcher::Create(url_, request_type, this);
fetcher->SetRequestContext(request_context_.get());
@@ -171,13 +182,30 @@ class RequestImpl : public WebHistoryService::Request,
fetcher->AddExtraRequestHeader("Authorization: Bearer " + access_token);
fetcher->AddExtraRequestHeader("X-Developer-Key: " +
GaiaUrls::GetInstance()->oauth2_chrome_client_id());
- if (request_type == net::URLFetcher::POST)
- fetcher->SetUploadData(kPostDataMimeType, post_data_);
+
+ if (!user_agent_.empty()) {
+ fetcher->AddExtraRequestHeader(
+ std::string(net::HttpRequestHeaders::kUserAgent) +
+ ": " + user_agent_);
+ }
+
+ if (post_data_)
+ fetcher->SetUploadData(post_data_mime_type_, *post_data_);
return fetcher;
}
void SetPostData(const std::string& post_data) override {
- post_data_ = post_data;
+ SetPostData(post_data, kPostDataMimeType);
+ }
+
+ void SetPostData(const std::string& post_data,
sdefresne 2016/05/24 08:32:29 Style guide discourage function/method overloading
msramek 2016/05/24 12:03:00 Done.
+ const std::string& mime_type) override {
msramek 2016/05/23 19:18:12 Another new method to change the mime type to appl
+ post_data_.reset(new std::string(post_data));
+ post_data_mime_type_ = mime_type;
+ }
+
+ void SetUserAgent(const std::string& user_agent) override {
+ user_agent_ = user_agent;
}
OAuth2TokenService* token_service_;
@@ -188,7 +216,13 @@ class RequestImpl : public WebHistoryService::Request,
GURL url_;
// POST data to be sent with the request (may be empty).
- std::string post_data_;
+ std::unique_ptr<std::string> post_data_;
msramek 2016/05/23 19:18:12 Changed this to a std::unique_ptr<>, so that we ca
sdefresne 2016/05/24 08:32:29 Can you use base::Optional<std::string> which is c
+
+ // MIME type of the post requests. Defaults to text/plain.
+ std::string post_data_mime_type_;
+
+ // 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 +336,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 +476,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 +490,45 @@ void WebHistoryService::QueryWebAndAppActivity(
request->Start();
}
+void WebHistoryService::QueryOtherFormsOfBrowsingHistory(
+ version_info::Channel channel,
+ bool is_tablet,
+ const QueryOtherFormsOfBrowsingHistoryCallback& callback) {
+ // Wrap the original callback into a generic completion callback.
+ CompletionCallback completion_callback = base::Bind(
+ &WebHistoryService::QueryOtherFormsOfBrowsingHistoryCompletionCallback,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback);
+
+ // Find the Sync request URL.
+ 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);
+
+ // Set the Sync-specific user agent.
msramek 2016/05/23 19:18:12 I realized that I was setting the user agent wrong
+ browser_sync::LocalDeviceInfoProviderImpl local_device_info_provider_(
+ channel, std::string() /* version (unused) */, is_tablet);
+ request->SetUserAgent(local_device_info_provider_.GetSyncUserAgent());
+
+ pending_other_forms_of_browsing_history_requests_.insert(request);
+
+ // Set the request protobuf.
+ std::unique_ptr<sync_pb::HistoryStatusResponse> request_proto(
+ new sync_pb::HistoryStatusResponse());
+ std::string post_data;
+ request_proto->SerializeToString(&post_data);
+ request->SetPostData(post_data, kSyncProtoMimeType);
+
+ request->Start();
+}
+
// static
void WebHistoryService::QueryHistoryCompletionCallback(
const WebHistoryService::QueryWebHistoryCallback& callback,
@@ -530,4 +598,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

Powered by Google App Engine
This is Rietveld 408576698