OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/native_notification_display_service.h" | 5 #include "chrome/browser/notifications/native_notification_display_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/metrics/histogram_macros.h" | |
9 #include "base/strings/nullable_string16.h" | 10 #include "base/strings/nullable_string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/notifications/message_center_display_service.h" | 13 #include "chrome/browser/notifications/message_center_display_service.h" |
13 #include "chrome/browser/notifications/non_persistent_notification_handler.h" | 14 #include "chrome/browser/notifications/non_persistent_notification_handler.h" |
14 #include "chrome/browser/notifications/notification.h" | 15 #include "chrome/browser/notifications/notification.h" |
15 #include "chrome/browser/notifications/notification_delegate.h" | 16 #include "chrome/browser/notifications/notification_delegate.h" |
16 #include "chrome/browser/notifications/notification_handler.h" | 17 #include "chrome/browser/notifications/notification_handler.h" |
17 #include "chrome/browser/notifications/notification_platform_bridge.h" | 18 #include "chrome/browser/notifications/notification_platform_bridge.h" |
18 #include "chrome/browser/notifications/persistent_notification_handler.h" | 19 #include "chrome/browser/notifications/persistent_notification_handler.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 #if BUILDFLAG(ENABLE_EXTENSIONS) | 60 #if BUILDFLAG(ENABLE_EXTENSIONS) |
60 AddNotificationHandler(NotificationCommon::EXTENSION, | 61 AddNotificationHandler(NotificationCommon::EXTENSION, |
61 base::MakeUnique<ExtensionNotificationHandler>()); | 62 base::MakeUnique<ExtensionNotificationHandler>()); |
62 #endif | 63 #endif |
63 } | 64 } |
64 | 65 |
65 NativeNotificationDisplayService::~NativeNotificationDisplayService() = default; | 66 NativeNotificationDisplayService::~NativeNotificationDisplayService() = default; |
66 | 67 |
67 void NativeNotificationDisplayService::OnNotificationPlatformBridgeReady( | 68 void NativeNotificationDisplayService::OnNotificationPlatformBridgeReady( |
68 bool success) { | 69 bool success) { |
70 // If NotificationPlatformBridge initialization succeeded, use | |
71 // native notifications, otherwise fallback to using the Chrome | |
72 // message center. | |
Peter Beverloo
2017/05/02 14:15:24
Did `git cl format` do this? These should be inden
Tom (Use chromium acct)
2017/05/02 18:49:41
Done.
| |
73 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
74 UMA_HISTOGRAM_BOOLEAN("Linux.NativeNotifications.UsingNativeNotifications", | |
Peter Beverloo
2017/05/02 14:15:24
What about using:
Notifications.UsingNativeNot
Tom (Use chromium acct)
2017/05/02 18:49:41
Done.
| |
75 success); | |
76 #endif | |
69 if (success) { | 77 if (success) { |
70 notification_bridge_ready_ = true; | 78 notification_bridge_ready_ = true; |
71 } else { | 79 } else { |
72 message_center_display_service_ = | 80 message_center_display_service_ = |
73 base::MakeUnique<MessageCenterDisplayService>( | 81 base::MakeUnique<MessageCenterDisplayService>( |
74 profile_, g_browser_process->notification_ui_manager()); | 82 profile_, g_browser_process->notification_ui_manager()); |
75 } | 83 } |
76 | 84 |
77 while (!actions_.empty()) { | 85 while (!actions_.empty()) { |
78 std::move(actions_.front()).Run(); | 86 std::move(actions_.front()).Run(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 notification_handlers_.erase(notification_type); | 179 notification_handlers_.erase(notification_type); |
172 } | 180 } |
173 | 181 |
174 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( | 182 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( |
175 NotificationCommon::Type notification_type) { | 183 NotificationCommon::Type notification_type) { |
176 DCHECK(notification_handlers_.find(notification_type) != | 184 DCHECK(notification_handlers_.find(notification_type) != |
177 notification_handlers_.end()) | 185 notification_handlers_.end()) |
178 << notification_type << " is not registered."; | 186 << notification_type << " is not registered."; |
179 return notification_handlers_[notification_type].get(); | 187 return notification_handlers_[notification_type].get(); |
180 } | 188 } |
OLD | NEW |