File: notification_ui_manager_impl.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (120 lines) | stat: -rw-r--r-- 4,675 bytes parent folder | download | duplicates (4)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_IMPL_H_
#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_IMPL_H_

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "base/gtest_prod_util.h"
#include "base/scoped_multi_source_observation.h"
#include "chrome/browser/notifications/notification_system_observer.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "ui/message_center/message_center_observer.h"
#include "ui/message_center/message_center_types.h"
#include "ui/message_center/public/cpp/notification.h"

class PopupsOnlyUiController;
class Profile;
class ProfileNotification;

namespace message_center {
class Notification;
class NotificationBlocker;
FORWARD_DECLARE_TEST(NotificationTrayTest, ManuallyCloseMessageCenter);
}  // namespace message_center

// This class extends NotificationUIManager and delegates actual display
// of notifications to MessageCenter, doing necessary conversions. This is only
// used on platforms that support non-native notifications.
class NotificationUIManagerImpl : public NotificationUIManager,
                                  public message_center::MessageCenterObserver,
                                  public ProfileObserver {
 public:
  NotificationUIManagerImpl();
  NotificationUIManagerImpl(const NotificationUIManagerImpl&) = delete;
  NotificationUIManagerImpl& operator=(const NotificationUIManagerImpl&) =
      delete;
  ~NotificationUIManagerImpl() override;

  // NotificationUIManager
  void Add(const message_center::Notification& notification,
           Profile* profile) override;
  bool Update(const message_center::Notification& notification,
              Profile* profile) override;
  const message_center::Notification* FindById(
      const std::string& delegate_id,
      ProfileNotification::ProfileID profile_id) const override;
  bool CancelById(const std::string& delegate_id,
                  ProfileNotification::ProfileID profile_id) override;
  std::set<std::string> GetAllIdsByProfile(
      ProfileNotification::ProfileID profile_id) override;
  std::set<std::string> GetAllIdsByProfileAndOrigin(
      ProfileNotification::ProfileID profile_id,
      const GURL& origin) override;
  bool CancelAllBySourceOrigin(const GURL& source_origin) override;
  void CancelAll() override;
  void StartShutdown() override;

  // MessageCenterObserver:
  void OnNotificationRemoved(const std::string& notification_id,
                             bool by_user) override;

  // ProfileObserver:
  void OnProfileWillBeDestroyed(Profile* profile) override;

  // Resets the ui controller.
  void ResetUiControllerForTest();

  // Returns the notification id which this manager will use to add to message
  // center, for this combination of delegate id and profile.
  std::string GetMessageCenterNotificationIdForTest(
      const std::string& delegate_id,
      Profile* profile);

  // Returns true if the popup bubbles are currently visible.
  bool popups_visible() const { return popups_visible_; }

 private:
  FRIEND_TEST_ALL_PREFIXES(message_center::NotificationTrayTest,
                           ManuallyCloseMessageCenter);

  // Use a map by notification_id since this mapping is the most often used.
  std::map<std::string, std::unique_ptr<ProfileNotification>>
      profile_notifications_;

  // Helpers that add/remove the notification from local map.
  // The local map takes ownership of profile_notification object.
  void AddProfileNotification(
      std::unique_ptr<ProfileNotification> profile_notification);
  void RemoveProfileNotification(const std::string& notification_id);

  // Returns the ProfileNotification for the |id|, or NULL if no such
  // notification is found.
  ProfileNotification* FindProfileNotification(const std::string& id) const;

  // To own the blockers.
  std::vector<std::unique_ptr<message_center::NotificationBlocker>> blockers_;

  NotificationSystemObserver system_observer_;

  base::ScopedMultiSourceObservation<Profile, ProfileObserver>
      observed_otr_profiles_{this};

  // Delegate of this class.
  std::unique_ptr<PopupsOnlyUiController> popups_only_ui_controller_;

  // Tracks if shutdown has started.
  bool is_shutdown_started_ = false;

  // Tracks the current visibility status of the popup bubbles.
  bool popups_visible_ = false;
};

#endif  // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_IMPL_H_