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..7acca6e6b41bca625b0e4b2c1a5bd7ac242f5726 100644 |
--- a/components/history/core/browser/web_history_service.cc |
+++ b/components/history/core/browser/web_history_service.cc |
@@ -4,15 +4,21 @@ |
#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" |
+#include "base/optional.h" |
#include "base/stl_util.h" |
#include "base/strings/string_number_conversions.h" |
#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 +29,8 @@ |
#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 "ui/base/device_form_factor.h" |
#include "url/gurl.h" |
namespace history { |
@@ -47,8 +55,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 +93,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 +173,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 +184,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_.value()); |
return fetcher; |
} |
void SetPostData(const std::string& post_data) override { |
+ SetPostDataAndType(post_data, kPostDataMimeType); |
+ } |
+ |
+ void SetPostDataAndType(const std::string& post_data, |
+ const std::string& mime_type) override { |
post_data_ = 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 +218,13 @@ class RequestImpl : public WebHistoryService::Request, |
GURL url_; |
// POST data to be sent with the request (may be empty). |
- std::string post_data_; |
+ base::Optional<std::string> post_data_; |
+ |
+ // 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 +338,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 +478,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 +492,45 @@ void WebHistoryService::QueryWebAndAppActivity( |
request->Start(); |
} |
+void WebHistoryService::QueryOtherFormsOfBrowsingHistory( |
+ version_info::Channel channel, |
+ 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. |
+ browser_sync::LocalDeviceInfoProviderImpl local_device_info_provider_( |
pavely
2016/05/24 22:05:04
Instantiating LocalDeviceInfoProviderImpl should n
msramek
2016/05/25 08:53:44
Done.
Yes, I thought the same - we have the stand
|
+ channel, std::string() /* version (unused) */, |
+ ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_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( |
pavely
2016/05/24 22:05:04
HistoryStatusResponse => HistoryStatusRequest
Also
msramek
2016/05/25 08:53:44
Done. Oops! At least the serialization is still th
|
+ new sync_pb::HistoryStatusResponse()); |
+ std::string post_data; |
+ request_proto->SerializeToString(&post_data); |
+ request->SetPostDataAndType(post_data, kSyncProtoMimeType); |
+ |
+ request->Start(); |
+} |
+ |
// static |
void WebHistoryService::QueryHistoryCompletionCallback( |
const WebHistoryService::QueryWebHistoryCallback& callback, |
@@ -530,4 +600,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( |
pavely
2016/05/24 22:05:04
Same comment as above: replace unique_ptr<HistoryS
msramek
2016/05/25 08:53:43
Done.
|
+ 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 |