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

Side by Side Diff: trunk/src/chrome/browser/notifications/sync_notifier/synced_notification.cc

Issue 14631021: Revert 199625 "Remove ENABLE_MESSAGE_CENTER" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 7 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/notifications/sync_notifier/synced_notification.h" 5 #include "chrome/browser/notifications/sync_notifier/synced_notification.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/notifications/notification.h" 11 #include "chrome/browser/notifications/notification.h"
12 #include "chrome/browser/notifications/notification_ui_manager.h" 12 #include "chrome/browser/notifications/notification_ui_manager.h"
13 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h" 13 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h"
14 #include "sync/protocol/sync.pb.h" 14 #include "sync/protocol/sync.pb.h"
15 #include "sync/protocol/synced_notification_specifics.pb.h" 15 #include "sync/protocol/synced_notification_specifics.pb.h"
16 #if defined(ENABLE_MESSAGE_CENTER)
16 #include "ui/message_center/message_center_util.h" 17 #include "ui/message_center/message_center_util.h"
17 #include "ui/message_center/notification_types.h" 18 #include "ui/message_center/notification_types.h"
19 #endif // ENABLE_MESSAGE_CENTER
18 20
19 namespace { 21 namespace {
20 const char kExtensionScheme[] = "chrome-extension://"; 22 const char kExtensionScheme[] = "chrome-extension://";
21 23
22 bool UseRichNotifications() { 24 bool UseRichNotifications() {
25 #if defined(ENABLE_MESSAGE_CENTER)
23 return message_center::IsRichNotificationEnabled(); 26 return message_center::IsRichNotificationEnabled();
27 #else // ENABLE_MESSAGE_CENTER
28 return false;
29 #endif // ENABLE_MESSAGE_CENTER
24 } 30 }
25 31
26 } // namespace 32 } // namespace
27 33
28 namespace notifier { 34 namespace notifier {
29 35
30 COMPILE_ASSERT(static_cast<sync_pb::CoalescedSyncedNotification_ReadState>( 36 COMPILE_ASSERT(static_cast<sync_pb::CoalescedSyncedNotification_ReadState>(
31 SyncedNotification::kUnread) == 37 SyncedNotification::kUnread) ==
32 sync_pb::CoalescedSyncedNotification_ReadState_UNREAD, 38 sync_pb::CoalescedSyncedNotification_ReadState_UNREAD,
33 local_enum_must_match_protobuf_enum); 39 local_enum_must_match_protobuf_enum);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // I change the interface to let NotificationUIManager know the right way. 83 // I change the interface to let NotificationUIManager know the right way.
78 if (SyncedNotification::kRead == GetReadState() || 84 if (SyncedNotification::kRead == GetReadState() ||
79 SyncedNotification::kDismissed == GetReadState() ) { 85 SyncedNotification::kDismissed == GetReadState() ) {
80 DVLOG(2) << "Dismissed notification arrived" 86 DVLOG(2) << "Dismissed notification arrived"
81 << GetHeading() << " " << GetText(); 87 << GetHeading() << " " << GetText();
82 return; 88 return;
83 } 89 }
84 90
85 // Some inputs and fields are only used if there is a notification center. 91 // Some inputs and fields are only used if there is a notification center.
86 if (UseRichNotifications()) { 92 if (UseRichNotifications()) {
93
94 #if defined(ENABLE_MESSAGE_CENTER)
87 double creation_time = static_cast<double>(GetCreationTime()); 95 double creation_time = static_cast<double>(GetCreationTime());
88 int priority = GetPriority(); 96 int priority = GetPriority();
89 int notification_count = GetNotificationCount(); 97 int notification_count = GetNotificationCount();
90 int button_count = GetButtonCount(); 98 int button_count = GetButtonCount();
91 // TODO(petewil): Refactor this for an arbitrary number of buttons. 99 // TODO(petewil): Refactor this for an arbitrary number of buttons.
92 std::string button_one_title = GetButtonOneTitle(); 100 std::string button_one_title = GetButtonOneTitle();
93 std::string button_one_icon_url = GetButtonOneIconUrl(); 101 std::string button_one_icon_url = GetButtonOneIconUrl();
94 std::string button_two_title = GetButtonTwoTitle(); 102 std::string button_two_title = GetButtonTwoTitle();
95 std::string button_two_icon_url = GetButtonTwoIconUrl(); 103 std::string button_two_icon_url = GetButtonTwoIconUrl();
96 104
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 GetAppIconUrl(), 155 GetAppIconUrl(),
148 heading, 156 heading,
149 text, 157 text,
150 WebKit::WebTextDirectionDefault, 158 WebKit::WebTextDirectionDefault,
151 display_source, 159 display_source,
152 replace_key, 160 replace_key,
153 &optional_fields, 161 &optional_fields,
154 delegate); 162 delegate);
155 163
156 notification_manager->Add(ui_notification, profile); 164 notification_manager->Add(ui_notification, profile);
165 #endif // ENABLE_MESSAGE_CENTER
166
157 } else { 167 } else {
158 168
159 Notification ui_notification(GetOriginUrl(), 169 Notification ui_notification(GetOriginUrl(),
160 GetAppIconUrl(), 170 GetAppIconUrl(),
161 heading, 171 heading,
162 text, 172 text,
163 WebKit::WebTextDirectionDefault, 173 WebKit::WebTextDirectionDefault,
164 display_source, 174 display_source,
165 replace_key, 175 replace_key,
166 delegate); 176 delegate);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 return 0; 332 return 0;
323 333
324 return specifics_.coalesced_notification().creation_time_msec(); 334 return specifics_.coalesced_notification().creation_time_msec();
325 } 335 }
326 336
327 int SyncedNotification::GetPriority() const { 337 int SyncedNotification::GetPriority() const {
328 if (!specifics_.coalesced_notification().has_priority()) 338 if (!specifics_.coalesced_notification().has_priority())
329 return kUndefinedPriority; 339 return kUndefinedPriority;
330 int protobuf_priority = specifics_.coalesced_notification().priority(); 340 int protobuf_priority = specifics_.coalesced_notification().priority();
331 341
342 #if defined(ENABLE_MESSAGE_CENTER)
332 // Convert the prioroty to the scheme used by the notification center. 343 // Convert the prioroty to the scheme used by the notification center.
333 if (protobuf_priority == 344 if (protobuf_priority ==
334 sync_pb::CoalescedSyncedNotification_Priority_LOW) { 345 sync_pb::CoalescedSyncedNotification_Priority_LOW) {
335 return message_center::LOW_PRIORITY; 346 return message_center::LOW_PRIORITY;
336 } else if (protobuf_priority == 347 } else if (protobuf_priority ==
337 sync_pb::CoalescedSyncedNotification_Priority_STANDARD) { 348 sync_pb::CoalescedSyncedNotification_Priority_STANDARD) {
338 return message_center::DEFAULT_PRIORITY; 349 return message_center::DEFAULT_PRIORITY;
339 } else if (protobuf_priority == 350 } else if (protobuf_priority ==
340 sync_pb::CoalescedSyncedNotification_Priority_HIGH) { 351 sync_pb::CoalescedSyncedNotification_Priority_HIGH) {
341 return message_center::HIGH_PRIORITY; 352 return message_center::HIGH_PRIORITY;
342 } else { 353 } else {
343 // Complain if this is a new priority we have not seen before. 354 // Complain if this is a new priority we have not seen before.
344 DCHECK(protobuf_priority < 355 DCHECK(protobuf_priority <
345 sync_pb::CoalescedSyncedNotification_Priority_LOW || 356 sync_pb::CoalescedSyncedNotification_Priority_LOW ||
346 sync_pb::CoalescedSyncedNotification_Priority_HIGH < 357 sync_pb::CoalescedSyncedNotification_Priority_HIGH <
347 protobuf_priority); 358 protobuf_priority);
348 return kUndefinedPriority; 359 return kUndefinedPriority;
349 } 360 }
361
362 #else // ENABLE_MESSAGE_CENTER
363 return protobuf_priority;
364
365 #endif // ENABLE_MESSAGE_CENTER
350 } 366 }
351 367
352 int SyncedNotification::GetNotificationCount() const { 368 int SyncedNotification::GetNotificationCount() const {
353 return specifics_.coalesced_notification().render_info(). 369 return specifics_.coalesced_notification().render_info().
354 expanded_info().collapsed_info_size(); 370 expanded_info().collapsed_info_size();
355 } 371 }
356 372
357 int SyncedNotification::GetButtonCount() const { 373 int SyncedNotification::GetButtonCount() const {
358 return specifics_.coalesced_notification().render_info().collapsed_info(). 374 return specifics_.coalesced_notification().render_info().collapsed_info().
359 target_size(); 375 target_size();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 int index) const { 488 int index) const {
473 if (specifics_.coalesced_notification().render_info().expanded_info(). 489 if (specifics_.coalesced_notification().render_info().expanded_info().
474 collapsed_info_size() < index + 1) 490 collapsed_info_size() < index + 1)
475 return std::string(); 491 return std::string();
476 492
477 return specifics_.coalesced_notification().render_info().expanded_info(). 493 return specifics_.coalesced_notification().render_info().expanded_info().
478 collapsed_info(index).simple_collapsed_layout().description(); 494 collapsed_info(index).simple_collapsed_layout().description();
479 } 495 }
480 496
481 } // namespace notifier 497 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698