blob: 1b46895650ed8a71dcb85e6c4fdec78058ed9c3a [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2014 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070016
Gilad Arnold48415f12014-06-27 07:10:58 -070017#ifndef UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_
18#define UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_
19
Ben Chan02f7c1d2014-10-18 15:18:02 -070020#include <memory>
Gilad Arnold48415f12014-06-27 07:10:58 -070021#include <string>
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070022
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070023#include "update_engine/system_state.h"
Alex Deymo63784a52014-05-28 10:46:14 -070024#include "update_engine/update_manager/generic_variables.h"
25#include "update_engine/update_manager/updater_provider.h"
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070026
Alex Deymo63784a52014-05-28 10:46:14 -070027namespace chromeos_update_manager {
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070028
29// A concrete UpdaterProvider implementation using local (in-process) bindings.
30class RealUpdaterProvider : public UpdaterProvider {
31 public:
32 // We assume that any other object handle we get from the system state is
33 // "volatile", and so must be re-acquired whenever access is needed; this
34 // guarantees that parts of the system state can be mocked out at any time
35 // during testing. We further assume that, by the time Init() is called, the
36 // system state object is fully populated and usable.
37 explicit RealUpdaterProvider(
38 chromeos_update_engine::SystemState* system_state);
39
Alex Deymo42c30c32014-04-24 18:41:18 -070040 // Initializes the provider and returns whether it succeeded.
41 bool Init() { return true; }
42
Alex Vakulenko157fe302014-08-11 15:59:58 -070043 Variable<base::Time>* var_updater_started_time() override {
Alex Deymoc7ab6162014-04-25 18:32:50 -070044 return &var_updater_started_time_;
45 }
46
Alex Vakulenko157fe302014-08-11 15:59:58 -070047 Variable<base::Time>* var_last_checked_time() override {
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070048 return var_last_checked_time_.get();
49 }
50
Alex Vakulenko157fe302014-08-11 15:59:58 -070051 Variable<base::Time>* var_update_completed_time() override {
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070052 return var_update_completed_time_.get();
53 }
54
Amin Hassani4b717432019-01-14 16:24:20 -080055 Variable<double>* var_progress() override { return var_progress_.get(); }
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070056
Amin Hassani4b717432019-01-14 16:24:20 -080057 Variable<Stage>* var_stage() override { return var_stage_.get(); }
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070058
Alex Vakulenko157fe302014-08-11 15:59:58 -070059 Variable<std::string>* var_new_version() override {
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070060 return var_new_version_.get();
61 }
62
Aaron Wood7f92e2b2017-08-28 14:51:21 -070063 Variable<uint64_t>* var_payload_size() override {
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070064 return var_payload_size_.get();
65 }
66
Alex Vakulenko157fe302014-08-11 15:59:58 -070067 Variable<std::string>* var_curr_channel() override {
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070068 return var_curr_channel_.get();
69 }
70
Alex Vakulenko157fe302014-08-11 15:59:58 -070071 Variable<std::string>* var_new_channel() override {
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070072 return var_new_channel_.get();
73 }
74
Amin Hassani4b717432019-01-14 16:24:20 -080075 Variable<bool>* var_p2p_enabled() override { return var_p2p_enabled_.get(); }
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070076
Alex Vakulenko157fe302014-08-11 15:59:58 -070077 Variable<bool>* var_cellular_enabled() override {
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070078 return var_cellular_enabled_.get();
79 }
80
Alex Vakulenko157fe302014-08-11 15:59:58 -070081 Variable<unsigned int>* var_consecutive_failed_update_checks() override {
Gilad Arnolda6dab942014-04-25 11:46:03 -070082 return var_consecutive_failed_update_checks_.get();
83 }
84
Alex Vakulenko157fe302014-08-11 15:59:58 -070085 Variable<unsigned int>* var_server_dictated_poll_interval() override {
Gilad Arnolda0258a52014-07-10 16:21:19 -070086 return var_server_dictated_poll_interval_.get();
87 }
88
Gilad Arnoldec7f9162014-07-15 13:24:46 -070089 Variable<UpdateRequestStatus>* var_forced_update_requested() override {
90 return var_forced_update_requested_.get();
Gilad Arnold44dc3bf2014-07-18 23:39:38 -070091 }
92
Aaron Woodbf5a2522017-10-04 10:58:36 -070093 Variable<UpdateRestrictions>* var_update_restrictions() override {
94 return var_update_restrictions_.get();
95 }
96
David Zeuthen21716e22014-04-23 15:42:05 -070097 private:
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070098 // A pointer to the update engine's system state aggregator.
99 chromeos_update_engine::SystemState* system_state_;
100
Alex Deymoc7ab6162014-04-25 18:32:50 -0700101 // Variable implementations.
102 ConstCopyVariable<base::Time> var_updater_started_time_;
Ben Chan02f7c1d2014-10-18 15:18:02 -0700103 std::unique_ptr<Variable<base::Time>> var_last_checked_time_;
104 std::unique_ptr<Variable<base::Time>> var_update_completed_time_;
105 std::unique_ptr<Variable<double>> var_progress_;
106 std::unique_ptr<Variable<Stage>> var_stage_;
107 std::unique_ptr<Variable<std::string>> var_new_version_;
Aaron Wood7f92e2b2017-08-28 14:51:21 -0700108 std::unique_ptr<Variable<uint64_t>> var_payload_size_;
Ben Chan02f7c1d2014-10-18 15:18:02 -0700109 std::unique_ptr<Variable<std::string>> var_curr_channel_;
110 std::unique_ptr<Variable<std::string>> var_new_channel_;
111 std::unique_ptr<Variable<bool>> var_p2p_enabled_;
112 std::unique_ptr<Variable<bool>> var_cellular_enabled_;
113 std::unique_ptr<Variable<unsigned int>> var_consecutive_failed_update_checks_;
114 std::unique_ptr<Variable<unsigned int>> var_server_dictated_poll_interval_;
115 std::unique_ptr<Variable<UpdateRequestStatus>> var_forced_update_requested_;
Aaron Woodbf5a2522017-10-04 10:58:36 -0700116 std::unique_ptr<Variable<UpdateRestrictions>> var_update_restrictions_;
Gilad Arnoldae47a9a2014-03-26 12:16:47 -0700117
118 DISALLOW_COPY_AND_ASSIGN(RealUpdaterProvider);
119};
120
Alex Deymo63784a52014-05-28 10:46:14 -0700121} // namespace chromeos_update_manager
Gilad Arnoldae47a9a2014-03-26 12:16:47 -0700122
Gilad Arnold48415f12014-06-27 07:10:58 -0700123#endif // UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_