blob: 90b40e1bb66ecdd9fe5c5733e1ac88f64165ed08 [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
jitendra.ks75541942015-11-03 20:17:5133namespace net {
34class URLRequestContextGetter;
35}
36
Mark Pilgrim7634f5b52018-06-27 19:53:2737namespace network {
38class SharedURLLoaderFactory;
39}
40
jitendra.ks75541942015-11-03 20:17:5141namespace gcm {
42
43class GCMClientFactory;
44class GCMDriver;
45
jitendra.ks75541942015-11-03 20:17:5146// Providing GCM service, via GCMDriver.
47class GCMProfileService : public KeyedService {
48 public:
Helen Li5f3d96a2018-08-10 20:37:2449 using GetProxyResolvingFactoryCallback = base::RepeatingCallback<void(
50 network::mojom::ProxyResolvingSocketFactoryRequest)>;
51
ralphnathaned5c0e02017-06-14 20:54:5652#if BUILDFLAG(USE_GCM_FROM_PLATFORM)
jitendra.ks75541942015-11-03 20:17:5153 GCMProfileService(
54 base::FilePath path,
55 scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
56#else
57 GCMProfileService(
58 PrefService* prefs,
59 base::FilePath path,
60 net::URLRequestContextGetter* request_context,
Helen Li5f3d96a2018-08-10 20:37:2461 base::RepeatingCallback<
62 void(base::WeakPtr<GCMProfileService>,
63 network::mojom::ProxyResolvingSocketFactoryRequest)>
64 get_socket_factory_callback,
Mark Pilgrim7634f5b52018-06-27 19:53:2765 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
jitendra.ks75541942015-11-03 20:17:5166 version_info::Channel channel,
johnme627dc8c72016-08-19 21:49:3967 const std::string& product_category_for_subtypes,
Colin Blundell354f2212018-07-16 14:45:0868 identity::IdentityManager* identity_manager,
dchenga77e28eb2016-04-21 21:34:3769 std::unique_ptr<GCMClientFactory> gcm_client_factory,
jitendra.ks75541942015-11-03 20:17:5170 const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
71 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
72 scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
73#endif
74 ~GCMProfileService() override;
75
76 // Returns whether GCM is enabled.
77 static bool IsGCMEnabled(PrefService* prefs);
78
79 // KeyedService:
80 void Shutdown() override;
81
Peter Beverloo34139462018-04-10 14:18:0682 // For testing purposes.
83 void SetDriverForTesting(std::unique_ptr<GCMDriver> driver);
jitendra.ks75541942015-11-03 20:17:5184
85 GCMDriver* driver() const { return driver_.get(); }
86
87 protected:
88 // Used for constructing fake GCMProfileService for testing purpose.
89 GCMProfileService();
90
91 private:
dchenga77e28eb2016-04-21 21:34:3792 std::unique_ptr<GCMDriver> driver_;
jitendra.ks75541942015-11-03 20:17:5193
ralphnathaned5c0e02017-06-14 20:54:5694#if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
Colin Blundell354f2212018-07-16 14:45:0895 identity::IdentityManager* identity_manager_;
Colin Blundellf8789932018-05-22 11:35:5696
Maks Orlovich8db7d0d62018-08-16 19:22:2797 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
pkastingd3b1a712016-05-20 21:20:1298
99 // Used for both account tracker and GCM.UserSignedIn UMA.
jitendra.ks75541942015-11-03 20:17:51100 class IdentityObserver;
dchenga77e28eb2016-04-21 21:34:37101 std::unique_ptr<IdentityObserver> identity_observer_;
jitendra.ks75541942015-11-03 20:17:51102#endif
103
Helen Li5f3d96a2018-08-10 20:37:24104 GetProxyResolvingFactoryCallback get_socket_factory_callback_;
105
106 // WeakPtr generated by the factory must be dereferenced on the UI thread.
107 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_{this};
108
jitendra.ks75541942015-11-03 20:17:51109 DISALLOW_COPY_AND_ASSIGN(GCMProfileService);
110};
111
112} // namespace gcm
113
114#endif // COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_
115