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 12namespace policy { 13class DeviceCloudPolicyInvalidatorTest; 14} 15 16namespace user_prefs { 17class PrefRegistrySyncable; 18} 19 20namespace syncer { 21class Invalidator; 22} 23 24class Profile; 25 26namespace invalidation { 27 28class 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. 35class 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 virtual ~ProfileInvalidationProviderFactory(); 56 57 // BrowserContextKeyedServiceFactory: 58 virtual KeyedService* BuildServiceInstanceFor( 59 content::BrowserContext* context) const OVERRIDE; 60 virtual 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_ 71