Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / invalidation / profile_invalidation_provider_factory.h
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.
4
5 #ifndef CHROME_BROWSER_INVALIDATION_PROFILE_INVALIDATION_PROVIDER_FACTORY_H_
6 #define CHROME_BROWSER_INVALIDATION_PROFILE_INVALIDATION_PROVIDER_FACTORY_H_
7
8 #include "base/basictypes.h"
9 #include "base/memory/singleton.h"
10 #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
11
12 namespace policy {
13 class DeviceCloudPolicyInvalidatorTest;
14 }
15
16 namespace user_prefs {
17 class PrefRegistrySyncable;
18 }
19
20 namespace syncer {
21 class Invalidator;
22 }
23
24 class Profile;
25
26 namespace invalidation {
27
28 class ProfileInvalidationProvider;
29
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 {
37  public:
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);
42
43   static ProfileInvalidationProviderFactory* GetInstance();
44
45   // Switches service creation to go through |testing_factory| for all browser
46   // contexts.
47   void RegisterTestingFactory(TestingFactoryFunction testing_factory);
48
49  private:
50   friend class ProfileInvalidationProviderFactoryTestBase;
51   friend class policy::DeviceCloudPolicyInvalidatorTest;
52   friend struct DefaultSingletonTraits<ProfileInvalidationProviderFactory>;
53
54   ProfileInvalidationProviderFactory();
55   ~ProfileInvalidationProviderFactory() override;
56
57   // BrowserContextKeyedServiceFactory:
58   KeyedService* BuildServiceInstanceFor(
59       content::BrowserContext* context) const override;
60   void RegisterProfilePrefs(
61       user_prefs::PrefRegistrySyncable* registry) override;
62
63   TestingFactoryFunction testing_factory_;
64
65   DISALLOW_COPY_AND_ASSIGN(ProfileInvalidationProviderFactory);
66 };
67
68 }  // namespace invalidation
69
70 #endif  // CHROME_BROWSER_INVALIDATION_PROFILE_INVALIDATION_PROVIDER_FACTORY_H_