| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_NOTIFICATIONS_PROFILE_NOTIFICATION_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_PROFILE_NOTIFICATION_H_ |
| 6 #define CHROME_BROWSER_NOTIFICATIONS_PROFILE_NOTIFICATION_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_PROFILE_NOTIFICATION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "chrome/browser/notifications/notification.h" | 10 #include "chrome/browser/notifications/notification.h" |
| 11 #include "chrome/browser/notifications/notification_ui_manager.h" | 11 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 12 #include "content/public/browser/notification_observer.h" |
| 13 #include "content/public/browser/notification_registrar.h" |
| 12 | 14 |
| 13 class ScopedKeepAlive; | 15 class ScopedKeepAlive; |
| 14 | 16 |
| 15 // This class keeps a Notification objects and its corresponding Profile, so | 17 // This class keeps a Notification objects and its corresponding Profile, so |
| 16 // that when the Notification UI manager needs to return or cancel all | 18 // that when the Notification UI manager needs to return or cancel all |
| 17 // notifications for a given Profile we have the ability to do this. | 19 // notifications for a given Profile we have the ability to do this. |
| 18 class ProfileNotification { | 20 class ProfileNotification : public content::NotificationObserver { |
| 19 public: | 21 public: |
| 20 // Returns a string that uniquely identifies a profile + delegate_id pair. | 22 // Returns a string that uniquely identifies a profile + delegate_id pair. |
| 21 // The profile_id is used as an identifier to identify a profile instance; it | 23 // The profile_id is used as an identifier to identify a profile instance; it |
| 22 // cannot be NULL. The ID becomes invalid when a profile is destroyed. | 24 // cannot be NULL. The ID becomes invalid when a profile is destroyed. |
| 23 static std::string GetProfileNotificationId(const std::string& delegate_id, | 25 static std::string GetProfileNotificationId(const std::string& delegate_id, |
| 24 ProfileID profile_id); | 26 ProfileID profile_id); |
| 25 | 27 |
| 26 ProfileNotification(Profile* profile, const Notification& notification); | 28 ProfileNotification(Profile* profile, const Notification& notification); |
| 27 ~ProfileNotification(); | 29 ~ProfileNotification() override; |
| 28 | 30 |
| 29 ProfileID profile_id() const { return profile_id_; } | 31 ProfileID profile_id() const { return profile_id_; } |
| 30 const Notification& notification() const { return notification_; } | 32 const Notification& notification() const { return notification_; } |
| 31 | 33 |
| 34 // content::NotificationObserver: |
| 35 void Observe(int type, |
| 36 const content::NotificationSource& source, |
| 37 const content::NotificationDetails& details) override; |
| 38 |
| 32 private: | 39 private: |
| 33 // Used for equality comparision in notification maps. | 40 // Used for equality comparision in notification maps. |
| 34 ProfileID profile_id_; | 41 ProfileID profile_id_; |
| 35 | 42 |
| 36 Notification notification_; | 43 Notification notification_; |
| 37 | 44 |
| 38 std::unique_ptr<ScopedKeepAlive> keep_alive_; | 45 std::unique_ptr<ScopedKeepAlive> keep_alive_; |
| 39 | 46 |
| 47 content::NotificationRegistrar registrar_; |
| 48 |
| 40 DISALLOW_COPY_AND_ASSIGN(ProfileNotification); | 49 DISALLOW_COPY_AND_ASSIGN(ProfileNotification); |
| 41 }; | 50 }; |
| 42 | 51 |
| 43 #endif // CHROME_BROWSER_NOTIFICATIONS_PROFILE_NOTIFICATION_H_ | 52 #endif // CHROME_BROWSER_NOTIFICATIONS_PROFILE_NOTIFICATION_H_ |
| OLD | NEW |