blob: 075ed3fa92163828bb32b95ca35168e61a568850 [file] [log] [blame]
Darin Petkova4a8a8c2010-07-15 22:21:12 -07001// 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 Petkov49d91322010-10-25 16:34:58 -070010#include <base/basictypes.h>
11#include <gtest/gtest_prod.h> // for FRIEND_TEST
Darin Petkova4a8a8c2010-07-15 22:21:12 -070012
13// This gathers local system information and prepares info used by the
14// Omaha request action.
15
16namespace 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.
20struct OmahaRequestParams {
21 OmahaRequestParams()
22 : os_platform(kOsPlatform), os_version(kOsVersion), app_id(kAppId) {}
Darin Petkov84c763c2010-07-29 16:27:58 -070023 OmahaRequestParams(const std::string& in_os_platform,
Darin Petkova4a8a8c2010-07-15 22:21:12 -070024 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 Petkovfbb40092010-07-29 17:05:50 -070031 const std::string& in_hardware_class,
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -070032 const bool in_delta_okay,
Darin Petkova4a8a8c2010-07-15 22:21:12 -070033 const std::string& in_update_url)
Darin Petkov84c763c2010-07-29 16:27:58 -070034 : os_platform(in_os_platform),
Darin Petkova4a8a8c2010-07-15 22:21:12 -070035 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 Petkovfbb40092010-07-29 17:05:50 -070042 hardware_class(in_hardware_class),
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -070043 delta_okay(in_delta_okay),
Darin Petkova4a8a8c2010-07-15 22:21:12 -070044 update_url(in_update_url) {}
45
Darin Petkova4a8a8c2010-07-15 22:21:12 -070046 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 Petkovfbb40092010-07-29 17:05:50 -070054 std::string hardware_class; // Hardware Qualification ID of the client
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -070055 bool delta_okay; // If this client can accept a delta
Darin Petkova4a8a8c2010-07-15 22:21:12 -070056
57 std::string update_url;
58
Darin Petkov49d91322010-10-25 16:34:58 -070059 static const char kUpdateTrackKey[];
60
Darin Petkova4a8a8c2010-07-15 22:21:12 -070061 // 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
68class OmahaRequestDeviceParams : public OmahaRequestParams {
69 public:
Darin Petkov49d91322010-10-25 16:34:58 -070070 OmahaRequestDeviceParams();
Darin Petkova4a8a8c2010-07-15 22:21:12 -070071
Darin Petkov5a7f5652010-07-22 21:40:09 -070072 // 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 Petkova4a8a8c2010-07-15 22:21:12 -070077
Darin Petkov49d91322010-10-25 16:34:58 -070078 // 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 Takabayashi583667b2010-10-27 13:09:57 +090083 // Returns the release track. On error, returns an empty string.
84 static std::string GetDeviceTrack();
85
Darin Petkova4a8a8c2010-07-15 22:21:12 -070086 // For unit-tests.
87 void set_root(const std::string& root) { root_ = root; }
88
Darin Petkov49d91322010-10-25 16:34:58 -070089 // Force build type for testing purposes.
90 void SetBuildTypeOfficial(bool is_official);
91
Darin Petkova4a8a8c2010-07-15 22:21:12 -070092 private:
Darin Petkov49d91322010-10-25 16:34:58 -070093 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 Petkova4a8a8c2010-07-15 22:21:12 -0700108 // Fetches the value for a given key from
Darin Petkova3df55b2010-11-15 13:33:55 -0800109 // /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 Petkova4a8a8c2010-07-15 22:21:12 -0700112 std::string GetLsbValue(const std::string& key,
Darin Petkov49d91322010-10-25 16:34:58 -0700113 const std::string& default_value,
Darin Petkova3df55b2010-11-15 13:33:55 -0800114 ValueValidator validator,
115 bool stateful_override) const;
Darin Petkova4a8a8c2010-07-15 22:21:12 -0700116
117 // Gets the machine type (e.g. "i686").
118 std::string GetMachineType() const;
119
Darin Petkovfbb40092010-07-29 17:05:50 -0700120 // Returns the hardware qualification ID of the system, or empty
121 // string if the HWID is unavailable.
122 std::string GetHardwareClass() const;
123
Darin Petkova4a8a8c2010-07-15 22:21:12 -0700124 // When reading files, prepend root_ to the paths. Useful for testing.
125 std::string root_;
126
Darin Petkov49d91322010-10-25 16:34:58 -0700127 // Force build type for testing purposes.
128 bool force_build_type_;
129 bool forced_official_build_;
130
Darin Petkova4a8a8c2010-07-15 22:21:12 -0700131 DISALLOW_COPY_AND_ASSIGN(OmahaRequestDeviceParams);
132};
133
134} // namespace chromeos_update_engine
135
136#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__