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/tab_restore_service_factory.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/sessions/chrome_tab_restore_service_client.h"
9 #include "components/keyed_service/content/browser_context_dependency_manager.h"
11 #if defined(OS_ANDROID)
12 #include "components/sessions/core/in_memory_tab_restore_service.h"
14 #include "components/sessions/core/persistent_tab_restore_service.h"
18 sessions::TabRestoreService
* TabRestoreServiceFactory::GetForProfile(
20 return static_cast<sessions::TabRestoreService
*>(
21 GetInstance()->GetServiceForBrowserContext(profile
, true));
25 sessions::TabRestoreService
* TabRestoreServiceFactory::GetForProfileIfExisting(
27 return static_cast<sessions::TabRestoreService
*>(
28 GetInstance()->GetServiceForBrowserContext(profile
, false));
32 void TabRestoreServiceFactory::ResetForProfile(Profile
* profile
) {
33 TabRestoreServiceFactory
* factory
= GetInstance();
34 factory
->BrowserContextShutdown(profile
);
35 factory
->BrowserContextDestroyed(profile
);
38 TabRestoreServiceFactory
* TabRestoreServiceFactory::GetInstance() {
39 return base::Singleton
<TabRestoreServiceFactory
>::get();
42 TabRestoreServiceFactory::TabRestoreServiceFactory()
43 : BrowserContextKeyedServiceFactory(
44 "sessions::TabRestoreService",
45 BrowserContextDependencyManager::GetInstance()) {}
47 TabRestoreServiceFactory::~TabRestoreServiceFactory() {
50 bool TabRestoreServiceFactory::ServiceIsNULLWhileTesting() const {
54 KeyedService
* TabRestoreServiceFactory::BuildServiceInstanceFor(
55 content::BrowserContext
* browser_context
) const {
56 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
57 DCHECK(!profile
->IsOffTheRecord());
58 scoped_ptr
<sessions::TabRestoreServiceClient
> client(
59 new ChromeTabRestoreServiceClient(profile
));
61 #if defined(OS_ANDROID)
62 return new sessions::InMemoryTabRestoreService(client
.Pass(), nullptr);
64 return new sessions::PersistentTabRestoreService(client
.Pass(), nullptr);