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 base::DefaultSingletonTraits
<
53 ProfileInvalidationProviderFactory
>;
55 ProfileInvalidationProviderFactory();
56 ~ProfileInvalidationProviderFactory() override
;
58 // BrowserContextKeyedServiceFactory:
59 KeyedService
* BuildServiceInstanceFor(
60 content::BrowserContext
* context
) const override
;
61 void RegisterProfilePrefs(
62 user_prefs::PrefRegistrySyncable
* registry
) override
;
64 TestingFactoryFunction testing_factory_
;
66 DISALLOW_COPY_AND_ASSIGN(ProfileInvalidationProviderFactory
);
69 } // namespace invalidation
71 #endif // CHROME_BROWSER_INVALIDATION_PROFILE_INVALIDATION_PROVIDER_FACTORY_H_