Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / download / all_download_item_notifier.cc
bloba0b3a02eff5b863d69f114a779f57b962bdfa5d3
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)
10 : manager_(manager),
11 observer_(observer) {
12 DCHECK(observer_);
13 manager_->AddObserver(this);
14 content::DownloadManager::DownloadVector items;
15 manager_->GetAllDownloads(&items);
16 for (content::DownloadManager::DownloadVector::const_iterator it =
17 items.begin();
18 it != items.end(); ++it) {
19 (*it)->AddObserver(this);
20 observing_.insert(*it);
24 AllDownloadItemNotifier::~AllDownloadItemNotifier() {
25 if (manager_)
26 manager_->RemoveObserver(this);
27 for (std::set<content::DownloadItem*>::const_iterator it =
28 observing_.begin();
29 it != observing_.end(); ++it) {
30 (*it)->RemoveObserver(this);
32 observing_.clear();
35 void AllDownloadItemNotifier::ManagerGoingDown(
36 content::DownloadManager* manager) {
37 DCHECK_EQ(manager_, manager);
38 manager_->RemoveObserver(this);
39 manager_ = NULL;
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);