blob: 1cb1b7b82a58d56deee666697df9f1337111eb8a [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2013 The Chromium Authors
jitendra.ks75541942015-11-03 20:17:512// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_
6#define COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_
7
dchenga77e28eb2016-04-21 21:34:378#include <memory>
jitendra.ks75541942015-11-03 20:17:519#include <string>
10
jitendra.ks75541942015-11-03 20:17:5111#include "base/compiler_specific.h"
12#include "base/files/file_path.h"
Avi Drissman12be0312023-01-11 09:16:0913#include "base/functional/callback_forward.h"
Keishi Hattori0e45c022021-11-27 09:25:5214#include "base/memory/raw_ptr.h"
jitendra.ks75541942015-11-03 20:17:5115#include "base/memory/ref_counted.h"
Helen Li5f3d96a2018-08-10 20:37:2416#include "base/memory/weak_ptr.h"
avi26062922015-12-26 00:14:1817#include "build/build_config.h"
Scott Violet9ae82892018-03-01 18:38:1218#include "components/gcm_driver/gcm_buildflags.h"
jitendra.ks75541942015-11-03 20:17:5119#include "components/keyed_service/core/keyed_service.h"
Takuto Ikuta35b64c82023-10-25 09:54:1720#include "components/version_info/channel.h"
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4821#include "mojo/public/cpp/bindings/pending_receiver.h"
Helen Li5f3d96a2018-08-10 20:37:2422#include "services/network/public/mojom/proxy_resolving_socket.mojom.h"
jitendra.ks75541942015-11-03 20:17:5123
24class PrefService;
jitendra.ks75541942015-11-03 20:17:5125
26namespace base {
27class SequencedTaskRunner;
28}
29
Miyoung Shin23737f62019-07-23 15:43:3130namespace signin {
Colin Blundell354f2212018-07-16 14:45:0831class IdentityManager;
32}
33
Mark Pilgrim7634f5b52018-06-27 19:53:2734namespace network {
Robbie McElrathb01499332018-09-25 00:53:1335class NetworkConnectionTracker;
Mark Pilgrim7634f5b52018-06-27 19:53:2736class SharedURLLoaderFactory;
37}
38
jitendra.ks75541942015-11-03 20:17:5139namespace gcm {
40
Rushan Suleymanovb8013dd2023-10-12 12:38:4141class GCMAccountTracker;
jitendra.ks75541942015-11-03 20:17:5142class GCMClientFactory;
43class GCMDriver;
44
jitendra.ks75541942015-11-03 20:17:5145// Providing GCM service, via GCMDriver.
46class GCMProfileService : public KeyedService {
47 public:
Helen Li5f3d96a2018-08-10 20:37:2448 using GetProxyResolvingFactoryCallback = base::RepeatingCallback<void(
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4849 mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>;
Helen Li5f3d96a2018-08-10 20:37:2450
ralphnathaned5c0e02017-06-14 20:54:5651#if BUILDFLAG(USE_GCM_FROM_PLATFORM)
jitendra.ks75541942015-11-03 20:17:5152 GCMProfileService(
53 base::FilePath path,
Alex Chauda2073d62020-01-29 11:26:0854 scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
jitendra.ks75541942015-11-03 20:17:5155#else
56 GCMProfileService(
57 PrefService* prefs,
58 base::FilePath path,
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4859 base::RepeatingCallback<void(
60 base::WeakPtr<GCMProfileService>,
61 mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>
Helen Li5f3d96a2018-08-10 20:37:2462 get_socket_factory_callback,
Mark Pilgrim7634f5b52018-06-27 19:53:2763 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
Robbie McElrathb01499332018-09-25 00:53:1364 network::NetworkConnectionTracker* network_connection_tracker,
jitendra.ks75541942015-11-03 20:17:5165 version_info::Channel channel,
johnme627dc8c72016-08-19 21:49:3966 const std::string& product_category_for_subtypes,
Miyoung Shin23737f62019-07-23 15:43:3167 signin::IdentityManager* identity_manager,
dchenga77e28eb2016-04-21 21:34:3768 std::unique_ptr<GCMClientFactory> gcm_client_factory,
jitendra.ks75541942015-11-03 20:17:5169 const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
70 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
71 scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
72#endif
Peter Boström09c01822021-09-20 22:43:2773
74 GCMProfileService(const GCMProfileService&) = delete;
75 GCMProfileService& operator=(const GCMProfileService&) = delete;
76
jitendra.ks75541942015-11-03 20:17:5177 ~GCMProfileService() override;
78
jitendra.ks75541942015-11-03 20:17:5179 // KeyedService:
80 void Shutdown() override;
81
jitendra.ks75541942015-11-03 20:17:5182 GCMDriver* driver() const { return driver_.get(); }
83
84 protected:
85 // Used for constructing fake GCMProfileService for testing purpose.
Rushan Suleymanov79aba4e2023-01-23 18:14:1686 explicit GCMProfileService(std::unique_ptr<GCMDriver> driver);
jitendra.ks75541942015-11-03 20:17:5187
88 private:
dchenga77e28eb2016-04-21 21:34:3789 std::unique_ptr<GCMDriver> driver_;
jitendra.ks75541942015-11-03 20:17:5190
ralphnathaned5c0e02017-06-14 20:54:5691#if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
Keishi Hattori0e45c022021-11-27 09:25:5292 raw_ptr<signin::IdentityManager> identity_manager_;
Colin Blundellf8789932018-05-22 11:35:5693
Maks Orlovich8db7d0d62018-08-16 19:22:2794 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
pkastingd3b1a712016-05-20 21:20:1295
Rushan Suleymanovb8013dd2023-10-12 12:38:4196 std::unique_ptr<GCMAccountTracker> gcm_account_tracker_;
jitendra.ks75541942015-11-03 20:17:5197#endif
98
Helen Li5f3d96a2018-08-10 20:37:2499 GetProxyResolvingFactoryCallback get_socket_factory_callback_;
100
101 // WeakPtr generated by the factory must be dereferenced on the UI thread.
102 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_{this};
jitendra.ks75541942015-11-03 20:17:51103};
104
105} // namespace gcm
106
107#endif // COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_