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