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