Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / sessions / session_service_factory.cc
blob99a7e8b7f40ea0a03d993b045405b50515078663
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/keyed_service/content/browser_context_dependency_manager.h"
12 // static
13 SessionService* SessionServiceFactory::GetForProfile(Profile* profile) {
14 #if defined(OS_ANDROID)
15 // For Android we do not store sessions in the SessionService.
16 return NULL;
17 #else
18 return static_cast<SessionService*>(
19 GetInstance()->GetServiceForBrowserContext(profile, true));
20 #endif
23 // static
24 SessionService* SessionServiceFactory::GetForProfileIfExisting(
25 Profile* profile) {
26 #if defined(OS_ANDROID)
27 // For Android we do not store sessions in the SessionService.
28 return NULL;
29 #else
30 return static_cast<SessionService*>(
31 GetInstance()->GetServiceForBrowserContext(profile, false));
32 #endif
35 // static
36 SessionService* SessionServiceFactory::GetForProfileForSessionRestore(
37 Profile* profile) {
38 SessionService* service = GetForProfile(profile);
39 if (!service) {
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);
45 return service;
48 // static
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(
71 "SessionService",
72 BrowserContextDependencyManager::GetInstance()) {
75 SessionServiceFactory::~SessionServiceFactory() {
78 KeyedService* SessionServiceFactory::BuildServiceInstanceFor(
79 content::BrowserContext* profile) const {
80 SessionService* service = NULL;
81 service = new SessionService(static_cast<Profile*>(profile));
82 service->ResetFromCurrentBrowsers();
83 return service;
86 bool SessionServiceFactory::ServiceIsCreatedWithBrowserContext() const {
87 return true;
90 bool SessionServiceFactory::ServiceIsNULLWhileTesting() const {
91 return true;