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 #include "ui/message_center/notification.h"
7 #include "base/logging.h"
8 #include "ui/message_center/notification_delegate.h"
9 #include "ui/message_center/notification_types.h"
12 unsigned g_next_serial_number_
= 0;
15 namespace message_center
{
17 NotificationItem::NotificationItem(const base::string16
& title
,
18 const base::string16
& message
)
23 ButtonInfo::ButtonInfo(const base::string16
& title
)
27 RichNotificationData::RichNotificationData()
28 : priority(DEFAULT_PRIORITY
),
30 timestamp(base::Time::Now()),
32 should_make_spoken_feedback_for_popup_updates(true),
35 RichNotificationData::RichNotificationData(const RichNotificationData
& other
)
36 : priority(other
.priority
),
37 never_timeout(other
.never_timeout
),
38 timestamp(other
.timestamp
),
39 context_message(other
.context_message
),
41 small_image(other
.small_image
),
43 progress(other
.progress
),
44 buttons(other
.buttons
),
45 should_make_spoken_feedback_for_popup_updates(
46 other
.should_make_spoken_feedback_for_popup_updates
),
47 clickable(other
.clickable
) {}
49 RichNotificationData::~RichNotificationData() {}
51 Notification::Notification(NotificationType type
,
52 const std::string
& id
,
53 const base::string16
& title
,
54 const base::string16
& message
,
55 const gfx::Image
& icon
,
56 const base::string16
& display_source
,
57 const NotifierId
& notifier_id
,
58 const RichNotificationData
& optional_fields
,
59 NotificationDelegate
* delegate
)
65 display_source_(display_source
),
66 notifier_id_(notifier_id
),
67 serial_number_(g_next_serial_number_
++),
68 optional_fields_(optional_fields
),
69 shown_as_popup_(false),
71 delegate_(delegate
) {}
73 Notification::Notification(const std::string
& id
, const Notification
& other
)
77 message_(other
.message_
),
79 display_source_(other
.display_source_
),
80 notifier_id_(other
.notifier_id_
),
81 serial_number_(other
.serial_number_
),
82 optional_fields_(other
.optional_fields_
),
83 shown_as_popup_(other
.shown_as_popup_
),
84 is_read_(other
.is_read_
),
85 delegate_(other
.delegate_
) {
88 Notification::Notification(const Notification
& other
)
92 message_(other
.message_
),
94 display_source_(other
.display_source_
),
95 notifier_id_(other
.notifier_id_
),
96 serial_number_(other
.serial_number_
),
97 optional_fields_(other
.optional_fields_
),
98 shown_as_popup_(other
.shown_as_popup_
),
99 is_read_(other
.is_read_
),
100 delegate_(other
.delegate_
) {}
102 Notification
& Notification::operator=(const Notification
& other
) {
105 title_
= other
.title_
;
106 message_
= other
.message_
;
108 display_source_
= other
.display_source_
;
109 notifier_id_
= other
.notifier_id_
;
110 serial_number_
= other
.serial_number_
;
111 optional_fields_
= other
.optional_fields_
;
112 shown_as_popup_
= other
.shown_as_popup_
;
113 is_read_
= other
.is_read_
;
114 delegate_
= other
.delegate_
;
119 Notification::~Notification() {}
121 bool Notification::IsRead() const {
122 return is_read_
|| optional_fields_
.priority
== MIN_PRIORITY
;
125 void Notification::CopyState(Notification
* base
) {
126 shown_as_popup_
= base
->shown_as_popup();
127 is_read_
= base
->is_read_
;
128 if (!delegate_
.get())
129 delegate_
= base
->delegate();
130 optional_fields_
.never_timeout
= base
->never_timeout();
133 void Notification::SetButtonIcon(size_t index
, const gfx::Image
& icon
) {
134 if (index
>= optional_fields_
.buttons
.size())
136 optional_fields_
.buttons
[index
].icon
= icon
;
139 void Notification::SetSystemPriority() {
140 optional_fields_
.priority
= SYSTEM_PRIORITY
;
141 optional_fields_
.never_timeout
= true;
145 scoped_ptr
<Notification
> Notification::CreateSystemNotification(
146 const std::string
& notification_id
,
147 const base::string16
& title
,
148 const base::string16
& message
,
149 const gfx::Image
& icon
,
150 const std::string
& system_component_id
,
151 const base::Closure
& click_callback
) {
152 scoped_ptr
<Notification
> notification(
154 NOTIFICATION_TYPE_SIMPLE
,
159 base::string16() /* display_source */,
160 NotifierId(NotifierId::SYSTEM_COMPONENT
, system_component_id
),
161 RichNotificationData(),
162 new HandleNotificationClickedDelegate(click_callback
)));
163 notification
->SetSystemPriority();
164 return notification
.Pass();
167 } // namespace message_center