OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 UI_MESSAGE_CENTER_NOTIFICATION_H_ | 5 #ifndef UI_MESSAGE_CENTER_NOTIFICATION_H_ |
6 #define UI_MESSAGE_CENTER_NOTIFICATION_H_ | 6 #define UI_MESSAGE_CENTER_NOTIFICATION_H_ |
7 | 7 |
| 8 #include <string> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/string16.h" | 11 #include "base/string16.h" |
11 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "base/values.h" |
12 #include "ui/gfx/image/image_skia.h" | 14 #include "ui/gfx/image/image_skia.h" |
13 #include "ui/message_center/message_center_export.h" | 15 #include "ui/message_center/message_center_export.h" |
14 #include "ui/notifications/notification_types.h" | 16 #include "ui/message_center/notification_types.h" |
15 | 17 |
16 namespace message_center { | 18 namespace message_center { |
17 | 19 |
18 struct MESSAGE_CENTER_EXPORT NotificationItem { | 20 struct MESSAGE_CENTER_EXPORT NotificationItem { |
19 string16 title; | 21 string16 title; |
20 string16 message; | 22 string16 message; |
21 | 23 |
22 NotificationItem(string16 title, string16 message); | 24 NotificationItem(const string16& title, const string16& message); |
23 }; | 25 }; |
24 | 26 |
25 struct MESSAGE_CENTER_EXPORT Notification { | 27 struct MESSAGE_CENTER_EXPORT ButtonInfo { |
26 Notification(); | 28 string16 title; |
| 29 gfx::ImageSkia icon; |
| 30 |
| 31 ButtonInfo(const string16& title); |
| 32 }; |
| 33 |
| 34 class MESSAGE_CENTER_EXPORT Notification { |
| 35 public: |
| 36 Notification(NotificationType type, |
| 37 const std::string& id, |
| 38 const string16& title, |
| 39 const string16& message, |
| 40 const string16& display_source, |
| 41 const std::string& extension_id, |
| 42 const DictionaryValue* optional_fields); // May be NULL. |
27 virtual ~Notification(); | 43 virtual ~Notification(); |
28 | 44 |
29 ui::notifications::NotificationType type; | 45 // Determines the general order of Notifications in system UI. |
30 std::string id; | 46 bool Notification::operator<(const Notification& other); |
31 string16 title; | |
32 string16 message; | |
33 string16 display_source; | |
34 std::string extension_id; | |
35 | 47 |
36 // Begin unpacked values from optional_fields | 48 NotificationType type() const { return type_; } |
37 int priority; | 49 const std::string& id() const { return id_; } |
38 base::Time timestamp; | 50 const string16& title() const { return title_; } |
39 int unread_count; | 51 const string16& message() const { return message_; } |
40 std::vector<string16> button_titles; | 52 const string16& display_source() const { return display_source_; } |
41 string16 expanded_message; | 53 const std::string& extension_id() const { return extension_id_; } |
42 std::vector<NotificationItem> items; | |
43 // End unpacked values | |
44 | 54 |
45 // Images fetched asynchronously | 55 // Begin unpacked values from optional_fields. |
46 gfx::ImageSkia primary_icon; | 56 int priority() { return priority_; } |
47 gfx::ImageSkia image; | 57 base::Time timestamp() const { return timestamp_; } |
48 std::vector<gfx::ImageSkia> button_icons; | 58 int unread_count() const { return unread_count_; } |
| 59 const string16& expanded_message() const { return expanded_message_; } |
| 60 const std::vector<NotificationItem>& items() const { return items_; } |
| 61 // End unpacked values. |
49 | 62 |
50 bool is_read; // True if this has been seen in the message center | 63 // Images fetched asynchronously. |
51 bool shown_as_popup; // True if this has been shown as a popup notification | 64 const gfx::ImageSkia& primary_icon() const { return primary_icon_; } |
| 65 void set_primary_icon(const gfx::ImageSkia& icon) { primary_icon_ = icon; } |
| 66 |
| 67 const gfx::ImageSkia& image() const { return image_; } |
| 68 void set_image(const gfx::ImageSkia& image) { image_ = image; } |
| 69 |
| 70 // Buttons, with icons fetched asynchronously. |
| 71 const std::vector<ButtonInfo>& buttons() const { return buttons_; } |
| 72 bool SetButtonIcon(size_t index, const gfx::ImageSkia& icon); |
| 73 |
| 74 // Status in MessageCenter. |
| 75 bool is_read() const { return is_read_; } |
| 76 void set_is_read(bool is_read) { is_read_ = is_read; } |
| 77 |
| 78 bool shown_as_popup() const { return shown_as_popup_; } |
| 79 void set_shown_as_popup(bool shown_as_popup) { |
| 80 shown_as_popup_ = shown_as_popup; |
| 81 } |
| 82 |
| 83 // Used to keep the order of notifications with the same timestamp. |
| 84 // The notification with lesser serial_number is considered 'older'. |
| 85 // Wrap up is not a concern since it only may affect visual sorting and it's |
| 86 // very unlikely to have 4 Billion of notifications shown between reboots. |
| 87 unsigned serial_number() { return serial_number_; } |
| 88 |
| 89 private: |
| 90 // Unpacks the provided |optional_fields| and applies the values to override |
| 91 // the notification's data members. |
| 92 void ApplyOptionalFields(const DictionaryValue* optional_fields); |
| 93 |
| 94 NotificationType type_; |
| 95 std::string id_; |
| 96 string16 title_; |
| 97 string16 message_; |
| 98 string16 display_source_; |
| 99 std::string extension_id_; |
| 100 int priority_; |
| 101 base::Time timestamp_; |
| 102 unsigned serial_number_; |
| 103 int unread_count_; |
| 104 string16 expanded_message_; |
| 105 std::vector<NotificationItem> items_; |
| 106 gfx::ImageSkia primary_icon_; |
| 107 gfx::ImageSkia image_; |
| 108 std::vector<ButtonInfo> buttons_; |
| 109 bool is_read_; // True if this has been seen in the message center. |
| 110 bool shown_as_popup_; // True if this has been shown as a popup notification. |
| 111 |
| 112 static unsigned s_next_serial_number_; |
| 113 |
| 114 DISALLOW_COPY_AND_ASSIGN(Notification); |
52 }; | 115 }; |
53 | 116 |
54 } // namespace message_center | 117 } // namespace message_center |
55 | 118 |
56 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_ | 119 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_ |
OLD | NEW |