/chrome/browser/sessions/session_service_factory.cc

https://gitlab.com/jonnialva90/iridium-browser · C++ · 92 lines · 62 code · 14 blank · 16 comment · 1 complexity · 9e25f53e272edadbe8f8de42dd0046a5 MD5 · raw file

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