Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: ui/message_center/notification.h

Issue 12277024: Notificaitons refactor step 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed latest nits Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 NotificationType type() const { return type_; }
30 std::string id; 46 const std::string& id() const { return id_; }
31 string16 title; 47 const string16& title() const { return title_; }
32 string16 message; 48 const string16& message() const { return message_; }
33 string16 display_source; 49 const string16& display_source() const { return display_source_; }
34 std::string extension_id; 50 const std::string& extension_id() const { return extension_id_; }
35 51
36 // Begin unpacked values from optional_fields 52 // Begin unpacked values from optional_fields.
37 int priority; 53 int priority() { return priority_; }
38 base::Time timestamp; 54 base::Time timestamp() const { return timestamp_; }
39 int unread_count; 55 int unread_count() const { return unread_count_; }
40 std::vector<string16> button_titles; 56 const string16& expanded_message() const { return expanded_message_; }
41 string16 expanded_message; 57 const std::vector<NotificationItem>& items() const { return items_; }
42 std::vector<NotificationItem> items; 58 // End unpacked values.
43 // End unpacked values
44 59
45 // Images fetched asynchronously 60 // Images fetched asynchronously.
46 gfx::ImageSkia primary_icon; 61 const gfx::ImageSkia& primary_icon() const { return primary_icon_; }
47 gfx::ImageSkia image; 62 void set_primary_icon(const gfx::ImageSkia& icon) { primary_icon_ = icon; }
48 std::vector<gfx::ImageSkia> button_icons;
49 63
50 bool is_read; // True if this has been seen in the message center 64 const gfx::ImageSkia& image() const { return image_; }
51 bool shown_as_popup; // True if this has been shown as a popup notification 65 void set_image(const gfx::ImageSkia& image) { image_ = image; }
66
67 // Buttons, with icons fetched asynchronously.
68 const std::vector<ButtonInfo>& buttons() const { return buttons_; }
69 bool SetButtonIcon(size_t index, const gfx::ImageSkia& icon);
70
71 // Status in MessageCenter.
72 bool is_read() const { return is_read_; }
73 void set_is_read(bool is_read) { is_read_ = is_read; }
74
75 bool shown_as_popup() const { return shown_as_popup_; }
76 void set_shown_as_popup(bool shown_as_popup) {
77 shown_as_popup_ = shown_as_popup;
78 }
79
80 // Used to keep the order of notifications with the same timestamp.
81 // The notification with lesser serial_number is considered 'older'.
82 // Wrap up is not a concern since it only may affect visual sorting and it's
83 // very unlikely to have 4 Billion of notifications shown between reboots.
stevenjb 2013/02/25 18:11:08 nit: last two lines should be well understood and
Dmitry Titov 2013/02/25 23:21:15 Updated comment. We discussed sorting last week w
84 unsigned serial_number() { return serial_number_; }
85
86 private:
87 // Unpacks the provided |optional_fields| and applies the values to override
88 // the notification's data members.
89 void ApplyOptionalFields(const DictionaryValue* optional_fields);
90
91 NotificationType type_;
92 std::string id_;
93 string16 title_;
94 string16 message_;
95 string16 display_source_;
96 std::string extension_id_;
97 int priority_;
98 base::Time timestamp_;
99 unsigned serial_number_;
100 int unread_count_;
101 string16 expanded_message_;
102 std::vector<NotificationItem> items_;
103 gfx::ImageSkia primary_icon_;
104 gfx::ImageSkia image_;
105 std::vector<ButtonInfo> buttons_;
106 bool is_read_; // True if this has been seen in the message center.
107 bool shown_as_popup_; // True if this has been shown as a popup notification.
108
109 static unsigned s_next_serial_number_;
stevenjb 2013/02/25 18:11:08 nit: make this file local instead of exposing it h
Dmitry Titov 2013/02/25 23:21:15 Done.
110
111 DISALLOW_COPY_AND_ASSIGN(Notification);
52 }; 112 };
53 113
54 } // namespace message_center 114 } // namespace message_center
55 115
56 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_ 116 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698