Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 1 | // Copyright (c) 2010 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_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> |
| 11 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 12 | |
| 13 | // This gathers local system information and prepares info used by the |
| 14 | // Omaha request action. |
| 15 | |
| 16 | namespace chromeos_update_engine { |
| 17 | |
| 18 | // This struct encapsulates the data Omaha gets for the request. |
| 19 | // These strings in this struct should not be XML escaped. |
| 20 | struct OmahaRequestParams { |
| 21 | OmahaRequestParams() |
| 22 | : os_platform(kOsPlatform), os_version(kOsVersion), app_id(kAppId) {} |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 23 | OmahaRequestParams(const std::string& in_os_platform, |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 24 | const std::string& in_os_version, |
| 25 | const std::string& in_os_sp, |
| 26 | const std::string& in_os_board, |
| 27 | const std::string& in_app_id, |
| 28 | const std::string& in_app_version, |
| 29 | const std::string& in_app_lang, |
| 30 | const std::string& in_app_track, |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 31 | const std::string& in_hardware_class, |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 32 | const bool in_delta_okay, |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 33 | const std::string& in_update_url) |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 34 | : os_platform(in_os_platform), |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 35 | os_version(in_os_version), |
| 36 | os_sp(in_os_sp), |
| 37 | os_board(in_os_board), |
| 38 | app_id(in_app_id), |
| 39 | app_version(in_app_version), |
| 40 | app_lang(in_app_lang), |
| 41 | app_track(in_app_track), |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 42 | hardware_class(in_hardware_class), |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 43 | delta_okay(in_delta_okay), |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 44 | update_url(in_update_url) {} |
| 45 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 46 | std::string os_platform; |
| 47 | std::string os_version; |
| 48 | std::string os_sp; |
| 49 | std::string os_board; |
| 50 | std::string app_id; |
| 51 | std::string app_version; |
| 52 | std::string app_lang; |
| 53 | std::string app_track; |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 54 | std::string hardware_class; // Hardware Qualification ID of the client |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 55 | bool delta_okay; // If this client can accept a delta |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 56 | |
| 57 | std::string update_url; |
| 58 | |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 59 | static const char kUpdateTrackKey[]; |
| 60 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 61 | // Suggested defaults |
| 62 | static const char* const kAppId; |
| 63 | static const char* const kOsPlatform; |
| 64 | static const char* const kOsVersion; |
| 65 | static const char* const kUpdateUrl; |
| 66 | }; |
| 67 | |
| 68 | class OmahaRequestDeviceParams : public OmahaRequestParams { |
| 69 | public: |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 70 | OmahaRequestDeviceParams(); |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 71 | |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 72 | // Initializes all the data in the object. Non-empty |
| 73 | // |in_app_version| or |in_update_url| prevents automatic detection |
| 74 | // of the parameter. Returns true on success, false otherwise. |
| 75 | bool Init(const std::string& in_app_version, |
| 76 | const std::string& in_update_url); |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 77 | |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 78 | // Permanently changes the release track to |track|. Returns true on success, |
| 79 | // false otherwise. |
| 80 | bool SetTrack(const std::string& track); |
| 81 | static bool SetDeviceTrack(const std::string& track); |
| 82 | |
Satoru Takabayashi | 583667b | 2010-10-27 13:09:57 +0900 | [diff] [blame] | 83 | // Returns the release track. On error, returns an empty string. |
| 84 | static std::string GetDeviceTrack(); |
| 85 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 86 | // For unit-tests. |
| 87 | void set_root(const std::string& root) { root_ = root; } |
| 88 | |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 89 | // Force build type for testing purposes. |
| 90 | void SetBuildTypeOfficial(bool is_official); |
| 91 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 92 | private: |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 93 | FRIEND_TEST(OmahaRequestDeviceParamsTest, IsValidTrackTest); |
| 94 | |
| 95 | // Use a validator that is a non-static member of this class so that its |
| 96 | // inputs can be mocked in unit tests (e.g., build type for IsValidTrack). |
| 97 | typedef bool(OmahaRequestDeviceParams::*ValueValidator)( |
| 98 | const std::string&) const; |
| 99 | |
| 100 | // Returns true if this is an official build, false otherwise. |
| 101 | bool IsOfficialBuild() const; |
| 102 | |
| 103 | // Returns true if |track| is a valid track, false otherwise. This method |
| 104 | // restricts the track value only if the image is official (see |
| 105 | // IsOfficialBuild). |
| 106 | bool IsValidTrack(const std::string& track) const; |
| 107 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 108 | // Fetches the value for a given key from |
Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 109 | // /mnt/stateful_partition/etc/lsb-release if possible and |stateful_override| |
| 110 | // is true. Failing that, it looks for the key in /etc/lsb-release. If |
| 111 | // |validator| is non-NULL, uses it to validate and ignore invalid valies. |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 112 | std::string GetLsbValue(const std::string& key, |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 113 | const std::string& default_value, |
Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 114 | ValueValidator validator, |
| 115 | bool stateful_override) const; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 116 | |
| 117 | // Gets the machine type (e.g. "i686"). |
| 118 | std::string GetMachineType() const; |
| 119 | |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 120 | // Returns the hardware qualification ID of the system, or empty |
| 121 | // string if the HWID is unavailable. |
| 122 | std::string GetHardwareClass() const; |
| 123 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 124 | // When reading files, prepend root_ to the paths. Useful for testing. |
| 125 | std::string root_; |
| 126 | |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 127 | // Force build type for testing purposes. |
| 128 | bool force_build_type_; |
| 129 | bool forced_official_build_; |
| 130 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 131 | DISALLOW_COPY_AND_ASSIGN(OmahaRequestDeviceParams); |
| 132 | }; |
| 133 | |
| 134 | } // namespace chromeos_update_engine |
| 135 | |
| 136 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__ |