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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_FACTORY_H_
6 #define CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_FACTORY_H_
8 #include "base/basictypes.h"
9 #include "base/memory/singleton.h"
10 #include "components/browser_context_keyed_service/browser_context_keyed_service_factory.h"
12 namespace user_prefs
{
13 class PrefRegistrySyncable
;
22 namespace invalidation
{
24 class InvalidationService
;
25 class P2PInvalidationService
;
26 class FakeInvalidationService
;
28 // A BrowserContextKeyedServiceFactory to construct InvalidationServices. The
29 // implementation of the InvalidationService may be completely different on
30 // different platforms; this class should help to hide this complexity. It also
31 // exposes some factory methods that are useful for setting up tests that rely
33 class InvalidationServiceFactory
: public BrowserContextKeyedServiceFactory
{
35 static InvalidationService
* GetForProfile(Profile
* profile
);
37 static InvalidationServiceFactory
* GetInstance();
39 // A helper function to set this factory to return FakeInvalidationServices
40 // instead of the default InvalidationService objects.
41 void SetBuildOnlyFakeInvalidatorsForTest(bool test_mode_enabled
);
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
);
49 friend struct DefaultSingletonTraits
<InvalidationServiceFactory
>;
51 InvalidationServiceFactory();
52 virtual ~InvalidationServiceFactory();
54 // BrowserContextKeyedServiceFactory:
55 virtual BrowserContextKeyedService
* BuildServiceInstanceFor(
56 content::BrowserContext
* context
) const OVERRIDE
;
57 virtual void RegisterProfilePrefs(
58 user_prefs::PrefRegistrySyncable
* registry
) OVERRIDE
;
60 // If true, this factory will return only FakeInvalidationService instances.
61 bool build_fake_invalidators_
;
63 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceFactory
);
66 } // namespace invalidation
68 #endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_FACTORY_H_