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
3 // found in the LICENSE file.
5 #ifndef UI_MESSAGE_CENTER_NOTIFICATION_H_
6 #define UI_MESSAGE_CENTER_NOTIFICATION_H_
11 #include "base/string16.h"
12 #include "base/time.h"
13 #include "base/values.h"
14 #include "ui/gfx/image/image.h"
15 #include "ui/message_center/message_center_export.h"
16 #include "ui/message_center/notification_types.h"
18 namespace message_center
{
20 struct MESSAGE_CENTER_EXPORT NotificationItem
{
24 NotificationItem(const string16
& title
, const string16
& message
);
27 struct MESSAGE_CENTER_EXPORT ButtonInfo
{
31 ButtonInfo(const string16
& title
);
34 class MESSAGE_CENTER_EXPORT Notification
{
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.
43 virtual ~Notification();
45 NotificationType
type() const { return type_
; }
46 const std::string
& id() const { return id_
; }
47 const string16
& title() const { return title_
; }
48 const string16
& message() const { return message_
; }
49 const string16
& display_source() const { return display_source_
; }
50 const std::string
& extension_id() const { return extension_id_
; }
52 // Begin unpacked values from optional_fields.
53 int priority() const { return priority_
; }
54 base::Time
timestamp() const { return timestamp_
; }
55 const string16
& expanded_message() const { return expanded_message_
; }
56 const std::vector
<NotificationItem
>& items() const { return items_
; }
57 // End unpacked values.
59 // Images fetched asynchronously.
60 const gfx::Image
& icon() const { return icon_
; }
61 void set_icon(const gfx::Image
& icon
) { icon_
= icon
; }
63 const gfx::Image
& image() const { return image_
; }
64 void set_image(const gfx::Image
& image
) { image_
= image
; }
66 // Buttons, with icons fetched asynchronously.
67 const std::vector
<ButtonInfo
>& buttons() const { return buttons_
; }
68 bool SetButtonIcon(size_t index
, const gfx::Image
& icon
);
70 bool shown_as_popup() const { return shown_as_popup_
; }
71 void set_shown_as_popup(bool shown_as_popup
) {
72 shown_as_popup_
= shown_as_popup
;
75 // Read status in the message center.
76 bool is_read() const { return is_read_
; }
77 void set_is_read(bool read
) { is_read_
= read
; }
79 // Expanded status in the message center (not the popups).
80 bool is_expanded() const { return is_expanded_
; }
81 void set_is_expanded(bool expanded
) { is_expanded_
= expanded
; }
83 // Used to keep the order of notifications with the same timestamp.
84 // The notification with lesser serial_number is considered 'older'.
85 unsigned serial_number() { return serial_number_
; }
87 bool never_timeout() const { return never_timeout_
; }
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
);
94 NotificationType type_
;
98 string16 display_source_
;
99 std::string extension_id_
;
101 base::Time timestamp_
;
102 unsigned serial_number_
;
103 string16 expanded_message_
;
104 std::vector
<NotificationItem
> items_
;
107 std::vector
<ButtonInfo
> buttons_
;
108 bool shown_as_popup_
; // True if this has been shown as a popup.
109 bool is_read_
; // True if this has been seen in the message center.
110 bool is_expanded_
; // True if this has been expanded in the message center.
111 bool never_timeout_
; // True if it doesn't timeout when it appears as a toast.
113 DISALLOW_COPY_AND_ASSIGN(Notification
);
116 } // namespace message_center
118 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_