blob: 26442a60292a5a5a88a445e89afe9129e1ab2d3b [file] [log] [blame]
jitendra.ks75541942015-11-03 20:17:511// 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
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
11#include "base/callback_forward.h"
12#include "base/compiler_specific.h"
13#include "base/files/file_path.h"
14#include "base/macros.h"
15#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"
jitendra.ks75541942015-11-03 20:17:5120#include "components/version_info/version_info.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
41class GCMClientFactory;
42class GCMDriver;
43
jitendra.ks75541942015-11-03 20:17:5144// Providing GCM service, via GCMDriver.
45class GCMProfileService : public KeyedService {
46 public:
Helen Li5f3d96a2018-08-10 20:37:2447 using GetProxyResolvingFactoryCallback = base::RepeatingCallback<void(
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4848 mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>;
Helen Li5f3d96a2018-08-10 20:37:2449
ralphnathaned5c0e02017-06-14 20:54:5650#if BUILDFLAG(USE_GCM_FROM_PLATFORM)
jitendra.ks75541942015-11-03 20:17:5151 GCMProfileService(
52 base::FilePath path,
Alex Chauda2073d62020-01-29 11:26:0853 scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
jitendra.ks75541942015-11-03 20:17:5154#else
55 GCMProfileService(
56 PrefService* prefs,
57 base::FilePath path,
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4858 base::RepeatingCallback<void(
59 base::WeakPtr<GCMProfileService>,
60 mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>
Helen Li5f3d96a2018-08-10 20:37:2461 get_socket_factory_callback,
Mark Pilgrim7634f5b52018-06-27 19:53:2762 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
Robbie McElrathb01499332018-09-25 00:53:1363 network::NetworkConnectionTracker* network_connection_tracker,
jitendra.ks75541942015-11-03 20:17:5164 version_info::Channel channel,
johnme627dc8c72016-08-19 21:49:3965 const std::string& product_category_for_subtypes,
Miyoung Shin23737f62019-07-23 15:43:3166 signin::IdentityManager* identity_manager,
dchenga77e28eb2016-04-21 21:34:3767 std::unique_ptr<GCMClientFactory> gcm_client_factory,
jitendra.ks75541942015-11-03 20:17:5168 const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
69 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
70 scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
71#endif
Peter Boström09c01822021-09-20 22:43:2772
73 GCMProfileService(const GCMProfileService&) = delete;
74 GCMProfileService& operator=(const GCMProfileService&) = delete;
75
jitendra.ks75541942015-11-03 20:17:5176 ~GCMProfileService() override;
77
jitendra.ks75541942015-11-03 20:17:5178 // KeyedService:
79 void Shutdown() override;
80
Peter Beverloo34139462018-04-10 14:18:0681 // For testing purposes.
82 void SetDriverForTesting(std::unique_ptr<GCMDriver> driver);
jitendra.ks75541942015-11-03 20:17:5183
84 GCMDriver* driver() const { return driver_.get(); }
85
86 protected:
87 // Used for constructing fake GCMProfileService for testing purpose.
88 GCMProfileService();
89
90 private:
dchenga77e28eb2016-04-21 21:34:3791 std::unique_ptr<GCMDriver> driver_;
jitendra.ks75541942015-11-03 20:17:5192
ralphnathaned5c0e02017-06-14 20:54:5693#if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
Miyoung Shin23737f62019-07-23 15:43:3194 signin::IdentityManager* identity_manager_;
Colin Blundellf8789932018-05-22 11:35:5695
Maks Orlovich8db7d0d62018-08-16 19:22:2796 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
pkastingd3b1a712016-05-20 21:20:1297
98 // Used for both account tracker and GCM.UserSignedIn UMA.
jitendra.ks75541942015-11-03 20:17:5199 class IdentityObserver;
dchenga77e28eb2016-04-21 21:34:37100 std::unique_ptr<IdentityObserver> identity_observer_;
jitendra.ks75541942015-11-03 20:17:51101#endif
102
Helen Li5f3d96a2018-08-10 20:37:24103 GetProxyResolvingFactoryCallback get_socket_factory_callback_;
104
105 // WeakPtr generated by the factory must be dereferenced on the UI thread.
106 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_{this};
jitendra.ks75541942015-11-03 20:17:51107};
108
109} // namespace gcm
110
111#endif // COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_