OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__ |
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include <base/basictypes.h> |
| 11 #include <gtest/gtest_prod.h> // for FRIEND_TEST |
11 | 12 |
12 // This gathers local system information and prepares info used by the | 13 // This gathers local system information and prepares info used by the |
13 // Omaha request action. | 14 // Omaha request action. |
14 | 15 |
15 namespace chromeos_update_engine { | 16 namespace chromeos_update_engine { |
16 | 17 |
17 // This struct encapsulates the data Omaha gets for the request. | 18 // This struct encapsulates the data Omaha gets for the request. |
18 // These strings in this struct should not be XML escaped. | 19 // These strings in this struct should not be XML escaped. |
19 struct OmahaRequestParams { | 20 struct OmahaRequestParams { |
20 OmahaRequestParams() | 21 OmahaRequestParams() |
(...skipping 27 matching lines...) Expand all Loading... |
48 std::string os_board; | 49 std::string os_board; |
49 std::string app_id; | 50 std::string app_id; |
50 std::string app_version; | 51 std::string app_version; |
51 std::string app_lang; | 52 std::string app_lang; |
52 std::string app_track; | 53 std::string app_track; |
53 std::string hardware_class; // Hardware Qualification ID of the client | 54 std::string hardware_class; // Hardware Qualification ID of the client |
54 bool delta_okay; // If this client can accept a delta | 55 bool delta_okay; // If this client can accept a delta |
55 | 56 |
56 std::string update_url; | 57 std::string update_url; |
57 | 58 |
| 59 static const char kUpdateTrackKey[]; |
| 60 |
58 // Suggested defaults | 61 // Suggested defaults |
59 static const char* const kAppId; | 62 static const char* const kAppId; |
60 static const char* const kOsPlatform; | 63 static const char* const kOsPlatform; |
61 static const char* const kOsVersion; | 64 static const char* const kOsVersion; |
62 static const char* const kUpdateUrl; | 65 static const char* const kUpdateUrl; |
63 }; | 66 }; |
64 | 67 |
65 class OmahaRequestDeviceParams : public OmahaRequestParams { | 68 class OmahaRequestDeviceParams : public OmahaRequestParams { |
66 public: | 69 public: |
67 OmahaRequestDeviceParams() {} | 70 OmahaRequestDeviceParams(); |
68 | 71 |
69 // Initializes all the data in the object. Non-empty | 72 // Initializes all the data in the object. Non-empty |
70 // |in_app_version| or |in_update_url| prevents automatic detection | 73 // |in_app_version| or |in_update_url| prevents automatic detection |
71 // of the parameter. Returns true on success, false otherwise. | 74 // of the parameter. Returns true on success, false otherwise. |
72 bool Init(const std::string& in_app_version, | 75 bool Init(const std::string& in_app_version, |
73 const std::string& in_update_url); | 76 const std::string& in_update_url); |
74 | 77 |
| 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 |
75 // For unit-tests. | 83 // For unit-tests. |
76 void set_root(const std::string& root) { root_ = root; } | 84 void set_root(const std::string& root) { root_ = root; } |
77 | 85 |
| 86 // Force build type for testing purposes. |
| 87 void SetBuildTypeOfficial(bool is_official); |
| 88 |
78 private: | 89 private: |
| 90 FRIEND_TEST(OmahaRequestDeviceParamsTest, IsValidTrackTest); |
| 91 |
| 92 // Use a validator that is a non-static member of this class so that its |
| 93 // inputs can be mocked in unit tests (e.g., build type for IsValidTrack). |
| 94 typedef bool(OmahaRequestDeviceParams::*ValueValidator)( |
| 95 const std::string&) const; |
| 96 |
| 97 // Returns true if this is an official build, false otherwise. |
| 98 bool IsOfficialBuild() const; |
| 99 |
| 100 // Returns true if |track| is a valid track, false otherwise. This method |
| 101 // restricts the track value only if the image is official (see |
| 102 // IsOfficialBuild). |
| 103 bool IsValidTrack(const std::string& track) const; |
| 104 |
79 // Fetches the value for a given key from | 105 // Fetches the value for a given key from |
80 // /mnt/stateful_partition/etc/lsb-release if possible. Failing that, | 106 // /mnt/stateful_partition/etc/lsb-release if possible. Failing that, it looks |
81 // it looks for the key in /etc/lsb-release. | 107 // for the key in /etc/lsb-release. If |validator| is non-NULL, uses it to |
| 108 // validate and ignore invalid valies. |
82 std::string GetLsbValue(const std::string& key, | 109 std::string GetLsbValue(const std::string& key, |
83 const std::string& default_value) const; | 110 const std::string& default_value, |
| 111 ValueValidator validator) const; |
84 | 112 |
85 // Gets the machine type (e.g. "i686"). | 113 // Gets the machine type (e.g. "i686"). |
86 std::string GetMachineType() const; | 114 std::string GetMachineType() const; |
87 | 115 |
88 // Returns the hardware qualification ID of the system, or empty | 116 // Returns the hardware qualification ID of the system, or empty |
89 // string if the HWID is unavailable. | 117 // string if the HWID is unavailable. |
90 std::string GetHardwareClass() const; | 118 std::string GetHardwareClass() const; |
91 | 119 |
92 // When reading files, prepend root_ to the paths. Useful for testing. | 120 // When reading files, prepend root_ to the paths. Useful for testing. |
93 std::string root_; | 121 std::string root_; |
94 | 122 |
| 123 // Force build type for testing purposes. |
| 124 bool force_build_type_; |
| 125 bool forced_official_build_; |
| 126 |
95 DISALLOW_COPY_AND_ASSIGN(OmahaRequestDeviceParams); | 127 DISALLOW_COPY_AND_ASSIGN(OmahaRequestDeviceParams); |
96 }; | 128 }; |
97 | 129 |
98 } // namespace chromeos_update_engine | 130 } // namespace chromeos_update_engine |
99 | 131 |
100 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__ | 132 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H__ |
OLD | NEW |