1 // Copyright 2014 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_PROFILE_INVALIDATION_PROVIDER_FACTORY_H_
6 #define CHROME_BROWSER_INVALIDATION_PROFILE_INVALIDATION_PROVIDER_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"
13 class AffiliatedInvalidationServiceProviderImplTest
;
16 namespace user_prefs
{
17 class PrefRegistrySyncable
;
26 namespace invalidation
{
28 class ProfileInvalidationProvider
;
30 // A BrowserContextKeyedServiceFactory to construct InvalidationServices wrapped
31 // in ProfileInvalidationProviders. The implementation of InvalidationService
32 // may be completely different on different platforms; this class should help to
33 // hide this complexity. It also exposes some factory methods that are useful
34 // for setting up tests that rely on invalidations.
35 class ProfileInvalidationProviderFactory
36 : public BrowserContextKeyedServiceFactory
{
38 // Returns the ProfileInvalidationProvider for the given |profile|, lazily
39 // creating one first if required. If |profile| does not support invalidation
40 // (Chrome OS login profile, Chrome OS guest), returns NULL instead.
41 static ProfileInvalidationProvider
* GetForProfile(Profile
* profile
);
43 static ProfileInvalidationProviderFactory
* GetInstance();
45 // Switches service creation to go through |testing_factory| for all browser
47 void RegisterTestingFactory(TestingFactoryFunction testing_factory
);
50 friend class ProfileInvalidationProviderFactoryTestBase
;
51 friend class policy::AffiliatedInvalidationServiceProviderImplTest
;
52 friend struct DefaultSingletonTraits
<ProfileInvalidationProviderFactory
>;
54 ProfileInvalidationProviderFactory();
55 ~ProfileInvalidationProviderFactory() override
;
57 // BrowserContextKeyedServiceFactory:
58 KeyedService
* BuildServiceInstanceFor(
59 content::BrowserContext
* context
) const override
;
60 void RegisterProfilePrefs(
61 user_prefs::PrefRegistrySyncable
* registry
) override
;
63 TestingFactoryFunction testing_factory_
;
65 DISALLOW_COPY_AND_ASSIGN(ProfileInvalidationProviderFactory
);
68 } // namespace invalidation
70 #endif // CHROME_BROWSER_INVALIDATION_PROFILE_INVALIDATION_PROVIDER_FACTORY_H_