blob: e9741f9c04473f7a2144a0070227cd1118ad53a4 [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"
avi26062922015-12-26 00:14:1816#include "build/build_config.h"
Scott Violet9ae82892018-03-01 18:38:1217#include "components/gcm_driver/gcm_buildflags.h"
jitendra.ks75541942015-11-03 20:17:5118#include "components/keyed_service/core/keyed_service.h"
Colin Blundellf8789932018-05-22 11:35:5619#include "components/signin/core/browser/profile_oauth2_token_service.h"
Colin Blundelldee2d72a2018-05-07 10:46:5220#include "components/signin/core/browser/signin_manager.h"
jitendra.ks75541942015-11-03 20:17:5121#include "components/version_info/version_info.h"
22
23class PrefService;
jitendra.ks75541942015-11-03 20:17:5124
25namespace base {
26class SequencedTaskRunner;
27}
28
29namespace net {
30class URLRequestContextGetter;
31}
32
Mark Pilgrim7634f5b52018-06-27 19:53:2733namespace network {
34class SharedURLLoaderFactory;
35}
36
jitendra.ks75541942015-11-03 20:17:5137namespace gcm {
38
39class GCMClientFactory;
40class GCMDriver;
41
jitendra.ks75541942015-11-03 20:17:5142// Providing GCM service, via GCMDriver.
43class GCMProfileService : public KeyedService {
44 public:
ralphnathaned5c0e02017-06-14 20:54:5645#if BUILDFLAG(USE_GCM_FROM_PLATFORM)
jitendra.ks75541942015-11-03 20:17:5146 GCMProfileService(
47 base::FilePath path,
48 scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
49#else
50 GCMProfileService(
51 PrefService* prefs,
52 base::FilePath path,
53 net::URLRequestContextGetter* request_context,
Mark Pilgrim7634f5b52018-06-27 19:53:2754 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
jitendra.ks75541942015-11-03 20:17:5155 version_info::Channel channel,
johnme627dc8c72016-08-19 21:49:3956 const std::string& product_category_for_subtypes,
Colin Blundelldee2d72a2018-05-07 10:46:5257 SigninManagerBase* signin_manager,
Colin Blundellf8789932018-05-22 11:35:5658 ProfileOAuth2TokenService* token_service,
dchenga77e28eb2016-04-21 21:34:3759 std::unique_ptr<GCMClientFactory> gcm_client_factory,
jitendra.ks75541942015-11-03 20:17:5160 const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
61 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
62 scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
63#endif
64 ~GCMProfileService() override;
65
66 // Returns whether GCM is enabled.
67 static bool IsGCMEnabled(PrefService* prefs);
68
69 // KeyedService:
70 void Shutdown() override;
71
Peter Beverloo34139462018-04-10 14:18:0672 // For testing purposes.
73 void SetDriverForTesting(std::unique_ptr<GCMDriver> driver);
jitendra.ks75541942015-11-03 20:17:5174
75 GCMDriver* driver() const { return driver_.get(); }
76
77 protected:
78 // Used for constructing fake GCMProfileService for testing purpose.
79 GCMProfileService();
80
81 private:
dchenga77e28eb2016-04-21 21:34:3782 std::unique_ptr<GCMDriver> driver_;
jitendra.ks75541942015-11-03 20:17:5183
ralphnathaned5c0e02017-06-14 20:54:5684#if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
Colin Blundelldee2d72a2018-05-07 10:46:5285 SigninManagerBase* signin_manager_;
Colin Blundellf8789932018-05-22 11:35:5686 ProfileOAuth2TokenService* token_service_;
87
pkastingd3b1a712016-05-20 21:20:1288 net::URLRequestContextGetter* request_context_ = nullptr;
89
90 // Used for both account tracker and GCM.UserSignedIn UMA.
jitendra.ks75541942015-11-03 20:17:5191 class IdentityObserver;
dchenga77e28eb2016-04-21 21:34:3792 std::unique_ptr<IdentityObserver> identity_observer_;
jitendra.ks75541942015-11-03 20:17:5193#endif
94
95 DISALLOW_COPY_AND_ASSIGN(GCMProfileService);
96};
97
98} // namespace gcm
99
100#endif // COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_
101