| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/history_ui.h" | 5 #include "chrome/browser/ui/webui/history_ui.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
| 13 #include "base/i18n/time_formatting.h" | 13 #include "base/i18n/time_formatting.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/metrics/histogram.h" |
| 16 #include "base/string16.h" | 17 #include "base/string16.h" |
| 17 #include "base/string_piece.h" | 18 #include "base/string_piece.h" |
| 18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 20 #include "base/time.h" | 21 #include "base/time.h" |
| 21 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
| 22 #include "base/values.h" | 23 #include "base/values.h" |
| 23 #include "chrome/browser/bookmarks/bookmark_model.h" | 24 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 24 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 25 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 25 #include "chrome/browser/bookmarks/bookmark_utils.h" | 26 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 using content::WebContents; | 69 using content::WebContents; |
| 69 | 70 |
| 70 static const char kStringsJsFile[] = "strings.js"; | 71 static const char kStringsJsFile[] = "strings.js"; |
| 71 static const char kHistoryJsFile[] = "history.js"; | 72 static const char kHistoryJsFile[] = "history.js"; |
| 72 | 73 |
| 73 // The amount of time to wait for a response from the WebHistoryService. | 74 // The amount of time to wait for a response from the WebHistoryService. |
| 74 static const int kWebHistoryTimeoutSeconds = 3; | 75 static const int kWebHistoryTimeoutSeconds = 3; |
| 75 | 76 |
| 76 namespace { | 77 namespace { |
| 77 | 78 |
| 79 // Buckets for UMA histograms. |
| 80 enum WebHistoryQueryBuckets { |
| 81 WEB_HISTORY_QUERY_FAILED = 0, |
| 82 WEB_HISTORY_QUERY_SUCCEEDED, |
| 83 WEB_HISTORY_QUERY_TIMED_OUT, |
| 84 NUM_WEB_HISTORY_QUERY_BUCKETS |
| 85 }; |
| 86 |
| 78 #if defined(OS_MACOSX) | 87 #if defined(OS_MACOSX) |
| 79 const char kIncognitoModeShortcut[] = "(" | 88 const char kIncognitoModeShortcut[] = "(" |
| 80 "\xE2\x87\xA7" // Shift symbol (U+21E7 'UPWARDS WHITE ARROW'). | 89 "\xE2\x87\xA7" // Shift symbol (U+21E7 'UPWARDS WHITE ARROW'). |
| 81 "\xE2\x8C\x98" // Command symbol (U+2318 'PLACE OF INTEREST SIGN'). | 90 "\xE2\x8C\x98" // Command symbol (U+2318 'PLACE OF INTEREST SIGN'). |
| 82 "N)"; | 91 "N)"; |
| 83 #elif defined(OS_WIN) | 92 #elif defined(OS_WIN) |
| 84 const char kIncognitoModeShortcut[] = "(Ctrl+Shift+N)"; | 93 const char kIncognitoModeShortcut[] = "(Ctrl+Shift+N)"; |
| 85 #else | 94 #else |
| 86 const char kIncognitoModeShortcut[] = "(Shift+Ctrl+N)"; | 95 const char kIncognitoModeShortcut[] = "(Shift+Ctrl+N)"; |
| 87 #endif | 96 #endif |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 191 |
| 183 if (result->GetAsDictionary(&result_dict) && | 192 if (result->GetAsDictionary(&result_dict) && |
| 184 result_dict->GetDouble("time", ×tamp) && | 193 result_dict->GetDouble("time", ×tamp) && |
| 185 result_dict->GetString("url", url)) { | 194 result_dict->GetString("url", url)) { |
| 186 *time = base::Time::FromJsTime(timestamp); | 195 *time = base::Time::FromJsTime(timestamp); |
| 187 return true; | 196 return true; |
| 188 } | 197 } |
| 189 return false; | 198 return false; |
| 190 } | 199 } |
| 191 | 200 |
| 201 // Removes all entries in |entry_list| that are older than the |cutoff|. |
| 202 // |entry_list| must already be sorted in reverse chronological order. |
| 203 void RemoveOlderEntries( |
| 204 std::vector<BrowsingHistoryHandler::HistoryEntry>* entry_list, |
| 205 base::Time cutoff) { |
| 206 for (std::vector<BrowsingHistoryHandler::HistoryEntry>::iterator it = |
| 207 entry_list->begin(); it != entry_list->end(); ++it) { |
| 208 if (it->time < cutoff) { |
| 209 entry_list->erase(it, entry_list->end()); |
| 210 break; |
| 211 } |
| 212 } |
| 213 } |
| 214 |
| 215 // Returns true if |entry| represents a local visit that had no corresponding |
| 216 // visit on the server. |
| 217 bool IsLocalOnlyResult(const BrowsingHistoryHandler::HistoryEntry& entry) { |
| 218 return entry.entry_type == BrowsingHistoryHandler::HistoryEntry::LOCAL_ENTRY; |
| 219 } |
| 220 |
| 192 } // namespace | 221 } // namespace |
| 193 | 222 |
| 194 //////////////////////////////////////////////////////////////////////////////// | 223 //////////////////////////////////////////////////////////////////////////////// |
| 195 // | 224 // |
| 196 // BrowsingHistoryHandler | 225 // BrowsingHistoryHandler |
| 197 // | 226 // |
| 198 //////////////////////////////////////////////////////////////////////////////// | 227 //////////////////////////////////////////////////////////////////////////////// |
| 199 | 228 |
| 200 BrowsingHistoryHandler::HistoryEntry::HistoryEntry( | 229 BrowsingHistoryHandler::HistoryEntry::HistoryEntry( |
| 230 BrowsingHistoryHandler::HistoryEntry::EntryType entry_type, |
| 201 const GURL& url, const string16& title, base::Time time, | 231 const GURL& url, const string16& title, base::Time time, |
| 202 const std::set<int64>& timestamps, bool is_search_result, | 232 const std::set<int64>& timestamps, |
| 203 const string16& snippet) : all_timestamps(timestamps) { | 233 bool is_search_result, const string16& snippet) |
| 234 : all_timestamps(timestamps) { |
| 235 this->entry_type = entry_type; |
| 204 this->url = url; | 236 this->url = url; |
| 205 this->title = title; | 237 this->title = title; |
| 206 this->time = time; | 238 this->time = time; |
| 207 this->is_search_result = is_search_result; | 239 this->is_search_result = is_search_result; |
| 208 this->snippet = snippet; | 240 this->snippet = snippet; |
| 209 } | 241 } |
| 210 | 242 |
| 211 BrowsingHistoryHandler::HistoryEntry::HistoryEntry() | 243 BrowsingHistoryHandler::HistoryEntry::HistoryEntry() |
| 212 : is_search_result(false) { | 244 : is_search_result(false) { |
| 213 } | 245 } |
| 214 | 246 |
| 215 BrowsingHistoryHandler::HistoryEntry::~HistoryEntry() { | 247 BrowsingHistoryHandler::HistoryEntry::~HistoryEntry() { |
| 216 } | 248 } |
| 217 | 249 |
| 218 void BrowsingHistoryHandler::HistoryEntry::SetUrlAndTitle( | 250 void BrowsingHistoryHandler::HistoryEntry::SetUrlAndTitle( |
| 219 DictionaryValue* result) { | 251 DictionaryValue* result) const { |
| 220 result->SetString("url", url.spec()); | 252 result->SetString("url", url.spec()); |
| 221 | 253 |
| 222 bool using_url_as_the_title = false; | 254 bool using_url_as_the_title = false; |
| 223 string16 title_to_set(title); | 255 string16 title_to_set(title); |
| 224 if (title.empty()) { | 256 if (title.empty()) { |
| 225 using_url_as_the_title = true; | 257 using_url_as_the_title = true; |
| 226 title_to_set = UTF8ToUTF16(url.spec()); | 258 title_to_set = UTF8ToUTF16(url.spec()); |
| 227 } | 259 } |
| 228 | 260 |
| 229 // Since the title can contain BiDi text, we need to mark the text as either | 261 // Since the title can contain BiDi text, we need to mark the text as either |
| 230 // RTL or LTR, depending on the characters in the string. If we use the URL | 262 // RTL or LTR, depending on the characters in the string. If we use the URL |
| 231 // as the title, we mark the title as LTR since URLs are always treated as | 263 // as the title, we mark the title as LTR since URLs are always treated as |
| 232 // left to right strings. | 264 // left to right strings. |
| 233 if (base::i18n::IsRTL()) { | 265 if (base::i18n::IsRTL()) { |
| 234 if (using_url_as_the_title) | 266 if (using_url_as_the_title) |
| 235 base::i18n::WrapStringWithLTRFormatting(&title_to_set); | 267 base::i18n::WrapStringWithLTRFormatting(&title_to_set); |
| 236 else | 268 else |
| 237 base::i18n::AdjustStringForLocaleDirection(&title_to_set); | 269 base::i18n::AdjustStringForLocaleDirection(&title_to_set); |
| 238 } | 270 } |
| 239 result->SetString("title", title_to_set); | 271 result->SetString("title", title_to_set); |
| 240 } | 272 } |
| 241 | 273 |
| 242 scoped_ptr<DictionaryValue> BrowsingHistoryHandler::HistoryEntry::ToValue( | 274 scoped_ptr<DictionaryValue> BrowsingHistoryHandler::HistoryEntry::ToValue( |
| 243 BookmarkModel* bookmark_model, ManagedUserService* managed_user_service) { | 275 BookmarkModel* bookmark_model, |
| 276 ManagedUserService* managed_user_service) const { |
| 244 scoped_ptr<DictionaryValue> result(new DictionaryValue()); | 277 scoped_ptr<DictionaryValue> result(new DictionaryValue()); |
| 245 SetUrlAndTitle(result.get()); | 278 SetUrlAndTitle(result.get()); |
| 246 result->SetDouble("time", time.ToJsTime()); | 279 result->SetDouble("time", time.ToJsTime()); |
| 247 | 280 |
| 248 // Pass the timestamps in a list. | 281 // Pass the timestamps in a list. |
| 249 scoped_ptr<ListValue> timestamps(new ListValue); | 282 scoped_ptr<ListValue> timestamps(new ListValue); |
| 250 for (std::set<int64>::const_iterator it = all_timestamps.begin(); | 283 for (std::set<int64>::const_iterator it = all_timestamps.begin(); |
| 251 it != all_timestamps.end(); ++it) { | 284 it != all_timestamps.end(); ++it) { |
| 252 timestamps->AppendDouble(base::Time::FromInternalValue(*it).ToJsTime()); | 285 timestamps->AppendDouble(base::Time::FromInternalValue(*it).ToJsTime()); |
| 253 } | 286 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 *out_int = static_cast<int>(double_value); | 392 *out_int = static_cast<int>(double_value); |
| 360 return true; | 393 return true; |
| 361 } | 394 } |
| 362 NOTREACHED(); | 395 NOTREACHED(); |
| 363 return false; | 396 return false; |
| 364 } | 397 } |
| 365 | 398 |
| 366 void BrowsingHistoryHandler::WebHistoryTimeout() { | 399 void BrowsingHistoryHandler::WebHistoryTimeout() { |
| 367 // TODO(dubroy): Communicate the failure to the front end. | 400 // TODO(dubroy): Communicate the failure to the front end. |
| 368 if (!results_info_value_.empty()) | 401 if (!results_info_value_.empty()) |
| 369 ReturnResultsToFrontEnd(false, 0); | 402 ReturnResultsToFrontEnd(); |
| 403 |
| 404 UMA_HISTOGRAM_ENUMERATION( |
| 405 "WebHistory.QueryCompletion", |
| 406 WEB_HISTORY_QUERY_TIMED_OUT, NUM_WEB_HISTORY_QUERY_BUCKETS); |
| 370 } | 407 } |
| 371 | 408 |
| 372 void BrowsingHistoryHandler::QueryHistory( | 409 void BrowsingHistoryHandler::QueryHistory( |
| 373 string16 search_text, const history::QueryOptions& options) { | 410 string16 search_text, const history::QueryOptions& options) { |
| 374 Profile* profile = Profile::FromWebUI(web_ui()); | 411 Profile* profile = Profile::FromWebUI(web_ui()); |
| 375 | 412 |
| 376 // Anything in-flight is invalid. | 413 // Anything in-flight is invalid. |
| 377 history_request_consumer_.CancelAllRequests(); | 414 history_request_consumer_.CancelAllRequests(); |
| 378 web_history_request_.reset(); | 415 web_history_request_.reset(); |
| 379 | 416 |
| 380 query_results_.clear(); | 417 query_results_.clear(); |
| 381 results_info_value_.Clear(); | 418 results_info_value_.Clear(); |
| 382 | 419 |
| 383 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 420 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 384 profile, Profile::EXPLICIT_ACCESS); | 421 profile, Profile::EXPLICIT_ACCESS); |
| 385 hs->QueryHistory(search_text, | 422 hs->QueryHistory(search_text, |
| 386 options, | 423 options, |
| 387 &history_request_consumer_, | 424 &history_request_consumer_, |
| 388 base::Bind(&BrowsingHistoryHandler::QueryComplete, | 425 base::Bind(&BrowsingHistoryHandler::QueryComplete, |
| 389 base::Unretained(this), search_text, options)); | 426 base::Unretained(this), search_text, options)); |
| 390 | 427 |
| 391 history::WebHistoryService* web_history = | 428 history::WebHistoryService* web_history = |
| 392 WebHistoryServiceFactory::GetForProfile(profile); | 429 WebHistoryServiceFactory::GetForProfile(profile); |
| 393 if (web_history) { | 430 if (web_history) { |
| 431 web_history_query_results_.clear(); |
| 394 web_history_request_ = web_history->QueryHistory( | 432 web_history_request_ = web_history->QueryHistory( |
| 395 search_text, | 433 search_text, |
| 396 options, | 434 options, |
| 397 base::Bind(&BrowsingHistoryHandler::WebHistoryQueryComplete, | 435 base::Bind(&BrowsingHistoryHandler::WebHistoryQueryComplete, |
| 398 base::Unretained(this), search_text, options)); | 436 base::Unretained(this), |
| 437 search_text, options, |
| 438 base::TimeTicks::Now())); |
| 399 // Start a timer so we know when to give up. | 439 // Start a timer so we know when to give up. |
| 400 web_history_timer_.Start( | 440 web_history_timer_.Start( |
| 401 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds), | 441 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds), |
| 402 this, &BrowsingHistoryHandler::WebHistoryTimeout); | 442 this, &BrowsingHistoryHandler::WebHistoryTimeout); |
| 403 } | 443 } |
| 404 } | 444 } |
| 405 | 445 |
| 406 void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) { | 446 void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) { |
| 407 history::QueryOptions options; | 447 history::QueryOptions options; |
| 408 | 448 |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 current_day_midnight = it->time.LocalMidnight(); | 779 current_day_midnight = it->time.LocalMidnight(); |
| 740 } | 780 } |
| 741 | 781 |
| 742 // Keep this visit if it's the first visit to this URL on the current day. | 782 // Keep this visit if it's the first visit to this URL on the current day. |
| 743 if (current_day_entries.count(it->url) == 0) { | 783 if (current_day_entries.count(it->url) == 0) { |
| 744 current_day_entries.insert( | 784 current_day_entries.insert( |
| 745 std::pair<GURL,BrowsingHistoryHandler::HistoryEntry>(it->url, *it)); | 785 std::pair<GURL,BrowsingHistoryHandler::HistoryEntry>(it->url, *it)); |
| 746 new_results.push_back(*it); | 786 new_results.push_back(*it); |
| 747 } else { | 787 } else { |
| 748 // Keep track of the timestamps of all visits to the URL on the same day. | 788 // Keep track of the timestamps of all visits to the URL on the same day. |
| 749 current_day_entries[it->url].all_timestamps.insert( | 789 BrowsingHistoryHandler::HistoryEntry* entry = |
| 790 ¤t_day_entries[it->url]; |
| 791 entry->all_timestamps.insert( |
| 750 it->all_timestamps.begin(), it->all_timestamps.end()); | 792 it->all_timestamps.begin(), it->all_timestamps.end()); |
| 793 |
| 794 if (entry->entry_type != it->entry_type) { |
| 795 entry->entry_type = |
| 796 BrowsingHistoryHandler::HistoryEntry::COMBINED_ENTRY; |
| 797 } |
| 751 } | 798 } |
| 752 } | 799 } |
| 753 results->swap(new_results); | 800 results->swap(new_results); |
| 754 } | 801 } |
| 755 | 802 |
| 756 void BrowsingHistoryHandler::ReturnResultsToFrontEnd( | 803 void BrowsingHistoryHandler::ReturnResultsToFrontEnd() { |
| 757 bool results_need_merge, int max_count) { | |
| 758 Profile* profile = Profile::FromWebUI(web_ui()); | 804 Profile* profile = Profile::FromWebUI(web_ui()); |
| 759 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile); | 805 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile); |
| 760 ManagedUserService* managed_user_service = | 806 ManagedUserService* managed_user_service = |
| 761 ManagedUserServiceFactory::GetForProfile(profile); | 807 ManagedUserServiceFactory::GetForProfile(profile); |
| 762 | 808 |
| 763 if (results_need_merge) | 809 // Combine the local and remote results into |query_results_|, and remove |
| 810 // any duplicates. |
| 811 if (query_results_.size() && web_history_query_results_.size()) { |
| 812 // Each result set covers a particular time range. Determine the |
| 813 // intersection of the two time ranges, discard any entries from either |
| 814 // set the are older than that, and then combine the results. |
| 815 base::Time cutoff_time = std::max(query_results_.back().time, |
| 816 web_history_query_results_.back().time); |
| 817 RemoveOlderEntries(&query_results_, cutoff_time); |
| 818 RemoveOlderEntries(&web_history_query_results_, cutoff_time); |
| 819 |
| 820 int local_result_count = query_results_.size(); |
| 821 query_results_.insert(query_results_.end(), |
| 822 web_history_query_results_.begin(), |
| 823 web_history_query_results_.end()); |
| 764 RemoveDuplicateResults(&query_results_); | 824 RemoveDuplicateResults(&query_results_); |
| 765 | 825 |
| 766 // Convert the result vector into a ListValue with at most |max_count| | 826 // In the best case, we expect that all local results are duplicated on the |
| 767 // elements. | 827 // server. Keep track of how many are missing. |
| 828 if (local_result_count) { |
| 829 int missing_count = std::count_if( |
| 830 query_results_.begin(), query_results_.end(), IsLocalOnlyResult); |
| 831 UMA_HISTOGRAM_PERCENTAGE("WebHistory.LocalResultMissingOnServer", |
| 832 missing_count * 100.0 / local_result_count); |
| 833 } |
| 834 } |
| 835 |
| 836 // Convert the result vector into a ListValue. |
| 768 ListValue results_value; | 837 ListValue results_value; |
| 769 int query_results_size = static_cast<int>(query_results_.size()); | 838 for (std::vector<BrowsingHistoryHandler::HistoryEntry>::iterator it = |
| 770 for (int i = 0; i < query_results_size && i < max_count; ++i) { | 839 query_results_.begin(); it != query_results_.end(); ++it) { |
| 771 scoped_ptr<base::Value> value( | 840 scoped_ptr<base::Value> value( |
| 772 query_results_[i].ToValue(bookmark_model, managed_user_service)); | 841 it->ToValue(bookmark_model, managed_user_service)); |
| 773 results_value.Append(value.release()); | 842 results_value.Append(value.release()); |
| 774 } | 843 } |
| 775 | 844 |
| 776 web_ui()->CallJavascriptFunction( | 845 web_ui()->CallJavascriptFunction( |
| 777 "historyResult", results_info_value_, results_value); | 846 "historyResult", results_info_value_, results_value); |
| 778 results_info_value_.Clear(); | 847 results_info_value_.Clear(); |
| 779 query_results_.clear(); | 848 query_results_.clear(); |
| 849 web_history_query_results_.clear(); |
| 780 } | 850 } |
| 781 | 851 |
| 782 void BrowsingHistoryHandler::QueryComplete( | 852 void BrowsingHistoryHandler::QueryComplete( |
| 783 const string16& search_text, | 853 const string16& search_text, |
| 784 const history::QueryOptions& options, | 854 const history::QueryOptions& options, |
| 785 HistoryService::Handle request_handle, | 855 HistoryService::Handle request_handle, |
| 786 history::QueryResults* results) { | 856 history::QueryResults* results) { |
| 787 // If we're appending to existing results, they will need merging. | 857 DCHECK_EQ(0U, query_results_.size()); |
| 788 bool needs_merge = query_results_.size() > 0; | 858 query_results_.reserve(results->size()); |
| 789 | 859 |
| 790 for (size_t i = 0; i < results->size(); ++i) { | 860 for (size_t i = 0; i < results->size(); ++i) { |
| 791 history::URLResult const &page = (*results)[i]; | 861 history::URLResult const &page = (*results)[i]; |
| 792 | 862 |
| 793 std::set<int64> timestamps; | 863 std::set<int64> timestamps; |
| 794 timestamps.insert(page.visit_time().ToInternalValue()); | 864 timestamps.insert(page.visit_time().ToInternalValue()); |
| 795 | 865 |
| 796 query_results_.push_back( | 866 query_results_.push_back( |
| 797 HistoryEntry(page.url(), | 867 HistoryEntry( |
| 798 page.title(), | 868 HistoryEntry::LOCAL_ENTRY, |
| 799 page.visit_time(), | 869 page.url(), |
| 800 timestamps, | 870 page.title(), |
| 801 !search_text.empty(), | 871 page.visit_time(), |
| 802 page.snippet().text())); | 872 timestamps, |
| 873 !search_text.empty(), |
| 874 page.snippet().text())); |
| 803 } | 875 } |
| 804 | 876 |
| 805 results_info_value_.SetString("term", search_text); | 877 results_info_value_.SetString("term", search_text); |
| 806 results_info_value_.SetBoolean("finished", results->reached_beginning()); | 878 results_info_value_.SetBoolean("finished", results->reached_beginning()); |
| 807 | 879 |
| 808 // Add the specific dates that were searched to display them. | 880 // Add the specific dates that were searched to display them. |
| 809 // TODO(sergiu): Put today if the start is in the future. | 881 // TODO(sergiu): Put today if the start is in the future. |
| 810 results_info_value_.SetString("queryStartTime", | 882 results_info_value_.SetString("queryStartTime", |
| 811 getRelativeDateLocalized(options.begin_time)); | 883 getRelativeDateLocalized(options.begin_time)); |
| 812 if (!options.end_time.is_null()) { | 884 if (!options.end_time.is_null()) { |
| 813 results_info_value_.SetString("queryEndTime", | 885 results_info_value_.SetString("queryEndTime", |
| 814 getRelativeDateLocalized(options.end_time - | 886 getRelativeDateLocalized(options.end_time - |
| 815 base::TimeDelta::FromDays(1))); | 887 base::TimeDelta::FromDays(1))); |
| 816 } else { | 888 } else { |
| 817 results_info_value_.SetString("queryEndTime", | 889 results_info_value_.SetString("queryEndTime", |
| 818 getRelativeDateLocalized(base::Time::Now())); | 890 getRelativeDateLocalized(base::Time::Now())); |
| 819 } | 891 } |
| 820 if (!web_history_timer_.IsRunning()) | 892 if (!web_history_timer_.IsRunning()) |
| 821 ReturnResultsToFrontEnd(needs_merge, options.max_count); | 893 ReturnResultsToFrontEnd(); |
| 822 } | 894 } |
| 823 | 895 |
| 824 void BrowsingHistoryHandler::WebHistoryQueryComplete( | 896 void BrowsingHistoryHandler::WebHistoryQueryComplete( |
| 825 const string16& search_text, | 897 const string16& search_text, |
| 826 const history::QueryOptions& options, | 898 const history::QueryOptions& options, |
| 899 base::TimeTicks start_time, |
| 827 history::WebHistoryService::Request* request, | 900 history::WebHistoryService::Request* request, |
| 828 const DictionaryValue* results_value) { | 901 const DictionaryValue* results_value) { |
| 902 base::TimeDelta delta = base::TimeTicks::Now() - start_time; |
| 903 UMA_HISTOGRAM_TIMES("WebHistory.ResponseTime", delta); |
| 904 |
| 905 // If the response came in too late, do nothing. |
| 906 // TODO(dubroy): Maybe show a banner, and prompt the user to reload? |
| 907 if (!web_history_timer_.IsRunning()) |
| 908 return; |
| 829 web_history_timer_.Stop(); | 909 web_history_timer_.Stop(); |
| 830 | 910 |
| 911 UMA_HISTOGRAM_ENUMERATION( |
| 912 "WebHistory.QueryCompletion", |
| 913 results_value ? WEB_HISTORY_QUERY_SUCCEEDED : WEB_HISTORY_QUERY_FAILED, |
| 914 NUM_WEB_HISTORY_QUERY_BUCKETS); |
| 915 |
| 916 DCHECK_EQ(0U, web_history_query_results_.size()); |
| 831 const ListValue* events = NULL; | 917 const ListValue* events = NULL; |
| 832 if (results_value && results_value->GetList("event", &events)) { | 918 if (results_value && results_value->GetList("event", &events)) { |
| 919 web_history_query_results_.reserve(events->GetSize()); |
| 833 for (unsigned int i = 0; i < events->GetSize(); ++i) { | 920 for (unsigned int i = 0; i < events->GetSize(); ++i) { |
| 834 const DictionaryValue* event = NULL; | 921 const DictionaryValue* event = NULL; |
| 835 const DictionaryValue* result = NULL; | 922 const DictionaryValue* result = NULL; |
| 836 const ListValue* results = NULL; | 923 const ListValue* results = NULL; |
| 837 const ListValue* ids = NULL; | 924 const ListValue* ids = NULL; |
| 838 string16 url; | 925 string16 url; |
| 839 string16 title; | 926 string16 title; |
| 840 base::Time visit_time; | 927 base::Time visit_time; |
| 841 | 928 |
| 842 if (!(events->GetDictionary(i, &event) && | 929 if (!(events->GetDictionary(i, &event) && |
| (...skipping 27 matching lines...) Expand all Loading... |
| 870 base::Time time = base::Time::UnixEpoch() + | 957 base::Time time = base::Time::UnixEpoch() + |
| 871 base::TimeDelta::FromMicroseconds(timestamp_usec); | 958 base::TimeDelta::FromMicroseconds(timestamp_usec); |
| 872 timestamps.insert(time.ToInternalValue()); | 959 timestamps.insert(time.ToInternalValue()); |
| 873 | 960 |
| 874 // Use the first timestamp as the visit time for this result. | 961 // Use the first timestamp as the visit time for this result. |
| 875 // TODO(dubroy): Use the sane time instead once it is available. | 962 // TODO(dubroy): Use the sane time instead once it is available. |
| 876 if (visit_time.is_null()) | 963 if (visit_time.is_null()) |
| 877 visit_time = time; | 964 visit_time = time; |
| 878 } | 965 } |
| 879 GURL gurl(url); | 966 GURL gurl(url); |
| 880 query_results_.push_back( | 967 web_history_query_results_.push_back( |
| 881 HistoryEntry( | 968 HistoryEntry( |
| 969 HistoryEntry::REMOTE_ENTRY, |
| 882 gurl, | 970 gurl, |
| 883 title, | 971 title, |
| 884 visit_time, | 972 visit_time, |
| 885 timestamps, | 973 timestamps, |
| 886 !search_text.empty(), | 974 !search_text.empty(), |
| 887 string16())); | 975 string16())); |
| 888 } | 976 } |
| 889 } else if (results_value) { | 977 } else if (results_value) { |
| 890 NOTREACHED() << "Failed to parse JSON response."; | 978 NOTREACHED() << "Failed to parse JSON response."; |
| 891 } | 979 } |
| 892 if (!results_info_value_.empty()) | 980 if (!results_info_value_.empty()) |
| 893 ReturnResultsToFrontEnd(true, options.max_count); | 981 ReturnResultsToFrontEnd(); |
| 894 } | 982 } |
| 895 | 983 |
| 896 void BrowsingHistoryHandler::RemoveComplete() { | 984 void BrowsingHistoryHandler::RemoveComplete() { |
| 897 urls_to_be_deleted_.clear(); | 985 urls_to_be_deleted_.clear(); |
| 898 | 986 |
| 899 // Notify the page that the deletion request succeeded. | 987 // Notify the page that the deletion request succeeded. |
| 900 web_ui()->CallJavascriptFunction("deleteComplete"); | 988 web_ui()->CallJavascriptFunction("deleteComplete"); |
| 901 } | 989 } |
| 902 | 990 |
| 903 void BrowsingHistoryHandler::RemoveWebHistoryComplete( | 991 void BrowsingHistoryHandler::RemoveWebHistoryComplete( |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + | 1088 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + |
| 1001 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); | 1089 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); |
| 1002 } | 1090 } |
| 1003 | 1091 |
| 1004 // static | 1092 // static |
| 1005 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( | 1093 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( |
| 1006 ui::ScaleFactor scale_factor) { | 1094 ui::ScaleFactor scale_factor) { |
| 1007 return ResourceBundle::GetSharedInstance(). | 1095 return ResourceBundle::GetSharedInstance(). |
| 1008 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); | 1096 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); |
| 1009 } | 1097 } |
| OLD | NEW |