Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/ui/webui/browsing_history_handler.cc

Issue 1841653003: Drop |languages| from {Format,Elide}Url* and IDNToUnicode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased, most Android targets locally built successfully Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 *name = l10n_util::GetStringUTF8(IDS_HISTORY_UNKNOWN_DEVICE); 155 *name = l10n_util::GetStringUTF8(IDS_HISTORY_UNKNOWN_DEVICE);
156 *type = kDeviceTypeLaptop; 156 *type = kDeviceTypeLaptop;
157 } 157 }
158 158
159 } // namespace 159 } // namespace
160 160
161 BrowsingHistoryHandler::HistoryEntry::HistoryEntry( 161 BrowsingHistoryHandler::HistoryEntry::HistoryEntry(
162 BrowsingHistoryHandler::HistoryEntry::EntryType entry_type, 162 BrowsingHistoryHandler::HistoryEntry::EntryType entry_type,
163 const GURL& url, const base::string16& title, base::Time time, 163 const GURL& url, const base::string16& title, base::Time time,
164 const std::string& client_id, bool is_search_result, 164 const std::string& client_id, bool is_search_result,
165 const base::string16& snippet, bool blocked_visit, 165 const base::string16& snippet, bool blocked_visit) {
166 const std::string& accept_languages) {
167 this->entry_type = entry_type; 166 this->entry_type = entry_type;
168 this->url = url; 167 this->url = url;
169 this->title = title; 168 this->title = title;
170 this->time = time; 169 this->time = time;
171 this->client_id = client_id; 170 this->client_id = client_id;
172 all_timestamps.insert(time.ToInternalValue()); 171 all_timestamps.insert(time.ToInternalValue());
173 this->is_search_result = is_search_result; 172 this->is_search_result = is_search_result;
174 this->snippet = snippet; 173 this->snippet = snippet;
175 this->blocked_visit = blocked_visit; 174 this->blocked_visit = blocked_visit;
176 this->accept_languages = accept_languages;
177 } 175 }
178 176
179 BrowsingHistoryHandler::HistoryEntry::HistoryEntry() 177 BrowsingHistoryHandler::HistoryEntry::HistoryEntry()
180 : entry_type(EMPTY_ENTRY), is_search_result(false), blocked_visit(false) { 178 : entry_type(EMPTY_ENTRY), is_search_result(false), blocked_visit(false) {
181 } 179 }
182 180
183 BrowsingHistoryHandler::HistoryEntry::HistoryEntry(const HistoryEntry& other) = 181 BrowsingHistoryHandler::HistoryEntry::HistoryEntry(const HistoryEntry& other) =
184 default; 182 default;
185 183
186 BrowsingHistoryHandler::HistoryEntry::~HistoryEntry() { 184 BrowsingHistoryHandler::HistoryEntry::~HistoryEntry() {
(...skipping 23 matching lines...) Expand all
210 result->SetString("title", title_to_set); 208 result->SetString("title", title_to_set);
211 } 209 }
212 210
213 scoped_ptr<base::DictionaryValue> BrowsingHistoryHandler::HistoryEntry::ToValue( 211 scoped_ptr<base::DictionaryValue> BrowsingHistoryHandler::HistoryEntry::ToValue(
214 BookmarkModel* bookmark_model, 212 BookmarkModel* bookmark_model,
215 SupervisedUserService* supervised_user_service, 213 SupervisedUserService* supervised_user_service,
216 const ProfileSyncService* sync_service) const { 214 const ProfileSyncService* sync_service) const {
217 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); 215 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue());
218 SetUrlAndTitle(result.get()); 216 SetUrlAndTitle(result.get());
219 217
220 base::string16 domain = 218 base::string16 domain = url_formatter::IDNToUnicode(url.host());
221 url_formatter::IDNToUnicode(url.host(), accept_languages);
222 // When the domain is empty, use the scheme instead. This allows for a 219 // When the domain is empty, use the scheme instead. This allows for a
223 // sensible treatment of e.g. file: URLs when group by domain is on. 220 // sensible treatment of e.g. file: URLs when group by domain is on.
224 if (domain.empty()) 221 if (domain.empty())
225 domain = base::UTF8ToUTF16(url.scheme() + ":"); 222 domain = base::UTF8ToUTF16(url.scheme() + ":");
226 223
227 // The items which are to be written into result are also described in 224 // The items which are to be written into result are also described in
228 // chrome/browser/resources/history/history.js in @typedef for 225 // chrome/browser/resources/history/history.js in @typedef for
229 // HistoryEntry. Please update it whenever you add or remove 226 // HistoryEntry. Please update it whenever you add or remove
230 // any keys in result. 227 // any keys in result.
231 result->SetString("domain", domain); 228 result->SetString("domain", domain);
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 query_results_.clear(); 691 query_results_.clear();
695 web_history_query_results_.clear(); 692 web_history_query_results_.clear();
696 } 693 }
697 694
698 void BrowsingHistoryHandler::QueryComplete( 695 void BrowsingHistoryHandler::QueryComplete(
699 const base::string16& search_text, 696 const base::string16& search_text,
700 const history::QueryOptions& options, 697 const history::QueryOptions& options,
701 history::QueryResults* results) { 698 history::QueryResults* results) {
702 DCHECK_EQ(0U, query_results_.size()); 699 DCHECK_EQ(0U, query_results_.size());
703 query_results_.reserve(results->size()); 700 query_results_.reserve(results->size());
704 const std::string accept_languages = GetAcceptLanguages();
705 701
706 for (size_t i = 0; i < results->size(); ++i) { 702 for (size_t i = 0; i < results->size(); ++i) {
707 history::URLResult const &page = (*results)[i]; 703 history::URLResult const &page = (*results)[i];
708 // TODO(dubroy): Use sane time (crbug.com/146090) here when it's ready. 704 // TODO(dubroy): Use sane time (crbug.com/146090) here when it's ready.
709 query_results_.push_back( 705 query_results_.push_back(
710 HistoryEntry( 706 HistoryEntry(
711 HistoryEntry::LOCAL_ENTRY, 707 HistoryEntry::LOCAL_ENTRY,
712 page.url(), 708 page.url(),
713 page.title(), 709 page.title(),
714 page.visit_time(), 710 page.visit_time(),
715 std::string(), 711 std::string(),
716 !search_text.empty(), 712 !search_text.empty(),
717 page.snippet().text(), 713 page.snippet().text(),
718 page.blocked_visit(), 714 page.blocked_visit()));
719 accept_languages));
720 } 715 }
721 716
722 // The items which are to be written into results_info_value_ are also 717 // The items which are to be written into results_info_value_ are also
723 // described in chrome/browser/resources/history/history.js in @typedef for 718 // described in chrome/browser/resources/history/history.js in @typedef for
724 // HistoryQuery. Please update it whenever you add or remove any keys in 719 // HistoryQuery. Please update it whenever you add or remove any keys in
725 // results_info_value_. 720 // results_info_value_.
726 results_info_value_.SetString("term", search_text); 721 results_info_value_.SetString("term", search_text);
727 results_info_value_.SetBoolean("finished", results->reached_beginning()); 722 results_info_value_.SetBoolean("finished", results->reached_beginning());
728 723
729 // Add the specific dates that were searched to display them. 724 // Add the specific dates that were searched to display them.
(...skipping 13 matching lines...) Expand all
743 } 738 }
744 739
745 void BrowsingHistoryHandler::WebHistoryQueryComplete( 740 void BrowsingHistoryHandler::WebHistoryQueryComplete(
746 const base::string16& search_text, 741 const base::string16& search_text,
747 const history::QueryOptions& options, 742 const history::QueryOptions& options,
748 base::TimeTicks start_time, 743 base::TimeTicks start_time,
749 history::WebHistoryService::Request* request, 744 history::WebHistoryService::Request* request,
750 const base::DictionaryValue* results_value) { 745 const base::DictionaryValue* results_value) {
751 base::TimeDelta delta = base::TimeTicks::Now() - start_time; 746 base::TimeDelta delta = base::TimeTicks::Now() - start_time;
752 UMA_HISTOGRAM_TIMES("WebHistory.ResponseTime", delta); 747 UMA_HISTOGRAM_TIMES("WebHistory.ResponseTime", delta);
753 const std::string accept_languages = GetAcceptLanguages();
754 748
755 // If the response came in too late, do nothing. 749 // If the response came in too late, do nothing.
756 // TODO(dubroy): Maybe show a banner, and prompt the user to reload? 750 // TODO(dubroy): Maybe show a banner, and prompt the user to reload?
757 if (!web_history_timer_.IsRunning()) 751 if (!web_history_timer_.IsRunning())
758 return; 752 return;
759 web_history_timer_.Stop(); 753 web_history_timer_.Stop();
760 754
761 UMA_HISTOGRAM_ENUMERATION( 755 UMA_HISTOGRAM_ENUMERATION(
762 "WebHistory.QueryCompletion", 756 "WebHistory.QueryCompletion",
763 results_value ? WEB_HISTORY_QUERY_SUCCEEDED : WEB_HISTORY_QUERY_FAILED, 757 results_value ? WEB_HISTORY_QUERY_SUCCEEDED : WEB_HISTORY_QUERY_FAILED,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 811
818 web_history_query_results_.push_back( 812 web_history_query_results_.push_back(
819 HistoryEntry( 813 HistoryEntry(
820 HistoryEntry::REMOTE_ENTRY, 814 HistoryEntry::REMOTE_ENTRY,
821 gurl, 815 gurl,
822 title, 816 title,
823 time, 817 time,
824 client_id, 818 client_id,
825 !search_text.empty(), 819 !search_text.empty(),
826 base::string16(), 820 base::string16(),
827 /* blocked_visit */ false, 821 /* blocked_visit */ false));
828 accept_languages));
829 } 822 }
830 } 823 }
831 } 824 }
832 results_info_value_.SetBoolean("hasSyncedResults", results_value != NULL); 825 results_info_value_.SetBoolean("hasSyncedResults", results_value != NULL);
833 if (!query_task_tracker_.HasTrackedTasks()) 826 if (!query_task_tracker_.HasTrackedTasks())
834 ReturnResultsToFrontEnd(); 827 ReturnResultsToFrontEnd();
835 } 828 }
836 829
837 void BrowsingHistoryHandler::RemoveComplete() { 830 void BrowsingHistoryHandler::RemoveComplete() {
838 urls_to_be_deleted_.clear(); 831 urls_to_be_deleted_.clear();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 const std::set<GURL>& urls_to_be_deleted) { 894 const std::set<GURL>& urls_to_be_deleted) {
902 if (deleted_rows.size() != urls_to_be_deleted.size()) 895 if (deleted_rows.size() != urls_to_be_deleted.size())
903 return true; 896 return true;
904 for (const auto& i : deleted_rows) { 897 for (const auto& i : deleted_rows) {
905 if (urls_to_be_deleted.find(i.url()) == urls_to_be_deleted.end()) 898 if (urls_to_be_deleted.find(i.url()) == urls_to_be_deleted.end())
906 return true; 899 return true;
907 } 900 }
908 return false; 901 return false;
909 } 902 }
910 903
911 std::string BrowsingHistoryHandler::GetAcceptLanguages() const {
912 Profile* profile = Profile::FromWebUI(web_ui());
913 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
914 }
915
916 void BrowsingHistoryHandler::OnURLsDeleted( 904 void BrowsingHistoryHandler::OnURLsDeleted(
917 history::HistoryService* history_service, 905 history::HistoryService* history_service,
918 bool all_history, 906 bool all_history,
919 bool expired, 907 bool expired,
920 const history::URLRows& deleted_rows, 908 const history::URLRows& deleted_rows,
921 const std::set<GURL>& favicon_urls) { 909 const std::set<GURL>& favicon_urls) {
922 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) 910 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_))
923 web_ui()->CallJavascriptFunction("historyDeleted"); 911 web_ui()->CallJavascriptFunction("historyDeleted");
924 } 912 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698