| 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 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/browser/sync/profile_sync_service_factory.h" | 30 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 31 #include "chrome/browser/ui/browser_finder.h" | 31 #include "chrome/browser/ui/browser_finder.h" |
| 32 #include "chrome/browser/ui/chrome_pages.h" | 32 #include "chrome/browser/ui/chrome_pages.h" |
| 33 #include "chrome/browser/ui/webui/favicon_source.h" | 33 #include "chrome/browser/ui/webui/favicon_source.h" |
| 34 #include "chrome/browser/ui/webui/large_icon_source.h" | 34 #include "chrome/browser/ui/webui/large_icon_source.h" |
| 35 #include "chrome/common/features.h" | 35 #include "chrome/common/features.h" |
| 36 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 37 #include "components/bookmarks/browser/bookmark_model.h" | 37 #include "components/bookmarks/browser/bookmark_model.h" |
| 38 #include "components/bookmarks/browser/bookmark_utils.h" | 38 #include "components/bookmarks/browser/bookmark_utils.h" |
| 39 #include "components/browser_sync/browser/profile_sync_service.h" | 39 #include "components/browser_sync/browser/profile_sync_service.h" |
| 40 #include "components/browsing_data_ui/history_notice_utils.h" |
| 40 #include "components/favicon/core/fallback_icon_service.h" | 41 #include "components/favicon/core/fallback_icon_service.h" |
| 41 #include "components/favicon/core/fallback_url_util.h" | 42 #include "components/favicon/core/fallback_url_util.h" |
| 42 #include "components/favicon/core/large_icon_service.h" | 43 #include "components/favicon/core/large_icon_service.h" |
| 43 #include "components/history/core/browser/history_service.h" | 44 #include "components/history/core/browser/history_service.h" |
| 44 #include "components/history/core/browser/history_types.h" | 45 #include "components/history/core/browser/history_types.h" |
| 45 #include "components/history/core/browser/web_history_service.h" | 46 #include "components/history/core/browser/web_history_service.h" |
| 46 #include "components/keyed_service/core/service_access_type.h" | 47 #include "components/keyed_service/core/service_access_type.h" |
| 47 #include "components/prefs/pref_service.h" | 48 #include "components/prefs/pref_service.h" |
| 48 #include "components/query_parser/snippet.h" | 49 #include "components/query_parser/snippet.h" |
| 49 #include "components/sync_driver/device_info.h" | 50 #include "components/sync_driver/device_info.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 | 304 |
| 304 bool BrowsingHistoryHandler::HistoryEntry::SortByTimeDescending( | 305 bool BrowsingHistoryHandler::HistoryEntry::SortByTimeDescending( |
| 305 const BrowsingHistoryHandler::HistoryEntry& entry1, | 306 const BrowsingHistoryHandler::HistoryEntry& entry1, |
| 306 const BrowsingHistoryHandler::HistoryEntry& entry2) { | 307 const BrowsingHistoryHandler::HistoryEntry& entry2) { |
| 307 return entry1.time > entry2.time; | 308 return entry1.time > entry2.time; |
| 308 } | 309 } |
| 309 | 310 |
| 310 BrowsingHistoryHandler::BrowsingHistoryHandler() | 311 BrowsingHistoryHandler::BrowsingHistoryHandler() |
| 311 : has_pending_delete_request_(false), | 312 : has_pending_delete_request_(false), |
| 312 history_service_observer_(this), | 313 history_service_observer_(this), |
| 314 has_synced_results_(false), |
| 315 has_other_forms_of_browsing_history_(false), |
| 313 weak_factory_(this) { | 316 weak_factory_(this) { |
| 314 } | 317 } |
| 315 | 318 |
| 316 BrowsingHistoryHandler::~BrowsingHistoryHandler() { | 319 BrowsingHistoryHandler::~BrowsingHistoryHandler() { |
| 317 query_task_tracker_.TryCancelAll(); | 320 query_task_tracker_.TryCancelAll(); |
| 318 web_history_request_.reset(); | 321 web_history_request_.reset(); |
| 319 } | 322 } |
| 320 | 323 |
| 321 void BrowsingHistoryHandler::RegisterMessages() { | 324 void BrowsingHistoryHandler::RegisterMessages() { |
| 322 // Create our favicon data source. | 325 // Create our favicon data source. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 const base::string16& search_text, | 384 const base::string16& search_text, |
| 382 const history::QueryOptions& options) { | 385 const history::QueryOptions& options) { |
| 383 Profile* profile = Profile::FromWebUI(web_ui()); | 386 Profile* profile = Profile::FromWebUI(web_ui()); |
| 384 | 387 |
| 385 // Anything in-flight is invalid. | 388 // Anything in-flight is invalid. |
| 386 query_task_tracker_.TryCancelAll(); | 389 query_task_tracker_.TryCancelAll(); |
| 387 web_history_request_.reset(); | 390 web_history_request_.reset(); |
| 388 | 391 |
| 389 query_results_.clear(); | 392 query_results_.clear(); |
| 390 results_info_value_.Clear(); | 393 results_info_value_.Clear(); |
| 394 has_synced_results_ = false; |
| 395 has_other_forms_of_browsing_history_ = false; |
| 391 | 396 |
| 392 history::HistoryService* hs = HistoryServiceFactory::GetForProfile( | 397 history::HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 393 profile, ServiceAccessType::EXPLICIT_ACCESS); | 398 profile, ServiceAccessType::EXPLICIT_ACCESS); |
| 394 hs->QueryHistory(search_text, | 399 hs->QueryHistory(search_text, |
| 395 options, | 400 options, |
| 396 base::Bind(&BrowsingHistoryHandler::QueryComplete, | 401 base::Bind(&BrowsingHistoryHandler::QueryComplete, |
| 397 base::Unretained(this), | 402 base::Unretained(this), |
| 398 search_text, | 403 search_text, |
| 399 options), | 404 options), |
| 400 &query_task_tracker_); | 405 &query_task_tracker_); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 411 search_text, | 416 search_text, |
| 412 options, | 417 options, |
| 413 base::Bind(&BrowsingHistoryHandler::WebHistoryQueryComplete, | 418 base::Bind(&BrowsingHistoryHandler::WebHistoryQueryComplete, |
| 414 base::Unretained(this), | 419 base::Unretained(this), |
| 415 search_text, options, | 420 search_text, options, |
| 416 base::TimeTicks::Now())); | 421 base::TimeTicks::Now())); |
| 417 // Start a timer so we know when to give up. | 422 // Start a timer so we know when to give up. |
| 418 web_history_timer_.Start( | 423 web_history_timer_.Start( |
| 419 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds), | 424 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds), |
| 420 this, &BrowsingHistoryHandler::WebHistoryTimeout); | 425 this, &BrowsingHistoryHandler::WebHistoryTimeout); |
| 426 |
| 427 // Test the existence of other forms of browsing history. |
| 428 browsing_data_ui::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( |
| 429 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile), |
| 430 web_history, |
| 431 base::Bind( |
| 432 &BrowsingHistoryHandler::OtherFormsOfBrowsingHistoryQueryComplete, |
| 433 weak_factory_.GetWeakPtr())); |
| 421 } | 434 } |
| 422 } | 435 } |
| 423 | 436 |
| 424 void BrowsingHistoryHandler::HandleQueryHistory(const base::ListValue* args) { | 437 void BrowsingHistoryHandler::HandleQueryHistory(const base::ListValue* args) { |
| 425 history::QueryOptions options; | 438 history::QueryOptions options; |
| 426 | 439 |
| 427 // Parse the arguments from JavaScript. There are five required arguments: | 440 // Parse the arguments from JavaScript. There are five required arguments: |
| 428 // - the text to search for (may be empty) | 441 // - the text to search for (may be empty) |
| 429 // - the offset from which the search should start (in multiples of week or | 442 // - the offset from which the search should start (in multiples of week or |
| 430 // month, set by the next argument). | 443 // month, set by the next argument). |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 base::ListValue results_value; | 696 base::ListValue results_value; |
| 684 for (std::vector<BrowsingHistoryHandler::HistoryEntry>::iterator it = | 697 for (std::vector<BrowsingHistoryHandler::HistoryEntry>::iterator it = |
| 685 query_results_.begin(); it != query_results_.end(); ++it) { | 698 query_results_.begin(); it != query_results_.end(); ++it) { |
| 686 scoped_ptr<base::Value> value( | 699 scoped_ptr<base::Value> value( |
| 687 it->ToValue(bookmark_model, supervised_user_service, sync_service)); | 700 it->ToValue(bookmark_model, supervised_user_service, sync_service)); |
| 688 results_value.Append(value.release()); | 701 results_value.Append(value.release()); |
| 689 } | 702 } |
| 690 | 703 |
| 691 web_ui()->CallJavascriptFunction( | 704 web_ui()->CallJavascriptFunction( |
| 692 "historyResult", results_info_value_, results_value); | 705 "historyResult", results_info_value_, results_value); |
| 706 web_ui()->CallJavascriptFunction( |
| 707 "showNotification", |
| 708 base::FundamentalValue(has_synced_results_), |
| 709 base::FundamentalValue(has_other_forms_of_browsing_history_)); |
| 693 results_info_value_.Clear(); | 710 results_info_value_.Clear(); |
| 694 query_results_.clear(); | 711 query_results_.clear(); |
| 695 web_history_query_results_.clear(); | 712 web_history_query_results_.clear(); |
| 696 } | 713 } |
| 697 | 714 |
| 698 void BrowsingHistoryHandler::QueryComplete( | 715 void BrowsingHistoryHandler::QueryComplete( |
| 699 const base::string16& search_text, | 716 const base::string16& search_text, |
| 700 const history::QueryOptions& options, | 717 const history::QueryOptions& options, |
| 701 history::QueryResults* results) { | 718 history::QueryResults* results) { |
| 702 DCHECK_EQ(0U, query_results_.size()); | 719 DCHECK_EQ(0U, query_results_.size()); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 title, | 839 title, |
| 823 time, | 840 time, |
| 824 client_id, | 841 client_id, |
| 825 !search_text.empty(), | 842 !search_text.empty(), |
| 826 base::string16(), | 843 base::string16(), |
| 827 /* blocked_visit */ false, | 844 /* blocked_visit */ false, |
| 828 accept_languages)); | 845 accept_languages)); |
| 829 } | 846 } |
| 830 } | 847 } |
| 831 } | 848 } |
| 832 results_info_value_.SetBoolean("hasSyncedResults", results_value != NULL); | 849 has_synced_results_ = results_value != nullptr; |
| 850 results_info_value_.SetBoolean("hasSyncedResults", has_synced_results_); |
| 833 if (!query_task_tracker_.HasTrackedTasks()) | 851 if (!query_task_tracker_.HasTrackedTasks()) |
| 834 ReturnResultsToFrontEnd(); | 852 ReturnResultsToFrontEnd(); |
| 835 } | 853 } |
| 836 | 854 |
| 855 void BrowsingHistoryHandler::OtherFormsOfBrowsingHistoryQueryComplete( |
| 856 bool found_other_forms_of_browsing_history) { |
| 857 has_other_forms_of_browsing_history_ = found_other_forms_of_browsing_history; |
| 858 web_ui()->CallJavascriptFunction( |
| 859 "showNotification", |
| 860 base::FundamentalValue(has_synced_results_), |
| 861 base::FundamentalValue(has_other_forms_of_browsing_history_)); |
| 862 } |
| 863 |
| 837 void BrowsingHistoryHandler::RemoveComplete() { | 864 void BrowsingHistoryHandler::RemoveComplete() { |
| 838 urls_to_be_deleted_.clear(); | 865 urls_to_be_deleted_.clear(); |
| 839 | 866 |
| 840 // Notify the page that the deletion request is complete, but only if a web | 867 // Notify the page that the deletion request is complete, but only if a web |
| 841 // history delete request is not still pending. | 868 // history delete request is not still pending. |
| 842 if (!has_pending_delete_request_) | 869 if (!has_pending_delete_request_) |
| 843 web_ui()->CallJavascriptFunction("deleteComplete"); | 870 web_ui()->CallJavascriptFunction("deleteComplete"); |
| 844 } | 871 } |
| 845 | 872 |
| 846 void BrowsingHistoryHandler::RemoveWebHistoryComplete(bool success) { | 873 void BrowsingHistoryHandler::RemoveWebHistoryComplete(bool success) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 | 942 |
| 916 void BrowsingHistoryHandler::OnURLsDeleted( | 943 void BrowsingHistoryHandler::OnURLsDeleted( |
| 917 history::HistoryService* history_service, | 944 history::HistoryService* history_service, |
| 918 bool all_history, | 945 bool all_history, |
| 919 bool expired, | 946 bool expired, |
| 920 const history::URLRows& deleted_rows, | 947 const history::URLRows& deleted_rows, |
| 921 const std::set<GURL>& favicon_urls) { | 948 const std::set<GURL>& favicon_urls) { |
| 922 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) | 949 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) |
| 923 web_ui()->CallJavascriptFunction("historyDeleted"); | 950 web_ui()->CallJavascriptFunction("historyDeleted"); |
| 924 } | 951 } |
| OLD | NEW |