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 | |
| 10 | #include "base/basictypes.h" |
| 11 | |
| 12 | // This gathers local system information and prepares info used by the |
| 13 | // Omaha request action. |
| 14 | |
| 15 | namespace chromeos_update_engine { |
| 16 | |
| 17 | // This struct encapsulates the data Omaha gets for the request. |
| 18 | // These strings in this struct should not be XML escaped. |
| 19 | struct OmahaRequestParams { |
| 20 | OmahaRequestParams() |
| 21 | : os_platform(kOsPlatform), os_version(kOsVersion), app_id(kAppId) {} |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 22 | OmahaRequestParams(const std::string& in_os_platform, |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 23 | const std::string& in_os_version, |
| 24 | const std::string& in_os_sp, |
| 25 | const std::string& in_os_board, |
| 26 | const std::string& in_app_id, |
| 27 | const std::string& in_app_version, |
| 28 | const std::string& in_app_lang, |
| 29 | const std::string& in_app_track, |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame^] | 30 | const std::string& in_hardware_class, |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 31 | const bool in_delta_okay, |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 32 | const std::string& in_update_url) |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 33 | : os_platform(in_os_platform), |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 34 | os_version(in_os_version), |
| 35 | os_sp(in_os_sp), |
| 36 | os_board(in_os_board), |
| 37 | app_id(in_app_id), |
| 38 | app_version(in_app_version), |
| 39 | app_lang(in_app_lang), |
| 40 | app_track(in_app_track), |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame^] | 41 | hardware_class(in_hardware_class), |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 42 | delta_okay(in_delta_okay), |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 43 | update_url(in_update_url) {} |
| 44 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 45 | std::string os_platform; |
| 46 | std::string os_version; |
| 47 | std::string os_sp; |
| 48 | std::string os_board; |
| 49 | std::string app_id; |
| 50 | std::string app_version; |
| 51 | std::string app_lang; |
| 52 | std::string app_track; |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame^] | 53 | std::string hardware_class; // Hardware Qualification ID of the client |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 54 | bool delta_okay; // If this client can accept a delta |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 55 | |
| 56 | std::string update_url; |
| 57 | |
| 58 | // Suggested defaults |
| 59 | static const char* const kAppId; |
| 60 | static const char* const kOsPlatform; |
| 61 | static const char* const kOsVersion; |
| 62 | static const char* const kUpdateUrl; |
| 63 | }; |
| 64 | |
| 65 | class OmahaRequestDeviceParams : public OmahaRequestParams { |
| 66 | public: |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 67 | OmahaRequestDeviceParams() {} |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 68 | |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 69 | // Initializes all the data in the object. Non-empty |
| 70 | // |in_app_version| or |in_update_url| prevents automatic detection |
| 71 | // of the parameter. Returns true on success, false otherwise. |
| 72 | bool Init(const std::string& in_app_version, |
| 73 | const std::string& in_update_url); |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 74 | |
| 75 | // For unit-tests. |
| 76 | void set_root(const std::string& root) { root_ = root; } |
| 77 | |
| 78 | private: |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 79 | // Fetches the value for a given key from |
| 80 | // /mnt/stateful_partition/etc/lsb-release if possible. Failing that, |
| 81 | // it looks for the key in /etc/lsb-release. |
| 82 | std::string GetLsbValue(const std::string& key, |
| 83 | const std::string& default_value) const; |
| 84 | |
| 85 | // Gets the machine type (e.g. "i686"). |
| 86 | std::string GetMachineType() const; |
| 87 | |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame^] | 88 | // Returns the hardware qualification ID of the system, or empty |
| 89 | // string if the HWID is unavailable. |
| 90 | std::string GetHardwareClass() const; |
| 91 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 92 | // When reading files, prepend root_ to the paths. Useful for testing. |
| 93 | std::string root_; |
| 94 | |
| 95 | DISALLOW_COPY_AND_ASSIGN(OmahaRequestDeviceParams); |
| 96 | }; |
| 97 | |
| 98 | } // namespace chromeos_update_engine |
| 99 | |
| 100 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__ |