OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_SERVICE_FACTORY_H_ | 5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_SERVICE_FACTORY_H_ |
6 #define CHROME_BROWSER_SESSIONS_SESSION_SERVICE_FACTORY_H_ | 6 #define CHROME_BROWSER_SESSIONS_SESSION_SERVICE_FACTORY_H_ |
7 | 7 |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "chrome/browser/sessions/session_service.h" | 9 #include "chrome/browser/sessions/session_service.h" |
10 #include "components/browser_context_keyed_service/browser_context_keyed_service
_factory.h" | 10 #include "components/browser_context_keyed_service/browser_context_keyed_service
_factory.h" |
11 | 11 |
12 class Profile; | 12 class Profile; |
13 | 13 |
14 // Singleton that owns all SessionServices and associates them with | 14 // Singleton that owns all SessionServices and associates them with |
15 // Profiles. Listens for the Profile's destruction notification and cleans up | 15 // Profiles. Listens for the Profile's destruction notification and cleans up |
16 // the associated SessionService. | 16 // the associated SessionService. |
17 class SessionServiceFactory : public ProfileKeyedServiceFactory { | 17 class SessionServiceFactory : public BrowserContextKeyedServiceFactory { |
18 public: | 18 public: |
19 // Returns the session service for |profile|. This may return NULL. If this | 19 // Returns the session service for |profile|. This may return NULL. If this |
20 // profile supports a session service (it isn't incognito), and the session | 20 // profile supports a session service (it isn't incognito), and the session |
21 // service hasn't yet been created, this forces creation of the session | 21 // service hasn't yet been created, this forces creation of the session |
22 // service. | 22 // service. |
23 // | 23 // |
24 // This returns NULL if the profile is incognito. Callers should always check | 24 // This returns NULL if the profile is incognito. Callers should always check |
25 // the return value for NULL. | 25 // the return value for NULL. |
26 static SessionService* GetForProfile(Profile* profile); | 26 static SessionService* GetForProfile(Profile* profile); |
27 | 27 |
28 // Returns the session service for |profile|, but do not create it if it | 28 // Returns the session service for |profile|, but do not create it if it |
29 // doesn't exist. This returns NULL if the profile is incognito or if session | 29 // doesn't exist. This returns NULL if the profile is incognito or if session |
30 // service has been explicitly shutdown (browser is exiting). Callers should | 30 // service has been explicitly shutdown (browser is exiting). Callers should |
31 // always check the return value for NULL. | 31 // always check the return value for NULL. |
32 static SessionService* GetForProfileIfExisting(Profile* profile); | 32 static SessionService* GetForProfileIfExisting(Profile* profile); |
33 | 33 |
34 // If |profile| has a session service, it is shut down. To properly record the | 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 | 35 // current state this forces creation of the session service, then shuts it |
36 // down. | 36 // down. |
37 static void ShutdownForProfile(Profile* profile); | 37 static void ShutdownForProfile(Profile* profile); |
38 | 38 |
39 #if defined(UNIT_TEST) | 39 #if defined(UNIT_TEST) |
40 // For test use: force setting of the session service for a given profile. | 40 // For test use: force setting of the session service for a given profile. |
41 // This will delete a previous session service for this profile if it exists. | 41 // This will delete a previous session service for this profile if it exists. |
42 static void SetForTestProfile(Profile* profile, SessionService* service) { | 42 static void SetForTestProfile(Profile* profile, SessionService* service) { |
43 GetInstance()->ProfileShutdown(profile); | 43 GetInstance()->BrowserContextShutdown(profile); |
44 GetInstance()->ProfileDestroyed(profile); | 44 GetInstance()->BrowserContextDestroyed(profile); |
45 GetInstance()->Associate(profile, service); | 45 GetInstance()->Associate(profile, service); |
46 } | 46 } |
47 #endif | 47 #endif |
48 | 48 |
49 static SessionServiceFactory* GetInstance(); | 49 static SessionServiceFactory* GetInstance(); |
50 | 50 |
51 private: | 51 private: |
52 friend struct DefaultSingletonTraits<SessionServiceFactory>; | 52 friend struct DefaultSingletonTraits<SessionServiceFactory>; |
53 | 53 |
54 SessionServiceFactory(); | 54 SessionServiceFactory(); |
55 virtual ~SessionServiceFactory(); | 55 virtual ~SessionServiceFactory(); |
56 | 56 |
57 // ProfileKeyedServiceFactory: | 57 // BrowserContextKeyedServiceFactory: |
58 virtual ProfileKeyedService* BuildServiceInstanceFor( | 58 virtual BrowserContextKeyedService* BuildServiceInstanceFor( |
59 content::BrowserContext* profile) const OVERRIDE; | 59 content::BrowserContext* profile) const OVERRIDE; |
60 virtual bool ServiceIsCreatedWithProfile() const OVERRIDE; | 60 virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE; |
61 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; | 61 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; |
62 }; | 62 }; |
63 | 63 |
64 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_FACTORY_H_ | 64 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_FACTORY_H_ |
OLD | NEW |