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.
5 #include "chrome/browser/sessions/session_service_factory.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/sessions/session_data_deleter.h"
9 #include "chrome/browser/sessions/session_service.h"
10 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
13 SessionService
* SessionServiceFactory::GetForProfile(Profile
* profile
) {
14 #if defined(OS_ANDROID)
15 // For Android we do not store sessions in the SessionService.
18 return static_cast<SessionService
*>(
19 GetInstance()->GetServiceForBrowserContext(profile
, true));
24 SessionService
* SessionServiceFactory::GetForProfileIfExisting(
26 #if defined(OS_ANDROID)
27 // For Android we do not store sessions in the SessionService.
30 return static_cast<SessionService
*>(
31 GetInstance()->GetServiceForBrowserContext(profile
, false));
36 SessionService
* SessionServiceFactory::GetForProfileForSessionRestore(
38 SessionService
* service
= GetForProfile(profile
);
40 // If the service has been shutdown, remove the reference to NULL for
41 // |profile| so GetForProfile will recreate it.
42 GetInstance()->Disassociate(profile
);
43 service
= GetForProfile(profile
);
49 void SessionServiceFactory::ShutdownForProfile(Profile
* profile
) {
50 DeleteSessionOnlyData(profile
);
52 // We're about to exit, force creation of the session service if it hasn't
53 // been created yet. We do this to ensure session state matches the point in
54 // time the user exited.
55 SessionServiceFactory
* factory
= GetInstance();
56 factory
->GetServiceForBrowserContext(profile
, true);
58 // Shut down and remove the reference to the session service, and replace it
59 // with an explicit NULL to prevent it being recreated on the next access.
60 factory
->BrowserContextShutdown(profile
);
61 factory
->BrowserContextDestroyed(profile
);
62 factory
->Associate(profile
, NULL
);
65 SessionServiceFactory
* SessionServiceFactory::GetInstance() {
66 return Singleton
<SessionServiceFactory
>::get();
69 SessionServiceFactory::SessionServiceFactory()
70 : BrowserContextKeyedServiceFactory(
72 BrowserContextDependencyManager::GetInstance()) {
75 SessionServiceFactory::~SessionServiceFactory() {
78 BrowserContextKeyedService
* SessionServiceFactory::BuildServiceInstanceFor(
79 content::BrowserContext
* profile
) const {
80 SessionService
* service
= NULL
;
81 service
= new SessionService(static_cast<Profile
*>(profile
));
82 service
->ResetFromCurrentBrowsers();
86 bool SessionServiceFactory::ServiceIsCreatedWithBrowserContext() const {
90 bool SessionServiceFactory::ServiceIsNULLWhileTesting() const {