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. |
| 73 UMA_HISTOGRAM_BOOLEAN("Notifications.UsingNativeNotificationCenter", success); |
69 if (success) { | 74 if (success) { |
70 notification_bridge_ready_ = true; | 75 notification_bridge_ready_ = true; |
71 } else { | 76 } else { |
72 message_center_display_service_ = | 77 message_center_display_service_ = |
73 base::MakeUnique<MessageCenterDisplayService>( | 78 base::MakeUnique<MessageCenterDisplayService>( |
74 profile_, g_browser_process->notification_ui_manager()); | 79 profile_, g_browser_process->notification_ui_manager()); |
75 } | 80 } |
76 | 81 |
77 while (!actions_.empty()) { | 82 while (!actions_.empty()) { |
78 std::move(actions_.front()).Run(); | 83 std::move(actions_.front()).Run(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 notification_handlers_.erase(notification_type); | 176 notification_handlers_.erase(notification_type); |
172 } | 177 } |
173 | 178 |
174 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( | 179 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( |
175 NotificationCommon::Type notification_type) { | 180 NotificationCommon::Type notification_type) { |
176 DCHECK(notification_handlers_.find(notification_type) != | 181 DCHECK(notification_handlers_.find(notification_type) != |
177 notification_handlers_.end()) | 182 notification_handlers_.end()) |
178 << notification_type << " is not registered."; | 183 << notification_type << " is not registered."; |
179 return notification_handlers_[notification_type].get(); | 184 return notification_handlers_[notification_type].get(); |
180 } | 185 } |
OLD | NEW |