| Index: ui/message_center/notification.cc
|
| diff --git a/ui/message_center/notification.cc b/ui/message_center/notification.cc
|
| index c52cb95cc7ea6c3ada7bbecb2171cb30845fe4d5..5a92c094c3855288378ef386eab2f702f1e77606 100644
|
| --- a/ui/message_center/notification.cc
|
| +++ b/ui/message_center/notification.cc
|
| @@ -4,19 +4,94 @@
|
|
|
| #include "ui/message_center/notification.h"
|
|
|
| +#include "base/logging.h"
|
| +#include "ui/message_center/notification_types.h"
|
| +
|
| +namespace {
|
| +unsigned g_next_serial_number_ = 0;
|
| +}
|
| +
|
| 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_next_serial_number_++),
|
| + 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_);
|
| + }
|
| + 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
|
|
|