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. 4 5 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_factory.h" 6 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/common/chrome_switches.h" 11 #include "chrome/common/chrome_version_info.h" 12 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" 13 14 namespace notifier { 15 16 // static 17 ChromeNotifierService* ChromeNotifierServiceFactory::GetForProfile( 18 Profile* profile, Profile::ServiceAccessType sat) { 19 return static_cast<ChromeNotifierService*>( 20 GetInstance()->GetServiceForBrowserContext(profile, true)); 21 } 22 23 // static 24 ChromeNotifierServiceFactory* ChromeNotifierServiceFactory::GetInstance() { 25 return Singleton<ChromeNotifierServiceFactory>::get(); 26 } 27 28 // static 29 bool ChromeNotifierServiceFactory::UseSyncedNotifications( 30 CommandLine* command_line) { 31 if (command_line->HasSwitch(switches::kDisableSyncSyncedNotifications)) 32 return false; 33 if (command_line->HasSwitch(switches::kEnableSyncSyncedNotifications)) 34 return true; 35 36 // enable it by default for canary and dev 37 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); 38 if (channel == chrome::VersionInfo::CHANNEL_UNKNOWN || 39 channel == chrome::VersionInfo::CHANNEL_DEV || 40 channel == chrome::VersionInfo::CHANNEL_CANARY) 41 return true; 42 else 43 44 return false; 45 } 46 47 ChromeNotifierServiceFactory::ChromeNotifierServiceFactory() 48 : BrowserContextKeyedServiceFactory( 49 "ChromeNotifierService", 50 BrowserContextDependencyManager::GetInstance()) {} 51 52 ChromeNotifierServiceFactory::~ChromeNotifierServiceFactory() { 53 } 54 55 BrowserContextKeyedService* 56 ChromeNotifierServiceFactory::BuildServiceInstanceFor( 57 content::BrowserContext* profile) const { 58 NotificationUIManager* notification_manager = 59 g_browser_process->notification_ui_manager(); 60 ChromeNotifierService* chrome_notifier_service = 61 new ChromeNotifierService(static_cast<Profile*>(profile), 62 notification_manager); 63 return chrome_notifier_service; 64 } 65 66 } // namespace notifier 67