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/keyed_service/content/browser_context_keyed_service_factory.h"
12 namespace user_prefs
{
13 class PrefRegistrySyncable
;
22 namespace invalidation
{
24 class FakeInvalidationService
;
25 class InvalidationService
;
26 class P2PInvalidationService
;
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 // Returns the InvalidationService for the given |profile|, lazily creating
36 // one first if required. If |profile| does not support invalidation
37 // (Chrome OS login profile, Chrome OS guest), returns NULL instead.
38 static InvalidationService
* GetForProfile(Profile
* profile
);
40 static InvalidationServiceFactory
* GetInstance();
42 // Switches service creation to go through |testing_factory| for all browser
44 void RegisterTestingFactory(TestingFactoryFunction testing_factory
);
47 friend class InvalidationServiceFactoryTestBase
;
48 friend struct DefaultSingletonTraits
<InvalidationServiceFactory
>;
50 InvalidationServiceFactory();
51 virtual ~InvalidationServiceFactory();
53 // BrowserContextKeyedServiceFactory:
54 virtual KeyedService
* BuildServiceInstanceFor(
55 content::BrowserContext
* context
) const OVERRIDE
;
56 virtual void RegisterProfilePrefs(
57 user_prefs::PrefRegistrySyncable
* registry
) OVERRIDE
;
59 TestingFactoryFunction testing_factory_
;
61 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceFactory
);
64 } // namespace invalidation
66 #endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_FACTORY_H_