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 <utility> | |
8 | |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/metrics/histogram_macros.h" | |
9 #include "base/strings/nullable_string16.h" | 12 #include "base/strings/nullable_string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/notifications/message_center_display_service.h" | 15 #include "chrome/browser/notifications/message_center_display_service.h" |
13 #include "chrome/browser/notifications/non_persistent_notification_handler.h" | 16 #include "chrome/browser/notifications/non_persistent_notification_handler.h" |
14 #include "chrome/browser/notifications/notification.h" | 17 #include "chrome/browser/notifications/notification.h" |
15 #include "chrome/browser/notifications/notification_delegate.h" | 18 #include "chrome/browser/notifications/notification_delegate.h" |
16 #include "chrome/browser/notifications/notification_handler.h" | 19 #include "chrome/browser/notifications/notification_handler.h" |
17 #include "chrome/browser/notifications/notification_platform_bridge.h" | 20 #include "chrome/browser/notifications/notification_platform_bridge.h" |
18 #include "chrome/browser/notifications/persistent_notification_handler.h" | 21 #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) | 62 #if BUILDFLAG(ENABLE_EXTENSIONS) |
60 AddNotificationHandler(NotificationCommon::EXTENSION, | 63 AddNotificationHandler(NotificationCommon::EXTENSION, |
61 base::MakeUnique<ExtensionNotificationHandler>()); | 64 base::MakeUnique<ExtensionNotificationHandler>()); |
62 #endif | 65 #endif |
63 } | 66 } |
64 | 67 |
65 NativeNotificationDisplayService::~NativeNotificationDisplayService() = default; | 68 NativeNotificationDisplayService::~NativeNotificationDisplayService() = default; |
66 | 69 |
67 void NativeNotificationDisplayService::OnNotificationPlatformBridgeReady( | 70 void NativeNotificationDisplayService::OnNotificationPlatformBridgeReady( |
68 bool success) { | 71 bool success) { |
72 // If NotificationPlatformBridge initialization succeeded, use | |
73 // native notifications, otherwise fallback to using the Chrome | |
74 // message center. | |
Peter Beverloo
2017/05/03 22:52:48
nit: I don't think this comment adds a lot, the co
Tom (Use chromium acct)
2017/05/04 00:07:38
Done.
| |
75 UMA_HISTOGRAM_BOOLEAN("Notifications.UsingNativeNotificationCenter", success); | |
69 if (success) { | 76 if (success) { |
70 notification_bridge_ready_ = true; | 77 notification_bridge_ready_ = true; |
71 } else { | 78 } else { |
72 message_center_display_service_ = | 79 message_center_display_service_ = |
73 base::MakeUnique<MessageCenterDisplayService>( | 80 base::MakeUnique<MessageCenterDisplayService>( |
74 profile_, g_browser_process->notification_ui_manager()); | 81 profile_, g_browser_process->notification_ui_manager()); |
75 } | 82 } |
76 | 83 |
77 while (!actions_.empty()) { | 84 while (!actions_.empty()) { |
78 std::move(actions_.front()).Run(); | 85 std::move(actions_.front()).Run(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 notification_handlers_.erase(notification_type); | 178 notification_handlers_.erase(notification_type); |
172 } | 179 } |
173 | 180 |
174 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( | 181 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( |
175 NotificationCommon::Type notification_type) { | 182 NotificationCommon::Type notification_type) { |
176 DCHECK(notification_handlers_.find(notification_type) != | 183 DCHECK(notification_handlers_.find(notification_type) != |
177 notification_handlers_.end()) | 184 notification_handlers_.end()) |
178 << notification_type << " is not registered."; | 185 << notification_type << " is not registered."; |
179 return notification_handlers_[notification_type].get(); | 186 return notification_handlers_[notification_type].get(); |
180 } | 187 } |
OLD | NEW |