OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/profiles/profile_keyed_service_factory.h" | 9 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
10 #include "chrome/browser/sessions/session_service.h" | 10 #include "chrome/browser/sessions/session_service.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 ProfileKeyedServiceFactory { |
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 in two situations: the profile is incognito, or the | 24 // This returns NULL if the profile is incognito. Callers should always check |
25 // session service has been explicitly shutdown (browser is exiting). Callers | 25 // the return value for NULL. |
26 // should always check the return value for NULL. | |
27 static SessionService* GetForProfile(Profile* profile); | 26 static SessionService* GetForProfile(Profile* profile); |
28 | 27 |
29 // 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 |
30 // doesn't exist. | 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 |
| 31 // always check the return value for NULL. |
31 static SessionService* GetForProfileIfExisting(Profile* profile); | 32 static SessionService* GetForProfileIfExisting(Profile* profile); |
32 | 33 |
33 // 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 |
34 // 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 |
35 // down. | 36 // down. |
36 static void ShutdownForProfile(Profile* profile); | 37 static void ShutdownForProfile(Profile* profile); |
37 | 38 |
38 #if defined(UNIT_TEST) | 39 #if defined(UNIT_TEST) |
39 // 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. |
40 // 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. |
(...skipping 13 matching lines...) Expand all Loading... |
54 virtual ~SessionServiceFactory(); | 55 virtual ~SessionServiceFactory(); |
55 | 56 |
56 // ProfileKeyedServiceFactory: | 57 // ProfileKeyedServiceFactory: |
57 virtual ProfileKeyedService* BuildServiceInstanceFor( | 58 virtual ProfileKeyedService* BuildServiceInstanceFor( |
58 Profile* profile) const OVERRIDE; | 59 Profile* profile) const OVERRIDE; |
59 virtual bool ServiceIsCreatedWithProfile() OVERRIDE; | 60 virtual bool ServiceIsCreatedWithProfile() OVERRIDE; |
60 virtual bool ServiceIsNULLWhileTesting() OVERRIDE; | 61 virtual bool ServiceIsNULLWhileTesting() OVERRIDE; |
61 }; | 62 }; |
62 | 63 |
63 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_FACTORY_H_ | 64 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_FACTORY_H_ |
OLD | NEW |