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" | 7 #include "base/logging.h" |
8 #include "ui/message_center/notification_types.h" | 8 #include "ui/message_center/notification_types.h" |
9 | 9 |
10 namespace { | 10 namespace { |
11 unsigned g_next_serial_number_ = 0; | 11 unsigned g_next_serial_number_ = 0; |
12 } | 12 } |
13 | 13 |
14 namespace message_center { | 14 namespace message_center { |
15 | 15 |
16 NotificationItem::NotificationItem(const string16& title, | 16 NotificationItem::NotificationItem(const string16& title, |
17 const string16& message) | 17 const string16& message) |
18 : title(title), | 18 : title(title), |
19 message(message) { | 19 message(message) { |
20 } | 20 } |
21 | 21 |
22 ButtonInfo::ButtonInfo(const string16& title) | 22 ButtonInfo::ButtonInfo(const string16& title) |
23 : title(title) { | 23 : title(title) { |
24 } | 24 } |
25 | 25 |
| 26 RichNotificationData::RichNotificationData() |
| 27 : priority(DEFAULT_PRIORITY), |
| 28 never_timeout(false), |
| 29 timestamp(base::Time::Now()) {} |
| 30 |
| 31 RichNotificationData::RichNotificationData(const RichNotificationData& other) |
| 32 : priority(other.priority), |
| 33 never_timeout(other.never_timeout), |
| 34 timestamp(other.timestamp), |
| 35 expanded_message(other.expanded_message), |
| 36 image(other.image), |
| 37 items(other.items), |
| 38 buttons(other.buttons) {} |
| 39 |
| 40 RichNotificationData::~RichNotificationData() {} |
| 41 |
26 Notification::Notification(NotificationType type, | 42 Notification::Notification(NotificationType type, |
27 const std::string& id, | 43 const std::string& id, |
28 const string16& title, | 44 const string16& title, |
29 const string16& message, | 45 const string16& message, |
| 46 const gfx::Image& icon, |
30 const string16& display_source, | 47 const string16& display_source, |
31 const std::string& extension_id, | 48 const std::string& extension_id, |
32 const DictionaryValue* optional_fields, | 49 const DictionaryValue* optional_fields, |
33 NotificationDelegate* delegate) | 50 NotificationDelegate* delegate) |
34 : type_(type), | 51 : type_(type), |
35 id_(id), | 52 id_(id), |
36 title_(title), | 53 title_(title), |
37 message_(message), | 54 message_(message), |
| 55 icon_(icon), |
38 display_source_(display_source), | 56 display_source_(display_source), |
39 extension_id_(extension_id), | 57 extension_id_(extension_id), |
40 priority_(DEFAULT_PRIORITY), | |
41 timestamp_(base::Time::Now()), | |
42 serial_number_(g_next_serial_number_++), | 58 serial_number_(g_next_serial_number_++), |
43 shown_as_popup_(false), | 59 shown_as_popup_(false), |
44 is_read_(false), | 60 is_read_(false), |
45 is_expanded_(false), | 61 is_expanded_(false), |
46 never_timeout_(false), | |
47 delegate_(delegate) { | 62 delegate_(delegate) { |
48 // This can override some data members initialized to deafule values above. | 63 // This can override some data members initialized to default values above. |
49 ApplyOptionalFields(optional_fields); | 64 ApplyOptionalFields(optional_fields); |
50 } | 65 } |
51 | 66 |
52 Notification::~Notification() { | 67 Notification::Notification(NotificationType type, |
| 68 const std::string& id, |
| 69 const string16& title, |
| 70 const string16& message, |
| 71 const gfx::Image& icon, |
| 72 const string16& display_source, |
| 73 const std::string& extension_id, |
| 74 const RichNotificationData& optional_fields, |
| 75 NotificationDelegate* delegate) |
| 76 : type_(type), |
| 77 id_(id), |
| 78 title_(title), |
| 79 message_(message), |
| 80 icon_(icon), |
| 81 display_source_(display_source), |
| 82 extension_id_(extension_id), |
| 83 serial_number_(g_next_serial_number_++), |
| 84 optional_fields_(optional_fields), |
| 85 delegate_(delegate) {} |
| 86 |
| 87 Notification::Notification(const Notification& other) |
| 88 : type_(other.type_), |
| 89 id_(other.id_), |
| 90 title_(other.title_), |
| 91 message_(other.message_), |
| 92 icon_(other.icon_), |
| 93 display_source_(other.display_source_), |
| 94 extension_id_(other.extension_id_), |
| 95 serial_number_(other.serial_number_), |
| 96 optional_fields_(other.optional_fields_), |
| 97 shown_as_popup_(other.shown_as_popup_), |
| 98 is_read_(other.is_read_), |
| 99 is_expanded_(other.is_expanded_), |
| 100 delegate_(other.delegate_) {} |
| 101 |
| 102 Notification& Notification::operator=(const Notification& other) { |
| 103 type_ = other.type_; |
| 104 id_ = other.id_; |
| 105 title_ = other.title_; |
| 106 message_ = other.message_; |
| 107 icon_ = other.icon_; |
| 108 display_source_ = other.display_source_; |
| 109 extension_id_ = other.extension_id_; |
| 110 serial_number_ = other.serial_number_; |
| 111 optional_fields_ = other.optional_fields_; |
| 112 shown_as_popup_ = other.shown_as_popup_; |
| 113 is_read_ = other.is_read_; |
| 114 is_expanded_ = other.is_expanded_; |
| 115 delegate_ = other.delegate_; |
| 116 |
| 117 return *this; |
53 } | 118 } |
54 | 119 |
| 120 Notification::~Notification() {} |
| 121 |
55 void Notification::CopyState(Notification* base) { | 122 void Notification::CopyState(Notification* base) { |
56 shown_as_popup_ = base->shown_as_popup(); | 123 shown_as_popup_ = base->shown_as_popup(); |
57 is_read_ = base->is_read(); | 124 is_read_ = base->is_read(); |
58 is_expanded_ = base->is_expanded(); | 125 is_expanded_ = base->is_expanded(); |
59 never_timeout_ = base->never_timeout(); | |
60 if (!delegate_.get()) | 126 if (!delegate_.get()) |
61 delegate_ = base->delegate(); | 127 delegate_ = base->delegate(); |
| 128 optional_fields_.never_timeout = base->never_timeout(); |
62 } | 129 } |
63 | 130 |
64 bool Notification::SetButtonIcon(size_t index, const gfx::Image& icon) { | 131 void Notification::SetButtonIcon(size_t index, const gfx::Image& icon) { |
65 if (index >= buttons_.size()) | 132 if (index >= optional_fields_.buttons.size()) |
66 return false; | 133 return; |
67 buttons_[index].icon = icon; | 134 optional_fields_.buttons[index].icon = icon; |
68 return true; | |
69 } | 135 } |
70 | 136 |
71 void Notification::ApplyOptionalFields(const DictionaryValue* fields) { | 137 void Notification::ApplyOptionalFields(const DictionaryValue* fields) { |
72 if (!fields) | 138 if (!fields) |
73 return; | 139 return; |
74 | 140 |
75 fields->GetInteger(kPriorityKey, &priority_); | 141 fields->GetInteger(kPriorityKey, &optional_fields_.priority); |
76 if (fields->HasKey(kTimestampKey)) { | 142 if (fields->HasKey(kTimestampKey)) { |
77 std::string time_string; | 143 std::string time_string; |
78 fields->GetString(kTimestampKey, &time_string); | 144 fields->GetString(kTimestampKey, &time_string); |
79 base::Time::FromString(time_string.c_str(), ×tamp_); | 145 base::Time::FromString(time_string.c_str(), &optional_fields_.timestamp); |
80 } | 146 } |
81 if (fields->HasKey(kButtonOneTitleKey) || | 147 if (fields->HasKey(kButtonOneTitleKey) || |
82 fields->HasKey(kButtonOneIconUrlKey)) { | 148 fields->HasKey(kButtonOneIconUrlKey)) { |
83 string16 title; | 149 string16 title; |
84 string16 icon; | 150 string16 icon; |
85 if (fields->GetString(kButtonOneTitleKey, &title) || | 151 if (fields->GetString(kButtonOneTitleKey, &title) || |
86 fields->GetString(kButtonOneIconUrlKey, &icon)) { | 152 fields->GetString(kButtonOneIconUrlKey, &icon)) { |
87 buttons_.push_back(ButtonInfo(title)); | 153 optional_fields_.buttons.push_back(ButtonInfo(title)); |
88 if (fields->GetString(kButtonTwoTitleKey, &title) || | 154 if (fields->GetString(kButtonTwoTitleKey, &title) || |
89 fields->GetString(kButtonTwoIconUrlKey, &icon)) { | 155 fields->GetString(kButtonTwoIconUrlKey, &icon)) { |
90 buttons_.push_back(ButtonInfo(title)); | 156 optional_fields_.buttons.push_back(ButtonInfo(title)); |
91 } | 157 } |
92 } | 158 } |
93 } | 159 } |
94 fields->GetString(kExpandedMessageKey, &expanded_message_); | 160 fields->GetString(kExpandedMessageKey, &optional_fields_.expanded_message); |
95 if (fields->HasKey(kItemsKey)) { | 161 if (fields->HasKey(kItemsKey)) { |
96 const ListValue* items; | 162 const ListValue* items; |
97 CHECK(fields->GetList(kItemsKey, &items)); | 163 CHECK(fields->GetList(kItemsKey, &items)); |
98 for (size_t i = 0; i < items->GetSize(); ++i) { | 164 for (size_t i = 0; i < items->GetSize(); ++i) { |
99 string16 title; | 165 string16 title; |
100 string16 message; | 166 string16 message; |
101 const base::DictionaryValue* item; | 167 const base::DictionaryValue* item; |
102 items->GetDictionary(i, &item); | 168 items->GetDictionary(i, &item); |
103 item->GetString(kItemTitleKey, &title); | 169 item->GetString(kItemTitleKey, &title); |
104 item->GetString(kItemMessageKey, &message); | 170 item->GetString(kItemMessageKey, &message); |
105 items_.push_back(NotificationItem(title, message)); | 171 optional_fields_.items.push_back(NotificationItem(title, message)); |
106 } | 172 } |
107 } | 173 } |
108 | 174 |
109 fields->GetBoolean(kPrivateNeverTimeoutKey, &never_timeout_); | 175 fields->GetBoolean(kPrivateNeverTimeoutKey, &optional_fields_.never_timeout); |
110 } | 176 } |
111 | 177 |
112 } // namespace message_center | 178 } // namespace message_center |
OLD | NEW |