Chromium Code Reviews| Index: chrome/browser/notifications/notification_display_service_factory.cc |
| diff --git a/chrome/browser/notifications/notification_display_service_factory.cc b/chrome/browser/notifications/notification_display_service_factory.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e794d52eb2a6634cfda3923fb0f5f1f618116353 |
| --- /dev/null |
| +++ b/chrome/browser/notifications/notification_display_service_factory.cc |
| @@ -0,0 +1,65 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/notifications/notification_display_service_factory.h" |
| + |
| +#include "base/command_line.h" |
| +#include "base/memory/singleton.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/notifications/chrome_notification_display_service.h" |
| +#include "chrome/browser/notifications/notification_ui_manager.h" |
| +#include "chrome/browser/profiles/incognito_helpers.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/common/chrome_switches.h" |
| + |
| +#if defined(OS_ANDROID) || defined(OS_MACOSX) |
| +#include "chrome/browser/notifications/native_notification_display_service.h" |
| +#endif |
| + |
| +// static |
| +NotificationDisplayService* NotificationDisplayServiceFactory::GetForProfile( |
| + Profile* profile) { |
| + return static_cast<NotificationDisplayService*>( |
| + GetInstance()->GetServiceForBrowserContext(profile, true)); |
|
Peter Beverloo
2016/04/18 14:57:10
GetInstance()->GetServiceForBrowserContext(profile
Miguel Garcia
2016/04/19 14:24:57
Done.
|
| +} |
| + |
| +// static |
| +NotificationDisplayServiceFactory* |
| +NotificationDisplayServiceFactory::GetInstance() { |
| + return base::Singleton<NotificationDisplayServiceFactory>::get(); |
| +} |
| + |
| +NotificationDisplayServiceFactory::NotificationDisplayServiceFactory() |
| + : BrowserContextKeyedServiceFactory( |
| + "NotificationDisplayService", |
| + BrowserContextDependencyManager::GetInstance()) {} |
| + |
| +// Android always uses the native service |
| +// MAC uses the native manager if chrome://flags#enable-native-notifications is |
| +// toggled |
| +// Everything else uses the chrome service |
| +KeyedService* NotificationDisplayServiceFactory::BuildServiceInstanceFor( |
| + content::BrowserContext* context) const { |
| +#if defined(OS_ANDROID) |
| + return new NativeNotificationDisplayService( |
| + Profile::FromBrowserContext(context), |
| + g_browser_process->notification_bridge()); |
| +#elif defined(OS_MACOSX) |
| + if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableNativeNotifications)) { |
| + return new NativeNotificationDisplayService( |
| + Profile::FromBrowserContext(context), |
| + g_browser_process->notification_bridge()); |
| + } |
| +#endif |
| + return new ChromeNotificationDisplayService( |
| + Profile::FromBrowserContext(context), |
| + g_browser_process->notification_ui_manager()); |
| +} |
| + |
| +content::BrowserContext* |
| +NotificationDisplayServiceFactory::GetBrowserContextToUse( |
| + content::BrowserContext* context) const { |
| + return chrome::GetBrowserContextOwnInstanceInIncognito(context); |
| +} |