blob: 5d41d17a105ae25131d323dfa1b00e9622b60216 [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"
Helen Li5f3d96a2018-08-10 20:37:2421#include "services/network/public/mojom/proxy_resolving_socket.mojom.h"
jitendra.ks75541942015-11-03 20:17:5122
23class PrefService;
jitendra.ks75541942015-11-03 20:17:5124
25namespace base {
26class SequencedTaskRunner;
27}
28
Colin Blundell354f2212018-07-16 14:45:0829namespace identity {
30class IdentityManager;
31}
32
Mark Pilgrim7634f5b52018-06-27 19:53:2733namespace network {
Robbie McElrathb01499332018-09-25 00:53:1334class NetworkConnectionTracker;
Mark Pilgrim7634f5b52018-06-27 19:53:2735class SharedURLLoaderFactory;
36}
37
jitendra.ks75541942015-11-03 20:17:5138namespace gcm {
39
40class GCMClientFactory;
41class GCMDriver;
42
jitendra.ks75541942015-11-03 20:17:5143// Providing GCM service, via GCMDriver.
44class GCMProfileService : public KeyedService {
45 public:
Helen Li5f3d96a2018-08-10 20:37:2446 using GetProxyResolvingFactoryCallback = base::RepeatingCallback<void(
47 network::mojom::ProxyResolvingSocketFactoryRequest)>;
48
ralphnathaned5c0e02017-06-14 20:54:5649#if BUILDFLAG(USE_GCM_FROM_PLATFORM)
jitendra.ks75541942015-11-03 20:17:5150 GCMProfileService(
51 base::FilePath path,
52 scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
53#else
54 GCMProfileService(
55 PrefService* prefs,
56 base::FilePath path,
Helen Li5f3d96a2018-08-10 20:37:2457 base::RepeatingCallback<
58 void(base::WeakPtr<GCMProfileService>,
59 network::mojom::ProxyResolvingSocketFactoryRequest)>
60 get_socket_factory_callback,
Mark Pilgrim7634f5b52018-06-27 19:53:2761 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
Robbie McElrathb01499332018-09-25 00:53:1362 network::NetworkConnectionTracker* network_connection_tracker,
jitendra.ks75541942015-11-03 20:17:5163 version_info::Channel channel,
johnme627dc8c72016-08-19 21:49:3964 const std::string& product_category_for_subtypes,
Colin Blundell354f2212018-07-16 14:45:0865 identity::IdentityManager* identity_manager,
dchenga77e28eb2016-04-21 21:34:3766 std::unique_ptr<GCMClientFactory> gcm_client_factory,
jitendra.ks75541942015-11-03 20:17:5167 const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
68 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
69 scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
70#endif
71 ~GCMProfileService() override;
72
73 // Returns whether GCM is enabled.
74 static bool IsGCMEnabled(PrefService* prefs);
75
76 // KeyedService:
77 void Shutdown() override;
78
Peter Beverloo34139462018-04-10 14:18:0679 // For testing purposes.
80 void SetDriverForTesting(std::unique_ptr<GCMDriver> driver);
jitendra.ks75541942015-11-03 20:17:5181
82 GCMDriver* driver() const { return driver_.get(); }
83
84 protected:
85 // Used for constructing fake GCMProfileService for testing purpose.
86 GCMProfileService();
87
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)
Colin Blundell354f2212018-07-16 14:45:0892 identity::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
96 // Used for both account tracker and GCM.UserSignedIn UMA.
jitendra.ks75541942015-11-03 20:17:5197 class IdentityObserver;
dchenga77e28eb2016-04-21 21:34:3798 std::unique_ptr<IdentityObserver> identity_observer_;
jitendra.ks75541942015-11-03 20:17:5199#endif
100
Helen Li5f3d96a2018-08-10 20:37:24101 GetProxyResolvingFactoryCallback get_socket_factory_callback_;
102
103 // WeakPtr generated by the factory must be dereferenced on the UI thread.
104 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_{this};
105
jitendra.ks75541942015-11-03 20:17:51106 DISALLOW_COPY_AND_ASSIGN(GCMProfileService);
107};
108
109} // namespace gcm
110
111#endif // COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_
112