ChildAccountService[Java] delegates everything to native side.
[chromium-blink-merge.git] / ui / message_center / notification.cc
blobaf35e57c3313e40ca3504832773597d883c7926e
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 context_message(base::string16()),
32 progress(0),
33 should_make_spoken_feedback_for_popup_updates(true),
34 clickable(true),
35 silent(false) {}
37 RichNotificationData::RichNotificationData(const RichNotificationData& other)
38 : priority(other.priority),
39 never_timeout(other.never_timeout),
40 timestamp(other.timestamp),
41 context_message(other.context_message),
42 image(other.image),
43 small_image(other.small_image),
44 items(other.items),
45 progress(other.progress),
46 buttons(other.buttons),
47 should_make_spoken_feedback_for_popup_updates(
48 other.should_make_spoken_feedback_for_popup_updates),
49 clickable(other.clickable),
50 vibration_pattern(other.vibration_pattern),
51 silent(other.silent) {}
53 RichNotificationData::~RichNotificationData() {}
55 Notification::Notification(NotificationType type,
56 const std::string& id,
57 const base::string16& title,
58 const base::string16& message,
59 const gfx::Image& icon,
60 const base::string16& display_source,
61 const GURL& origin_url,
62 const NotifierId& notifier_id,
63 const RichNotificationData& optional_fields,
64 NotificationDelegate* delegate)
65 : type_(type),
66 id_(id),
67 title_(title),
68 message_(message),
69 icon_(icon),
70 adjust_icon_(true),
71 display_source_(display_source),
72 origin_url_(origin_url),
73 notifier_id_(notifier_id),
74 serial_number_(g_next_serial_number_++),
75 optional_fields_(optional_fields),
76 shown_as_popup_(false),
77 is_read_(false),
78 delegate_(delegate) {}
80 Notification::Notification(const std::string& id, const Notification& other)
81 : type_(other.type_),
82 id_(id),
83 title_(other.title_),
84 message_(other.message_),
85 icon_(other.icon_),
86 adjust_icon_(other.adjust_icon_),
87 display_source_(other.display_source_),
88 origin_url_(other.origin_url_),
89 notifier_id_(other.notifier_id_),
90 serial_number_(other.serial_number_),
91 optional_fields_(other.optional_fields_),
92 shown_as_popup_(other.shown_as_popup_),
93 is_read_(other.is_read_),
94 delegate_(other.delegate_) {}
96 Notification::Notification(const Notification& other)
97 : type_(other.type_),
98 id_(other.id_),
99 title_(other.title_),
100 message_(other.message_),
101 icon_(other.icon_),
102 adjust_icon_(other.adjust_icon_),
103 display_source_(other.display_source_),
104 origin_url_(other.origin_url_),
105 notifier_id_(other.notifier_id_),
106 serial_number_(other.serial_number_),
107 optional_fields_(other.optional_fields_),
108 shown_as_popup_(other.shown_as_popup_),
109 is_read_(other.is_read_),
110 delegate_(other.delegate_) {}
112 Notification& Notification::operator=(const Notification& other) {
113 type_ = other.type_;
114 id_ = other.id_;
115 title_ = other.title_;
116 message_ = other.message_;
117 icon_ = other.icon_;
118 adjust_icon_ = other.adjust_icon_;
119 display_source_ = other.display_source_;
120 origin_url_ = other.origin_url_;
121 notifier_id_ = other.notifier_id_;
122 serial_number_ = other.serial_number_;
123 optional_fields_ = other.optional_fields_;
124 shown_as_popup_ = other.shown_as_popup_;
125 is_read_ = other.is_read_;
126 delegate_ = other.delegate_;
128 return *this;
131 Notification::~Notification() {}
133 bool Notification::IsRead() const {
134 return is_read_ || optional_fields_.priority == MIN_PRIORITY;
137 void Notification::CopyState(Notification* base) {
138 shown_as_popup_ = base->shown_as_popup();
139 is_read_ = base->is_read_;
140 if (!delegate_.get())
141 delegate_ = base->delegate();
142 optional_fields_.never_timeout = base->never_timeout();
145 void Notification::SetButtonIcon(size_t index, const gfx::Image& icon) {
146 if (index >= optional_fields_.buttons.size())
147 return;
148 optional_fields_.buttons[index].icon = icon;
151 void Notification::SetSystemPriority() {
152 optional_fields_.priority = SYSTEM_PRIORITY;
153 optional_fields_.never_timeout = true;
156 bool Notification::UseOriginAsContextMessage() const {
157 return optional_fields_.context_message.empty() && origin_url_.is_valid() &&
158 origin_url_.SchemeIsHTTPOrHTTPS();
161 // static
162 scoped_ptr<Notification> Notification::CreateSystemNotification(
163 const std::string& notification_id,
164 const base::string16& title,
165 const base::string16& message,
166 const gfx::Image& icon,
167 const std::string& system_component_id,
168 const base::Closure& click_callback) {
169 scoped_ptr<Notification> notification(new Notification(
170 NOTIFICATION_TYPE_SIMPLE, notification_id, title, message, icon,
171 base::string16() /* display_source */, GURL(),
172 NotifierId(NotifierId::SYSTEM_COMPONENT, system_component_id),
173 RichNotificationData(),
174 new HandleNotificationClickedDelegate(click_callback)));
175 notification->SetSystemPriority();
176 return notification.Pass();
179 } // namespace message_center