Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 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_OMAHA_REQUEST_PARAMS_H__ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__ |
| 7 | |
| 8 | #include <string> |
| 9 | |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 10 | #include <base/basictypes.h> |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 11 | #include <base/time.h> |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 12 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 13 | |
| 14 | // This gathers local system information and prepares info used by the |
| 15 | // Omaha request action. |
| 16 | |
| 17 | namespace chromeos_update_engine { |
| 18 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 19 | // The default "official" Omaha update URL. |
| 20 | extern const char* const kProductionOmahaUrl; |
| 21 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 22 | // This struct encapsulates the data Omaha gets for the request, along with |
| 23 | // essential state needed for the processing of the request/response. |
| 24 | // The strings in this struct should not be XML escaped. |
| 25 | // TODO (jaysri): Consider renaming this to reflect its lifetime more |
| 26 | // appropriately. |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 27 | struct OmahaRequestParams { |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 28 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 29 | OmahaRequestParams() |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 30 | : os_platform(kOsPlatform), |
| 31 | os_version(kOsVersion), |
| 32 | app_id(kAppId), |
| 33 | delta_okay(true), |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 34 | update_disabled(false), |
| 35 | wall_clock_based_wait_enabled(false), |
| 36 | update_check_count_wait_enabled(false), |
| 37 | min_update_checks_needed(kDefaultMinUpdateChecks), |
| 38 | max_update_checks_allowed(kDefaultMaxUpdateChecks) {} |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 39 | |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 40 | OmahaRequestParams(const std::string& in_os_platform, |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 41 | const std::string& in_os_version, |
| 42 | const std::string& in_os_sp, |
| 43 | const std::string& in_os_board, |
| 44 | const std::string& in_app_id, |
| 45 | const std::string& in_app_version, |
| 46 | const std::string& in_app_lang, |
| 47 | const std::string& in_app_track, |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 48 | const std::string& in_hardware_class, |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 49 | bool in_delta_okay, |
| 50 | const std::string& in_update_url, |
| 51 | bool in_update_disabled, |
| 52 | const std::string& in_target_version_prefix) |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 53 | : os_platform(in_os_platform), |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 54 | os_version(in_os_version), |
| 55 | os_sp(in_os_sp), |
| 56 | os_board(in_os_board), |
| 57 | app_id(in_app_id), |
| 58 | app_version(in_app_version), |
| 59 | app_lang(in_app_lang), |
| 60 | app_track(in_app_track), |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 61 | hardware_class(in_hardware_class), |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 62 | delta_okay(in_delta_okay), |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 63 | update_url(in_update_url), |
| 64 | update_disabled(in_update_disabled), |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 65 | target_version_prefix(in_target_version_prefix), |
| 66 | wall_clock_based_wait_enabled(false), |
| 67 | update_check_count_wait_enabled(false), |
| 68 | min_update_checks_needed(kDefaultMinUpdateChecks), |
| 69 | max_update_checks_allowed(kDefaultMaxUpdateChecks) {} |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 70 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 71 | std::string os_platform; |
| 72 | std::string os_version; |
| 73 | std::string os_sp; |
| 74 | std::string os_board; |
| 75 | std::string app_id; |
| 76 | std::string app_version; |
| 77 | std::string app_lang; |
| 78 | std::string app_track; |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 79 | std::string hardware_class; // Hardware Qualification ID of the client |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 80 | bool delta_okay; // If this client can accept a delta |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 81 | |
| 82 | std::string update_url; |
| 83 | |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 84 | static const char kUpdateTrackKey[]; |
| 85 | |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 86 | bool update_disabled; |
| 87 | std::string target_version_prefix; |
| 88 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 89 | bool wall_clock_based_wait_enabled; |
| 90 | base::TimeDelta waiting_period; |
| 91 | |
| 92 | bool update_check_count_wait_enabled; |
| 93 | int64 min_update_checks_needed; |
| 94 | int64 max_update_checks_allowed; |
| 95 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 96 | // Suggested defaults |
| 97 | static const char* const kAppId; |
| 98 | static const char* const kOsPlatform; |
| 99 | static const char* const kOsVersion; |
| 100 | static const char* const kUpdateUrl; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 101 | static const int64 kDefaultMinUpdateChecks = 0; |
| 102 | static const int64 kDefaultMaxUpdateChecks = 8; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | class OmahaRequestDeviceParams : public OmahaRequestParams { |
| 106 | public: |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 107 | OmahaRequestDeviceParams(); |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 108 | |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 109 | // Initializes all the data in the object. Non-empty |
| 110 | // |in_app_version| or |in_update_url| prevents automatic detection |
| 111 | // of the parameter. Returns true on success, false otherwise. |
| 112 | bool Init(const std::string& in_app_version, |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 113 | const std::string& in_update_url, |
| 114 | const std::string& in_release_track); |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 115 | |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 116 | // Permanently changes the release track to |track|. Returns true on success, |
| 117 | // false otherwise. |
| 118 | bool SetTrack(const std::string& track); |
| 119 | static bool SetDeviceTrack(const std::string& track); |
| 120 | |
Satoru Takabayashi | 583667b | 2010-10-27 13:09:57 +0900 | [diff] [blame] | 121 | // Returns the release track. On error, returns an empty string. |
| 122 | static std::string GetDeviceTrack(); |
| 123 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 124 | // For unit-tests. |
| 125 | void set_root(const std::string& root) { root_ = root; } |
| 126 | |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 127 | // Enforce security mode for testing purposes. |
| 128 | void SetLockDown(bool lock); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 129 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 130 | private: |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 131 | FRIEND_TEST(OmahaRequestDeviceParamsTest, IsValidTrackTest); |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 132 | FRIEND_TEST(OmahaRequestDeviceParamsTest, ShouldLockDownTest); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 133 | |
| 134 | // Use a validator that is a non-static member of this class so that its |
| 135 | // inputs can be mocked in unit tests (e.g., build type for IsValidTrack). |
| 136 | typedef bool(OmahaRequestDeviceParams::*ValueValidator)( |
| 137 | const std::string&) const; |
| 138 | |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 139 | // Returns true if parameter values should be locked down for security |
| 140 | // reasons. If this is an official build running in normal boot mode, all |
| 141 | // values except the release track are parsed only from the read-only rootfs |
| 142 | // partition and the track values are restricted to a pre-approved set. |
| 143 | bool ShouldLockDown() const; |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 144 | |
| 145 | // Returns true if |track| is a valid track, false otherwise. This method |
| 146 | // restricts the track value only if the image is official (see |
| 147 | // IsOfficialBuild). |
| 148 | bool IsValidTrack(const std::string& track) const; |
| 149 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 150 | // Fetches the value for a given key from |
Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 151 | // /mnt/stateful_partition/etc/lsb-release if possible and |stateful_override| |
| 152 | // is true. Failing that, it looks for the key in /etc/lsb-release. If |
| 153 | // |validator| is non-NULL, uses it to validate and ignore invalid valies. |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 154 | std::string GetLsbValue(const std::string& key, |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 155 | const std::string& default_value, |
Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 156 | ValueValidator validator, |
| 157 | bool stateful_override) const; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 158 | |
| 159 | // Gets the machine type (e.g. "i686"). |
| 160 | std::string GetMachineType() const; |
| 161 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 162 | // When reading files, prepend root_ to the paths. Useful for testing. |
| 163 | std::string root_; |
| 164 | |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 165 | // Force security lock down for testing purposes. |
| 166 | bool force_lock_down_; |
| 167 | bool forced_lock_down_; |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 168 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 169 | DISALLOW_COPY_AND_ASSIGN(OmahaRequestDeviceParams); |
| 170 | }; |
| 171 | |
| 172 | } // namespace chromeos_update_engine |
| 173 | |
| 174 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__ |