OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/browsing_history_handler.h" | 5 #include "chrome/browser/ui/webui/browsing_history_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 *name = l10n_util::GetStringUTF8(IDS_HISTORY_UNKNOWN_DEVICE); | 156 *name = l10n_util::GetStringUTF8(IDS_HISTORY_UNKNOWN_DEVICE); |
157 *type = kDeviceTypeLaptop; | 157 *type = kDeviceTypeLaptop; |
158 } | 158 } |
159 | 159 |
160 } // namespace | 160 } // namespace |
161 | 161 |
162 BrowsingHistoryHandler::HistoryEntry::HistoryEntry( | 162 BrowsingHistoryHandler::HistoryEntry::HistoryEntry( |
163 BrowsingHistoryHandler::HistoryEntry::EntryType entry_type, | 163 BrowsingHistoryHandler::HistoryEntry::EntryType entry_type, |
164 const GURL& url, const base::string16& title, base::Time time, | 164 const GURL& url, const base::string16& title, base::Time time, |
165 const std::string& client_id, bool is_search_result, | 165 const std::string& client_id, bool is_search_result, |
166 const base::string16& snippet, bool blocked_visit, | 166 const base::string16& snippet, bool blocked_visit) { |
167 const std::string& accept_languages) { | |
168 this->entry_type = entry_type; | 167 this->entry_type = entry_type; |
169 this->url = url; | 168 this->url = url; |
170 this->title = title; | 169 this->title = title; |
171 this->time = time; | 170 this->time = time; |
172 this->client_id = client_id; | 171 this->client_id = client_id; |
173 all_timestamps.insert(time.ToInternalValue()); | 172 all_timestamps.insert(time.ToInternalValue()); |
174 this->is_search_result = is_search_result; | 173 this->is_search_result = is_search_result; |
175 this->snippet = snippet; | 174 this->snippet = snippet; |
176 this->blocked_visit = blocked_visit; | 175 this->blocked_visit = blocked_visit; |
177 this->accept_languages = accept_languages; | |
178 } | 176 } |
179 | 177 |
180 BrowsingHistoryHandler::HistoryEntry::HistoryEntry() | 178 BrowsingHistoryHandler::HistoryEntry::HistoryEntry() |
181 : entry_type(EMPTY_ENTRY), is_search_result(false), blocked_visit(false) { | 179 : entry_type(EMPTY_ENTRY), is_search_result(false), blocked_visit(false) { |
182 } | 180 } |
183 | 181 |
184 BrowsingHistoryHandler::HistoryEntry::HistoryEntry(const HistoryEntry& other) = | 182 BrowsingHistoryHandler::HistoryEntry::HistoryEntry(const HistoryEntry& other) = |
185 default; | 183 default; |
186 | 184 |
187 BrowsingHistoryHandler::HistoryEntry::~HistoryEntry() { | 185 BrowsingHistoryHandler::HistoryEntry::~HistoryEntry() { |
(...skipping 23 matching lines...) Expand all Loading... |
211 result->SetString("title", title_to_set); | 209 result->SetString("title", title_to_set); |
212 } | 210 } |
213 | 211 |
214 scoped_ptr<base::DictionaryValue> BrowsingHistoryHandler::HistoryEntry::ToValue( | 212 scoped_ptr<base::DictionaryValue> BrowsingHistoryHandler::HistoryEntry::ToValue( |
215 BookmarkModel* bookmark_model, | 213 BookmarkModel* bookmark_model, |
216 SupervisedUserService* supervised_user_service, | 214 SupervisedUserService* supervised_user_service, |
217 const ProfileSyncService* sync_service) const { | 215 const ProfileSyncService* sync_service) const { |
218 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 216 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
219 SetUrlAndTitle(result.get()); | 217 SetUrlAndTitle(result.get()); |
220 | 218 |
221 base::string16 domain = | 219 base::string16 domain = url_formatter::IDNToUnicode(url.host()); |
222 url_formatter::IDNToUnicode(url.host(), accept_languages); | |
223 // When the domain is empty, use the scheme instead. This allows for a | 220 // When the domain is empty, use the scheme instead. This allows for a |
224 // sensible treatment of e.g. file: URLs when group by domain is on. | 221 // sensible treatment of e.g. file: URLs when group by domain is on. |
225 if (domain.empty()) | 222 if (domain.empty()) |
226 domain = base::UTF8ToUTF16(url.scheme() + ":"); | 223 domain = base::UTF8ToUTF16(url.scheme() + ":"); |
227 | 224 |
228 // The items which are to be written into result are also described in | 225 // The items which are to be written into result are also described in |
229 // chrome/browser/resources/history/history.js in @typedef for | 226 // chrome/browser/resources/history/history.js in @typedef for |
230 // HistoryEntry. Please update it whenever you add or remove | 227 // HistoryEntry. Please update it whenever you add or remove |
231 // any keys in result. | 228 // any keys in result. |
232 result->SetString("domain", domain); | 229 result->SetString("domain", domain); |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 query_results_.clear(); | 708 query_results_.clear(); |
712 web_history_query_results_.clear(); | 709 web_history_query_results_.clear(); |
713 } | 710 } |
714 | 711 |
715 void BrowsingHistoryHandler::QueryComplete( | 712 void BrowsingHistoryHandler::QueryComplete( |
716 const base::string16& search_text, | 713 const base::string16& search_text, |
717 const history::QueryOptions& options, | 714 const history::QueryOptions& options, |
718 history::QueryResults* results) { | 715 history::QueryResults* results) { |
719 DCHECK_EQ(0U, query_results_.size()); | 716 DCHECK_EQ(0U, query_results_.size()); |
720 query_results_.reserve(results->size()); | 717 query_results_.reserve(results->size()); |
721 const std::string accept_languages = GetAcceptLanguages(); | |
722 | 718 |
723 for (size_t i = 0; i < results->size(); ++i) { | 719 for (size_t i = 0; i < results->size(); ++i) { |
724 history::URLResult const &page = (*results)[i]; | 720 history::URLResult const &page = (*results)[i]; |
725 // TODO(dubroy): Use sane time (crbug.com/146090) here when it's ready. | 721 // TODO(dubroy): Use sane time (crbug.com/146090) here when it's ready. |
726 query_results_.push_back( | 722 query_results_.push_back( |
727 HistoryEntry( | 723 HistoryEntry( |
728 HistoryEntry::LOCAL_ENTRY, | 724 HistoryEntry::LOCAL_ENTRY, |
729 page.url(), | 725 page.url(), |
730 page.title(), | 726 page.title(), |
731 page.visit_time(), | 727 page.visit_time(), |
732 std::string(), | 728 std::string(), |
733 !search_text.empty(), | 729 !search_text.empty(), |
734 page.snippet().text(), | 730 page.snippet().text(), |
735 page.blocked_visit(), | 731 page.blocked_visit())); |
736 accept_languages)); | |
737 } | 732 } |
738 | 733 |
739 // The items which are to be written into results_info_value_ are also | 734 // The items which are to be written into results_info_value_ are also |
740 // described in chrome/browser/resources/history/history.js in @typedef for | 735 // described in chrome/browser/resources/history/history.js in @typedef for |
741 // HistoryQuery. Please update it whenever you add or remove any keys in | 736 // HistoryQuery. Please update it whenever you add or remove any keys in |
742 // results_info_value_. | 737 // results_info_value_. |
743 results_info_value_.SetString("term", search_text); | 738 results_info_value_.SetString("term", search_text); |
744 results_info_value_.SetBoolean("finished", results->reached_beginning()); | 739 results_info_value_.SetBoolean("finished", results->reached_beginning()); |
745 | 740 |
746 // Add the specific dates that were searched to display them. | 741 // Add the specific dates that were searched to display them. |
(...skipping 13 matching lines...) Expand all Loading... |
760 } | 755 } |
761 | 756 |
762 void BrowsingHistoryHandler::WebHistoryQueryComplete( | 757 void BrowsingHistoryHandler::WebHistoryQueryComplete( |
763 const base::string16& search_text, | 758 const base::string16& search_text, |
764 const history::QueryOptions& options, | 759 const history::QueryOptions& options, |
765 base::TimeTicks start_time, | 760 base::TimeTicks start_time, |
766 history::WebHistoryService::Request* request, | 761 history::WebHistoryService::Request* request, |
767 const base::DictionaryValue* results_value) { | 762 const base::DictionaryValue* results_value) { |
768 base::TimeDelta delta = base::TimeTicks::Now() - start_time; | 763 base::TimeDelta delta = base::TimeTicks::Now() - start_time; |
769 UMA_HISTOGRAM_TIMES("WebHistory.ResponseTime", delta); | 764 UMA_HISTOGRAM_TIMES("WebHistory.ResponseTime", delta); |
770 const std::string accept_languages = GetAcceptLanguages(); | |
771 | 765 |
772 // If the response came in too late, do nothing. | 766 // If the response came in too late, do nothing. |
773 // TODO(dubroy): Maybe show a banner, and prompt the user to reload? | 767 // TODO(dubroy): Maybe show a banner, and prompt the user to reload? |
774 if (!web_history_timer_.IsRunning()) | 768 if (!web_history_timer_.IsRunning()) |
775 return; | 769 return; |
776 web_history_timer_.Stop(); | 770 web_history_timer_.Stop(); |
777 | 771 |
778 UMA_HISTOGRAM_ENUMERATION( | 772 UMA_HISTOGRAM_ENUMERATION( |
779 "WebHistory.QueryCompletion", | 773 "WebHistory.QueryCompletion", |
780 results_value ? WEB_HISTORY_QUERY_SUCCEEDED : WEB_HISTORY_QUERY_FAILED, | 774 results_value ? WEB_HISTORY_QUERY_SUCCEEDED : WEB_HISTORY_QUERY_FAILED, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 | 828 |
835 web_history_query_results_.push_back( | 829 web_history_query_results_.push_back( |
836 HistoryEntry( | 830 HistoryEntry( |
837 HistoryEntry::REMOTE_ENTRY, | 831 HistoryEntry::REMOTE_ENTRY, |
838 gurl, | 832 gurl, |
839 title, | 833 title, |
840 time, | 834 time, |
841 client_id, | 835 client_id, |
842 !search_text.empty(), | 836 !search_text.empty(), |
843 base::string16(), | 837 base::string16(), |
844 /* blocked_visit */ false, | 838 /* blocked_visit */ false)); |
845 accept_languages)); | |
846 } | 839 } |
847 } | 840 } |
848 } | 841 } |
849 has_synced_results_ = results_value != nullptr; | 842 has_synced_results_ = results_value != nullptr; |
850 results_info_value_.SetBoolean("hasSyncedResults", has_synced_results_); | 843 results_info_value_.SetBoolean("hasSyncedResults", has_synced_results_); |
851 if (!query_task_tracker_.HasTrackedTasks()) | 844 if (!query_task_tracker_.HasTrackedTasks()) |
852 ReturnResultsToFrontEnd(); | 845 ReturnResultsToFrontEnd(); |
853 } | 846 } |
854 | 847 |
855 void BrowsingHistoryHandler::OtherFormsOfBrowsingHistoryQueryComplete( | 848 void BrowsingHistoryHandler::OtherFormsOfBrowsingHistoryQueryComplete( |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 const std::set<GURL>& urls_to_be_deleted) { | 921 const std::set<GURL>& urls_to_be_deleted) { |
929 if (deleted_rows.size() != urls_to_be_deleted.size()) | 922 if (deleted_rows.size() != urls_to_be_deleted.size()) |
930 return true; | 923 return true; |
931 for (const auto& i : deleted_rows) { | 924 for (const auto& i : deleted_rows) { |
932 if (urls_to_be_deleted.find(i.url()) == urls_to_be_deleted.end()) | 925 if (urls_to_be_deleted.find(i.url()) == urls_to_be_deleted.end()) |
933 return true; | 926 return true; |
934 } | 927 } |
935 return false; | 928 return false; |
936 } | 929 } |
937 | 930 |
938 std::string BrowsingHistoryHandler::GetAcceptLanguages() const { | |
939 Profile* profile = Profile::FromWebUI(web_ui()); | |
940 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | |
941 } | |
942 | |
943 void BrowsingHistoryHandler::OnURLsDeleted( | 931 void BrowsingHistoryHandler::OnURLsDeleted( |
944 history::HistoryService* history_service, | 932 history::HistoryService* history_service, |
945 bool all_history, | 933 bool all_history, |
946 bool expired, | 934 bool expired, |
947 const history::URLRows& deleted_rows, | 935 const history::URLRows& deleted_rows, |
948 const std::set<GURL>& favicon_urls) { | 936 const std::set<GURL>& favicon_urls) { |
949 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) | 937 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) |
950 web_ui()->CallJavascriptFunction("historyDeleted"); | 938 web_ui()->CallJavascriptFunction("historyDeleted"); |
951 } | 939 } |
OLD | NEW |