Commit aff3fd11 authored by dubroy@chromium.org's avatar dubroy@chromium.org

History: Include search term in queries to history server.

History server now supports searches using q=your+query syntax. When
searching history, combine local results with results from the server.
Fixed bug where server results would be ignored if there were no local
results.

TBR=brettw@chromium.org
BUG=180970
TEST=Open chrome://history in a signed-in profile, and type a search
into the search box. Results should include vists from other devices.

Review URL: https://codereview.chromium.org/12930011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@190503 0039d316-1c4b-4281-b951-d872f2087c98
parent 805117fd
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/signin/oauth2_token_service.h" #include "chrome/browser/signin/oauth2_token_service.h"
#include "chrome/browser/signin/oauth2_token_service_factory.h" #include "chrome/browser/signin/oauth2_token_service_factory.h"
...@@ -177,7 +178,8 @@ std::string ServerTimeString(base::Time time) { ...@@ -177,7 +178,8 @@ std::string ServerTimeString(base::Time time) {
// Returns a URL for querying the history server for a query specified by // Returns a URL for querying the history server for a query specified by
// |options|. // |options|.
std::string GetQueryUrl(const QueryOptions& options) { std::string GetQueryUrl(const string16& text_query,
const QueryOptions& options) {
GURL url = GURL(kHistoryQueryHistoryUrl); GURL url = GURL(kHistoryQueryHistoryUrl);
url = net::AppendQueryParameter(url, "titles", "1"); url = net::AppendQueryParameter(url, "titles", "1");
...@@ -199,6 +201,9 @@ std::string GetQueryUrl(const QueryOptions& options) { ...@@ -199,6 +201,9 @@ std::string GetQueryUrl(const QueryOptions& options) {
url, "num", base::IntToString(options.max_count)); url, "num", base::IntToString(options.max_count));
} }
if (!text_query.empty())
url = net::AppendQueryParameter(url, "q", UTF16ToUTF8(text_query));
return url.spec(); return url.spec();
} }
...@@ -241,8 +246,9 @@ scoped_ptr<WebHistoryService::Request> WebHistoryService::QueryHistory( ...@@ -241,8 +246,9 @@ scoped_ptr<WebHistoryService::Request> WebHistoryService::QueryHistory(
RequestImpl::CompletionCallback completion_callback = base::Bind( RequestImpl::CompletionCallback completion_callback = base::Bind(
&QueryHistoryCompletionCallback, callback); &QueryHistoryCompletionCallback, callback);
std::string url = GetQueryUrl(text_query, options);
scoped_ptr<RequestImpl> request( scoped_ptr<RequestImpl> request(
new RequestImpl(profile_, GetQueryUrl(options), completion_callback)); new RequestImpl(profile_, url, completion_callback));
request->Start(); request->Start();
return request.PassAs<Request>(); return request.PassAs<Request>();
} }
......
...@@ -825,14 +825,17 @@ void BrowsingHistoryHandler::ReturnResultsToFrontEnd() { ...@@ -825,14 +825,17 @@ void BrowsingHistoryHandler::ReturnResultsToFrontEnd() {
// Combine the local and remote results into |query_results_|, and remove // Combine the local and remote results into |query_results_|, and remove
// any duplicates. // any duplicates.
if (query_results_.size() && web_history_query_results_.size()) { if (!web_history_query_results_.empty()) {
// Each result set covers a particular time range. Determine the if (!query_results_.empty()) {
// intersection of the two time ranges, discard any entries from either // Each result set covers a particular time range. Determine the
// set the are older than that, and then combine the results. // intersection of the two time ranges, discard any entries from either
base::Time cutoff_time = std::max(query_results_.back().time, // set that are older than that, and then combine the results.
web_history_query_results_.back().time); base::Time cutoff_time = std::max(
RemoveOlderEntries(&query_results_, cutoff_time); query_results_.back().time,
RemoveOlderEntries(&web_history_query_results_, cutoff_time); web_history_query_results_.back().time);
RemoveOlderEntries(&query_results_, cutoff_time);
RemoveOlderEntries(&web_history_query_results_, cutoff_time);
}
int local_result_count = query_results_.size(); int local_result_count = query_results_.size();
query_results_.insert(query_results_.end(), query_results_.insert(query_results_.end(),
...@@ -840,9 +843,9 @@ void BrowsingHistoryHandler::ReturnResultsToFrontEnd() { ...@@ -840,9 +843,9 @@ void BrowsingHistoryHandler::ReturnResultsToFrontEnd() {
web_history_query_results_.end()); web_history_query_results_.end());
RemoveDuplicateResults(&query_results_); RemoveDuplicateResults(&query_results_);
// In the best case, we expect that all local results are duplicated on the
// server. Keep track of how many are missing.
if (local_result_count) { if (local_result_count) {
// In the best case, we expect that all local results are duplicated on
// the server. Keep track of how many are missing.
int missing_count = std::count_if( int missing_count = std::count_if(
query_results_.begin(), query_results_.end(), IsLocalOnlyResult); query_results_.begin(), query_results_.end(), IsLocalOnlyResult);
UMA_HISTOGRAM_PERCENTAGE("WebHistory.LocalResultMissingOnServer", UMA_HISTOGRAM_PERCENTAGE("WebHistory.LocalResultMissingOnServer",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment