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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 void GetDeviceNameAndType(const ProfileSyncService* sync_service, | 129 void GetDeviceNameAndType(const ProfileSyncService* sync_service, |
130 const std::string& client_id, | 130 const std::string& client_id, |
131 std::string* name, | 131 std::string* name, |
132 std::string* type) { | 132 std::string* type) { |
133 // DeviceInfoTracker must be syncing in order for remote history entries to | 133 // DeviceInfoTracker must be syncing in order for remote history entries to |
134 // be available. | 134 // be available. |
135 DCHECK(sync_service); | 135 DCHECK(sync_service); |
136 DCHECK(sync_service->GetDeviceInfoTracker()); | 136 DCHECK(sync_service->GetDeviceInfoTracker()); |
137 DCHECK(sync_service->GetDeviceInfoTracker()->IsSyncing()); | 137 DCHECK(sync_service->GetDeviceInfoTracker()->IsSyncing()); |
138 | 138 |
139 scoped_ptr<sync_driver::DeviceInfo> device_info = | 139 std::unique_ptr<sync_driver::DeviceInfo> device_info = |
140 sync_service->GetDeviceInfoTracker()->GetDeviceInfo(client_id); | 140 sync_service->GetDeviceInfoTracker()->GetDeviceInfo(client_id); |
141 if (device_info.get()) { | 141 if (device_info.get()) { |
142 *name = device_info->client_name(); | 142 *name = device_info->client_name(); |
143 switch (device_info->device_type()) { | 143 switch (device_info->device_type()) { |
144 case sync_pb::SyncEnums::TYPE_PHONE: | 144 case sync_pb::SyncEnums::TYPE_PHONE: |
145 *type = kDeviceTypePhone; | 145 *type = kDeviceTypePhone; |
146 break; | 146 break; |
147 case sync_pb::SyncEnums::TYPE_TABLET: | 147 case sync_pb::SyncEnums::TYPE_TABLET: |
148 *type = kDeviceTypeTablet; | 148 *type = kDeviceTypeTablet; |
149 break; | 149 break; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 // left to right strings. | 202 // left to right strings. |
203 if (base::i18n::IsRTL()) { | 203 if (base::i18n::IsRTL()) { |
204 if (using_url_as_the_title) | 204 if (using_url_as_the_title) |
205 base::i18n::WrapStringWithLTRFormatting(&title_to_set); | 205 base::i18n::WrapStringWithLTRFormatting(&title_to_set); |
206 else | 206 else |
207 base::i18n::AdjustStringForLocaleDirection(&title_to_set); | 207 base::i18n::AdjustStringForLocaleDirection(&title_to_set); |
208 } | 208 } |
209 result->SetString("title", title_to_set); | 209 result->SetString("title", title_to_set); |
210 } | 210 } |
211 | 211 |
212 scoped_ptr<base::DictionaryValue> BrowsingHistoryHandler::HistoryEntry::ToValue( | 212 std::unique_ptr<base::DictionaryValue> |
| 213 BrowsingHistoryHandler::HistoryEntry::ToValue( |
213 BookmarkModel* bookmark_model, | 214 BookmarkModel* bookmark_model, |
214 SupervisedUserService* supervised_user_service, | 215 SupervisedUserService* supervised_user_service, |
215 const ProfileSyncService* sync_service) const { | 216 const ProfileSyncService* sync_service) const { |
216 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 217 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
217 SetUrlAndTitle(result.get()); | 218 SetUrlAndTitle(result.get()); |
218 | 219 |
219 base::string16 domain = url_formatter::IDNToUnicode(url.host()); | 220 base::string16 domain = url_formatter::IDNToUnicode(url.host()); |
220 // When the domain is empty, use the scheme instead. This allows for a | 221 // When the domain is empty, use the scheme instead. This allows for a |
221 // sensible treatment of e.g. file: URLs when group by domain is on. | 222 // sensible treatment of e.g. file: URLs when group by domain is on. |
222 if (domain.empty()) | 223 if (domain.empty()) |
223 domain = base::UTF8ToUTF16(url.scheme() + ":"); | 224 domain = base::UTF8ToUTF16(url.scheme() + ":"); |
224 | 225 |
225 // The items which are to be written into result are also described in | 226 // The items which are to be written into result are also described in |
226 // chrome/browser/resources/history/history.js in @typedef for | 227 // chrome/browser/resources/history/history.js in @typedef for |
227 // HistoryEntry. Please update it whenever you add or remove | 228 // HistoryEntry. Please update it whenever you add or remove |
228 // any keys in result. | 229 // any keys in result. |
229 result->SetString("domain", domain); | 230 result->SetString("domain", domain); |
230 | 231 |
231 result->SetString("fallbackFaviconText", | 232 result->SetString("fallbackFaviconText", |
232 base::UTF16ToASCII(favicon::GetFallbackIconText(url))); | 233 base::UTF16ToASCII(favicon::GetFallbackIconText(url))); |
233 | 234 |
234 result->SetDouble("time", time.ToJsTime()); | 235 result->SetDouble("time", time.ToJsTime()); |
235 | 236 |
236 // Pass the timestamps in a list. | 237 // Pass the timestamps in a list. |
237 scoped_ptr<base::ListValue> timestamps(new base::ListValue); | 238 std::unique_ptr<base::ListValue> timestamps(new base::ListValue); |
238 for (std::set<int64_t>::const_iterator it = all_timestamps.begin(); | 239 for (std::set<int64_t>::const_iterator it = all_timestamps.begin(); |
239 it != all_timestamps.end(); ++it) { | 240 it != all_timestamps.end(); ++it) { |
240 timestamps->AppendDouble(base::Time::FromInternalValue(*it).ToJsTime()); | 241 timestamps->AppendDouble(base::Time::FromInternalValue(*it).ToJsTime()); |
241 } | 242 } |
242 result->Set("allTimestamps", timestamps.release()); | 243 result->Set("allTimestamps", timestamps.release()); |
243 | 244 |
244 // Always pass the short date since it is needed both in the search and in | 245 // Always pass the short date since it is needed both in the search and in |
245 // the monthly view. | 246 // the monthly view. |
246 result->SetString("dateShort", base::TimeFormatShortDate(time)); | 247 result->SetString("dateShort", base::TimeFormatShortDate(time)); |
247 | 248 |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 query_results_.begin(), query_results_.end(), IsLocalOnlyResult); | 687 query_results_.begin(), query_results_.end(), IsLocalOnlyResult); |
687 UMA_HISTOGRAM_PERCENTAGE("WebHistory.LocalResultMissingOnServer", | 688 UMA_HISTOGRAM_PERCENTAGE("WebHistory.LocalResultMissingOnServer", |
688 missing_count * 100.0 / local_result_count); | 689 missing_count * 100.0 / local_result_count); |
689 } | 690 } |
690 } | 691 } |
691 | 692 |
692 // Convert the result vector into a ListValue. | 693 // Convert the result vector into a ListValue. |
693 base::ListValue results_value; | 694 base::ListValue results_value; |
694 for (std::vector<BrowsingHistoryHandler::HistoryEntry>::iterator it = | 695 for (std::vector<BrowsingHistoryHandler::HistoryEntry>::iterator it = |
695 query_results_.begin(); it != query_results_.end(); ++it) { | 696 query_results_.begin(); it != query_results_.end(); ++it) { |
696 scoped_ptr<base::Value> value( | 697 std::unique_ptr<base::Value> value( |
697 it->ToValue(bookmark_model, supervised_user_service, sync_service)); | 698 it->ToValue(bookmark_model, supervised_user_service, sync_service)); |
698 results_value.Append(value.release()); | 699 results_value.Append(value.release()); |
699 } | 700 } |
700 | 701 |
701 web_ui()->CallJavascriptFunction( | 702 web_ui()->CallJavascriptFunction( |
702 "historyResult", results_info_value_, results_value); | 703 "historyResult", results_info_value_, results_value); |
703 web_ui()->CallJavascriptFunction( | 704 web_ui()->CallJavascriptFunction( |
704 "showNotification", | 705 "showNotification", |
705 base::FundamentalValue(has_synced_results_), | 706 base::FundamentalValue(has_synced_results_), |
706 base::FundamentalValue(has_other_forms_of_browsing_history_)); | 707 base::FundamentalValue(has_other_forms_of_browsing_history_)); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 | 931 |
931 void BrowsingHistoryHandler::OnURLsDeleted( | 932 void BrowsingHistoryHandler::OnURLsDeleted( |
932 history::HistoryService* history_service, | 933 history::HistoryService* history_service, |
933 bool all_history, | 934 bool all_history, |
934 bool expired, | 935 bool expired, |
935 const history::URLRows& deleted_rows, | 936 const history::URLRows& deleted_rows, |
936 const std::set<GURL>& favicon_urls) { | 937 const std::set<GURL>& favicon_urls) { |
937 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) | 938 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) |
938 web_ui()->CallJavascriptFunction("historyDeleted"); | 939 web_ui()->CallJavascriptFunction("historyDeleted"); |
939 } | 940 } |
OLD | NEW |