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/sessions/session_service_factory.h" 6 7 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/sessions/session_service.h" 9 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" 10 11 // static 12 SessionService* SessionServiceFactory::GetForProfile(Profile* profile) { 13 #if defined(OS_ANDROID) 14 // For Android we do not store sessions in the SessionService. 15 return NULL; 16 #else 17 return static_cast<SessionService*>( 18 GetInstance()->GetServiceForBrowserContext(profile, true)); 19 #endif 20 } 21 22 // static 23 SessionService* SessionServiceFactory::GetForProfileIfExisting( 24 Profile* profile) { 25 #if defined(OS_ANDROID) 26 // For Android we do not store sessions in the SessionService. 27 return NULL; 28 #else 29 return static_cast<SessionService*>( 30 GetInstance()->GetServiceForBrowserContext(profile, false)); 31 #endif 32 } 33 34 // static 35 void SessionServiceFactory::ShutdownForProfile(Profile* profile) { 36 // We're about to exit, force creation of the session service if it hasn't 37 // been created yet. We do this to ensure session state matches the point in 38 // time the user exited. 39 SessionServiceFactory* factory = GetInstance(); 40 factory->GetServiceForBrowserContext(profile, true); 41 42 // Shut down and remove the reference to the session service, and replace it 43 // with an explicit NULL to prevent it being recreated on the next access. 44 factory->BrowserContextShutdown(profile); 45 factory->BrowserContextDestroyed(profile); 46 factory->Associate(profile, NULL); 47 } 48 49 SessionServiceFactory* SessionServiceFactory::GetInstance() { 50 return Singleton<SessionServiceFactory>::get(); 51 } 52 53 SessionServiceFactory::SessionServiceFactory() 54 : BrowserContextKeyedServiceFactory( 55 "SessionService", 56 BrowserContextDependencyManager::GetInstance()) { 57 } 58 59 SessionServiceFactory::~SessionServiceFactory() { 60 } 61 62 BrowserContextKeyedService* SessionServiceFactory::BuildServiceInstanceFor( 63 content::BrowserContext* profile) const { 64 SessionService* service = NULL; 65 service = new SessionService(static_cast<Profile*>(profile)); 66 service->ResetFromCurrentBrowsers(); 67 return service; 68 } 69 70 bool SessionServiceFactory::ServiceIsCreatedWithBrowserContext() const { 71 return true; 72 } 73 74 bool SessionServiceFactory::ServiceIsNULLWhileTesting() const { 75 return true; 76 } 77