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

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

Issue 2033093003: [Notification] Make HTML5 Notification use ActionCenter on Windows 10, behind Flags. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/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 "base/win/windows_version.h"
9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/notifications/message_center_display_service.h" 11 #include "chrome/browser/notifications/message_center_display_service.h"
11 #include "chrome/browser/notifications/notification_ui_manager.h" 12 #include "chrome/browser/notifications/notification_ui_manager.h"
12 #include "chrome/browser/profiles/incognito_helpers.h" 13 #include "chrome/browser/profiles/incognito_helpers.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.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 defined(OS_WIN) || defined(OS_ANDROID) || defined(OS_MACOSX)
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 the 43 // NativeNotificationDisplayService by using the chrome://flags or the
43 // --enable-native-notifications command line flag. 44 // --enable-native-notifications 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 {
47 #if defined(OS_ANDROID) 48 #if defined(OS_WIN)
49 if (base::win::GetVersion() >= base::win::VERSION_WIN10 &&
50 base::CommandLine::ForCurrentProcess()->HasSwitch(
51 switches::kEnableNativeNotifications)) {
52 return new NativeNotificationDisplayService(
53 Profile::FromBrowserContext(context),
54 g_browser_process->notification_platform_bridge());
55 }
56 #elif defined(OS_ANDROID)
48 return new NativeNotificationDisplayService( 57 return new NativeNotificationDisplayService(
49 Profile::FromBrowserContext(context), 58 Profile::FromBrowserContext(context),
50 g_browser_process->notification_platform_bridge()); 59 g_browser_process->notification_platform_bridge());
51 #elif defined(OS_MACOSX) 60 #elif defined(OS_MACOSX)
52 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 61 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
53 switches::kEnableNativeNotifications)) { 62 switches::kEnableNativeNotifications)) {
54 return new NativeNotificationDisplayService( 63 return new NativeNotificationDisplayService(
55 Profile::FromBrowserContext(context), 64 Profile::FromBrowserContext(context),
56 g_browser_process->notification_platform_bridge()); 65 g_browser_process->notification_platform_bridge());
57 } 66 }
58 #endif 67 #endif
59 return new MessageCenterDisplayService( 68 return new MessageCenterDisplayService(
60 Profile::FromBrowserContext(context), 69 Profile::FromBrowserContext(context),
61 g_browser_process->notification_ui_manager()); 70 g_browser_process->notification_ui_manager());
62 } 71 }
63 72
64 content::BrowserContext* 73 content::BrowserContext*
65 NotificationDisplayServiceFactory::GetBrowserContextToUse( 74 NotificationDisplayServiceFactory::GetBrowserContextToUse(
66 content::BrowserContext* context) const { 75 content::BrowserContext* context) const {
67 return chrome::GetBrowserContextOwnInstanceInIncognito(context); 76 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
68 } 77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698