1 // Copyright (c) 2012 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/desktop_notification_service_factory.h" 6 7 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/notifications/desktop_notification_service.h" 9 #include "chrome/browser/profiles/incognito_helpers.h" 10 #include "chrome/browser/profiles/profile.h" 11 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" 12 #include "content/public/browser/browser_thread.h" 13 14 using content::BrowserThread; 15 16 // static 17 DesktopNotificationService* DesktopNotificationServiceFactory::GetForProfile( 18 Profile* profile) { 19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 20 return static_cast<DesktopNotificationService*>( 21 GetInstance()->GetServiceForBrowserContext(profile, true)); 22 } 23 24 // static 25 DesktopNotificationServiceFactory* DesktopNotificationServiceFactory:: 26 GetInstance() { 27 return Singleton<DesktopNotificationServiceFactory>::get(); 28 } 29 30 DesktopNotificationServiceFactory::DesktopNotificationServiceFactory() 31 : BrowserContextKeyedServiceFactory( 32 "DesktopNotificationService", 33 BrowserContextDependencyManager::GetInstance()) { 34 } 35 36 DesktopNotificationServiceFactory::~DesktopNotificationServiceFactory() { 37 } 38 39 BrowserContextKeyedService* 40 DesktopNotificationServiceFactory::BuildServiceInstanceFor( 41 content::BrowserContext* profile) const { 42 DesktopNotificationService* service = 43 new DesktopNotificationService(static_cast<Profile*>(profile), NULL); 44 return service; 45 } 46 47 content::BrowserContext* 48 DesktopNotificationServiceFactory::GetBrowserContextToUse( 49 content::BrowserContext* context) const { 50 return chrome::GetBrowserContextOwnInstanceInIncognito(context); 51 } 52