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

Side by Side Diff: chrome/browser/notifications/native_notification_display_service.cc

Issue 2703213004: Migrate extension notifications to the new NotificationDisplayService (Closed)
Patch Set: Miguel's comments Created 3 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
OLDNEW
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/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/strings/nullable_string16.h" 8 #include "base/strings/nullable_string16.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/notifications/non_persistent_notification_handler.h" 10 #include "chrome/browser/notifications/non_persistent_notification_handler.h"
11 #include "chrome/browser/notifications/notification.h" 11 #include "chrome/browser/notifications/notification.h"
12 #include "chrome/browser/notifications/notification_delegate.h" 12 #include "chrome/browser/notifications/notification_delegate.h"
13 #include "chrome/browser/notifications/notification_handler.h" 13 #include "chrome/browser/notifications/notification_handler.h"
14 #include "chrome/browser/notifications/notification_platform_bridge.h" 14 #include "chrome/browser/notifications/notification_platform_bridge.h"
15 #include "chrome/browser/notifications/persistent_notification_handler.h" 15 #include "chrome/browser/notifications/persistent_notification_handler.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "extensions/features/features.h"
18
19 #if BUILDFLAG(ENABLE_EXTENSIONS)
20 #include "chrome/browser/extensions/api/notifications/extension_notification_han dler.h"
21 #endif
17 22
18 namespace { 23 namespace {
19 24
20 std::string GetProfileId(Profile* profile) { 25 std::string GetProfileId(Profile* profile) {
21 #if defined(OS_WIN) 26 #if defined(OS_WIN)
22 std::string profile_id = 27 std::string profile_id =
23 base::WideToUTF8(profile->GetPath().BaseName().value()); 28 base::WideToUTF8(profile->GetPath().BaseName().value());
24 #elif defined(OS_POSIX) 29 #elif defined(OS_POSIX)
25 std::string profile_id = profile->GetPath().BaseName().value(); 30 std::string profile_id = profile->GetPath().BaseName().value();
26 #endif 31 #endif
27 return profile_id; 32 return profile_id;
28 } 33 }
29 34
30 } // namespace 35 } // namespace
31 36
32 NativeNotificationDisplayService::NativeNotificationDisplayService( 37 NativeNotificationDisplayService::NativeNotificationDisplayService(
33 Profile* profile, 38 Profile* profile,
34 NotificationPlatformBridge* notification_bridge) 39 NotificationPlatformBridge* notification_bridge)
35 : profile_(profile), notification_bridge_(notification_bridge) { 40 : profile_(profile), notification_bridge_(notification_bridge) {
36 DCHECK(profile_); 41 DCHECK(profile_);
37 DCHECK(notification_bridge_); 42 DCHECK(notification_bridge_);
38 43
39 AddNotificationHandler(NotificationCommon::NON_PERSISTENT, 44 AddNotificationHandler(NotificationCommon::NON_PERSISTENT,
40 base::MakeUnique<NonPersistentNotificationHandler>()); 45 base::MakeUnique<NonPersistentNotificationHandler>());
41 AddNotificationHandler(NotificationCommon::PERSISTENT, 46 AddNotificationHandler(NotificationCommon::PERSISTENT,
42 base::MakeUnique<PersistentNotificationHandler>()); 47 base::MakeUnique<PersistentNotificationHandler>());
48 #if BUILDFLAG(ENABLE_EXTENSIONS)
49 AddNotificationHandler(NotificationCommon::EXTENSION,
50 base::MakeUnique<ExtensionNotificationHandler>());
51 #endif
43 } 52 }
44 53
45 NativeNotificationDisplayService::~NativeNotificationDisplayService() {} 54 NativeNotificationDisplayService::~NativeNotificationDisplayService() {}
46 55
47 void NativeNotificationDisplayService::Display( 56 void NativeNotificationDisplayService::Display(
48 NotificationCommon::Type notification_type, 57 NotificationCommon::Type notification_type,
49 const std::string& notification_id, 58 const std::string& notification_id,
50 const Notification& notification) { 59 const Notification& notification) {
51 notification_bridge_->Display(notification_type, notification_id, 60 notification_bridge_->Display(notification_type, notification_id,
52 GetProfileId(profile_), 61 GetProfileId(profile_),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 notification_handlers_.erase(notification_type); 119 notification_handlers_.erase(notification_type);
111 } 120 }
112 121
113 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler( 122 NotificationHandler* NativeNotificationDisplayService::GetNotificationHandler(
114 NotificationCommon::Type notification_type) { 123 NotificationCommon::Type notification_type) {
115 DCHECK(notification_handlers_.find(notification_type) != 124 DCHECK(notification_handlers_.find(notification_type) !=
116 notification_handlers_.end()) 125 notification_handlers_.end())
117 << notification_type << " is not registered."; 126 << notification_type << " is not registered.";
118 return notification_handlers_[notification_type].get(); 127 return notification_handlers_[notification_type].get();
119 } 128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698