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