| 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/download/hyperbolic_download_item_notifier.h" | 5 #include "chrome/browser/download/all_download_item_notifier.h" |
| 6 | 6 |
| 7 HyperbolicDownloadItemNotifier::HyperbolicDownloadItemNotifier( | 7 AllDownloadItemNotifier::AllDownloadItemNotifier( |
| 8 content::DownloadManager* manager, | 8 content::DownloadManager* manager, |
| 9 HyperbolicDownloadItemNotifier::Observer* observer) | 9 AllDownloadItemNotifier::Observer* observer) |
| 10 : manager_(manager), | 10 : manager_(manager), |
| 11 observer_(observer) { | 11 observer_(observer) { |
| 12 DCHECK(observer_); | 12 DCHECK(observer_); |
| 13 manager_->AddObserver(this); | 13 manager_->AddObserver(this); |
| 14 content::DownloadManager::DownloadVector items; | 14 content::DownloadManager::DownloadVector items; |
| 15 manager_->GetAllDownloads(&items); | 15 manager_->GetAllDownloads(&items); |
| 16 for (content::DownloadManager::DownloadVector::const_iterator it = | 16 for (content::DownloadManager::DownloadVector::const_iterator it = |
| 17 items.begin(); | 17 items.begin(); |
| 18 it != items.end(); ++it) { | 18 it != items.end(); ++it) { |
| 19 (*it)->AddObserver(this); | 19 (*it)->AddObserver(this); |
| 20 observing_.insert(*it); | 20 observing_.insert(*it); |
| 21 } | 21 } |
| 22 } | 22 } |
| 23 | 23 |
| 24 HyperbolicDownloadItemNotifier::~HyperbolicDownloadItemNotifier() { | 24 AllDownloadItemNotifier::~AllDownloadItemNotifier() { |
| 25 if (manager_) | 25 if (manager_) |
| 26 manager_->RemoveObserver(this); | 26 manager_->RemoveObserver(this); |
| 27 for (std::set<content::DownloadItem*>::const_iterator it = | 27 for (std::set<content::DownloadItem*>::const_iterator it = |
| 28 observing_.begin(); | 28 observing_.begin(); |
| 29 it != observing_.end(); ++it) { | 29 it != observing_.end(); ++it) { |
| 30 (*it)->RemoveObserver(this); | 30 (*it)->RemoveObserver(this); |
| 31 } | 31 } |
| 32 observing_.clear(); | 32 observing_.clear(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void HyperbolicDownloadItemNotifier::ManagerGoingDown( | 35 void AllDownloadItemNotifier::ManagerGoingDown( |
| 36 content::DownloadManager* manager) { | 36 content::DownloadManager* manager) { |
| 37 DCHECK_EQ(manager_, manager); | 37 DCHECK_EQ(manager_, manager); |
| 38 manager_->RemoveObserver(this); | 38 manager_->RemoveObserver(this); |
| 39 manager_ = NULL; | 39 manager_ = NULL; |
| 40 } | 40 } |
| 41 | 41 |
| 42 void HyperbolicDownloadItemNotifier::OnDownloadCreated( | 42 void AllDownloadItemNotifier::OnDownloadCreated( |
| 43 content::DownloadManager* manager, | 43 content::DownloadManager* manager, |
| 44 content::DownloadItem* item) { | 44 content::DownloadItem* item) { |
| 45 item->AddObserver(this); | 45 item->AddObserver(this); |
| 46 observing_.insert(item); | 46 observing_.insert(item); |
| 47 observer_->OnDownloadCreated(manager, item); | 47 observer_->OnDownloadCreated(manager, item); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void HyperbolicDownloadItemNotifier::OnDownloadUpdated( | 50 void AllDownloadItemNotifier::OnDownloadUpdated( |
| 51 content::DownloadItem* item) { | 51 content::DownloadItem* item) { |
| 52 observer_->OnDownloadUpdated(manager_, item); | 52 observer_->OnDownloadUpdated(manager_, item); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void HyperbolicDownloadItemNotifier::OnDownloadOpened( | 55 void AllDownloadItemNotifier::OnDownloadOpened( |
| 56 content::DownloadItem* item) { | 56 content::DownloadItem* item) { |
| 57 observer_->OnDownloadOpened(manager_, item); | 57 observer_->OnDownloadOpened(manager_, item); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void HyperbolicDownloadItemNotifier::OnDownloadRemoved( | 60 void AllDownloadItemNotifier::OnDownloadRemoved( |
| 61 content::DownloadItem* item) { | 61 content::DownloadItem* item) { |
| 62 observer_->OnDownloadRemoved(manager_, item); | 62 observer_->OnDownloadRemoved(manager_, item); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void HyperbolicDownloadItemNotifier::OnDownloadDestroyed( | 65 void AllDownloadItemNotifier::OnDownloadDestroyed( |
| 66 content::DownloadItem* item) { | 66 content::DownloadItem* item) { |
| 67 item->RemoveObserver(this); | 67 item->RemoveObserver(this); |
| 68 observing_.erase(item); | 68 observing_.erase(item); |
| 69 } | 69 } |
| OLD | NEW |