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

Side by Side Diff: ui/message_center/notification.cc

Issue 12277024: Notificaitons refactor step 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix the remaining test Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
10 namespace {
11 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
12 }
13
7 namespace message_center { 14 namespace message_center {
8 15
9 NotificationItem::NotificationItem(string16 title, string16 message) 16 NotificationItem::NotificationItem(const string16& title,
17 const string16& message)
10 : title(title), 18 : title(title),
11 message(message) { 19 message(message) {
12 } 20 }
13 21
14 Notification::Notification() 22 ButtonInfo::ButtonInfo(const string16& title)
15 : is_read(false), 23 : title(title) {
16 shown_as_popup(false) { 24 }
25
26 Notification::Notification(NotificationType type,
27 const std::string& id,
28 const string16& title,
29 const string16& message,
30 const string16& display_source,
31 const std::string& extension_id,
32 const DictionaryValue* optional_fields)
33 : type_(type),
34 id_(id),
35 title_(title),
36 message_(message),
37 display_source_(display_source),
38 extension_id_(extension_id),
39 priority_(DEFAULT_PRIORITY),
40 timestamp_(base::Time::Now()),
41 serial_number_(g_serial_number++),
42 unread_count_(0),
43 is_read_(false),
44 shown_as_popup_(false) {
45 // This can override some data members initialized to deafule values above.
46 ApplyOptionalFields(optional_fields);
17 } 47 }
18 48
19 Notification::~Notification() { 49 Notification::~Notification() {
20 } 50 }
21 51
52 bool Notification::SetButtonIcon(size_t index, const gfx::ImageSkia& icon) {
53 if (index >= buttons_.size())
54 return false;
55 buttons_[index].icon = icon;
56 return true;
57 }
58
59 void Notification::ApplyOptionalFields(const DictionaryValue* fields) {
60 if (!fields)
61 return;
62
63 fields->GetInteger(kPriorityKey, &priority_);
64 if (fields->HasKey(kTimestampKey)) {
65 std::string time_string;
66 fields->GetString(kTimestampKey, &time_string);
67 base::Time::FromString(time_string.c_str(), &timestamp_);
68 }
69 fields->GetInteger(kUnreadCountKey, &unread_count_);
70 if (fields->HasKey(kButtonOneTitleKey) ||
71 fields->HasKey(kButtonOneIconUrlKey)) {
72 string16 title;
73 string16 icon;
74 if (fields->GetString(kButtonOneTitleKey, &title) ||
75 fields->GetString(kButtonOneIconUrlKey, &icon)) {
76 buttons_.push_back(ButtonInfo(title));
77 if (fields->GetString(kButtonTwoTitleKey, &title) ||
78 fields->GetString(kButtonTwoIconUrlKey, &icon)) {
79 buttons_.push_back(ButtonInfo(title));
80 }
81 }
82 }
83 fields->GetString(kExpandedMessageKey, &expanded_message_);
84 if (fields->HasKey(kItemsKey)) {
85 const ListValue* items;
86 CHECK(fields->GetList(kItemsKey, &items));
87 for (size_t i = 0; i < items->GetSize(); ++i) {
88 string16 title;
89 string16 message;
90 const base::DictionaryValue* item;
91 items->GetDictionary(i, &item);
92 item->GetString(kItemTitleKey, &title);
93 item->GetString(kItemMessageKey, &message);
94 items_.push_back(NotificationItem(title, message));
95 }
96 }
97 }
98
22 } // namespace message_center 99 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698