gcm_profile_service.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright (c) 2013 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_GCM_DRIVER_GCM_PROFILE_SERVICE_H_
  5. #define COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/callback_forward.h"
  9. #include "base/compiler_specific.h"
  10. #include "base/files/file_path.h"
  11. #include "base/memory/raw_ptr.h"
  12. #include "base/memory/ref_counted.h"
  13. #include "base/memory/weak_ptr.h"
  14. #include "build/build_config.h"
  15. #include "components/gcm_driver/gcm_buildflags.h"
  16. #include "components/keyed_service/core/keyed_service.h"
  17. #include "components/version_info/version_info.h"
  18. #include "mojo/public/cpp/bindings/pending_receiver.h"
  19. #include "services/network/public/mojom/proxy_resolving_socket.mojom.h"
  20. class PrefService;
  21. namespace base {
  22. class SequencedTaskRunner;
  23. }
  24. namespace signin {
  25. class IdentityManager;
  26. }
  27. namespace network {
  28. class NetworkConnectionTracker;
  29. class SharedURLLoaderFactory;
  30. }
  31. namespace gcm {
  32. class GCMClientFactory;
  33. class GCMDriver;
  34. // Providing GCM service, via GCMDriver.
  35. class GCMProfileService : public KeyedService {
  36. public:
  37. using GetProxyResolvingFactoryCallback = base::RepeatingCallback<void(
  38. mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>;
  39. #if BUILDFLAG(USE_GCM_FROM_PLATFORM)
  40. GCMProfileService(
  41. base::FilePath path,
  42. scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
  43. #else
  44. GCMProfileService(
  45. PrefService* prefs,
  46. base::FilePath path,
  47. base::RepeatingCallback<void(
  48. base::WeakPtr<GCMProfileService>,
  49. mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>
  50. get_socket_factory_callback,
  51. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
  52. network::NetworkConnectionTracker* network_connection_tracker,
  53. version_info::Channel channel,
  54. const std::string& product_category_for_subtypes,
  55. signin::IdentityManager* identity_manager,
  56. std::unique_ptr<GCMClientFactory> gcm_client_factory,
  57. const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
  58. const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
  59. scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
  60. #endif
  61. GCMProfileService(const GCMProfileService&) = delete;
  62. GCMProfileService& operator=(const GCMProfileService&) = delete;
  63. ~GCMProfileService() override;
  64. // KeyedService:
  65. void Shutdown() override;
  66. // For testing purposes.
  67. void SetDriverForTesting(std::unique_ptr<GCMDriver> driver);
  68. GCMDriver* driver() const { return driver_.get(); }
  69. protected:
  70. // Used for constructing fake GCMProfileService for testing purpose.
  71. GCMProfileService();
  72. private:
  73. std::unique_ptr<GCMDriver> driver_;
  74. #if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
  75. raw_ptr<signin::IdentityManager> identity_manager_;
  76. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
  77. // Used for both account tracker and GCM.UserSignedIn UMA.
  78. class IdentityObserver;
  79. std::unique_ptr<IdentityObserver> identity_observer_;
  80. #endif
  81. GetProxyResolvingFactoryCallback get_socket_factory_callback_;
  82. // WeakPtr generated by the factory must be dereferenced on the UI thread.
  83. base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_{this};
  84. };
  85. } // namespace gcm
  86. #endif // COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_