Chromium Code Reviews| 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), |
| 313 weak_factory_(this) { | 314 weak_factory_(this) { |
|
Dan Beam
2016/03/31 01:05:44
your newly added booleans should also be initializ
msramek
2016/03/31 19:20:02
Done.
I originally had them here, and then remove
| |
| 314 } | 315 } |
| 315 | 316 |
| 316 BrowsingHistoryHandler::~BrowsingHistoryHandler() { | 317 BrowsingHistoryHandler::~BrowsingHistoryHandler() { |
| 317 query_task_tracker_.TryCancelAll(); | 318 query_task_tracker_.TryCancelAll(); |
| 318 web_history_request_.reset(); | 319 web_history_request_.reset(); |
| 319 } | 320 } |
| 320 | 321 |
| 321 void BrowsingHistoryHandler::RegisterMessages() { | 322 void BrowsingHistoryHandler::RegisterMessages() { |
| 322 // Create our favicon data source. | 323 // Create our favicon data source. |
| 323 Profile* profile = Profile::FromWebUI(web_ui()); | 324 Profile* profile = Profile::FromWebUI(web_ui()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 const base::string16& search_text, | 382 const base::string16& search_text, |
| 382 const history::QueryOptions& options) { | 383 const history::QueryOptions& options) { |
| 383 Profile* profile = Profile::FromWebUI(web_ui()); | 384 Profile* profile = Profile::FromWebUI(web_ui()); |
| 384 | 385 |
| 385 // Anything in-flight is invalid. | 386 // Anything in-flight is invalid. |
| 386 query_task_tracker_.TryCancelAll(); | 387 query_task_tracker_.TryCancelAll(); |
| 387 web_history_request_.reset(); | 388 web_history_request_.reset(); |
| 388 | 389 |
| 389 query_results_.clear(); | 390 query_results_.clear(); |
| 390 results_info_value_.Clear(); | 391 results_info_value_.Clear(); |
| 392 has_synced_results_ = false; | |
| 393 has_other_forms_of_browsing_history_ = false; | |
| 391 | 394 |
| 392 history::HistoryService* hs = HistoryServiceFactory::GetForProfile( | 395 history::HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 393 profile, ServiceAccessType::EXPLICIT_ACCESS); | 396 profile, ServiceAccessType::EXPLICIT_ACCESS); |
| 394 hs->QueryHistory(search_text, | 397 hs->QueryHistory(search_text, |
| 395 options, | 398 options, |
| 396 base::Bind(&BrowsingHistoryHandler::QueryComplete, | 399 base::Bind(&BrowsingHistoryHandler::QueryComplete, |
| 397 base::Unretained(this), | 400 base::Unretained(this), |
| 398 search_text, | 401 search_text, |
| 399 options), | 402 options), |
| 400 &query_task_tracker_); | 403 &query_task_tracker_); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 411 search_text, | 414 search_text, |
| 412 options, | 415 options, |
| 413 base::Bind(&BrowsingHistoryHandler::WebHistoryQueryComplete, | 416 base::Bind(&BrowsingHistoryHandler::WebHistoryQueryComplete, |
| 414 base::Unretained(this), | 417 base::Unretained(this), |
| 415 search_text, options, | 418 search_text, options, |
| 416 base::TimeTicks::Now())); | 419 base::TimeTicks::Now())); |
| 417 // Start a timer so we know when to give up. | 420 // Start a timer so we know when to give up. |
| 418 web_history_timer_.Start( | 421 web_history_timer_.Start( |
| 419 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds), | 422 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds), |
| 420 this, &BrowsingHistoryHandler::WebHistoryTimeout); | 423 this, &BrowsingHistoryHandler::WebHistoryTimeout); |
| 424 | |
| 425 // Test the existence of other forms of browsing history. | |
| 426 browsing_data_ui::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( | |
| 427 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile), | |
| 428 web_history, | |
| 429 base::Bind( | |
| 430 &BrowsingHistoryHandler::OtherFormsOfBrowsingHistoryQueryComplete, | |
| 431 weak_factory_.GetWeakPtr())); | |
| 421 } | 432 } |
| 422 } | 433 } |
| 423 | 434 |
| 424 void BrowsingHistoryHandler::HandleQueryHistory(const base::ListValue* args) { | 435 void BrowsingHistoryHandler::HandleQueryHistory(const base::ListValue* args) { |
| 425 history::QueryOptions options; | 436 history::QueryOptions options; |
| 426 | 437 |
| 427 // Parse the arguments from JavaScript. There are five required arguments: | 438 // Parse the arguments from JavaScript. There are five required arguments: |
| 428 // - the text to search for (may be empty) | 439 // - the text to search for (may be empty) |
| 429 // - the offset from which the search should start (in multiples of week or | 440 // - the offset from which the search should start (in multiples of week or |
| 430 // month, set by the next argument). | 441 // month, set by the next argument). |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 683 base::ListValue results_value; | 694 base::ListValue results_value; |
| 684 for (std::vector<BrowsingHistoryHandler::HistoryEntry>::iterator it = | 695 for (std::vector<BrowsingHistoryHandler::HistoryEntry>::iterator it = |
| 685 query_results_.begin(); it != query_results_.end(); ++it) { | 696 query_results_.begin(); it != query_results_.end(); ++it) { |
| 686 scoped_ptr<base::Value> value( | 697 scoped_ptr<base::Value> value( |
| 687 it->ToValue(bookmark_model, supervised_user_service, sync_service)); | 698 it->ToValue(bookmark_model, supervised_user_service, sync_service)); |
| 688 results_value.Append(value.release()); | 699 results_value.Append(value.release()); |
| 689 } | 700 } |
| 690 | 701 |
| 691 web_ui()->CallJavascriptFunction( | 702 web_ui()->CallJavascriptFunction( |
| 692 "historyResult", results_info_value_, results_value); | 703 "historyResult", results_info_value_, results_value); |
| 704 web_ui()->CallJavascriptFunction( | |
| 705 "showNotification", | |
| 706 base::FundamentalValue(has_synced_results_), | |
| 707 base::FundamentalValue(has_other_forms_of_browsing_history_)); | |
| 693 results_info_value_.Clear(); | 708 results_info_value_.Clear(); |
| 694 query_results_.clear(); | 709 query_results_.clear(); |
| 695 web_history_query_results_.clear(); | 710 web_history_query_results_.clear(); |
| 696 } | 711 } |
| 697 | 712 |
| 698 void BrowsingHistoryHandler::QueryComplete( | 713 void BrowsingHistoryHandler::QueryComplete( |
| 699 const base::string16& search_text, | 714 const base::string16& search_text, |
| 700 const history::QueryOptions& options, | 715 const history::QueryOptions& options, |
| 701 history::QueryResults* results) { | 716 history::QueryResults* results) { |
| 702 DCHECK_EQ(0U, query_results_.size()); | 717 DCHECK_EQ(0U, query_results_.size()); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 title, | 837 title, |
| 823 time, | 838 time, |
| 824 client_id, | 839 client_id, |
| 825 !search_text.empty(), | 840 !search_text.empty(), |
| 826 base::string16(), | 841 base::string16(), |
| 827 /* blocked_visit */ false, | 842 /* blocked_visit */ false, |
| 828 accept_languages)); | 843 accept_languages)); |
| 829 } | 844 } |
| 830 } | 845 } |
| 831 } | 846 } |
| 832 results_info_value_.SetBoolean("hasSyncedResults", results_value != NULL); | 847 has_synced_results_ = (results_value != NULL); |
|
Dan Beam
2016/03/31 01:05:44
nit: nullptr
Dan Beam
2016/03/31 01:05:44
nit: remove extra parens
msramek
2016/03/31 19:20:01
Done.
msramek
2016/03/31 19:20:02
Done.
| |
| 848 results_info_value_.SetBoolean("hasSyncedResults", has_synced_results_); | |
| 833 if (!query_task_tracker_.HasTrackedTasks()) | 849 if (!query_task_tracker_.HasTrackedTasks()) |
| 834 ReturnResultsToFrontEnd(); | 850 ReturnResultsToFrontEnd(); |
| 835 } | 851 } |
| 836 | 852 |
| 853 void BrowsingHistoryHandler::OtherFormsOfBrowsingHistoryQueryComplete( | |
| 854 bool foundOtherFormsOfBrowsingHistory) { | |
| 855 has_other_forms_of_browsing_history_ = foundOtherFormsOfBrowsingHistory; | |
| 856 web_ui()->CallJavascriptFunction( | |
| 857 "showNotification", | |
| 858 base::FundamentalValue(has_synced_results_), | |
| 859 base::FundamentalValue(has_other_forms_of_browsing_history_)); | |
| 860 } | |
| 861 | |
| 837 void BrowsingHistoryHandler::RemoveComplete() { | 862 void BrowsingHistoryHandler::RemoveComplete() { |
| 838 urls_to_be_deleted_.clear(); | 863 urls_to_be_deleted_.clear(); |
| 839 | 864 |
| 840 // Notify the page that the deletion request is complete, but only if a web | 865 // Notify the page that the deletion request is complete, but only if a web |
| 841 // history delete request is not still pending. | 866 // history delete request is not still pending. |
| 842 if (!has_pending_delete_request_) | 867 if (!has_pending_delete_request_) |
| 843 web_ui()->CallJavascriptFunction("deleteComplete"); | 868 web_ui()->CallJavascriptFunction("deleteComplete"); |
| 844 } | 869 } |
| 845 | 870 |
| 846 void BrowsingHistoryHandler::RemoveWebHistoryComplete(bool success) { | 871 void BrowsingHistoryHandler::RemoveWebHistoryComplete(bool success) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 915 | 940 |
| 916 void BrowsingHistoryHandler::OnURLsDeleted( | 941 void BrowsingHistoryHandler::OnURLsDeleted( |
| 917 history::HistoryService* history_service, | 942 history::HistoryService* history_service, |
| 918 bool all_history, | 943 bool all_history, |
| 919 bool expired, | 944 bool expired, |
| 920 const history::URLRows& deleted_rows, | 945 const history::URLRows& deleted_rows, |
| 921 const std::set<GURL>& favicon_urls) { | 946 const std::set<GURL>& favicon_urls) { |
| 922 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) | 947 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) |
| 923 web_ui()->CallJavascriptFunction("historyDeleted"); | 948 web_ui()->CallJavascriptFunction("historyDeleted"); |
| 924 } | 949 } |
| OLD | NEW |