Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / ui / message_center / notification.cc
blob605662083dd0c0ec3d81bb69eda73b5bbf92eb89
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"
11 namespace {
12 unsigned g_next_serial_number_ = 0;
15 namespace message_center {
17 NotificationItem::NotificationItem(const base::string16& title,
18 const base::string16& message)
19 : title(title),
20 message(message) {
23 ButtonInfo::ButtonInfo(const base::string16& title)
24 : title(title) {
27 RichNotificationData::RichNotificationData()
28 : priority(DEFAULT_PRIORITY),
29 never_timeout(false),
30 timestamp(base::Time::Now()),
31 progress(0),
32 should_make_spoken_feedback_for_popup_updates(true),
33 clickable(true),
34 silent(false) {}
36 RichNotificationData::RichNotificationData(const RichNotificationData& other)
37 : priority(other.priority),
38 never_timeout(other.never_timeout),
39 timestamp(other.timestamp),
40 context_message(other.context_message),
41 image(other.image),
42 small_image(other.small_image),
43 items(other.items),
44 progress(other.progress),
45 buttons(other.buttons),
46 should_make_spoken_feedback_for_popup_updates(
47 other.should_make_spoken_feedback_for_popup_updates),
48 clickable(other.clickable),
49 silent(other.silent) {}
51 RichNotificationData::~RichNotificationData() {}
53 Notification::Notification(NotificationType type,
54 const std::string& id,
55 const base::string16& title,
56 const base::string16& message,
57 const gfx::Image& icon,
58 const base::string16& display_source,
59 const NotifierId& notifier_id,
60 const RichNotificationData& optional_fields,
61 NotificationDelegate* delegate)
62 : type_(type),
63 id_(id),
64 title_(title),
65 message_(message),
66 icon_(icon),
67 display_source_(display_source),
68 notifier_id_(notifier_id),
69 serial_number_(g_next_serial_number_++),
70 optional_fields_(optional_fields),
71 shown_as_popup_(false),
72 is_read_(false),
73 delegate_(delegate) {}
75 Notification::Notification(const std::string& id, const Notification& other)
76 : type_(other.type_),
77 id_(id),
78 title_(other.title_),
79 message_(other.message_),
80 icon_(other.icon_),
81 display_source_(other.display_source_),
82 notifier_id_(other.notifier_id_),
83 serial_number_(other.serial_number_),
84 optional_fields_(other.optional_fields_),
85 shown_as_popup_(other.shown_as_popup_),
86 is_read_(other.is_read_),
87 delegate_(other.delegate_) {
90 Notification::Notification(const Notification& other)
91 : type_(other.type_),
92 id_(other.id_),
93 title_(other.title_),
94 message_(other.message_),
95 icon_(other.icon_),
96 display_source_(other.display_source_),
97 notifier_id_(other.notifier_id_),
98 serial_number_(other.serial_number_),
99 optional_fields_(other.optional_fields_),
100 shown_as_popup_(other.shown_as_popup_),
101 is_read_(other.is_read_),
102 delegate_(other.delegate_) {}
104 Notification& Notification::operator=(const Notification& other) {
105 type_ = other.type_;
106 id_ = other.id_;
107 title_ = other.title_;
108 message_ = other.message_;
109 icon_ = other.icon_;
110 display_source_ = other.display_source_;
111 notifier_id_ = other.notifier_id_;
112 serial_number_ = other.serial_number_;
113 optional_fields_ = other.optional_fields_;
114 shown_as_popup_ = other.shown_as_popup_;
115 is_read_ = other.is_read_;
116 delegate_ = other.delegate_;
118 return *this;
121 Notification::~Notification() {}
123 bool Notification::IsRead() const {
124 return is_read_ || optional_fields_.priority == MIN_PRIORITY;
127 void Notification::CopyState(Notification* base) {
128 shown_as_popup_ = base->shown_as_popup();
129 is_read_ = base->is_read_;
130 if (!delegate_.get())
131 delegate_ = base->delegate();
132 optional_fields_.never_timeout = base->never_timeout();
135 void Notification::SetButtonIcon(size_t index, const gfx::Image& icon) {
136 if (index >= optional_fields_.buttons.size())
137 return;
138 optional_fields_.buttons[index].icon = icon;
141 void Notification::SetSystemPriority() {
142 optional_fields_.priority = SYSTEM_PRIORITY;
143 optional_fields_.never_timeout = true;
146 // static
147 scoped_ptr<Notification> Notification::CreateSystemNotification(
148 const std::string& notification_id,
149 const base::string16& title,
150 const base::string16& message,
151 const gfx::Image& icon,
152 const std::string& system_component_id,
153 const base::Closure& click_callback) {
154 scoped_ptr<Notification> notification(
155 new Notification(
156 NOTIFICATION_TYPE_SIMPLE,
157 notification_id,
158 title,
159 message,
160 icon,
161 base::string16() /* display_source */,
162 NotifierId(NotifierId::SYSTEM_COMPONENT, system_component_id),
163 RichNotificationData(),
164 new HandleNotificationClickedDelegate(click_callback)));
165 notification->SetSystemPriority();
166 return notification.Pass();
169 } // namespace message_center