/chrome/browser/sessions/session_service_factory.h

https://gitlab.com/jonnialva90/iridium-browser · C Header · 73 lines · 34 code · 12 blank · 27 comment · 0 complexity · c6097f37df026f4ff8bedede1d8d6b7d 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. #ifndef CHROME_BROWSER_SESSIONS_SESSION_SERVICE_FACTORY_H_
  5. #define CHROME_BROWSER_SESSIONS_SESSION_SERVICE_FACTORY_H_
  6. #include "base/gtest_prod_util.h"
  7. #include "base/memory/singleton.h"
  8. #include "chrome/browser/profiles/profile.h"
  9. #include "chrome/browser/sessions/session_service.h"
  10. #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
  11. // Singleton that owns all SessionServices and associates them with
  12. // Profiles. Listens for the Profile's destruction notification and cleans up
  13. // the associated SessionService.
  14. class SessionServiceFactory : public BrowserContextKeyedServiceFactory {
  15. public:
  16. // Returns the session service for |profile|. This may return NULL. If this
  17. // profile supports a session service (it isn't incognito), and the session
  18. // service hasn't yet been created, this forces creation of the session
  19. // service. This returns NULL if ShutdownForProfile has been called for
  20. // |profile|.
  21. //
  22. // This returns NULL if the profile is incognito. Callers should always check
  23. // the return value for NULL.
  24. static SessionService* GetForProfile(Profile* profile);
  25. // Returns the session service for |profile|, but do not create it if it
  26. // doesn't exist. This returns NULL if the profile is incognito or if session
  27. // service has been explicitly shutdown (browser is exiting). Callers should
  28. // always check the return value for NULL.
  29. static SessionService* GetForProfileIfExisting(Profile* profile);
  30. // Returns the session service for |profile|. This is the same as
  31. // GetForProfile, but will force creation of the session service even if
  32. // ShutdownForProfile has been called for |profile|.
  33. static SessionService* GetForProfileForSessionRestore(Profile* profile);
  34. // If |profile| has a session service, it is shut down. To properly record the
  35. // current state this forces creation of the session service, then shuts it
  36. // down.
  37. static void ShutdownForProfile(Profile* profile);
  38. #if defined(UNIT_TEST)
  39. // For test use: force setting of the session service for a given profile.
  40. // This will delete a previous session service for this profile if it exists.
  41. static void SetForTestProfile(Profile* profile,
  42. scoped_ptr<SessionService> service) {
  43. GetInstance()->BrowserContextShutdown(profile);
  44. GetInstance()->BrowserContextDestroyed(profile);
  45. GetInstance()->Associate(profile, service.Pass());
  46. }
  47. #endif
  48. static SessionServiceFactory* GetInstance();
  49. private:
  50. friend struct base::DefaultSingletonTraits<SessionServiceFactory>;
  51. FRIEND_TEST_ALL_PREFIXES(SessionCrashedInfoBarDelegateUnitTest,
  52. DetachingTabWithCrashedInfoBar);
  53. SessionServiceFactory();
  54. ~SessionServiceFactory() override;
  55. // BrowserContextKeyedServiceFactory:
  56. KeyedService* BuildServiceInstanceFor(
  57. content::BrowserContext* profile) const override;
  58. bool ServiceIsCreatedWithBrowserContext() const override;
  59. bool ServiceIsNULLWhileTesting() const override;
  60. };
  61. #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_FACTORY_H_