Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 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 Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 16 | |
Gilad Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_ |
| 18 | #define UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_ |
| 19 | |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 20 | #include <memory> |
Gilad Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 21 | #include <string> |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 22 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 23 | #include "update_engine/update_manager/generic_variables.h" |
| 24 | #include "update_engine/update_manager/updater_provider.h" |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 25 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 26 | namespace chromeos_update_manager { |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 27 | |
| 28 | // A concrete UpdaterProvider implementation using local (in-process) bindings. |
| 29 | class RealUpdaterProvider : public UpdaterProvider { |
| 30 | public: |
| 31 | // We assume that any other object handle we get from the system state is |
| 32 | // "volatile", and so must be re-acquired whenever access is needed; this |
| 33 | // guarantees that parts of the system state can be mocked out at any time |
| 34 | // during testing. We further assume that, by the time Init() is called, the |
| 35 | // system state object is fully populated and usable. |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 36 | RealUpdaterProvider(); |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 37 | |
Alex Deymo | 42c30c3 | 2014-04-24 18:41:18 -0700 | [diff] [blame] | 38 | // Initializes the provider and returns whether it succeeded. |
| 39 | bool Init() { return true; } |
| 40 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 41 | Variable<base::Time>* var_updater_started_time() override { |
Alex Deymo | c7ab616 | 2014-04-25 18:32:50 -0700 | [diff] [blame] | 42 | return &var_updater_started_time_; |
| 43 | } |
| 44 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 45 | Variable<base::Time>* var_last_checked_time() override { |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 46 | return var_last_checked_time_.get(); |
| 47 | } |
| 48 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 49 | Variable<base::Time>* var_update_completed_time() override { |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 50 | return var_update_completed_time_.get(); |
| 51 | } |
| 52 | |
Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 53 | Variable<double>* var_progress() override { return var_progress_.get(); } |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 54 | |
Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 55 | Variable<Stage>* var_stage() override { return var_stage_.get(); } |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 56 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 57 | Variable<std::string>* var_new_version() override { |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 58 | return var_new_version_.get(); |
| 59 | } |
| 60 | |
Aaron Wood | 7f92e2b | 2017-08-28 14:51:21 -0700 | [diff] [blame] | 61 | Variable<uint64_t>* var_payload_size() override { |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 62 | return var_payload_size_.get(); |
| 63 | } |
| 64 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 65 | Variable<std::string>* var_curr_channel() override { |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 66 | return var_curr_channel_.get(); |
| 67 | } |
| 68 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 69 | Variable<std::string>* var_new_channel() override { |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 70 | return var_new_channel_.get(); |
| 71 | } |
| 72 | |
Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 73 | Variable<bool>* var_p2p_enabled() override { return var_p2p_enabled_.get(); } |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 74 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 75 | Variable<bool>* var_cellular_enabled() override { |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 76 | return var_cellular_enabled_.get(); |
| 77 | } |
| 78 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 79 | Variable<unsigned int>* var_consecutive_failed_update_checks() override { |
Gilad Arnold | a6dab94 | 2014-04-25 11:46:03 -0700 | [diff] [blame] | 80 | return var_consecutive_failed_update_checks_.get(); |
| 81 | } |
| 82 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 83 | Variable<unsigned int>* var_server_dictated_poll_interval() override { |
Gilad Arnold | a0258a5 | 2014-07-10 16:21:19 -0700 | [diff] [blame] | 84 | return var_server_dictated_poll_interval_.get(); |
| 85 | } |
| 86 | |
Gilad Arnold | ec7f916 | 2014-07-15 13:24:46 -0700 | [diff] [blame] | 87 | Variable<UpdateRequestStatus>* var_forced_update_requested() override { |
| 88 | return var_forced_update_requested_.get(); |
Gilad Arnold | 44dc3bf | 2014-07-18 23:39:38 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Aaron Wood | bf5a252 | 2017-10-04 10:58:36 -0700 | [diff] [blame] | 91 | Variable<UpdateRestrictions>* var_update_restrictions() override { |
| 92 | return var_update_restrictions_.get(); |
| 93 | } |
| 94 | |
Amin Hassani | 03277de | 2020-07-28 12:32:49 -0700 | [diff] [blame] | 95 | Variable<int64_t>* var_test_update_check_interval_timeout() override { |
| 96 | return var_test_update_check_interval_timeout_.get(); |
| 97 | } |
| 98 | |
David Zeuthen | 21716e2 | 2014-04-23 15:42:05 -0700 | [diff] [blame] | 99 | private: |
Alex Deymo | c7ab616 | 2014-04-25 18:32:50 -0700 | [diff] [blame] | 100 | // Variable implementations. |
| 101 | ConstCopyVariable<base::Time> var_updater_started_time_; |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 102 | std::unique_ptr<Variable<base::Time>> var_last_checked_time_; |
| 103 | std::unique_ptr<Variable<base::Time>> var_update_completed_time_; |
| 104 | std::unique_ptr<Variable<double>> var_progress_; |
| 105 | std::unique_ptr<Variable<Stage>> var_stage_; |
| 106 | std::unique_ptr<Variable<std::string>> var_new_version_; |
Aaron Wood | 7f92e2b | 2017-08-28 14:51:21 -0700 | [diff] [blame] | 107 | std::unique_ptr<Variable<uint64_t>> var_payload_size_; |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 108 | std::unique_ptr<Variable<std::string>> var_curr_channel_; |
| 109 | std::unique_ptr<Variable<std::string>> var_new_channel_; |
| 110 | std::unique_ptr<Variable<bool>> var_p2p_enabled_; |
| 111 | std::unique_ptr<Variable<bool>> var_cellular_enabled_; |
| 112 | std::unique_ptr<Variable<unsigned int>> var_consecutive_failed_update_checks_; |
| 113 | std::unique_ptr<Variable<unsigned int>> var_server_dictated_poll_interval_; |
| 114 | std::unique_ptr<Variable<UpdateRequestStatus>> var_forced_update_requested_; |
Aaron Wood | bf5a252 | 2017-10-04 10:58:36 -0700 | [diff] [blame] | 115 | std::unique_ptr<Variable<UpdateRestrictions>> var_update_restrictions_; |
Amin Hassani | 03277de | 2020-07-28 12:32:49 -0700 | [diff] [blame] | 116 | std::unique_ptr<Variable<int64_t>> var_test_update_check_interval_timeout_; |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 117 | |
| 118 | DISALLOW_COPY_AND_ASSIGN(RealUpdaterProvider); |
| 119 | }; |
| 120 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 121 | } // namespace chromeos_update_manager |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 122 | |
Gilad Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 123 | #endif // UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_ |