profile_invalidation_provider.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifndef COMPONENTS_INVALIDATION_IMPL_PROFILE_INVALIDATION_PROVIDER_H_
  5. #define COMPONENTS_INVALIDATION_IMPL_PROFILE_INVALIDATION_PROVIDER_H_
  6. #include <memory>
  7. #include <string>
  8. #include <unordered_map>
  9. #include "base/compiler_specific.h"
  10. #include "components/invalidation/impl/profile_identity_provider.h"
  11. #include "components/keyed_service/core/keyed_service.h"
  12. namespace user_prefs {
  13. class PrefRegistrySyncable;
  14. }
  15. namespace invalidation {
  16. class InvalidationService;
  17. // A KeyedService that owns an InvalidationService.
  18. class ProfileInvalidationProvider : public KeyedService {
  19. public:
  20. using CustomSenderInvalidationServiceFactory =
  21. base::RepeatingCallback<std::unique_ptr<InvalidationService>(
  22. const std::string&)>;
  23. ProfileInvalidationProvider(
  24. std::unique_ptr<InvalidationService> invalidation_service,
  25. std::unique_ptr<IdentityProvider> identity_provider,
  26. CustomSenderInvalidationServiceFactory
  27. custom_sender_invalidation_service_factory = {});
  28. ProfileInvalidationProvider(const ProfileInvalidationProvider& other) =
  29. delete;
  30. ProfileInvalidationProvider& operator=(
  31. const ProfileInvalidationProvider& other) = delete;
  32. ~ProfileInvalidationProvider() override;
  33. // Returns the common Profile-wide InvalidationService; this should be used
  34. // when using the deprecated invalidation provider or the FCM invalidation
  35. // provider for Chrome Sync.
  36. InvalidationService* GetInvalidationService();
  37. // Returns the InvalidationService specific to |sender_id|. This should be
  38. // used with the FCM invalidation provider for senders other than Chrome Sync.
  39. InvalidationService* GetInvalidationServiceForCustomSender(
  40. const std::string& sender_id);
  41. IdentityProvider* GetIdentityProvider();
  42. // KeyedService:
  43. void Shutdown() override;
  44. // Register prefs to be used by per-Profile instances of this class which
  45. // store invalidation state in Profile prefs.
  46. static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
  47. private:
  48. // The order of members |identity_provider_| and |invalidation_service_|
  49. // shouldn't change. The reason is that service has a pointer to the
  50. // provider. So this particular order in the declarations ensures order
  51. // in destruction.
  52. std::unique_ptr<IdentityProvider> identity_provider_;
  53. std::unique_ptr<InvalidationService> invalidation_service_;
  54. CustomSenderInvalidationServiceFactory
  55. custom_sender_invalidation_service_factory_;
  56. std::unordered_map<std::string, std::unique_ptr<InvalidationService>>
  57. custom_sender_invalidation_services_;
  58. };
  59. } // namespace invalidation
  60. #endif // COMPONENTS_INVALIDATION_IMPL_PROFILE_INVALIDATION_PROVIDER_H_