OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/message_center/notification.h" | 5 #include "ui/message_center/notification.h" |
6 | 6 |
| 7 #include "base/logging.h" |
| 8 #include "ui/message_center/notification_types.h" |
| 9 |
7 namespace message_center { | 10 namespace message_center { |
8 | 11 |
9 NotificationItem::NotificationItem(string16 title, string16 message) | 12 unsigned Notification::s_next_serial_number_ = 0; |
| 13 |
| 14 NotificationItem::NotificationItem(const string16& title, |
| 15 const string16& message) |
10 : title(title), | 16 : title(title), |
11 message(message) { | 17 message(message) { |
12 } | 18 } |
13 | 19 |
14 Notification::Notification() | 20 ButtonInfo::ButtonInfo(const string16& title) |
15 : is_read(false), | 21 : title(title) { |
16 shown_as_popup(false) { | 22 } |
| 23 |
| 24 Notification::Notification(NotificationType type, |
| 25 const std::string& id, |
| 26 const string16& title, |
| 27 const string16& message, |
| 28 const string16& display_source, |
| 29 const std::string& extension_id, |
| 30 const DictionaryValue* optional_fields) |
| 31 : type_(type), |
| 32 id_(id), |
| 33 title_(title), |
| 34 message_(message), |
| 35 display_source_(display_source), |
| 36 extension_id_(extension_id), |
| 37 priority_(DEFAULT_PRIORITY), |
| 38 timestamp_(base::Time::Now()), |
| 39 serial_number_(s_next_serial_number_++), |
| 40 unread_count_(0), |
| 41 is_read_(false), |
| 42 shown_as_popup_(false) { |
| 43 // This can override some data members initialized to deafule values above. |
| 44 ApplyOptionalFields(optional_fields); |
17 } | 45 } |
18 | 46 |
19 Notification::~Notification() { | 47 Notification::~Notification() { |
20 } | 48 } |
21 | 49 |
| 50 bool Notification::SetButtonIcon(size_t index, const gfx::ImageSkia& icon) { |
| 51 if (index >= buttons_.size()) |
| 52 return false; |
| 53 buttons_[index].icon = icon; |
| 54 return true; |
| 55 } |
| 56 |
| 57 void Notification::ApplyOptionalFields(const DictionaryValue* fields) { |
| 58 if (!fields) |
| 59 return; |
| 60 |
| 61 fields->GetInteger(kPriorityKey, &priority_); |
| 62 if (fields->HasKey(kTimestampKey)) { |
| 63 std::string time_string; |
| 64 fields->GetString(kTimestampKey, &time_string); |
| 65 base::Time::FromString(time_string.c_str(), ×tamp_); |
| 66 } |
| 67 fields->GetInteger(kUnreadCountKey, &unread_count_); |
| 68 if (fields->HasKey(kButtonOneTitleKey) || |
| 69 fields->HasKey(kButtonOneIconUrlKey)) { |
| 70 string16 title; |
| 71 string16 icon; |
| 72 if (fields->GetString(kButtonOneTitleKey, &title) || |
| 73 fields->GetString(kButtonOneIconUrlKey, &icon)) { |
| 74 buttons_.push_back(ButtonInfo(title)); |
| 75 if (fields->GetString(kButtonTwoTitleKey, &title) || |
| 76 fields->GetString(kButtonTwoIconUrlKey, &icon)) { |
| 77 buttons_.push_back(ButtonInfo(title)); |
| 78 } |
| 79 } |
| 80 } |
| 81 fields->GetString(kExpandedMessageKey, &expanded_message_); |
| 82 if (fields->HasKey(kItemsKey)) { |
| 83 const ListValue* items; |
| 84 CHECK(fields->GetList(kItemsKey, &items)); |
| 85 for (size_t i = 0; i < items->GetSize(); ++i) { |
| 86 string16 title; |
| 87 string16 message; |
| 88 const base::DictionaryValue* item; |
| 89 items->GetDictionary(i, &item); |
| 90 item->GetString(kItemTitleKey, &title); |
| 91 item->GetString(kItemMessageKey, &message); |
| 92 items_.push_back(NotificationItem(title, message)); |
| 93 } |
| 94 } |
| 95 } |
| 96 |
22 } // namespace message_center | 97 } // namespace message_center |
OLD | NEW |