blob: 0f6956d3e9b3097500a31c29188c7adee2fd3f4f [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 Chaua76a6e32019-06-26 16:20:0153 scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
54 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
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
73 ~GCMProfileService() override;
74
75 // Returns whether GCM is enabled.
76 static bool IsGCMEnabled(PrefService* prefs);
77
78 // 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};
107
jitendra.ks75541942015-11-03 20:17:51108 DISALLOW_COPY_AND_ASSIGN(GCMProfileService);
109};
110
111} // namespace gcm
112
113#endif // COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_