Chromium Code Reviews| Index: ui/message_center/notification.cc |
| diff --git a/ui/message_center/notification.cc b/ui/message_center/notification.cc |
| index c52cb95cc7ea6c3ada7bbecb2171cb30845fe4d5..623ca084090c4d79fc472be99b36b7fb742b41f7 100644 |
| --- a/ui/message_center/notification.cc |
| +++ b/ui/message_center/notification.cc |
| @@ -4,19 +4,96 @@ |
| #include "ui/message_center/notification.h" |
| +#include "base/logging.h" |
| +#include "ui/message_center/notification_types.h" |
| + |
| +namespace { |
| +unsigned g_serial_number = 0; |
|
dewittj
2013/02/20 23:47:54
Should this be a message center instance variable?
Dmitry Titov
2013/02/23 00:58:51
A notification can be created w/o having a Message
|
| +} |
| + |
| namespace message_center { |
| -NotificationItem::NotificationItem(string16 title, string16 message) |
| +NotificationItem::NotificationItem(const string16& title, |
| + const string16& message) |
| : title(title), |
| message(message) { |
| } |
| -Notification::Notification() |
| - : is_read(false), |
| - shown_as_popup(false) { |
| +ButtonInfo::ButtonInfo(const string16& title) |
| + : title(title) { |
| +} |
| + |
| +Notification::Notification(NotificationType type, |
| + const std::string& id, |
| + const string16& title, |
| + const string16& message, |
| + const string16& display_source, |
| + const std::string& extension_id, |
| + const DictionaryValue* optional_fields) |
| + : type_(type), |
| + id_(id), |
| + title_(title), |
| + message_(message), |
| + display_source_(display_source), |
| + extension_id_(extension_id), |
| + priority_(DEFAULT_PRIORITY), |
| + timestamp_(base::Time::Now()), |
| + serial_number_(g_serial_number++), |
| + unread_count_(0), |
| + is_read_(false), |
| + shown_as_popup_(false) { |
| + // This can override some data members initialized to deafule values above. |
| + ApplyOptionalFields(optional_fields); |
| } |
| Notification::~Notification() { |
| } |
| +bool Notification::SetButtonIcon(size_t index, const gfx::ImageSkia& icon) { |
| + if (index >= buttons_.size()) |
| + return false; |
| + buttons_[index].icon = icon; |
| + return true; |
| +} |
| + |
| +void Notification::ApplyOptionalFields(const DictionaryValue* fields) { |
| + if (!fields) |
| + return; |
| + |
| + fields->GetInteger(kPriorityKey, &priority_); |
| + if (fields->HasKey(kTimestampKey)) { |
| + std::string time_string; |
| + fields->GetString(kTimestampKey, &time_string); |
| + base::Time::FromString(time_string.c_str(), ×tamp_); |
| + } |
| + fields->GetInteger(kUnreadCountKey, &unread_count_); |
| + if (fields->HasKey(kButtonOneTitleKey) || |
| + fields->HasKey(kButtonOneIconUrlKey)) { |
| + string16 title; |
| + string16 icon; |
| + if (fields->GetString(kButtonOneTitleKey, &title) || |
| + fields->GetString(kButtonOneIconUrlKey, &icon)) { |
| + buttons_.push_back(ButtonInfo(title)); |
| + if (fields->GetString(kButtonTwoTitleKey, &title) || |
| + fields->GetString(kButtonTwoIconUrlKey, &icon)) { |
| + buttons_.push_back(ButtonInfo(title)); |
| + } |
| + } |
| + } |
| + fields->GetString(kExpandedMessageKey, &expanded_message_); |
| + if (fields->HasKey(kItemsKey)) { |
| + const ListValue* items; |
| + CHECK(fields->GetList(kItemsKey, &items)); |
| + for (size_t i = 0; i < items->GetSize(); ++i) { |
| + string16 title; |
| + string16 message; |
| + const base::DictionaryValue* item; |
| + items->GetDictionary(i, &item); |
| + item->GetString(kItemTitleKey, &title); |
| + item->GetString(kItemMessageKey, &message); |
| + items_.push_back(NotificationItem(title, message)); |
| + } |
| + } |
| +} |
| + |
| } // namespace message_center |