OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_INVALIDATION_INVALIDATION_SERVICE_FACTORY_H_ | 5 #ifndef CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_FACTORY_H_ |
6 #define CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_FACTORY_H_ | 6 #define CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_FACTORY_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.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 namespace user_prefs { |
| 13 class PrefRegistrySyncable; |
| 14 } |
| 15 |
12 namespace syncer { | 16 namespace syncer { |
13 class Invalidator; | 17 class Invalidator; |
14 } | 18 } |
15 | 19 |
16 class InvalidationFrontend; | 20 class InvalidationService; |
17 class Profile; | 21 class Profile; |
18 | 22 |
19 namespace invalidation { | 23 namespace invalidation { |
20 | 24 |
| 25 class InvalidationService; |
| 26 class P2PInvalidationService; |
| 27 class FakeInvalidationService; |
| 28 |
21 // A ProfileKeyedServiceFactory to construct InvalidationServices. The | 29 // A ProfileKeyedServiceFactory to construct InvalidationServices. The |
22 // implementation of the InvalidationService may be completely different on | 30 // implementation of the InvalidationService may be completely different on |
23 // different platforms; this class should help to hide this complexity. It also | 31 // different platforms; this class should help to hide this complexity. It also |
24 // exposes some factory methods that are useful for setting up tests that rely | 32 // exposes some factory methods that are useful for setting up tests that rely |
25 // on invalidations. | 33 // on invalidations. |
26 class InvalidationServiceFactory : public ProfileKeyedServiceFactory { | 34 class InvalidationServiceFactory : public ProfileKeyedServiceFactory { |
27 public: | 35 public: |
28 // TODO(rlarocque): Re-enable this once InvalidationFrontend can extend | 36 static InvalidationService* GetForProfile(Profile* profile); |
29 // ProfileKeyedService. | |
30 // static InvalidationFrontend* GetForProfile(Profile* profile); | |
31 | 37 |
32 static InvalidationServiceFactory* GetInstance(); | 38 static InvalidationServiceFactory* GetInstance(); |
33 | 39 |
34 static ProfileKeyedService* BuildP2PInvalidationServiceFor(Profile* profile); | 40 // A helper function to set this factory to return a FakeInvalidationService. |
35 static ProfileKeyedService* BuildTestServiceInstanceFor(Profile* profile); | 41 void SetFakeInvalidationServiceForTest(content::BrowserContext* context); |
| 42 |
| 43 // These helper functions to set the factory to build a test-only type of |
| 44 // invalidator and return the instance immeidately. |
| 45 P2PInvalidationService* BuildAndUseP2PInvalidationServiceForTest( |
| 46 content::BrowserContext* context); |
| 47 FakeInvalidationService* BuildAndUseFakeInvalidationServiceForTest( |
| 48 content::BrowserContext* context); |
36 | 49 |
37 private: | 50 private: |
38 friend struct DefaultSingletonTraits<InvalidationServiceFactory>; | 51 friend struct DefaultSingletonTraits<InvalidationServiceFactory>; |
39 | 52 |
40 InvalidationServiceFactory(); | 53 InvalidationServiceFactory(); |
41 virtual ~InvalidationServiceFactory(); | 54 virtual ~InvalidationServiceFactory(); |
42 | 55 |
43 // ProfileKeyedServiceFactory: | 56 // ProfileKeyedServiceFactory: |
44 virtual ProfileKeyedService* BuildServiceInstanceFor( | 57 virtual ProfileKeyedService* BuildServiceInstanceFor( |
45 content::BrowserContext* profile) const OVERRIDE; | 58 content::BrowserContext* context) const OVERRIDE; |
46 // TODO(rlarocque): Use this class, not InvalidatorStorage, to register | 59 virtual void RegisterUserPrefs( |
47 // for user prefs. | 60 user_prefs::PrefRegistrySyncable* registry) OVERRIDE; |
48 // virtual void RegisterUserPrefs(PrefRegistrySyncable* registry) OVERRIDE; | |
49 | 61 |
50 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceFactory); | 62 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceFactory); |
51 }; | 63 }; |
52 | 64 |
53 } // namespace invalidation | 65 } // namespace invalidation |
54 | 66 |
55 #endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_FACTORY_H_ | 67 #endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_FACTORY_H_ |
OLD | NEW |