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 | |
| 8 | #include <string> |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 9 | |
Alex Deymo | 1f01291 | 2014-04-24 19:08:04 -0700 | [diff] [blame] | 10 | #include <base/memory/scoped_ptr.h> |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 11 | |
| 12 | #include "update_engine/system_state.h" |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 13 | #include "update_engine/update_manager/generic_variables.h" |
| 14 | #include "update_engine/update_manager/updater_provider.h" |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 15 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 16 | namespace chromeos_update_manager { |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 17 | |
| 18 | // A concrete UpdaterProvider implementation using local (in-process) bindings. |
| 19 | class 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 Deymo | 42c30c3 | 2014-04-24 18:41:18 -0700 | [diff] [blame] | 29 | // Initializes the provider and returns whether it succeeded. |
| 30 | bool Init() { return true; } |
| 31 | |
Alex Deymo | c7ab616 | 2014-04-25 18:32:50 -0700 | [diff] [blame] | 32 | virtual Variable<base::Time>* var_updater_started_time() override { |
| 33 | return &var_updater_started_time_; |
| 34 | } |
| 35 | |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 36 | 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 Deymo | f967ebe | 2014-05-05 14:46:17 -0700 | [diff] [blame] | 56 | virtual Variable<int64_t>* var_payload_size() override { |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 57 | 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 Arnold | a6dab94 | 2014-04-25 11:46:03 -0700 | [diff] [blame] | 76 | virtual Variable<unsigned int>* |
| 77 | var_consecutive_failed_update_checks() override { |
| 78 | return var_consecutive_failed_update_checks_.get(); |
| 79 | } |
| 80 | |
Gilad Arnold | a0258a5 | 2014-07-10 16:21:19 -0700 | [diff] [blame] | 81 | virtual Variable<unsigned int>* |
| 82 | var_server_dictated_poll_interval() override { |
| 83 | return var_server_dictated_poll_interval_.get(); |
| 84 | } |
| 85 | |
Gilad Arnold | 44dc3bf | 2014-07-18 23:39:38 -0700 | [diff] [blame^] | 86 | virtual Variable<bool>* var_interactive_update_requested() override { |
| 87 | return var_interactive_update_requested_.get(); |
| 88 | } |
| 89 | |
David Zeuthen | 21716e2 | 2014-04-23 15:42:05 -0700 | [diff] [blame] | 90 | private: |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 91 | // A pointer to the update engine's system state aggregator. |
| 92 | chromeos_update_engine::SystemState* system_state_; |
| 93 | |
Alex Deymo | c7ab616 | 2014-04-25 18:32:50 -0700 | [diff] [blame] | 94 | // Variable implementations. |
| 95 | ConstCopyVariable<base::Time> var_updater_started_time_; |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 96 | 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 Deymo | f967ebe | 2014-05-05 14:46:17 -0700 | [diff] [blame] | 101 | scoped_ptr<Variable<int64_t>> var_payload_size_; |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 102 | 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 Arnold | a6dab94 | 2014-04-25 11:46:03 -0700 | [diff] [blame] | 106 | scoped_ptr<Variable<unsigned int>> var_consecutive_failed_update_checks_; |
Gilad Arnold | a0258a5 | 2014-07-10 16:21:19 -0700 | [diff] [blame] | 107 | scoped_ptr<Variable<unsigned int>> var_server_dictated_poll_interval_; |
Gilad Arnold | 44dc3bf | 2014-07-18 23:39:38 -0700 | [diff] [blame^] | 108 | scoped_ptr<Variable<bool>> var_interactive_update_requested_; |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 109 | |
| 110 | DISALLOW_COPY_AND_ASSIGN(RealUpdaterProvider); |
| 111 | }; |
| 112 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 113 | } // namespace chromeos_update_manager |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 114 | |
Gilad Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 115 | #endif // UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_ |