summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download/notification/download_notification_manager.h
blob: 7490c1a0396dd0923b7e81dc37341eb737e2bff4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_MANAGER_H_
#define CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_MANAGER_H_

#include <set>

#include "chrome/browser/download/download_ui_controller.h"
#include "chrome/browser/download/notification/download_item_notification.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/download_item.h"

class DownloadNotificationManagerForProfile;

class DownloadNotificationManager : public DownloadUIController::Delegate {
 public:
  static bool IsEnabled();

  explicit DownloadNotificationManager(Profile* profile);
  ~DownloadNotificationManager() override;

  void OnAllDownloadsRemoving(Profile* profile);
  // DownloadUIController::Delegate:
  void OnNewDownloadReady(content::DownloadItem* item) override;

  DownloadNotificationManagerForProfile* GetForProfile(Profile* profile) const;

 private:
  friend class test::DownloadItemNotificationTest;

  Profile* main_profile_ = nullptr;
  std::map<Profile*, DownloadNotificationManagerForProfile*>
      manager_for_profile_;

  STLValueDeleter<std::map<Profile*, DownloadNotificationManagerForProfile*>>
      items_deleter_;
};

class DownloadNotificationManagerForProfile
    : public content::DownloadItem::Observer {
 public:
  DownloadNotificationManagerForProfile(
      Profile* profile, DownloadNotificationManager* parent_manager);
  ~DownloadNotificationManagerForProfile() override;

  message_center::MessageCenter* message_center() const {
    return message_center_;
  }

  // DownloadItem::Observer overrides:
  void OnDownloadUpdated(content::DownloadItem* download) override;
  void OnDownloadOpened(content::DownloadItem* download) override;
  void OnDownloadRemoved(content::DownloadItem* download) override;
  void OnDownloadDestroyed(content::DownloadItem* download) override;

  void OnNewDownloadReady(content::DownloadItem* item);

 private:
  friend class test::DownloadItemNotificationTest;

  void OverrideMessageCenterForTest(
      message_center::MessageCenter* message_center);

  Profile* profile_ = nullptr;
  DownloadNotificationManager* parent_manager_;  // weak
  std::set<content::DownloadItem*> downloading_items_;
  std::map<content::DownloadItem*, DownloadItemNotification*> items_;

  // Pointer to the message center instance.
  message_center::MessageCenter* message_center_;

  STLValueDeleter<std::map<content::DownloadItem*, DownloadItemNotification*>>
      items_deleter_;
};

#endif  // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_MANAGER_H_