1aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 2aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Copyright (C) 2012 The Android Open Source Project 3aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 4aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Licensed under the Apache License, Version 2.0 (the "License"); 5aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// you may not use this file except in compliance with the License. 6aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// You may obtain a copy of the License at 7aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 8aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// http://www.apache.org/licenses/LICENSE-2.0 9aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 10aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Unless required by applicable law or agreed to in writing, software 11aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// distributed under the License is distributed on an "AS IS" BASIS, 12aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// See the License for the specific language governing permissions and 14aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// limitations under the License. 15aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 16a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov 17cf175a098081f3f0e9ca52d997a7ce1585c14c2dGilad Arnold#ifndef UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H_ 18cf175a098081f3f0e9ca52d997a7ce1585c14c2dGilad Arnold#define UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H_ 19a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov 209abb763fa3840d69cc1098c0233162557a7f99eaBen Chan#include <stdint.h> 219abb763fa3840d69cc1098c0233162557a7f99eaBen Chan 22a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov#include <string> 23a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov 2405735a1879a553153458aae0a25fa5d42e3e408fBen Chan#include <base/macros.h> 2575039d7397f03dff77bdf4e26398049ff88edc4cAlex Vakulenko#include <base/time/time.h> 2649d91329a3a84d7e2b35f6e1ffc8a9b4d478515bDarin Petkov#include <gtest/gtest_prod.h> // for FRIEND_TEST 27a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov 2839910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#include "update_engine/common/platform_constants.h" 29856166594771c61973856f563e622ccb7dd48aa1Alex Deymo#include "update_engine/image_properties.h" 30ac41a82e4be1be43913292d13d58b5eb2c572f53Alex Deymo 31a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov// This gathers local system information and prepares info used by the 32a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov// Omaha request action. 33a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov 34a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkovnamespace chromeos_update_engine { 35a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov 36ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasanclass SystemState; 37ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 38ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan// This class encapsulates the data Omaha gets for the request, along with 39ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan// essential state needed for the processing of the request/response. The 40ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan// strings in this struct should not be XML escaped. 41ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan// 42d2779df63aaad8b65fc5d4badee7dbc9bed7f2b6Alex Vakulenko// TODO(jaysri): chromium-os:39752 tracks the need to rename this class to 43ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan// reflect its lifetime more appropriately. 44ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasanclass OmahaRequestParams { 45ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan public: 46d2779df63aaad8b65fc5d4badee7dbc9bed7f2b6Alex Vakulenko explicit OmahaRequestParams(SystemState* system_state) 47ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan : system_state_(system_state), 48ac41a82e4be1be43913292d13d58b5eb2c572f53Alex Deymo os_platform_(constants::kOmahaPlatformName), 49ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan os_version_(kOsVersion), 50ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan delta_okay_(true), 51ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan interactive_(false), 52ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan wall_clock_based_wait_enabled_(false), 53ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan update_check_count_wait_enabled_(false), 54ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan min_update_checks_needed_(kDefaultMinUpdateChecks), 55856166594771c61973856f563e622ccb7dd48aa1Alex Deymo max_update_checks_allowed_(kDefaultMaxUpdateChecks) {} 56ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 57ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan OmahaRequestParams(SystemState* system_state, 58ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan const std::string& in_os_platform, 59a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov const std::string& in_os_version, 60a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov const std::string& in_os_sp, 61a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov const std::string& in_os_board, 62a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov const std::string& in_app_id, 63a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov const std::string& in_app_version, 64a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov const std::string& in_app_lang, 65ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan const std::string& in_target_channel, 66ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan const std::string& in_hwid, 67c1972483fa3446852b42ce97d1ea43b9caaaf56fChris Sosa const std::string& in_fw_version, 68c1972483fa3446852b42ce97d1ea43b9caaaf56fChris Sosa const std::string& in_ec_version, 690a70874c61118a2b276edc731ad890c6826be2beJay Srinivasan bool in_delta_okay, 70bbdd4909bcd20448ad89aa1e02c936e42aedf548Gilad Arnold bool in_interactive, 710a70874c61118a2b276edc731ad890c6826be2beJay Srinivasan const std::string& in_update_url, 7274b5f55e6ff608857664fe151f54d78bfe0b75bbGilad Arnold const std::string& in_target_version_prefix) 73ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan : system_state_(system_state), 74ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan os_platform_(in_os_platform), 75ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan os_version_(in_os_version), 76ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan os_sp_(in_os_sp), 77ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan app_lang_(in_app_lang), 78ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan hwid_(in_hwid), 79c1972483fa3446852b42ce97d1ea43b9caaaf56fChris Sosa fw_version_(in_fw_version), 80c1972483fa3446852b42ce97d1ea43b9caaaf56fChris Sosa ec_version_(in_ec_version), 81ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan delta_okay_(in_delta_okay), 82ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan interactive_(in_interactive), 83ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan update_url_(in_update_url), 84ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan target_version_prefix_(in_target_version_prefix), 85ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan wall_clock_based_wait_enabled_(false), 86ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan update_check_count_wait_enabled_(false), 87ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan min_update_checks_needed_(kDefaultMinUpdateChecks), 88856166594771c61973856f563e622ccb7dd48aa1Alex Deymo max_update_checks_allowed_(kDefaultMaxUpdateChecks) { 89856166594771c61973856f563e622ccb7dd48aa1Alex Deymo image_props_.board = in_os_board; 90856166594771c61973856f563e622ccb7dd48aa1Alex Deymo image_props_.product_id = in_app_id; 91856166594771c61973856f563e622ccb7dd48aa1Alex Deymo image_props_.canary_product_id = in_app_id; 92856166594771c61973856f563e622ccb7dd48aa1Alex Deymo image_props_.version = in_app_version; 93856166594771c61973856f563e622ccb7dd48aa1Alex Deymo image_props_.current_channel = in_target_channel; 94856166594771c61973856f563e622ccb7dd48aa1Alex Deymo mutable_image_props_.target_channel = in_target_channel; 95856166594771c61973856f563e622ccb7dd48aa1Alex Deymo mutable_image_props_.is_powerwash_allowed = false; 96856166594771c61973856f563e622ccb7dd48aa1Alex Deymo } 97ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 983be05c82442b2fbab693b6399f64610e8542462bAlex Deymo virtual ~OmahaRequestParams(); 99e89487039d0eca8130d822cabf75a729609509e0Alex Deymo 100ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // Setters and getters for the various properties. 101ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline std::string os_platform() const { return os_platform_; } 102ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline std::string os_version() const { return os_version_; } 103ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline std::string os_sp() const { return os_sp_; } 104856166594771c61973856f563e622ccb7dd48aa1Alex Deymo inline std::string os_board() const { return image_props_.board; } 105856166594771c61973856f563e622ccb7dd48aa1Alex Deymo inline std::string board_app_id() const { return image_props_.product_id; } 106856166594771c61973856f563e622ccb7dd48aa1Alex Deymo inline std::string canary_app_id() const { 107856166594771c61973856f563e622ccb7dd48aa1Alex Deymo return image_props_.canary_product_id; 108856166594771c61973856f563e622ccb7dd48aa1Alex Deymo } 109ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline std::string app_lang() const { return app_lang_; } 110ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline std::string hwid() const { return hwid_; } 111c1972483fa3446852b42ce97d1ea43b9caaaf56fChris Sosa inline std::string fw_version() const { return fw_version_; } 112c1972483fa3446852b42ce97d1ea43b9caaaf56fChris Sosa inline std::string ec_version() const { return ec_version_; } 113ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 114ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline void set_app_version(const std::string& version) { 115856166594771c61973856f563e622ccb7dd48aa1Alex Deymo image_props_.version = version; 116ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan } 117856166594771c61973856f563e622ccb7dd48aa1Alex Deymo inline std::string app_version() const { return image_props_.version; } 118ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 119856166594771c61973856f563e622ccb7dd48aa1Alex Deymo inline std::string current_channel() const { 120856166594771c61973856f563e622ccb7dd48aa1Alex Deymo return image_props_.current_channel; 121856166594771c61973856f563e622ccb7dd48aa1Alex Deymo } 122856166594771c61973856f563e622ccb7dd48aa1Alex Deymo inline std::string target_channel() const { 123856166594771c61973856f563e622ccb7dd48aa1Alex Deymo return mutable_image_props_.target_channel; 124856166594771c61973856f563e622ccb7dd48aa1Alex Deymo } 1251c0fe79c7ef2b43946d756b54c8505d2bf48b93bJay Srinivasan inline std::string download_channel() const { return download_channel_; } 126ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 127ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // Can client accept a delta ? 128ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline void set_delta_okay(bool ok) { delta_okay_ = ok; } 129ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline bool delta_okay() const { return delta_okay_; } 130ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 131ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // True if this is a user-initiated update check. 132968d057f7a37bc981e2a732fb07521cfc8dcb16aChris Sosa inline void set_interactive(bool interactive) { interactive_ = interactive; } 133ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline bool interactive() const { return interactive_; } 134ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 135ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline void set_update_url(const std::string& url) { update_url_ = url; } 136ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline std::string update_url() const { return update_url_; } 137ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 138ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline void set_target_version_prefix(const std::string& prefix) { 139ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan target_version_prefix_ = prefix; 140ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan } 141ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 142ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline std::string target_version_prefix() const { 143ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan return target_version_prefix_; 144ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan } 145ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 146ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline void set_wall_clock_based_wait_enabled(bool enabled) { 147ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan wall_clock_based_wait_enabled_ = enabled; 148ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan } 149ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline bool wall_clock_based_wait_enabled() const { 150ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan return wall_clock_based_wait_enabled_; 151ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan } 152ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 153ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline void set_waiting_period(base::TimeDelta period) { 154ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan waiting_period_ = period; 155ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan } 156ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan base::TimeDelta waiting_period() const { return waiting_period_; } 157ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 158ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline void set_update_check_count_wait_enabled(bool enabled) { 159ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan update_check_count_wait_enabled_ = enabled; 160ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan } 161ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 162ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan inline bool update_check_count_wait_enabled() const { 163ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan return update_check_count_wait_enabled_; 164ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan } 165ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 1669abb763fa3840d69cc1098c0233162557a7f99eaBen Chan inline void set_min_update_checks_needed(int64_t min) { 167ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan min_update_checks_needed_ = min; 168ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan } 1699abb763fa3840d69cc1098c0233162557a7f99eaBen Chan inline int64_t min_update_checks_needed() const { 170ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan return min_update_checks_needed_; 171ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan } 172ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 1739abb763fa3840d69cc1098c0233162557a7f99eaBen Chan inline void set_max_update_checks_allowed(int64_t max) { 174ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan max_update_checks_allowed_ = max; 175ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan } 1769abb763fa3840d69cc1098c0233162557a7f99eaBen Chan inline int64_t max_update_checks_allowed() const { 177ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan return max_update_checks_allowed_; 178ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan } 179ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 180ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // True if we're trying to update to a more stable channel. 181ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // i.e. index(target_channel) > index(current_channel). 182560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo virtual bool to_more_stable_channel() const; 183480ddfa079ebd01ed87e495332dec121d9ae781fJay Srinivasan 184db0acdfca1ea33987e8b29325f4594417d1fae57Jay Srinivasan // Returns the app id corresponding to the current value of the 185db0acdfca1ea33987e8b29325f4594417d1fae57Jay Srinivasan // download channel. 186560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo virtual std::string GetAppId() const; 187db0acdfca1ea33987e8b29325f4594417d1fae57Jay Srinivasan 188a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov // Suggested defaults 18902c1864e204997175302b1aebe3e0be9c6699ea5David Pursell static const char kOsVersion[]; 19002c1864e204997175302b1aebe3e0be9c6699ea5David Pursell static const char kIsPowerwashAllowedKey[]; 1919abb763fa3840d69cc1098c0233162557a7f99eaBen Chan static const int64_t kDefaultMinUpdateChecks = 0; 1929abb763fa3840d69cc1098c0233162557a7f99eaBen Chan static const int64_t kDefaultMaxUpdateChecks = 8; 193a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov 1945a7f565a542196f24eb87ddac96508f8a84e3329Darin Petkov // Initializes all the data in the object. Non-empty 1955a7f565a542196f24eb87ddac96508f8a84e3329Darin Petkov // |in_app_version| or |in_update_url| prevents automatic detection 1965a7f565a542196f24eb87ddac96508f8a84e3329Darin Petkov // of the parameter. Returns true on success, false otherwise. 1975a7f565a542196f24eb87ddac96508f8a84e3329Darin Petkov bool Init(const std::string& in_app_version, 1987fbbe8a9e57ec52f7bc597d0cb607036300ac54cPatrick Dubroy const std::string& in_update_url, 199bbdd4909bcd20448ad89aa1e02c936e42aedf548Gilad Arnold bool in_interactive); 200a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov 201ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // Permanently changes the release channel to |channel|. Performs a 202ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // powerwash, if required and allowed. 203ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // Returns true on success, false otherwise. Note: This call will fail if 204ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // there's a channel change pending already. This is to serialize all the 205ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // channel changes done by the user in order to avoid having to solve 206ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // numerous edge cases around ensuring the powerwash happens as intended in 207ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // all such cases. 208560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo virtual bool SetTargetChannel(const std::string& channel, 209d942f9d3c8529f896329b19261df6eba044de1b2Alex Deymo bool is_powerwash_allowed, 210d942f9d3c8529f896329b19261df6eba044de1b2Alex Deymo std::string* error_message); 21149d91329a3a84d7e2b35f6e1ffc8a9b4d478515bDarin Petkov 2121c0fe79c7ef2b43946d756b54c8505d2bf48b93bJay Srinivasan // Updates the download channel for this particular attempt from the current 2131c0fe79c7ef2b43946d756b54c8505d2bf48b93bJay Srinivasan // value of target channel. This method takes a "snapshot" of the current 2141c0fe79c7ef2b43946d756b54c8505d2bf48b93bJay Srinivasan // value of target channel and uses it for all subsequent Omaha requests for 2151c0fe79c7ef2b43946d756b54c8505d2bf48b93bJay Srinivasan // this attempt (i.e. initial request as well as download progress/error 2161c0fe79c7ef2b43946d756b54c8505d2bf48b93bJay Srinivasan // event requests). The snapshot will be updated only when either this method 2171c0fe79c7ef2b43946d756b54c8505d2bf48b93bJay Srinivasan // or Init is called again. 218560ae1da0e62f7897699f63631452f0c4144d413Alex Deymo virtual void UpdateDownloadChannel(); 2191c0fe79c7ef2b43946d756b54c8505d2bf48b93bJay Srinivasan 220856166594771c61973856f563e622ccb7dd48aa1Alex Deymo virtual bool is_powerwash_allowed() const { 221856166594771c61973856f563e622ccb7dd48aa1Alex Deymo return mutable_image_props_.is_powerwash_allowed; 222856166594771c61973856f563e622ccb7dd48aa1Alex Deymo } 223583667b33cb62b97fbbd792d6c830c530d759ec1Satoru Takabayashi 22402c1864e204997175302b1aebe3e0be9c6699ea5David Pursell // Check if the provided update URL is official, meaning either the default 22502c1864e204997175302b1aebe3e0be9c6699ea5David Pursell // autoupdate server or the autoupdate autotest server. 22602c1864e204997175302b1aebe3e0be9c6699ea5David Pursell virtual bool IsUpdateUrlOfficial() const; 22702c1864e204997175302b1aebe3e0be9c6699ea5David Pursell 228a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov // For unit-tests. 229ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan void set_root(const std::string& root); 23028e479c3b08cb4d1280905f5d3510f8ec4ed719cChris Sosa void set_current_channel(const std::string& channel) { 231856166594771c61973856f563e622ccb7dd48aa1Alex Deymo image_props_.current_channel = channel; 23228e479c3b08cb4d1280905f5d3510f8ec4ed719cChris Sosa } 23376b2b4822d57360d0c77f070bd8fc25bc08fd93eGilad Arnold void set_target_channel(const std::string& channel) { 234856166594771c61973856f563e622ccb7dd48aa1Alex Deymo mutable_image_props_.target_channel = channel; 23576b2b4822d57360d0c77f070bd8fc25bc08fd93eGilad Arnold } 236a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov 237a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov private: 238ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan FRIEND_TEST(OmahaRequestParamsTest, IsValidChannelTest); 239ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan FRIEND_TEST(OmahaRequestParamsTest, ShouldLockDownTest); 240ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan FRIEND_TEST(OmahaRequestParamsTest, ChannelIndexTest); 241ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan FRIEND_TEST(OmahaRequestParamsTest, LsbPreserveTest); 242c1972483fa3446852b42ce97d1ea43b9caaaf56fChris Sosa FRIEND_TEST(OmahaRequestParamsTest, CollectECFWVersionsTest); 24349d91329a3a84d7e2b35f6e1ffc8a9b4d478515bDarin Petkov 244856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // Returns true if |channel| is a valid channel, false otherwise. 245ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan bool IsValidChannel(const std::string& channel) const; 246ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 247ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // Returns the index of the given channel. 248ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan int GetChannelIndex(const std::string& channel) const; 249ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 250c1972483fa3446852b42ce97d1ea43b9caaaf56fChris Sosa // Returns True if we should store the fw/ec versions based on our hwid_. 251c1972483fa3446852b42ce97d1ea43b9caaaf56fChris Sosa // Compares hwid to a set of whitelisted prefixes. 252c1972483fa3446852b42ce97d1ea43b9caaaf56fChris Sosa bool CollectECFWVersions() const; 253c1972483fa3446852b42ce97d1ea43b9caaaf56fChris Sosa 254ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // These are individual helper methods to initialize the said properties from 255ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // the LSB value. 256ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan void SetTargetChannelFromLsbValue(); 257ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan void SetCurrentChannelFromLsbValue(); 258ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan void SetIsPowerwashAllowedFromLsbValue(); 259ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 260ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // Initializes the required properties from the LSB value. 261ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan void InitFromLsbValue(); 26249d91329a3a84d7e2b35f6e1ffc8a9b4d478515bDarin Petkov 263a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov // Gets the machine type (e.g. "i686"). 264a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov std::string GetMachineType() const; 265a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov 266ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // Global system context. 267ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan SystemState* system_state_; 268ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 269856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // The system image properties. 270856166594771c61973856f563e622ccb7dd48aa1Alex Deymo ImageProperties image_props_; 271856166594771c61973856f563e622ccb7dd48aa1Alex Deymo MutableImageProperties mutable_image_props_; 272856166594771c61973856f563e622ccb7dd48aa1Alex Deymo 273ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // Basic properties of the OS and Application that go into the Omaha request. 274ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan std::string os_platform_; 275ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan std::string os_version_; 276ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan std::string os_sp_; 277ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan std::string app_lang_; 278ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 279856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // There are three channel values we deal with: 280856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // * The channel we got the image we are running from or "current channel" 281856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // stored in |image_props_.current_channel|. 282856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // 283856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // * The release channel we are tracking, where we should get updates from, 284856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // stored in |mutable_image_props_.target_channel|. This channel is 285856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // normally the same as the current_channel, except when the user changes 286856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // the channel. In that case it'll have the release channel the user 287856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // switched to, regardless of whether we downloaded an update from that 288856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // channel or not, or if we are in the middle of a download from a 289856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // previously selected channel (as opposed to download channel 290856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // which gets updated only at the start of next download). 291856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // 292856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // * The channel from which we're downloading the payload. This should 293856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // normally be the same as target channel. But if the user made another 294856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // channel change after we started the download, then they'd be different, 295856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // in which case, we'd detect elsewhere that the target channel has been 296856166594771c61973856f563e622ccb7dd48aa1Alex Deymo // changed and cancel the current download attempt. 2971c0fe79c7ef2b43946d756b54c8505d2bf48b93bJay Srinivasan std::string download_channel_; 2981c0fe79c7ef2b43946d756b54c8505d2bf48b93bJay Srinivasan 299ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan std::string hwid_; // Hardware Qualification ID of the client 300c1972483fa3446852b42ce97d1ea43b9caaaf56fChris Sosa std::string fw_version_; // Chrome OS Firmware Version. 301c1972483fa3446852b42ce97d1ea43b9caaaf56fChris Sosa std::string ec_version_; // Chrome OS EC Version. 302ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan bool delta_okay_; // If this client can accept a delta 303ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan bool interactive_; // Whether this is a user-initiated update check 304ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 305ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // The URL to send the Omaha request to. 306ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan std::string update_url_; 307ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 308ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // Prefix of the target OS version that the enterprise wants this device 309ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // to be pinned to. It's empty otherwise. 310ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan std::string target_version_prefix_; 311ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 312ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // True if scattering is enabled, in which case waiting_period_ specifies the 313ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // amount of absolute time that we've to wait for before sending a request to 314ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // Omaha. 315ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan bool wall_clock_based_wait_enabled_; 316ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan base::TimeDelta waiting_period_; 317ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 318ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // True if scattering is enabled to denote the number of update checks 319ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // we've to skip before we can send a request to Omaha. The min and max 320ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // values establish the bounds for a random number to be chosen within that 321ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // range to enable such a wait. 322ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan bool update_check_count_wait_enabled_; 3239abb763fa3840d69cc1098c0233162557a7f99eaBen Chan int64_t min_update_checks_needed_; 3249abb763fa3840d69cc1098c0233162557a7f99eaBen Chan int64_t max_update_checks_allowed_; 325ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan 326a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov // When reading files, prepend root_ to the paths. Useful for testing. 327a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov std::string root_; 328a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov 329ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // TODO(jaysri): Uncomment this after fixing unit tests, as part of 330ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // chromium-os:39752 331ae4697c073b84b260990a141acd53c6806da0708Jay Srinivasan // DISALLOW_COPY_AND_ASSIGN(OmahaRequestParams); 332a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov}; 333a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov 334a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov} // namespace chromeos_update_engine 335a4a8a8ccc2d9e0285728ed247b43f09433e63323Darin Petkov 336cf175a098081f3f0e9ca52d997a7ce1585c14c2dGilad Arnold#endif // UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H_ 337