| Index: chrome/browser/ui/webui/browsing_history_handler.cc
|
| diff --git a/chrome/browser/ui/webui/browsing_history_handler.cc b/chrome/browser/ui/webui/browsing_history_handler.cc
|
| index e90e4e6ebaf4588a30ee1980e2e9181a3de6b1ce..2109e202664fbb0e845406020b1a04d3431fa411 100644
|
| --- a/chrome/browser/ui/webui/browsing_history_handler.cc
|
| +++ b/chrome/browser/ui/webui/browsing_history_handler.cc
|
| @@ -13,6 +13,7 @@
|
| #include "base/bind_helpers.h"
|
| #include "base/i18n/rtl.h"
|
| #include "base/i18n/time_formatting.h"
|
| +#include "base/logging.h"
|
| #include "base/metrics/histogram_macros.h"
|
| #include "base/strings/string16.h"
|
| #include "base/strings/string_number_conversions.h"
|
| @@ -75,9 +76,16 @@
|
| #include "chrome/browser/android/chrome_application.h"
|
| #endif
|
|
|
| +#if !defined(OS_ANDROID)
|
| +#include "chrome/browser/ui/webui/md_history_ui.h"
|
| +#endif
|
| +
|
| // The amount of time to wait for a response from the WebHistoryService.
|
| static const int kWebHistoryTimeoutSeconds = 3;
|
|
|
| +// Number of chars to truncate titles when making them "short".
|
| +static const size_t kShortTitleLength = 300;
|
| +
|
| using bookmarks::BookmarkModel;
|
|
|
| namespace {
|
| @@ -194,7 +202,8 @@ BrowsingHistoryHandler::HistoryEntry::~HistoryEntry() {
|
| }
|
|
|
| void BrowsingHistoryHandler::HistoryEntry::SetUrlAndTitle(
|
| - base::DictionaryValue* result) const {
|
| + base::DictionaryValue* result,
|
| + bool limit_title_length) const {
|
| result->SetString("url", url.spec());
|
|
|
| bool using_url_as_the_title = false;
|
| @@ -214,16 +223,20 @@ void BrowsingHistoryHandler::HistoryEntry::SetUrlAndTitle(
|
| else
|
| base::i18n::AdjustStringForLocaleDirection(&title_to_set);
|
| }
|
| - result->SetString("title", title_to_set);
|
| +
|
| + result->SetString("title",
|
| + limit_title_length ? title_to_set.substr(0, kShortTitleLength)
|
| + : title_to_set);
|
| }
|
|
|
| std::unique_ptr<base::DictionaryValue>
|
| BrowsingHistoryHandler::HistoryEntry::ToValue(
|
| BookmarkModel* bookmark_model,
|
| SupervisedUserService* supervised_user_service,
|
| - const ProfileSyncService* sync_service) const {
|
| + const ProfileSyncService* sync_service,
|
| + bool limit_title_length) const {
|
| std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
|
| - SetUrlAndTitle(result.get());
|
| + SetUrlAndTitle(result.get(), limit_title_length);
|
|
|
| base::string16 domain = url_formatter::IDNToUnicode(url.host());
|
| // When the domain is empty, use the scheme instead. This allows for a
|
| @@ -698,6 +711,51 @@ void BrowsingHistoryHandler::MergeDuplicateResults(
|
| results->swap(new_results);
|
| }
|
|
|
| +void BrowsingHistoryHandler::QueryComplete(
|
| + const base::string16& search_text,
|
| + const history::QueryOptions& options,
|
| + history::QueryResults* results) {
|
| + DCHECK_EQ(0U, query_results_.size());
|
| + query_results_.reserve(results->size());
|
| +
|
| + for (size_t i = 0; i < results->size(); ++i) {
|
| + history::URLResult const &page = (*results)[i];
|
| + // TODO(dubroy): Use sane time (crbug.com/146090) here when it's ready.
|
| + query_results_.push_back(
|
| + HistoryEntry(
|
| + HistoryEntry::LOCAL_ENTRY,
|
| + page.url(),
|
| + page.title(),
|
| + page.visit_time(),
|
| + std::string(),
|
| + !search_text.empty(),
|
| + page.snippet().text(),
|
| + page.blocked_visit()));
|
| + }
|
| +
|
| + // The items which are to be written into results_info_value_ are also
|
| + // described in chrome/browser/resources/history/history.js in @typedef for
|
| + // HistoryQuery. Please update it whenever you add or remove any keys in
|
| + // results_info_value_.
|
| + results_info_value_.SetString("term", search_text);
|
| + results_info_value_.SetBoolean("finished", results->reached_beginning());
|
| +
|
| + // Add the specific dates that were searched to display them.
|
| + // TODO(sergiu): Put today if the start is in the future.
|
| + results_info_value_.SetString("queryStartTime",
|
| + GetRelativeDateLocalized(options.begin_time));
|
| + if (!options.end_time.is_null()) {
|
| + results_info_value_.SetString("queryEndTime",
|
| + GetRelativeDateLocalized(options.end_time -
|
| + base::TimeDelta::FromDays(1)));
|
| + } else {
|
| + results_info_value_.SetString("queryEndTime",
|
| + GetRelativeDateLocalized(base::Time::Now()));
|
| + }
|
| + if (!web_history_timer_.IsRunning())
|
| + ReturnResultsToFrontEnd();
|
| +}
|
| +
|
| void BrowsingHistoryHandler::ReturnResultsToFrontEnd() {
|
| Profile* profile = Profile::FromWebUI(web_ui());
|
| BookmarkModel* bookmark_model =
|
| @@ -730,12 +788,17 @@ void BrowsingHistoryHandler::ReturnResultsToFrontEnd() {
|
| }
|
| }
|
|
|
| + bool is_md = false;
|
| +#if !defined(OS_ANDROID)
|
| + is_md = MdHistoryUI::IsEnabled(profile);
|
| +#endif
|
| +
|
| // Convert the result vector into a ListValue.
|
| base::ListValue results_value;
|
| for (std::vector<BrowsingHistoryHandler::HistoryEntry>::iterator it =
|
| query_results_.begin(); it != query_results_.end(); ++it) {
|
| - std::unique_ptr<base::Value> value(
|
| - it->ToValue(bookmark_model, supervised_user_service, sync_service));
|
| + std::unique_ptr<base::Value> value(it->ToValue(
|
| + bookmark_model, supervised_user_service, sync_service, is_md));
|
| results_value.Append(std::move(value));
|
| }
|
|
|
| @@ -749,51 +812,6 @@ void BrowsingHistoryHandler::ReturnResultsToFrontEnd() {
|
| web_history_query_results_.clear();
|
| }
|
|
|
| -void BrowsingHistoryHandler::QueryComplete(
|
| - const base::string16& search_text,
|
| - const history::QueryOptions& options,
|
| - history::QueryResults* results) {
|
| - DCHECK_EQ(0U, query_results_.size());
|
| - query_results_.reserve(results->size());
|
| -
|
| - for (size_t i = 0; i < results->size(); ++i) {
|
| - history::URLResult const &page = (*results)[i];
|
| - // TODO(dubroy): Use sane time (crbug.com/146090) here when it's ready.
|
| - query_results_.push_back(
|
| - HistoryEntry(
|
| - HistoryEntry::LOCAL_ENTRY,
|
| - page.url(),
|
| - page.title(),
|
| - page.visit_time(),
|
| - std::string(),
|
| - !search_text.empty(),
|
| - page.snippet().text(),
|
| - page.blocked_visit()));
|
| - }
|
| -
|
| - // The items which are to be written into results_info_value_ are also
|
| - // described in chrome/browser/resources/history/history.js in @typedef for
|
| - // HistoryQuery. Please update it whenever you add or remove any keys in
|
| - // results_info_value_.
|
| - results_info_value_.SetString("term", search_text);
|
| - results_info_value_.SetBoolean("finished", results->reached_beginning());
|
| -
|
| - // Add the specific dates that were searched to display them.
|
| - // TODO(sergiu): Put today if the start is in the future.
|
| - results_info_value_.SetString("queryStartTime",
|
| - GetRelativeDateLocalized(options.begin_time));
|
| - if (!options.end_time.is_null()) {
|
| - results_info_value_.SetString("queryEndTime",
|
| - GetRelativeDateLocalized(options.end_time -
|
| - base::TimeDelta::FromDays(1)));
|
| - } else {
|
| - results_info_value_.SetString("queryEndTime",
|
| - GetRelativeDateLocalized(base::Time::Now()));
|
| - }
|
| - if (!web_history_timer_.IsRunning())
|
| - ReturnResultsToFrontEnd();
|
| -}
|
| -
|
| void BrowsingHistoryHandler::WebHistoryQueryComplete(
|
| const base::string16& search_text,
|
| const history::QueryOptions& options,
|
|
|