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