blob: b3305b63ad2240e219f751fa7a92e8d5c7c1f909 [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"
jitendra.ks75541942015-11-03 20:17:5117#include "components/keyed_service/core/keyed_service.h"
18#include "components/signin/core/browser/profile_identity_provider.h"
19#include "components/version_info/version_info.h"
20
21class PrefService;
jitendra.ks75541942015-11-03 20:17:5122
23namespace base {
24class SequencedTaskRunner;
25}
26
27namespace net {
28class URLRequestContextGetter;
29}
30
jitendra.ks75541942015-11-03 20:17:5131namespace gcm {
32
33class GCMClientFactory;
34class GCMDriver;
35
jitendra.ks75541942015-11-03 20:17:5136// Providing GCM service, via GCMDriver.
37class GCMProfileService : public KeyedService {
38 public:
39#if defined(OS_ANDROID)
40 GCMProfileService(
41 base::FilePath path,
42 scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
43#else
44 GCMProfileService(
45 PrefService* prefs,
46 base::FilePath path,
47 net::URLRequestContextGetter* request_context,
48 version_info::Channel channel,
johnme627dc8c72016-08-19 21:49:3949 const std::string& product_category_for_subtypes,
dchenga77e28eb2016-04-21 21:34:3750 std::unique_ptr<ProfileIdentityProvider> identity_provider,
51 std::unique_ptr<GCMClientFactory> gcm_client_factory,
jitendra.ks75541942015-11-03 20:17:5152 const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
53 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
54 scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
55#endif
56 ~GCMProfileService() override;
57
58 // Returns whether GCM is enabled.
59 static bool IsGCMEnabled(PrefService* prefs);
60
61 // KeyedService:
62 void Shutdown() override;
63
64 // For testing purpose.
peterc5634e8f2015-12-02 15:34:5965 void SetDriverForTesting(GCMDriver* driver);
jitendra.ks75541942015-11-03 20:17:5166
67 GCMDriver* driver() const { return driver_.get(); }
68
69 protected:
70 // Used for constructing fake GCMProfileService for testing purpose.
71 GCMProfileService();
72
73 private:
dchenga77e28eb2016-04-21 21:34:3774 std::unique_ptr<ProfileIdentityProvider> profile_identity_provider_;
dchenga77e28eb2016-04-21 21:34:3775 std::unique_ptr<GCMDriver> driver_;
jitendra.ks75541942015-11-03 20:17:5176
jitendra.ks75541942015-11-03 20:17:5177#if !defined(OS_ANDROID)
pkastingd3b1a712016-05-20 21:20:1278 net::URLRequestContextGetter* request_context_ = nullptr;
79
80 // Used for both account tracker and GCM.UserSignedIn UMA.
jitendra.ks75541942015-11-03 20:17:5181 class IdentityObserver;
dchenga77e28eb2016-04-21 21:34:3782 std::unique_ptr<IdentityObserver> identity_observer_;
jitendra.ks75541942015-11-03 20:17:5183#endif
84
85 DISALLOW_COPY_AND_ASSIGN(GCMProfileService);
86};
87
88} // namespace gcm
89
90#endif // COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_
91