Chromium Code Reviews| 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 #include "update_engine/omaha_request_params.h" | 5 #include "update_engine/omaha_request_params.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/utsname.h> | 9 #include <sys/utsname.h> |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 "{87efface-864d-49a5-9bb3-4b050a7c227a}"); | 32 "{87efface-864d-49a5-9bb3-4b050a7c227a}"); |
| 33 const char* const OmahaRequestParams::kOsPlatform("Chrome OS"); | 33 const char* const OmahaRequestParams::kOsPlatform("Chrome OS"); |
| 34 const char* const OmahaRequestParams::kOsVersion("Indy"); | 34 const char* const OmahaRequestParams::kOsVersion("Indy"); |
| 35 const char* const OmahaRequestParams::kUpdateUrl( | 35 const char* const OmahaRequestParams::kUpdateUrl( |
| 36 "https://tools.google.com/service/update2"); | 36 "https://tools.google.com/service/update2"); |
| 37 | 37 |
| 38 static const char kHWIDPath[] = "/sys/devices/platform/chromeos_acpi/HWID"; | 38 static const char kHWIDPath[] = "/sys/devices/platform/chromeos_acpi/HWID"; |
| 39 | 39 |
| 40 OmahaRequestDeviceParams::OmahaRequestDeviceParams() : | 40 OmahaRequestDeviceParams::OmahaRequestDeviceParams() : |
| 41 force_build_type_(false), | 41 force_build_type_(false), |
| 42 forced_official_build_(false) {} | 42 forced_official_build_(false), |
| 43 force_boot_mode_(false), | |
| 44 forced_normal_boot_(false) {} | |
| 43 | 45 |
| 44 bool OmahaRequestDeviceParams::Init(const std::string& in_app_version, | 46 bool OmahaRequestDeviceParams::Init(const std::string& in_app_version, |
| 45 const std::string& in_update_url) { | 47 const std::string& in_update_url) { |
| 48 // Stateful /etc/lsb-release is not read on official builds in normal boot | |
| 49 // mode (except for setting the release track). | |
| 50 bool stateful_override = !IsOfficialBuild() || !IsNormalBootMode(); | |
| 46 os_platform = OmahaRequestParams::kOsPlatform; | 51 os_platform = OmahaRequestParams::kOsPlatform; |
| 47 os_version = OmahaRequestParams::kOsVersion; | 52 os_version = OmahaRequestParams::kOsVersion; |
| 48 app_version = in_app_version.empty() ? | 53 app_version = in_app_version.empty() ? |
| 49 GetLsbValue("CHROMEOS_RELEASE_VERSION", "", NULL, true) : in_app_version; | 54 GetLsbValue("CHROMEOS_RELEASE_VERSION", "", NULL, stateful_override) : |
| 55 in_app_version; | |
| 50 os_sp = app_version + "_" + GetMachineType(); | 56 os_sp = app_version + "_" + GetMachineType(); |
| 51 os_board = GetLsbValue("CHROMEOS_RELEASE_BOARD", "", NULL, true); | 57 os_board = GetLsbValue("CHROMEOS_RELEASE_BOARD", "", NULL, stateful_override); |
| 52 app_id = GetLsbValue("CHROMEOS_RELEASE_APPID", | 58 app_id = GetLsbValue("CHROMEOS_RELEASE_APPID", |
| 53 OmahaRequestParams::kAppId, | 59 OmahaRequestParams::kAppId, |
| 54 NULL, | 60 NULL, |
| 55 true); | 61 stateful_override); |
| 56 app_lang = "en-US"; | 62 app_lang = "en-US"; |
| 57 app_track = GetLsbValue( | 63 app_track = GetLsbValue( |
| 58 kUpdateTrackKey, | 64 kUpdateTrackKey, |
| 59 "", | 65 "", |
| 60 &chromeos_update_engine::OmahaRequestDeviceParams::IsValidTrack, | 66 &chromeos_update_engine::OmahaRequestDeviceParams::IsValidTrack, |
| 61 true); | 67 true); // stateful_override |
| 62 hardware_class = GetHardwareClass(); | 68 hardware_class = GetHardwareClass(); |
| 63 struct stat stbuf; | 69 struct stat stbuf; |
| 64 | 70 |
| 65 // Deltas are only okay if the /.nodelta file does not exist. If we don't | 71 // Deltas are only okay if the /.nodelta file does not exist. If we don't |
| 66 // know (i.e. stat() returns some unexpected error), then err on the side of | 72 // know (i.e. stat() returns some unexpected error), then err on the side of |
| 67 // caution and say deltas are not okay. | 73 // caution and say deltas are not okay. |
| 68 delta_okay = (stat((root_ + "/.nodelta").c_str(), &stbuf) < 0) && | 74 delta_okay = (stat((root_ + "/.nodelta").c_str(), &stbuf) < 0) && |
| 69 (errno == ENOENT); | 75 (errno == ENOENT); |
| 70 | 76 |
| 71 // For now, disable delta updates if the rootfs track is different than the | 77 // For now, disable delta updates if the rootfs track is different than the |
| 72 // track that we're sending to the update server because such updates are | 78 // track that we're sending to the update server because such updates are |
| 73 // destined to fail -- the source rootfs hash will be different than the | 79 // destined to fail -- the source rootfs hash will be different than the |
| 74 // expected hash due to the different track in /etc/lsb-release. | 80 // expected hash due to the different track in /etc/lsb-release. |
| 75 // | 81 // |
| 76 // Longer term we should consider an alternative: (a) clients can send | 82 // Longer term we should consider an alternative: (a) clients can send |
| 77 // (current_version, current_channel, new_channel) information, or (b) the | 83 // (current_version, current_channel, new_channel) information, or (b) the |
| 78 // build process can make sure releases on separate tracks are identical (i.e, | 84 // build process can make sure releases on separate tracks are identical (i.e, |
| 79 // by not stamping the release with the channel), or (c) the release process | 85 // by not stamping the release with the channel), or (c) the release process |
| 80 // can ensure that different channels get different version numbers. | 86 // can ensure that different channels get different version numbers. |
| 81 const string rootfs_track = GetLsbValue( | 87 const string rootfs_track = GetLsbValue( |
| 82 kUpdateTrackKey, | 88 kUpdateTrackKey, |
| 83 "", | 89 "", |
| 84 &chromeos_update_engine::OmahaRequestDeviceParams::IsValidTrack, | 90 &chromeos_update_engine::OmahaRequestDeviceParams::IsValidTrack, |
| 85 false); | 91 false); // stateful_override |
| 86 delta_okay = delta_okay && rootfs_track == app_track; | 92 delta_okay = delta_okay && rootfs_track == app_track; |
| 87 | 93 |
| 88 update_url = in_update_url.empty() ? | 94 update_url = in_update_url.empty() ? |
| 89 GetLsbValue("CHROMEOS_AUSERVER", | 95 GetLsbValue("CHROMEOS_AUSERVER", |
| 90 OmahaRequestParams::kUpdateUrl, | 96 OmahaRequestParams::kUpdateUrl, |
| 91 NULL, | 97 NULL, |
| 92 true) : | 98 stateful_override) : |
| 93 in_update_url; | 99 in_update_url; |
| 94 return true; | 100 return true; |
| 95 } | 101 } |
| 96 | 102 |
| 97 bool OmahaRequestDeviceParams::SetTrack(const std::string& track) { | 103 bool OmahaRequestDeviceParams::SetTrack(const std::string& track) { |
| 98 TEST_AND_RETURN_FALSE(IsValidTrack(track)); | 104 TEST_AND_RETURN_FALSE(IsValidTrack(track)); |
| 99 FilePath kFile(root_ + utils::kStatefulPartition + "/etc/lsb-release"); | 105 FilePath kFile(root_ + utils::kStatefulPartition + "/etc/lsb-release"); |
| 100 string file_data; | 106 string file_data; |
| 101 map<string, string> data; | 107 map<string, string> data; |
| 102 if (file_util::ReadFileToString(kFile, &file_data)) { | 108 if (file_util::ReadFileToString(kFile, &file_data)) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 return ""; | 176 return ""; |
| 171 } | 177 } |
| 172 TrimWhitespaceASCII(hwid, TRIM_ALL, &hwid); | 178 TrimWhitespaceASCII(hwid, TRIM_ALL, &hwid); |
| 173 return hwid; | 179 return hwid; |
| 174 } | 180 } |
| 175 | 181 |
| 176 bool OmahaRequestDeviceParams::IsOfficialBuild() const { | 182 bool OmahaRequestDeviceParams::IsOfficialBuild() const { |
| 177 return force_build_type_ ? forced_official_build_ : utils::IsOfficialBuild(); | 183 return force_build_type_ ? forced_official_build_ : utils::IsOfficialBuild(); |
| 178 } | 184 } |
| 179 | 185 |
| 186 bool OmahaRequestDeviceParams::IsNormalBootMode() const { | |
| 187 return force_boot_mode_ ? forced_normal_boot_ : utils::IsNormalBootMode(); | |
| 188 } | |
| 189 | |
| 180 bool OmahaRequestDeviceParams::IsValidTrack(const std::string& track) const { | 190 bool OmahaRequestDeviceParams::IsValidTrack(const std::string& track) const { |
| 181 static const char* kValidTracks[] = { | 191 static const char* kValidTracks[] = { |
| 182 "canary-channel", | 192 "canary-channel", |
| 183 "beta-channel", | 193 "beta-channel", |
| 184 "dev-channel", | 194 "dev-channel", |
| 185 }; | 195 }; |
| 186 if (!IsOfficialBuild()) { | 196 if (!IsOfficialBuild()) { |
|
adlr
2011/01/10 22:16:17
perhaps:
if (!IsOfficialBuild() || Dev_Mode_is_Act
petkov
2011/01/10 22:51:14
Sure.
| |
| 187 return true; | 197 return true; |
| 188 } | 198 } |
| 189 for (size_t t = 0; t < arraysize(kValidTracks); ++t) { | 199 for (size_t t = 0; t < arraysize(kValidTracks); ++t) { |
| 190 if (track == kValidTracks[t]) { | 200 if (track == kValidTracks[t]) { |
| 191 return true; | 201 return true; |
| 192 } | 202 } |
| 193 } | 203 } |
| 194 return false; | 204 return false; |
| 195 } | 205 } |
| 196 | 206 |
| 197 void OmahaRequestDeviceParams::SetBuildTypeOfficial(bool is_official) { | 207 void OmahaRequestDeviceParams::SetBuildTypeOfficial(bool is_official) { |
| 198 force_build_type_ = true; | 208 force_build_type_ = true; |
| 199 forced_official_build_ = is_official; | 209 forced_official_build_ = is_official; |
| 200 } | 210 } |
| 201 | 211 |
| 212 void OmahaRequestDeviceParams::SetBootModeNormal(bool is_normal) { | |
| 213 force_boot_mode_ = true; | |
| 214 forced_normal_boot_ = is_normal; | |
| 215 } | |
| 216 | |
| 202 } // namespace chromeos_update_engine | 217 } // namespace chromeos_update_engine |
| OLD | NEW |