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 // 16 17 #ifndef UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_ 18 #define UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_ 19 20 #include <memory> 21 #include <string> 22 23 #include "update_engine/system_state.h" 24 #include "update_engine/update_manager/generic_variables.h" 25 #include "update_engine/update_manager/updater_provider.h" 26 27 namespace chromeos_update_manager { 28 29 // A concrete UpdaterProvider implementation using local (in-process) bindings. 30 class 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 40 // Initializes the provider and returns whether it succeeded. Init()41 bool Init() { return true; } 42 var_updater_started_time()43 Variable<base::Time>* var_updater_started_time() override { 44 return &var_updater_started_time_; 45 } 46 var_last_checked_time()47 Variable<base::Time>* var_last_checked_time() override { 48 return var_last_checked_time_.get(); 49 } 50 var_update_completed_time()51 Variable<base::Time>* var_update_completed_time() override { 52 return var_update_completed_time_.get(); 53 } 54 var_progress()55 Variable<double>* var_progress() override { return var_progress_.get(); } 56 var_stage()57 Variable<Stage>* var_stage() override { return var_stage_.get(); } 58 var_new_version()59 Variable<std::string>* var_new_version() override { 60 return var_new_version_.get(); 61 } 62 var_payload_size()63 Variable<uint64_t>* var_payload_size() override { 64 return var_payload_size_.get(); 65 } 66 var_curr_channel()67 Variable<std::string>* var_curr_channel() override { 68 return var_curr_channel_.get(); 69 } 70 var_new_channel()71 Variable<std::string>* var_new_channel() override { 72 return var_new_channel_.get(); 73 } 74 var_p2p_enabled()75 Variable<bool>* var_p2p_enabled() override { return var_p2p_enabled_.get(); } 76 var_cellular_enabled()77 Variable<bool>* var_cellular_enabled() override { 78 return var_cellular_enabled_.get(); 79 } 80 var_consecutive_failed_update_checks()81 Variable<unsigned int>* var_consecutive_failed_update_checks() override { 82 return var_consecutive_failed_update_checks_.get(); 83 } 84 var_server_dictated_poll_interval()85 Variable<unsigned int>* var_server_dictated_poll_interval() override { 86 return var_server_dictated_poll_interval_.get(); 87 } 88 var_forced_update_requested()89 Variable<UpdateRequestStatus>* var_forced_update_requested() override { 90 return var_forced_update_requested_.get(); 91 } 92 var_update_restrictions()93 Variable<UpdateRestrictions>* var_update_restrictions() override { 94 return var_update_restrictions_.get(); 95 } 96 97 private: 98 // A pointer to the update engine's system state aggregator. 99 chromeos_update_engine::SystemState* system_state_; 100 101 // Variable implementations. 102 ConstCopyVariable<base::Time> var_updater_started_time_; 103 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_; 108 std::unique_ptr<Variable<uint64_t>> var_payload_size_; 109 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_; 116 std::unique_ptr<Variable<UpdateRestrictions>> var_update_restrictions_; 117 118 DISALLOW_COPY_AND_ASSIGN(RealUpdaterProvider); 119 }; 120 121 } // namespace chromeos_update_manager 122 123 #endif // UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_ 124