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

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

Issue 1574063003: MD History: Add basic material design history cards and history items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed 1 line Created 4 years, 10 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 for (std::set<int64_t>::const_iterator it = all_timestamps.begin(); 227 for (std::set<int64_t>::const_iterator it = all_timestamps.begin();
228 it != all_timestamps.end(); ++it) { 228 it != all_timestamps.end(); ++it) {
229 timestamps->AppendDouble(base::Time::FromInternalValue(*it).ToJsTime()); 229 timestamps->AppendDouble(base::Time::FromInternalValue(*it).ToJsTime());
230 } 230 }
231 result->Set("allTimestamps", timestamps.release()); 231 result->Set("allTimestamps", timestamps.release());
232 232
233 // Always pass the short date since it is needed both in the search and in 233 // Always pass the short date since it is needed both in the search and in
234 // the monthly view. 234 // the monthly view.
235 result->SetString("dateShort", base::TimeFormatShortDate(time)); 235 result->SetString("dateShort", base::TimeFormatShortDate(time));
236 236
237 base::string16 snippet_string;
238 base::string16 date_relative_day;
239 base::string16 date_time_of_day;
240 bool is_blocked_visit = false;
241 int host_filtering_behavior = -1;
242
237 // Only pass in the strings we need (search results need a shortdate 243 // Only pass in the strings we need (search results need a shortdate
238 // and snippet, browse results need day and time information). 244 // and snippet, browse results need day and time information). Makes sure that
245 // values of result are never undefined
239 if (is_search_result) { 246 if (is_search_result) {
240 result->SetString("snippet", snippet); 247 snippet_string = snippet;
241 } else { 248 } else {
242 base::Time midnight = base::Time::Now().LocalMidnight(); 249 base::Time midnight = base::Time::Now().LocalMidnight();
243 base::string16 date_str = ui::TimeFormat::RelativeDate(time, &midnight); 250 base::string16 date_str = ui::TimeFormat::RelativeDate(time, &midnight);
244 if (date_str.empty()) { 251 if (date_str.empty()) {
245 date_str = base::TimeFormatFriendlyDate(time); 252 date_str = base::TimeFormatFriendlyDate(time);
246 } else { 253 } else {
247 date_str = l10n_util::GetStringFUTF16( 254 date_str = l10n_util::GetStringFUTF16(
248 IDS_HISTORY_DATE_WITH_RELATIVE_TIME, 255 IDS_HISTORY_DATE_WITH_RELATIVE_TIME,
249 date_str, 256 date_str,
250 base::TimeFormatFriendlyDate(time)); 257 base::TimeFormatFriendlyDate(time));
251 } 258 }
252 result->SetString("dateRelativeDay", date_str); 259 date_relative_day = date_str;
253 result->SetString("dateTimeOfDay", base::TimeFormatTimeOfDay(time)); 260 date_time_of_day = base::TimeFormatTimeOfDay(time);
254 } 261 }
255 result->SetBoolean("starred", bookmark_model->IsBookmarked(url));
256 262
257 std::string device_name; 263 std::string device_name;
258 std::string device_type; 264 std::string device_type;
259 if (!client_id.empty()) 265 if (!client_id.empty())
260 GetDeviceNameAndType(sync_service, client_id, &device_name, &device_type); 266 GetDeviceNameAndType(sync_service, client_id, &device_name, &device_type);
261 result->SetString("deviceName", device_name); 267 result->SetString("deviceName", device_name);
262 result->SetString("deviceType", device_type); 268 result->SetString("deviceType", device_type);
263 269
264 #if defined(ENABLE_SUPERVISED_USERS) 270 #if defined(ENABLE_SUPERVISED_USERS)
265 if (supervised_user_service) { 271 if (supervised_user_service) {
266 const SupervisedUserURLFilter* url_filter = 272 const SupervisedUserURLFilter* url_filter =
267 supervised_user_service->GetURLFilterForUIThread(); 273 supervised_user_service->GetURLFilterForUIThread();
268 int filtering_behavior = 274 int filtering_behavior =
269 url_filter->GetFilteringBehaviorForURL(url.GetWithEmptyPath()); 275 url_filter->GetFilteringBehaviorForURL(url.GetWithEmptyPath());
270 result->SetInteger("hostFilteringBehavior", filtering_behavior); 276 is_blocked_visit = blocked_visit;
271 277 host_filtering_behavior = filtering_behavior;
272 result->SetBoolean("blockedVisit", blocked_visit);
273 } 278 }
274 #endif 279 #endif
275 280
281 result->SetString("dateTimeOfDay", date_time_of_day);
282 result->SetString("dateRelativeDay", date_relative_day);
283 result->SetString("snippet", snippet_string);
284 result->SetBoolean("starred", bookmark_model->IsBookmarked(url));
285 result->SetInteger("hostFilteringBehavior", host_filtering_behavior);
286 result->SetBoolean("blockedVisit", is_blocked_visit);
287
276 return result; 288 return result;
277 } 289 }
278 290
279 bool BrowsingHistoryHandler::HistoryEntry::SortByTimeDescending( 291 bool BrowsingHistoryHandler::HistoryEntry::SortByTimeDescending(
280 const BrowsingHistoryHandler::HistoryEntry& entry1, 292 const BrowsingHistoryHandler::HistoryEntry& entry1,
281 const BrowsingHistoryHandler::HistoryEntry& entry2) { 293 const BrowsingHistoryHandler::HistoryEntry& entry2) {
282 return entry1.time > entry2.time; 294 return entry1.time > entry2.time;
283 } 295 }
284 296
285 BrowsingHistoryHandler::BrowsingHistoryHandler() 297 BrowsingHistoryHandler::BrowsingHistoryHandler()
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 hs->QueryHistory(search_text, 371 hs->QueryHistory(search_text,
360 options, 372 options,
361 base::Bind(&BrowsingHistoryHandler::QueryComplete, 373 base::Bind(&BrowsingHistoryHandler::QueryComplete,
362 base::Unretained(this), 374 base::Unretained(this),
363 search_text, 375 search_text,
364 options), 376 options),
365 &query_task_tracker_); 377 &query_task_tracker_);
366 378
367 history::WebHistoryService* web_history = 379 history::WebHistoryService* web_history =
368 WebHistoryServiceFactory::GetForProfile(profile); 380 WebHistoryServiceFactory::GetForProfile(profile);
381
382 // Set this to false until the results actually arrive.
383 results_info_value_.SetBoolean("hasSyncedResults", false);
384
369 if (web_history) { 385 if (web_history) {
370 web_history_query_results_.clear(); 386 web_history_query_results_.clear();
371 web_history_request_ = web_history->QueryHistory( 387 web_history_request_ = web_history->QueryHistory(
372 search_text, 388 search_text,
373 options, 389 options,
374 base::Bind(&BrowsingHistoryHandler::WebHistoryQueryComplete, 390 base::Bind(&BrowsingHistoryHandler::WebHistoryQueryComplete,
375 base::Unretained(this), 391 base::Unretained(this),
376 search_text, options, 392 search_text, options,
377 base::TimeTicks::Now())); 393 base::TimeTicks::Now()));
378 // Start a timer so we know when to give up. 394 // Start a timer so we know when to give up.
379 web_history_timer_.Start( 395 web_history_timer_.Start(
380 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds), 396 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds),
381 this, &BrowsingHistoryHandler::WebHistoryTimeout); 397 this, &BrowsingHistoryHandler::WebHistoryTimeout);
382
383 // Set this to false until the results actually arrive.
384 results_info_value_.SetBoolean("hasSyncedResults", false);
385 } 398 }
386 } 399 }
387 400
388 void BrowsingHistoryHandler::HandleQueryHistory(const base::ListValue* args) { 401 void BrowsingHistoryHandler::HandleQueryHistory(const base::ListValue* args) {
389 history::QueryOptions options; 402 history::QueryOptions options;
390 403
391 // Parse the arguments from JavaScript. There are five required arguments: 404 // Parse the arguments from JavaScript. There are five required arguments:
392 // - the text to search for (may be empty) 405 // - the text to search for (may be empty)
393 // - the offset from which the search should start (in multiples of week or 406 // - the offset from which the search should start (in multiples of week or
394 // month, set by the next argument). 407 // month, set by the next argument).
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 892
880 void BrowsingHistoryHandler::OnURLsDeleted( 893 void BrowsingHistoryHandler::OnURLsDeleted(
881 history::HistoryService* history_service, 894 history::HistoryService* history_service,
882 bool all_history, 895 bool all_history,
883 bool expired, 896 bool expired,
884 const history::URLRows& deleted_rows, 897 const history::URLRows& deleted_rows,
885 const std::set<GURL>& favicon_urls) { 898 const std::set<GURL>& favicon_urls) {
886 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) 899 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_))
887 web_ui()->CallJavascriptFunction("historyDeleted"); 900 web_ui()->CallJavascriptFunction("historyDeleted");
888 } 901 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698