Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/history_ui.h" | 5 #include "chrome/browser/ui/webui/history_ui.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 | 379 |
| 380 return result.Pass(); | 380 return result.Pass(); |
| 381 } | 381 } |
| 382 | 382 |
| 383 bool BrowsingHistoryHandler::HistoryEntry::SortByTimeDescending( | 383 bool BrowsingHistoryHandler::HistoryEntry::SortByTimeDescending( |
| 384 const BrowsingHistoryHandler::HistoryEntry& entry1, | 384 const BrowsingHistoryHandler::HistoryEntry& entry1, |
| 385 const BrowsingHistoryHandler::HistoryEntry& entry2) { | 385 const BrowsingHistoryHandler::HistoryEntry& entry2) { |
| 386 return entry1.time > entry2.time; | 386 return entry1.time > entry2.time; |
| 387 } | 387 } |
| 388 | 388 |
| 389 BrowsingHistoryHandler::BrowsingHistoryHandler() {} | 389 BrowsingHistoryHandler::BrowsingHistoryHandler() |
| 390 : pending_delete_requests_(0), | |
| 391 weak_factory_(this) { | |
| 392 } | |
| 390 | 393 |
| 391 BrowsingHistoryHandler::~BrowsingHistoryHandler() { | 394 BrowsingHistoryHandler::~BrowsingHistoryHandler() { |
| 392 history_request_consumer_.CancelAllRequests(); | 395 history_request_consumer_.CancelAllRequests(); |
| 393 web_history_request_.reset(); | 396 web_history_request_.reset(); |
| 394 } | 397 } |
| 395 | 398 |
| 396 void BrowsingHistoryHandler::RegisterMessages() { | 399 void BrowsingHistoryHandler::RegisterMessages() { |
| 397 // Create our favicon data source. | 400 // Create our favicon data source. |
| 398 Profile* profile = Profile::FromWebUI(web_ui()); | 401 Profile* profile = Profile::FromWebUI(web_ui()); |
| 399 content::URLDataSource::Add( | 402 content::URLDataSource::Add( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 NOTREACHED() << "Failed to convert argument 4."; | 525 NOTREACHED() << "Failed to convert argument 4."; |
| 523 return; | 526 return; |
| 524 } | 527 } |
| 525 | 528 |
| 526 options.duplicate_policy = history::QueryOptions::REMOVE_DUPLICATES_PER_DAY; | 529 options.duplicate_policy = history::QueryOptions::REMOVE_DUPLICATES_PER_DAY; |
| 527 QueryHistory(search_text, options); | 530 QueryHistory(search_text, options); |
| 528 } | 531 } |
| 529 | 532 |
| 530 void BrowsingHistoryHandler::HandleRemoveVisits(const base::ListValue* args) { | 533 void BrowsingHistoryHandler::HandleRemoveVisits(const base::ListValue* args) { |
| 531 Profile* profile = Profile::FromWebUI(web_ui()); | 534 Profile* profile = Profile::FromWebUI(web_ui()); |
| 532 if (delete_task_tracker_.HasTrackedTasks() || | 535 if (delete_task_tracker_.HasTrackedTasks() || |
|
Patrick Dubroy
2014/02/20 12:56:55
See comment below -- the deletion should also fail
davidben
2014/02/20 18:08:01
Done. And added a TODO because it doesn't look lik
| |
| 533 !profile->GetPrefs()->GetBoolean(prefs::kAllowDeletingBrowserHistory)) { | 536 !profile->GetPrefs()->GetBoolean(prefs::kAllowDeletingBrowserHistory)) { |
| 534 web_ui()->CallJavascriptFunction("deleteFailed"); | 537 web_ui()->CallJavascriptFunction("deleteFailed"); |
| 535 return; | 538 return; |
| 536 } | 539 } |
| 537 | 540 |
| 538 HistoryService* history_service = | 541 HistoryService* history_service = |
| 539 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); | 542 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); |
| 540 history::WebHistoryService* web_history = | 543 history::WebHistoryService* web_history = |
| 541 WebHistoryServiceFactory::GetForProfile(profile); | 544 WebHistoryServiceFactory::GetForProfile(profile); |
| 542 | 545 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 605 history_service->ProcessLocalDeleteDirective(delete_directive); | 608 history_service->ProcessLocalDeleteDirective(delete_directive); |
| 606 } | 609 } |
| 607 | 610 |
| 608 history_service->ExpireHistory( | 611 history_service->ExpireHistory( |
| 609 expire_list, | 612 expire_list, |
| 610 base::Bind(&BrowsingHistoryHandler::RemoveComplete, | 613 base::Bind(&BrowsingHistoryHandler::RemoveComplete, |
| 611 base::Unretained(this)), | 614 base::Unretained(this)), |
| 612 &delete_task_tracker_); | 615 &delete_task_tracker_); |
| 613 | 616 |
| 614 if (web_history) { | 617 if (web_history) { |
| 615 web_history_delete_request_ = web_history->ExpireHistory( | 618 pending_delete_requests_++; |
|
Patrick Dubroy
2014/02/20 12:56:55
This seems to imply that there can be multiple del
davidben
2014/02/20 18:08:01
Done.
| |
| 619 web_history->ExpireHistory( | |
| 616 expire_list, | 620 expire_list, |
| 617 base::Bind(&BrowsingHistoryHandler::RemoveWebHistoryComplete, | 621 base::Bind(&BrowsingHistoryHandler::RemoveWebHistoryComplete, |
| 618 base::Unretained(this))); | 622 weak_factory_.GetWeakPtr())); |
| 619 } | 623 } |
| 620 | 624 |
| 621 #if defined(ENABLE_EXTENSIONS) | 625 #if defined(ENABLE_EXTENSIONS) |
| 622 // If the profile has activity logging enabled also clean up any URLs from | 626 // If the profile has activity logging enabled also clean up any URLs from |
| 623 // the extension activity log. The extension activity log contains URLS | 627 // the extension activity log. The extension activity log contains URLS |
| 624 // which websites an extension has activity on so it will indirectly | 628 // which websites an extension has activity on so it will indirectly |
| 625 // contain websites that a user has visited. | 629 // contain websites that a user has visited. |
| 626 extensions::ActivityLog* activity_log = | 630 extensions::ActivityLog* activity_log = |
| 627 extensions::ActivityLog::GetInstance(profile); | 631 extensions::ActivityLog::GetInstance(profile); |
| 628 for (std::vector<history::ExpireHistoryArgs>::const_iterator it = | 632 for (std::vector<history::ExpireHistoryArgs>::const_iterator it = |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 879 results_info_value_.SetBoolean("hasSyncedResults", results_value != NULL); | 883 results_info_value_.SetBoolean("hasSyncedResults", results_value != NULL); |
| 880 if (!history_request_consumer_.HasPendingRequests()) | 884 if (!history_request_consumer_.HasPendingRequests()) |
| 881 ReturnResultsToFrontEnd(); | 885 ReturnResultsToFrontEnd(); |
| 882 } | 886 } |
| 883 | 887 |
| 884 void BrowsingHistoryHandler::RemoveComplete() { | 888 void BrowsingHistoryHandler::RemoveComplete() { |
| 885 urls_to_be_deleted_.clear(); | 889 urls_to_be_deleted_.clear(); |
| 886 | 890 |
| 887 // Notify the page that the deletion request is complete, but only if a web | 891 // Notify the page that the deletion request is complete, but only if a web |
| 888 // history delete request is not still pending. | 892 // history delete request is not still pending. |
| 889 if (!(web_history_delete_request_.get() && | 893 if (pending_delete_requests_ == 0) { |
| 890 web_history_delete_request_->is_pending())) { | |
| 891 web_ui()->CallJavascriptFunction("deleteComplete"); | 894 web_ui()->CallJavascriptFunction("deleteComplete"); |
| 892 } | 895 } |
| 893 } | 896 } |
| 894 | 897 |
| 895 void BrowsingHistoryHandler::RemoveWebHistoryComplete( | 898 void BrowsingHistoryHandler::RemoveWebHistoryComplete(bool success) { |
| 896 history::WebHistoryService::Request* request, bool success) { | 899 pending_delete_requests_--; |
| 897 // TODO(dubroy): Should we handle failure somehow? Delete directives will | 900 // TODO(dubroy): Should we handle failure somehow? Delete directives will |
| 898 // ensure that the visits are eventually deleted, so maybe it's not necessary. | 901 // ensure that the visits are eventually deleted, so maybe it's not necessary. |
| 899 if (!delete_task_tracker_.HasTrackedTasks()) | 902 if (!delete_task_tracker_.HasTrackedTasks()) |
| 900 RemoveComplete(); | 903 RemoveComplete(); |
| 901 } | 904 } |
| 902 | 905 |
| 903 void BrowsingHistoryHandler::SetQueryTimeInWeeks( | 906 void BrowsingHistoryHandler::SetQueryTimeInWeeks( |
| 904 int offset, history::QueryOptions* options) { | 907 int offset, history::QueryOptions* options) { |
| 905 // LocalMidnight returns the beginning of the current day so get the | 908 // LocalMidnight returns the beginning of the current day so get the |
| 906 // beginning of the next one. | 909 // beginning of the next one. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1006 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + | 1009 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + |
| 1007 net::EscapeQueryParamValue(base::UTF16ToUTF8(text), true)); | 1010 net::EscapeQueryParamValue(base::UTF16ToUTF8(text), true)); |
| 1008 } | 1011 } |
| 1009 | 1012 |
| 1010 // static | 1013 // static |
| 1011 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( | 1014 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( |
| 1012 ui::ScaleFactor scale_factor) { | 1015 ui::ScaleFactor scale_factor) { |
| 1013 return ResourceBundle::GetSharedInstance(). | 1016 return ResourceBundle::GetSharedInstance(). |
| 1014 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); | 1017 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); |
| 1015 } | 1018 } |
| OLD | NEW |