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/downloads_dom_handler.h" | 5 #include "chrome/browser/ui/webui/downloads_dom_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 file->Cancel(true); | 525 file->Cancel(true); |
526 } | 526 } |
527 | 527 |
528 void DownloadsDOMHandler::HandleClearAll(const base::ListValue* args) { | 528 void DownloadsDOMHandler::HandleClearAll(const base::ListValue* args) { |
529 if (!IsDeletingHistoryAllowed()) | 529 if (!IsDeletingHistoryAllowed()) |
530 return; | 530 return; |
531 | 531 |
532 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); | 532 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); |
533 | 533 |
534 std::vector<content::DownloadItem*> downloads; | 534 std::vector<content::DownloadItem*> downloads; |
535 if (main_notifier_.GetManager()) | 535 if (GetMainNotifierManager()) |
536 main_notifier_.GetManager()->GetAllDownloads(&downloads); | 536 GetMainNotifierManager()->GetAllDownloads(&downloads); |
537 if (original_notifier_ && original_notifier_->GetManager()) | 537 if (original_notifier_ && original_notifier_->GetManager()) |
538 original_notifier_->GetManager()->GetAllDownloads(&downloads); | 538 original_notifier_->GetManager()->GetAllDownloads(&downloads); |
539 RemoveDownloads(downloads); | 539 RemoveDownloads(downloads); |
540 } | 540 } |
541 | 541 |
542 void DownloadsDOMHandler::RemoveDownloads( | 542 void DownloadsDOMHandler::RemoveDownloads( |
543 const std::vector<content::DownloadItem*>& to_remove) { | 543 const std::vector<content::DownloadItem*>& to_remove) { |
544 std::set<uint32> ids; | 544 std::set<uint32> ids; |
545 for (auto* download : to_remove) { | 545 for (auto* download : to_remove) { |
546 if (IsRemoved(*download)) | 546 if (IsRemoved(*download) || |
| 547 download->GetState() == content::DownloadItem::IN_PROGRESS) { |
547 continue; | 548 continue; |
| 549 } |
548 | 550 |
549 DownloadsDOMHandlerData::Create(download)->set_is_removed(true); | 551 DownloadsDOMHandlerData::Create(download)->set_is_removed(true); |
550 ids.insert(download->GetId()); | 552 ids.insert(download->GetId()); |
551 download->UpdateObservers(); | 553 download->UpdateObservers(); |
552 } | 554 } |
553 removes_.push_back(ids); | 555 removes_.push_back(ids); |
554 } | 556 } |
555 | 557 |
556 void DownloadsDOMHandler::HandleOpenDownloadsFolder( | 558 void DownloadsDOMHandler::HandleOpenDownloadsFolder( |
557 const base::ListValue* args) { | 559 const base::ListValue* args) { |
(...skipping 14 matching lines...) Expand all Loading... |
572 // in a single UI message loop iteration when the user Clears All downloads. | 574 // in a single UI message loop iteration when the user Clears All downloads. |
573 if (update_scheduled_) | 575 if (update_scheduled_) |
574 return; | 576 return; |
575 update_scheduled_ = true; | 577 update_scheduled_ = true; |
576 BrowserThread::PostTask( | 578 BrowserThread::PostTask( |
577 BrowserThread::UI, FROM_HERE, | 579 BrowserThread::UI, FROM_HERE, |
578 base::Bind(&DownloadsDOMHandler::SendCurrentDownloads, | 580 base::Bind(&DownloadsDOMHandler::SendCurrentDownloads, |
579 weak_ptr_factory_.GetWeakPtr())); | 581 weak_ptr_factory_.GetWeakPtr())); |
580 } | 582 } |
581 | 583 |
| 584 content::DownloadManager* DownloadsDOMHandler::GetMainNotifierManager() { |
| 585 return main_notifier_.GetManager(); |
| 586 } |
| 587 |
582 void DownloadsDOMHandler::SendCurrentDownloads() { | 588 void DownloadsDOMHandler::SendCurrentDownloads() { |
583 update_scheduled_ = false; | 589 update_scheduled_ = false; |
584 content::DownloadManager::DownloadVector all_items, filtered_items; | 590 content::DownloadManager::DownloadVector all_items, filtered_items; |
585 if (main_notifier_.GetManager()) { | 591 if (main_notifier_.GetManager()) { |
586 main_notifier_.GetManager()->GetAllDownloads(&all_items); | 592 main_notifier_.GetManager()->GetAllDownloads(&all_items); |
587 main_notifier_.GetManager()->CheckForHistoryFilesRemoval(); | 593 main_notifier_.GetManager()->CheckForHistoryFilesRemoval(); |
588 } | 594 } |
589 if (original_notifier_.get() && original_notifier_->GetManager()) { | 595 if (original_notifier_.get() && original_notifier_->GetManager()) { |
590 original_notifier_->GetManager()->GetAllDownloads(&all_items); | 596 original_notifier_->GetManager()->GetAllDownloads(&all_items); |
591 original_notifier_->GetManager()->CheckForHistoryFilesRemoval(); | 597 original_notifier_->GetManager()->CheckForHistoryFilesRemoval(); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 } | 682 } |
677 | 683 |
678 void DownloadsDOMHandler::CallDownloadsList(const base::ListValue& downloads) { | 684 void DownloadsDOMHandler::CallDownloadsList(const base::ListValue& downloads) { |
679 web_ui()->CallJavascriptFunction("downloadsList", downloads); | 685 web_ui()->CallJavascriptFunction("downloadsList", downloads); |
680 } | 686 } |
681 | 687 |
682 void DownloadsDOMHandler::CallDownloadUpdated( | 688 void DownloadsDOMHandler::CallDownloadUpdated( |
683 const base::ListValue& download_item) { | 689 const base::ListValue& download_item) { |
684 web_ui()->CallJavascriptFunction("downloadUpdated", download_item); | 690 web_ui()->CallJavascriptFunction("downloadUpdated", download_item); |
685 } | 691 } |
OLD | NEW |