cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ui / message_center / notification.cc
blobaf5bc1f089ae1ea7aaf6d38ba5d9b0d80b3562d4
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 display_source_(display_source),
71 origin_url_(origin_url),
72 notifier_id_(notifier_id),
73 serial_number_(g_next_serial_number_++),
74 optional_fields_(optional_fields),
75 shown_as_popup_(false),
76 is_read_(false),
77 delegate_(delegate) {}
79 Notification::Notification(const std::string& id, const Notification& other)
80 : type_(other.type_),
81 id_(id),
82 title_(other.title_),
83 message_(other.message_),
84 icon_(other.icon_),
85 display_source_(other.display_source_),
86 origin_url_(other.origin_url_),
87 notifier_id_(other.notifier_id_),
88 serial_number_(other.serial_number_),
89 optional_fields_(other.optional_fields_),
90 shown_as_popup_(other.shown_as_popup_),
91 is_read_(other.is_read_),
92 delegate_(other.delegate_) {}
94 Notification::Notification(const Notification& other)
95 : type_(other.type_),
96 id_(other.id_),
97 title_(other.title_),
98 message_(other.message_),
99 icon_(other.icon_),
100 display_source_(other.display_source_),
101 origin_url_(other.origin_url_),
102 notifier_id_(other.notifier_id_),
103 serial_number_(other.serial_number_),
104 optional_fields_(other.optional_fields_),
105 shown_as_popup_(other.shown_as_popup_),
106 is_read_(other.is_read_),
107 delegate_(other.delegate_) {}
109 Notification& Notification::operator=(const Notification& other) {
110 type_ = other.type_;
111 id_ = other.id_;
112 title_ = other.title_;
113 message_ = other.message_;
114 icon_ = other.icon_;
115 display_source_ = other.display_source_;
116 origin_url_ = other.origin_url_;
117 notifier_id_ = other.notifier_id_;
118 serial_number_ = other.serial_number_;
119 optional_fields_ = other.optional_fields_;
120 shown_as_popup_ = other.shown_as_popup_;
121 is_read_ = other.is_read_;
122 delegate_ = other.delegate_;
124 return *this;
127 Notification::~Notification() {}
129 bool Notification::IsRead() const {
130 return is_read_ || optional_fields_.priority == MIN_PRIORITY;
133 void Notification::CopyState(Notification* base) {
134 shown_as_popup_ = base->shown_as_popup();
135 is_read_ = base->is_read_;
136 if (!delegate_.get())
137 delegate_ = base->delegate();
138 optional_fields_.never_timeout = base->never_timeout();
141 void Notification::SetButtonIcon(size_t index, const gfx::Image& icon) {
142 if (index >= optional_fields_.buttons.size())
143 return;
144 optional_fields_.buttons[index].icon = icon;
147 void Notification::SetSystemPriority() {
148 optional_fields_.priority = SYSTEM_PRIORITY;
149 optional_fields_.never_timeout = true;
152 bool Notification::UseOriginAsContextMessage() const {
153 return optional_fields_.context_message.empty() && origin_url_.is_valid() &&
154 origin_url_.SchemeIsHTTPOrHTTPS();
157 // static
158 scoped_ptr<Notification> Notification::CreateSystemNotification(
159 const std::string& notification_id,
160 const base::string16& title,
161 const base::string16& message,
162 const gfx::Image& icon,
163 const std::string& system_component_id,
164 const base::Closure& click_callback) {
165 scoped_ptr<Notification> notification(new Notification(
166 NOTIFICATION_TYPE_SIMPLE, notification_id, title, message, icon,
167 base::string16() /* display_source */, GURL(),
168 NotifierId(NotifierId::SYSTEM_COMPONENT, system_component_id),
169 RichNotificationData(),
170 new HandleNotificationClickedDelegate(click_callback)));
171 notification->SetSystemPriority();
172 return notification.Pass();
175 } // namespace message_center