Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(551)

Unified Diff: ui/message_center/notification.cc

Issue 14631005: Enable users of NotificationUIManager to specify binary images. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove fake image from synced notification, stop checking icon_url in unit test. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/message_center/notification.cc
diff --git a/ui/message_center/notification.cc b/ui/message_center/notification.cc
index c4db2d50b17585d63211e2f7fa7c1776c4b405cf..05e6651da2b78b3523f023cbec24fa8b5a267889 100644
--- a/ui/message_center/notification.cc
+++ b/ui/message_center/notification.cc
@@ -23,10 +23,28 @@ ButtonInfo::ButtonInfo(const string16& title)
: title(title) {
}
+RichNotificationData::RichNotificationData()
+ : priority(DEFAULT_PRIORITY),
+ never_timeout(false),
+ timestamp(base::Time::Now()) {}
+
+RichNotificationData::RichNotificationData(const RichNotificationData& other)
+ : priority(other.priority),
+ never_timeout(other.never_timeout),
+ timestamp(other.timestamp),
+ expanded_message(other.expanded_message),
+ icon(other.icon),
+ image(other.image),
+ items(other.items),
+ buttons(other.buttons) {}
+
+RichNotificationData::~RichNotificationData() {}
+
Notification::Notification(NotificationType type,
const std::string& id,
const string16& title,
const string16& message,
+ const gfx::Image& icon,
const string16& display_source,
const std::string& extension_id,
const DictionaryValue* optional_fields,
@@ -37,46 +55,59 @@ Notification::Notification(NotificationType type,
message_(message),
display_source_(display_source),
extension_id_(extension_id),
- priority_(DEFAULT_PRIORITY),
- timestamp_(base::Time::Now()),
serial_number_(g_next_serial_number_++),
shown_as_popup_(false),
is_read_(false),
is_expanded_(false),
- never_timeout_(false),
delegate_(delegate) {
- // This can override some data members initialized to deafule values above.
+ // This can override some data members initialized to default values above.
+ optional_fields_.icon = icon;
ApplyOptionalFields(optional_fields);
}
-Notification::~Notification() {
-}
+Notification::Notification(NotificationType type,
+ const std::string& id,
+ const string16& title,
+ const string16& message,
+ const string16& display_source,
+ const std::string& extension_id,
+ const RichNotificationData& optional_fields,
+ NotificationDelegate* delegate)
+ : type_(type),
+ id_(id),
+ title_(title),
+ message_(message),
+ display_source_(display_source),
+ extension_id_(extension_id),
+ optional_fields_(optional_fields),
+ delegate_(delegate) {}
+
+Notification::~Notification() {}
void Notification::CopyState(Notification* base) {
shown_as_popup_ = base->shown_as_popup();
is_read_ = base->is_read();
is_expanded_ = base->is_expanded();
- never_timeout_ = base->never_timeout();
if (!delegate_.get())
delegate_ = base->delegate();
+ optional_fields_.never_timeout = base->never_timeout();
}
-bool Notification::SetButtonIcon(size_t index, const gfx::Image& icon) {
- if (index >= buttons_.size())
- return false;
- buttons_[index].icon = icon;
- return true;
+void Notification::SetButtonIcon(size_t index, const gfx::Image& icon) {
+ if (index >= optional_fields_.buttons.size())
+ return;
+ optional_fields_.buttons[index].icon = icon;
}
void Notification::ApplyOptionalFields(const DictionaryValue* fields) {
if (!fields)
return;
- fields->GetInteger(kPriorityKey, &priority_);
+ fields->GetInteger(kPriorityKey, &optional_fields_.priority);
if (fields->HasKey(kTimestampKey)) {
std::string time_string;
fields->GetString(kTimestampKey, &time_string);
- base::Time::FromString(time_string.c_str(), &timestamp_);
+ base::Time::FromString(time_string.c_str(), &optional_fields_.timestamp);
}
if (fields->HasKey(kButtonOneTitleKey) ||
fields->HasKey(kButtonOneIconUrlKey)) {
@@ -84,14 +115,14 @@ void Notification::ApplyOptionalFields(const DictionaryValue* fields) {
string16 icon;
if (fields->GetString(kButtonOneTitleKey, &title) ||
fields->GetString(kButtonOneIconUrlKey, &icon)) {
- buttons_.push_back(ButtonInfo(title));
+ optional_fields_.buttons.push_back(ButtonInfo(title));
if (fields->GetString(kButtonTwoTitleKey, &title) ||
fields->GetString(kButtonTwoIconUrlKey, &icon)) {
- buttons_.push_back(ButtonInfo(title));
+ optional_fields_.buttons.push_back(ButtonInfo(title));
}
}
}
- fields->GetString(kExpandedMessageKey, &expanded_message_);
+ fields->GetString(kExpandedMessageKey, &optional_fields_.expanded_message);
if (fields->HasKey(kItemsKey)) {
const ListValue* items;
CHECK(fields->GetList(kItemsKey, &items));
@@ -102,11 +133,11 @@ void Notification::ApplyOptionalFields(const DictionaryValue* fields) {
items->GetDictionary(i, &item);
item->GetString(kItemTitleKey, &title);
item->GetString(kItemMessageKey, &message);
- items_.push_back(NotificationItem(title, message));
+ optional_fields_.items.push_back(NotificationItem(title, message));
}
}
- fields->GetBoolean(kPrivateNeverTimeoutKey, &never_timeout_);
+ fields->GetBoolean(kPrivateNeverTimeoutKey, &optional_fields_.never_timeout);
}
} // namespace message_center

Powered by Google App Engine
This is Rietveld 408576698