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
3 // found in the LICENSE file.
5 #include "chrome/browser/download/all_download_item_notifier.h"
7 AllDownloadItemNotifier::AllDownloadItemNotifier(
8 content::DownloadManager
* manager
,
9 AllDownloadItemNotifier::Observer
* observer
)
13 manager_
->AddObserver(this);
14 content::DownloadManager::DownloadVector items
;
15 manager_
->GetAllDownloads(&items
);
16 for (content::DownloadManager::DownloadVector::const_iterator it
=
18 it
!= items
.end(); ++it
) {
19 (*it
)->AddObserver(this);
20 observing_
.insert(*it
);
24 AllDownloadItemNotifier::~AllDownloadItemNotifier() {
26 manager_
->RemoveObserver(this);
27 for (std::set
<content::DownloadItem
*>::const_iterator it
=
29 it
!= observing_
.end(); ++it
) {
30 (*it
)->RemoveObserver(this);
35 void AllDownloadItemNotifier::ManagerGoingDown(
36 content::DownloadManager
* manager
) {
37 DCHECK_EQ(manager_
, manager
);
38 manager_
->RemoveObserver(this);
42 void AllDownloadItemNotifier::OnDownloadCreated(
43 content::DownloadManager
* manager
,
44 content::DownloadItem
* item
) {
45 item
->AddObserver(this);
46 observing_
.insert(item
);
47 observer_
->OnDownloadCreated(manager
, item
);
50 void AllDownloadItemNotifier::OnDownloadUpdated(
51 content::DownloadItem
* item
) {
52 observer_
->OnDownloadUpdated(manager_
, item
);
55 void AllDownloadItemNotifier::OnDownloadOpened(
56 content::DownloadItem
* item
) {
57 observer_
->OnDownloadOpened(manager_
, item
);
60 void AllDownloadItemNotifier::OnDownloadRemoved(
61 content::DownloadItem
* item
) {
62 observer_
->OnDownloadRemoved(manager_
, item
);
65 void AllDownloadItemNotifier::OnDownloadDestroyed(
66 content::DownloadItem
* item
) {
67 item
->RemoveObserver(this);
68 observing_
.erase(item
);