blob: 6a3bc1970fe54dada4542acc65508a3796e97c1a [file] [log] [blame]
Gilad Arnoldae47a9a2014-03-26 12:16:47 -07001// Copyright (c) 2014 The Chromium OS 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
Gilad Arnold48415f12014-06-27 07:10:58 -07005#ifndef UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_
6#define UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_
7
8#include <string>
Gilad Arnoldae47a9a2014-03-26 12:16:47 -07009
Alex Deymo1f012912014-04-24 19:08:04 -070010#include <base/memory/scoped_ptr.h>
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070011
12#include "update_engine/system_state.h"
Alex Deymo63784a52014-05-28 10:46:14 -070013#include "update_engine/update_manager/generic_variables.h"
14#include "update_engine/update_manager/updater_provider.h"
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070015
Alex Deymo63784a52014-05-28 10:46:14 -070016namespace chromeos_update_manager {
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070017
18// A concrete UpdaterProvider implementation using local (in-process) bindings.
19class RealUpdaterProvider : public UpdaterProvider {
20 public:
21 // We assume that any other object handle we get from the system state is
22 // "volatile", and so must be re-acquired whenever access is needed; this
23 // guarantees that parts of the system state can be mocked out at any time
24 // during testing. We further assume that, by the time Init() is called, the
25 // system state object is fully populated and usable.
26 explicit RealUpdaterProvider(
27 chromeos_update_engine::SystemState* system_state);
28
Alex Deymo42c30c32014-04-24 18:41:18 -070029 // Initializes the provider and returns whether it succeeded.
30 bool Init() { return true; }
31
Alex Deymoc7ab6162014-04-25 18:32:50 -070032 virtual Variable<base::Time>* var_updater_started_time() override {
33 return &var_updater_started_time_;
34 }
35
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070036 virtual Variable<base::Time>* var_last_checked_time() override {
37 return var_last_checked_time_.get();
38 }
39
40 virtual Variable<base::Time>* var_update_completed_time() override {
41 return var_update_completed_time_.get();
42 }
43
44 virtual Variable<double>* var_progress() override {
45 return var_progress_.get();
46 }
47
48 virtual Variable<Stage>* var_stage() override {
49 return var_stage_.get();
50 }
51
52 virtual Variable<std::string>* var_new_version() override {
53 return var_new_version_.get();
54 }
55
Alex Deymof967ebe2014-05-05 14:46:17 -070056 virtual Variable<int64_t>* var_payload_size() override {
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070057 return var_payload_size_.get();
58 }
59
60 virtual Variable<std::string>* var_curr_channel() override {
61 return var_curr_channel_.get();
62 }
63
64 virtual Variable<std::string>* var_new_channel() override {
65 return var_new_channel_.get();
66 }
67
68 virtual Variable<bool>* var_p2p_enabled() override {
69 return var_p2p_enabled_.get();
70 }
71
72 virtual Variable<bool>* var_cellular_enabled() override {
73 return var_cellular_enabled_.get();
74 }
75
Gilad Arnolda6dab942014-04-25 11:46:03 -070076 virtual Variable<unsigned int>*
77 var_consecutive_failed_update_checks() override {
78 return var_consecutive_failed_update_checks_.get();
79 }
80
Gilad Arnolda0258a52014-07-10 16:21:19 -070081 virtual Variable<unsigned int>*
82 var_server_dictated_poll_interval() override {
83 return var_server_dictated_poll_interval_.get();
84 }
85
Gilad Arnold44dc3bf2014-07-18 23:39:38 -070086 virtual Variable<bool>* var_interactive_update_requested() override {
87 return var_interactive_update_requested_.get();
88 }
89
David Zeuthen21716e22014-04-23 15:42:05 -070090 private:
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070091 // A pointer to the update engine's system state aggregator.
92 chromeos_update_engine::SystemState* system_state_;
93
Alex Deymoc7ab6162014-04-25 18:32:50 -070094 // Variable implementations.
95 ConstCopyVariable<base::Time> var_updater_started_time_;
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070096 scoped_ptr<Variable<base::Time>> var_last_checked_time_;
97 scoped_ptr<Variable<base::Time>> var_update_completed_time_;
98 scoped_ptr<Variable<double>> var_progress_;
99 scoped_ptr<Variable<Stage>> var_stage_;
100 scoped_ptr<Variable<std::string>> var_new_version_;
Alex Deymof967ebe2014-05-05 14:46:17 -0700101 scoped_ptr<Variable<int64_t>> var_payload_size_;
Gilad Arnoldae47a9a2014-03-26 12:16:47 -0700102 scoped_ptr<Variable<std::string>> var_curr_channel_;
103 scoped_ptr<Variable<std::string>> var_new_channel_;
104 scoped_ptr<Variable<bool>> var_p2p_enabled_;
105 scoped_ptr<Variable<bool>> var_cellular_enabled_;
Gilad Arnolda6dab942014-04-25 11:46:03 -0700106 scoped_ptr<Variable<unsigned int>> var_consecutive_failed_update_checks_;
Gilad Arnolda0258a52014-07-10 16:21:19 -0700107 scoped_ptr<Variable<unsigned int>> var_server_dictated_poll_interval_;
Gilad Arnold44dc3bf2014-07-18 23:39:38 -0700108 scoped_ptr<Variable<bool>> var_interactive_update_requested_;
Gilad Arnoldae47a9a2014-03-26 12:16:47 -0700109
110 DISALLOW_COPY_AND_ASSIGN(RealUpdaterProvider);
111};
112
Alex Deymo63784a52014-05-28 10:46:14 -0700113} // namespace chromeos_update_manager
Gilad Arnoldae47a9a2014-03-26 12:16:47 -0700114
Gilad Arnold48415f12014-06-27 07:10:58 -0700115#endif // UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_