// // Copyright (C) 2014 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #include "update_engine/update_manager/real_updater_provider.h" #include #include #include #include #include #include #include "update_engine/client_library/include/update_engine/update_status.h" #include "update_engine/common/clock_interface.h" #include "update_engine/common/prefs.h" #include "update_engine/omaha_request_params.h" #include "update_engine/update_attempter.h" #include "update_engine/update_status_utils.h" using base::StringPrintf; using base::Time; using base::TimeDelta; using chromeos_update_engine::OmahaRequestParams; using chromeos_update_engine::SystemState; using std::string; using update_engine::UpdateAttemptFlags; using update_engine::UpdateEngineStatus; namespace chromeos_update_manager { // A templated base class for all update related variables. Provides uniform // construction and a system state handle. template class UpdaterVariableBase : public Variable { public: UpdaterVariableBase(const string& name, VariableMode mode, SystemState* system_state) : Variable(name, mode), system_state_(system_state) {} protected: // The system state used for pulling information from the updater. inline SystemState* system_state() const { return system_state_; } private: SystemState* const system_state_; }; // Helper class for issuing a GetStatus() to the UpdateAttempter. class GetStatusHelper { public: GetStatusHelper(SystemState* system_state, string* errmsg) { is_success_ = system_state->update_attempter()->GetStatus(&update_engine_status_); if (!is_success_ && errmsg) { *errmsg = "Failed to get a status update from the update engine"; } } inline bool is_success() { return is_success_; } inline int64_t last_checked_time() { return update_engine_status_.last_checked_time; } inline double progress() { return update_engine_status_.progress; } inline const string update_status() { return chromeos_update_engine::UpdateStatusToString( update_engine_status_.status); } inline const string& new_version() { return update_engine_status_.new_version; } inline uint64_t payload_size() { return update_engine_status_.new_size_bytes; } private: bool is_success_; UpdateEngineStatus update_engine_status_; }; // A variable reporting the time when a last update check was issued. class LastCheckedTimeVariable : public UpdaterVariableBase