| 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/automation/automation_provider_observers.h" | 5 #include "chrome/browser/automation/automation_provider_observers.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1424 .SendError("Cannot convert ID of prior download to integer."); | 1424 .SendError("Cannot convert ID of prior download to integer."); |
| 1425 delete this; | 1425 delete this; |
| 1426 return; | 1426 return; |
| 1427 } | 1427 } |
| 1428 } | 1428 } |
| 1429 download_manager_->AddObserver(this); // Will call initial ModelChanged(). | 1429 download_manager_->AddObserver(this); // Will call initial ModelChanged(). |
| 1430 } | 1430 } |
| 1431 | 1431 |
| 1432 AllDownloadsCompleteObserver::~AllDownloadsCompleteObserver() {} | 1432 AllDownloadsCompleteObserver::~AllDownloadsCompleteObserver() {} |
| 1433 | 1433 |
| 1434 void AllDownloadsCompleteObserver::ModelChanged(DownloadManager* manager) { | 1434 |
| 1435 DCHECK_EQ(manager, download_manager_); | 1435 void AllDownloadsCompleteObserver::OnDownloadCreated( |
| 1436 // The set of downloads in the download manager has changed. If there are | 1436 DownloadManager* manager, DownloadItem* item) { |
| 1437 // any new downloads that are still in progress, add them to the pending list. | 1437 if (pre_download_ids_.find(item->GetId()) == pre_download_ids_.end()) { |
| 1438 std::vector<DownloadItem*> downloads; | 1438 item->AddObserver(this); |
| 1439 download_manager_->GetAllDownloads(FilePath(), &downloads); | 1439 pending_downloads_.insert(item); |
| 1440 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | |
| 1441 it != downloads.end(); ++it) { | |
| 1442 if ((*it)->GetState() == DownloadItem::IN_PROGRESS && | |
| 1443 pre_download_ids_.find((*it)->GetId()) == pre_download_ids_.end()) { | |
| 1444 (*it)->AddObserver(this); | |
| 1445 pending_downloads_.insert(*it); | |
| 1446 } | |
| 1447 } | 1440 } |
| 1448 ReplyIfNecessary(); | |
| 1449 } | 1441 } |
| 1450 | 1442 |
| 1451 void AllDownloadsCompleteObserver::OnDownloadUpdated(DownloadItem* download) { | 1443 void AllDownloadsCompleteObserver::OnDownloadUpdated(DownloadItem* download) { |
| 1452 // If the current download's status has changed to a final state (not state | 1444 // If the current download's status has changed to a final state (not state |
| 1453 // "in progress"), remove it from the pending list. | 1445 // "in progress"), remove it from the pending list. |
| 1454 if (download->GetState() != DownloadItem::IN_PROGRESS) { | 1446 if (download->GetState() != DownloadItem::IN_PROGRESS) { |
| 1455 download->RemoveObserver(this); | 1447 download->RemoveObserver(this); |
| 1456 pending_downloads_.erase(download); | 1448 pending_downloads_.erase(download); |
| 1457 ReplyIfNecessary(); | 1449 ReplyIfNecessary(); |
| 1458 } | 1450 } |
| (...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2857 if (automation_) { | 2849 if (automation_) { |
| 2858 AutomationJSONReply(automation_, reply_message_.release()) | 2850 AutomationJSONReply(automation_, reply_message_.release()) |
| 2859 .SendSuccess(NULL); | 2851 .SendSuccess(NULL); |
| 2860 } | 2852 } |
| 2861 delete this; | 2853 delete this; |
| 2862 } | 2854 } |
| 2863 } else { | 2855 } else { |
| 2864 NOTREACHED(); | 2856 NOTREACHED(); |
| 2865 } | 2857 } |
| 2866 } | 2858 } |
| OLD | NEW |