1 // Copyright (c) 2013 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.
5 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_factory.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
10 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_info_service_factory.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/chrome_version_info.h"
13 #include "components/keyed_service/content/browser_context_dependency_manager.h"
18 ChromeNotifierService* ChromeNotifierServiceFactory::GetForProfile(
19 Profile* profile, Profile::ServiceAccessType service_access_type) {
20 return static_cast<ChromeNotifierService*>(
21 GetInstance()->GetServiceForBrowserContext(profile, true));
25 ChromeNotifierServiceFactory* ChromeNotifierServiceFactory::GetInstance() {
26 return Singleton<ChromeNotifierServiceFactory>::get();
30 bool ChromeNotifierServiceFactory::UseSyncedNotifications(
31 CommandLine* command_line) {
32 if (command_line->HasSwitch(switches::kDisableSyncSyncedNotifications))
34 if (command_line->HasSwitch(switches::kEnableSyncSyncedNotifications))
37 // enable it by default for canary and dev
38 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
39 if (channel == chrome::VersionInfo::CHANNEL_UNKNOWN ||
40 channel == chrome::VersionInfo::CHANNEL_DEV ||
41 channel == chrome::VersionInfo::CHANNEL_CANARY)
47 ChromeNotifierServiceFactory::ChromeNotifierServiceFactory()
48 : BrowserContextKeyedServiceFactory(
49 "ChromeNotifierService",
50 BrowserContextDependencyManager::GetInstance()) {
51 // Mark this service as depending on the SyncedNotificationAppInfoService.
52 // Marking it provides a guarantee that the other service will alwasys be
53 // running whenever the ChromeNotifierServiceFactory is.
54 DependsOn(SyncedNotificationAppInfoServiceFactory::GetInstance());
57 ChromeNotifierServiceFactory::~ChromeNotifierServiceFactory() {
60 KeyedService* ChromeNotifierServiceFactory::BuildServiceInstanceFor(
61 content::BrowserContext* profile) const {
62 NotificationUIManager* notification_manager =
63 g_browser_process->notification_ui_manager();
64 ChromeNotifierService* chrome_notifier_service =
65 new ChromeNotifierService(static_cast<Profile*>(profile),
66 notification_manager);
67 return chrome_notifier_service;
70 } // namespace notifier