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/notification_display_service_factory.h" | 5 #include "chrome/browser/notifications/notification_display_service_factory.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/notifications/message_center_display_service.h" | 10 #include "chrome/browser/notifications/message_center_display_service.h" |
11 #include "chrome/browser/notifications/notification_ui_manager.h" | 11 #include "chrome/browser/notifications/notification_ui_manager.h" |
12 #include "chrome/browser/profiles/incognito_helpers.h" | 12 #include "chrome/browser/profiles/incognito_helpers.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/common/chrome_features.h" | 14 #include "chrome/common/chrome_features.h" |
| 15 #include "chrome/common/features.h" |
15 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 16 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
16 | 17 |
17 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 18 #if BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS) |
18 #include "chrome/browser/notifications/native_notification_display_service.h" | 19 #include "chrome/browser/notifications/native_notification_display_service.h" |
19 #endif | 20 #endif |
20 | 21 |
21 // static | 22 // static |
22 NotificationDisplayService* NotificationDisplayServiceFactory::GetForProfile( | 23 NotificationDisplayService* NotificationDisplayServiceFactory::GetForProfile( |
23 Profile* profile) { | 24 Profile* profile) { |
24 return static_cast<NotificationDisplayService*>( | 25 return static_cast<NotificationDisplayService*>( |
25 GetInstance()->GetServiceForBrowserContext(profile, true /* create */)); | 26 GetInstance()->GetServiceForBrowserContext(profile, true /* create */)); |
26 } | 27 } |
27 | 28 |
28 // static | 29 // static |
29 NotificationDisplayServiceFactory* | 30 NotificationDisplayServiceFactory* |
30 NotificationDisplayServiceFactory::GetInstance() { | 31 NotificationDisplayServiceFactory::GetInstance() { |
31 return base::Singleton<NotificationDisplayServiceFactory>::get(); | 32 return base::Singleton<NotificationDisplayServiceFactory>::get(); |
32 } | 33 } |
33 | 34 |
34 NotificationDisplayServiceFactory::NotificationDisplayServiceFactory() | 35 NotificationDisplayServiceFactory::NotificationDisplayServiceFactory() |
35 : BrowserContextKeyedServiceFactory( | 36 : BrowserContextKeyedServiceFactory( |
36 "NotificationDisplayService", | 37 "NotificationDisplayService", |
37 BrowserContextDependencyManager::GetInstance()) {} | 38 BrowserContextDependencyManager::GetInstance()) {} |
38 | 39 |
39 // Selection of the implementation works as follows: | 40 // Selection of the implementation works as follows: |
40 // - Android always uses the NativeNotificationDisplayService. | 41 // - Android always uses the NativeNotificationDisplayService. |
41 // - Mac uses the MessageCenterDisplayService by default, but can use the | 42 // - Mac uses the MessageCenterDisplayService by default, but can use the |
42 // NativeNotificationDisplayService by using the chrome://flags or via | 43 // NativeNotificationDisplayService by using the chrome://flags or via |
43 // the --enable-features=NativeNotifications command line flag. | 44 // the --enable-features=NativeNotifications command line flag. |
44 // - All other platforms always use the MessageCenterDisplayService. | 45 // - All other platforms always use the MessageCenterDisplayService. |
45 KeyedService* NotificationDisplayServiceFactory::BuildServiceInstanceFor( | 46 KeyedService* NotificationDisplayServiceFactory::BuildServiceInstanceFor( |
46 content::BrowserContext* context) const { | 47 content::BrowserContext* context) const { |
| 48 #if BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS) |
47 #if defined(OS_ANDROID) | 49 #if defined(OS_ANDROID) |
48 return new NativeNotificationDisplayService( | 50 return new NativeNotificationDisplayService( |
49 Profile::FromBrowserContext(context), | 51 Profile::FromBrowserContext(context), |
50 g_browser_process->notification_platform_bridge()); | 52 g_browser_process->notification_platform_bridge()); |
51 #elif defined(OS_MACOSX) | 53 #else // defined(OS_ANDROID) |
52 if (base::FeatureList::IsEnabled(features::kNativeNotifications)) { | 54 if (base::FeatureList::IsEnabled(features::kNativeNotifications) && |
| 55 g_browser_process->notification_platform_bridge()) { |
53 return new NativeNotificationDisplayService( | 56 return new NativeNotificationDisplayService( |
54 Profile::FromBrowserContext(context), | 57 Profile::FromBrowserContext(context), |
55 g_browser_process->notification_platform_bridge()); | 58 g_browser_process->notification_platform_bridge()); |
56 } | 59 } |
57 #endif | 60 #endif // defined(OS_ANDROID) |
| 61 #endif // BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS) |
58 return new MessageCenterDisplayService( | 62 return new MessageCenterDisplayService( |
59 Profile::FromBrowserContext(context), | 63 Profile::FromBrowserContext(context), |
60 g_browser_process->notification_ui_manager()); | 64 g_browser_process->notification_ui_manager()); |
61 } | 65 } |
62 | 66 |
63 content::BrowserContext* | 67 content::BrowserContext* |
64 NotificationDisplayServiceFactory::GetBrowserContextToUse( | 68 NotificationDisplayServiceFactory::GetBrowserContextToUse( |
65 content::BrowserContext* context) const { | 69 content::BrowserContext* context) const { |
66 return chrome::GetBrowserContextOwnInstanceInIncognito(context); | 70 return chrome::GetBrowserContextOwnInstanceInIncognito(context); |
67 } | 71 } |
OLD | NEW |