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

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: Rebase for relanding. Created 7 years, 6 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
« no previous file with comments | « ui/message_center/notification.h ('k') | ui/message_center/notification_list.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/message_center/notification.cc
diff --git a/ui/message_center/notification.cc b/ui/message_center/notification.cc
index c4db2d50b17585d63211e2f7fa7c1776c4b405cf..43e3de751daad4e80a94a651f5cc2e73f3aed709 100644
--- a/ui/message_center/notification.cc
+++ b/ui/message_center/notification.cc
@@ -23,10 +23,27 @@ 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),
+ 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,
@@ -35,48 +52,97 @@ Notification::Notification(NotificationType type,
id_(id),
title_(title),
message_(message),
+ icon_(icon),
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.
ApplyOptionalFields(optional_fields);
}
-Notification::~Notification() {
+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 RichNotificationData& optional_fields,
+ NotificationDelegate* delegate)
+ : type_(type),
+ id_(id),
+ title_(title),
+ message_(message),
+ icon_(icon),
+ display_source_(display_source),
+ extension_id_(extension_id),
+ serial_number_(g_next_serial_number_++),
+ optional_fields_(optional_fields),
+ delegate_(delegate) {}
+
+Notification::Notification(const Notification& other)
+ : type_(other.type_),
+ id_(other.id_),
+ title_(other.title_),
+ message_(other.message_),
+ icon_(other.icon_),
+ display_source_(other.display_source_),
+ extension_id_(other.extension_id_),
+ serial_number_(other.serial_number_),
+ optional_fields_(other.optional_fields_),
+ shown_as_popup_(other.shown_as_popup_),
+ is_read_(other.is_read_),
+ is_expanded_(other.is_expanded_),
+ delegate_(other.delegate_) {}
+
+Notification& Notification::operator=(const Notification& other) {
+ type_ = other.type_;
+ id_ = other.id_;
+ title_ = other.title_;
+ message_ = other.message_;
+ icon_ = other.icon_;
+ display_source_ = other.display_source_;
+ extension_id_ = other.extension_id_;
+ serial_number_ = other.serial_number_;
+ optional_fields_ = other.optional_fields_;
+ shown_as_popup_ = other.shown_as_popup_;
+ is_read_ = other.is_read_;
+ is_expanded_ = other.is_expanded_;
+ delegate_ = other.delegate_;
+
+ return *this;
}
+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 +150,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 +168,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
« no previous file with comments | « ui/message_center/notification.h ('k') | ui/message_center/notification_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698