[Android] Add a java.lang.System wrapper.
[chromium-blink-merge.git] / ui / message_center / notification.cc
blob6633a014d76038ea6676174cd3379cff2a10b5f9
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 vibration_pattern(other.vibration_pattern),
50 silent(other.silent) {}
52 RichNotificationData::~RichNotificationData() {}
54 Notification::Notification(NotificationType type,
55 const std::string& id,
56 const base::string16& title,
57 const base::string16& message,
58 const gfx::Image& icon,
59 const base::string16& display_source,
60 const NotifierId& notifier_id,
61 const RichNotificationData& optional_fields,
62 NotificationDelegate* delegate)
63 : type_(type),
64 id_(id),
65 title_(title),
66 message_(message),
67 icon_(icon),
68 display_source_(display_source),
69 notifier_id_(notifier_id),
70 serial_number_(g_next_serial_number_++),
71 optional_fields_(optional_fields),
72 shown_as_popup_(false),
73 is_read_(false),
74 delegate_(delegate) {}
76 Notification::Notification(const std::string& id, const Notification& other)
77 : type_(other.type_),
78 id_(id),
79 title_(other.title_),
80 message_(other.message_),
81 icon_(other.icon_),
82 display_source_(other.display_source_),
83 notifier_id_(other.notifier_id_),
84 serial_number_(other.serial_number_),
85 optional_fields_(other.optional_fields_),
86 shown_as_popup_(other.shown_as_popup_),
87 is_read_(other.is_read_),
88 delegate_(other.delegate_) {
91 Notification::Notification(const Notification& other)
92 : type_(other.type_),
93 id_(other.id_),
94 title_(other.title_),
95 message_(other.message_),
96 icon_(other.icon_),
97 display_source_(other.display_source_),
98 notifier_id_(other.notifier_id_),
99 serial_number_(other.serial_number_),
100 optional_fields_(other.optional_fields_),
101 shown_as_popup_(other.shown_as_popup_),
102 is_read_(other.is_read_),
103 delegate_(other.delegate_) {}
105 Notification& Notification::operator=(const Notification& other) {
106 type_ = other.type_;
107 id_ = other.id_;
108 title_ = other.title_;
109 message_ = other.message_;
110 icon_ = other.icon_;
111 display_source_ = other.display_source_;
112 notifier_id_ = other.notifier_id_;
113 serial_number_ = other.serial_number_;
114 optional_fields_ = other.optional_fields_;
115 shown_as_popup_ = other.shown_as_popup_;
116 is_read_ = other.is_read_;
117 delegate_ = other.delegate_;
119 return *this;
122 Notification::~Notification() {}
124 bool Notification::IsRead() const {
125 return is_read_ || optional_fields_.priority == MIN_PRIORITY;
128 void Notification::CopyState(Notification* base) {
129 shown_as_popup_ = base->shown_as_popup();
130 is_read_ = base->is_read_;
131 if (!delegate_.get())
132 delegate_ = base->delegate();
133 optional_fields_.never_timeout = base->never_timeout();
136 void Notification::SetButtonIcon(size_t index, const gfx::Image& icon) {
137 if (index >= optional_fields_.buttons.size())
138 return;
139 optional_fields_.buttons[index].icon = icon;
142 void Notification::SetSystemPriority() {
143 optional_fields_.priority = SYSTEM_PRIORITY;
144 optional_fields_.never_timeout = true;
147 // static
148 scoped_ptr<Notification> Notification::CreateSystemNotification(
149 const std::string& notification_id,
150 const base::string16& title,
151 const base::string16& message,
152 const gfx::Image& icon,
153 const std::string& system_component_id,
154 const base::Closure& click_callback) {
155 scoped_ptr<Notification> notification(
156 new Notification(
157 NOTIFICATION_TYPE_SIMPLE,
158 notification_id,
159 title,
160 message,
161 icon,
162 base::string16() /* display_source */,
163 NotifierId(NotifierId::SYSTEM_COMPONENT, system_component_id),
164 RichNotificationData(),
165 new HandleNotificationClickedDelegate(click_callback)));
166 notification->SetSystemPriority();
167 return notification.Pass();
170 } // namespace message_center