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 |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "update_engine/simple_key_value_store.h" | 15 #include "update_engine/simple_key_value_store.h" |
16 #include "update_engine/utils.h" | 16 #include "update_engine/utils.h" |
17 | 17 |
18 using std::map; | 18 using std::map; |
19 using std::string; | 19 using std::string; |
20 | 20 |
21 namespace { | 21 namespace { |
22 const string OmahaIdPath() { | 22 const string OmahaIdPath() { |
23 return string(chromeos_update_engine::utils::kStatefulPartition) + | 23 return string(chromeos_update_engine::utils::kStatefulPartition) + |
24 "/etc/omaha_id"; | 24 "/etc/omaha_id"; |
25 } | 25 } |
26 } // namespace {} | 26 } // namespace {} |
27 | 27 |
28 namespace chromeos_update_engine { | 28 namespace chromeos_update_engine { |
29 | 29 |
30 bool OmahaRequestDeviceParams::Init() { | 30 const char* const OmahaRequestParams::kAppId( |
| 31 "{87efface-864d-49a5-9bb3-4b050a7c227a}"); |
| 32 const char* const OmahaRequestParams::kOsPlatform("Chrome OS"); |
| 33 const char* const OmahaRequestParams::kOsVersion("Indy"); |
| 34 const char* const OmahaRequestParams::kUpdateUrl( |
| 35 "https://tools.google.com/service/update2"); |
| 36 |
| 37 bool OmahaRequestDeviceParams::Init(const std::string& in_app_version, |
| 38 const std::string& in_update_url) { |
31 TEST_AND_RETURN_FALSE(GetMachineId(&machine_id)); | 39 TEST_AND_RETURN_FALSE(GetMachineId(&machine_id)); |
32 user_id = machine_id; | 40 user_id = machine_id; |
33 os_platform = OmahaRequestParams::kOsPlatform; | 41 os_platform = OmahaRequestParams::kOsPlatform; |
34 os_version = OmahaRequestParams::kOsVersion; | 42 os_version = OmahaRequestParams::kOsVersion; |
35 app_version = GetLsbValue("CHROMEOS_RELEASE_VERSION", ""); | 43 app_version = in_app_version.empty() ? |
| 44 GetLsbValue("CHROMEOS_RELEASE_VERSION", "") : in_app_version; |
36 os_sp = app_version + "_" + GetMachineType(); | 45 os_sp = app_version + "_" + GetMachineType(); |
37 os_board = GetLsbValue("CHROMEOS_RELEASE_BOARD", ""); | 46 os_board = GetLsbValue("CHROMEOS_RELEASE_BOARD", ""); |
38 app_id = OmahaRequestParams::kAppId; | 47 app_id = OmahaRequestParams::kAppId; |
39 app_lang = "en-US"; | 48 app_lang = "en-US"; |
40 app_track = GetLsbValue("CHROMEOS_RELEASE_TRACK", ""); | 49 app_track = GetLsbValue("CHROMEOS_RELEASE_TRACK", ""); |
41 struct stat stbuf; | 50 struct stat stbuf; |
42 | 51 |
43 // Deltas are only okay if the /.nodelta file does not exist. | 52 // Deltas are only okay if the /.nodelta file does not exist. |
44 // If we don't know (i.e. stat() returns some unexpected error), | 53 // If we don't know (i.e. stat() returns some unexpected error), |
45 // then err on the side of caution and say deltas are not okay | 54 // then err on the side of caution and say deltas are not okay |
46 delta_okay = (stat((root_ + "/.nodelta").c_str(), &stbuf) < 0) && | 55 delta_okay = (stat((root_ + "/.nodelta").c_str(), &stbuf) < 0) && |
47 (errno == ENOENT); | 56 (errno == ENOENT); |
48 | 57 |
49 update_url = GetLsbValue("CHROMEOS_AUSERVER", | 58 update_url = in_update_url.empty() ? |
50 OmahaRequestParams::kUpdateUrl); | 59 GetLsbValue("CHROMEOS_AUSERVER", OmahaRequestParams::kUpdateUrl) : |
| 60 in_update_url; |
51 return true; | 61 return true; |
52 } | 62 } |
53 | 63 |
54 namespace { | 64 namespace { |
55 const size_t kGuidDataByteLength = 128 / 8; | 65 const size_t kGuidDataByteLength = 128 / 8; |
56 const string::size_type kGuidStringLength = 38; | 66 const string::size_type kGuidStringLength = 38; |
57 // Formats 16 bytes (128 bits) of data as a GUID: | 67 // Formats 16 bytes (128 bits) of data as a GUID: |
58 // "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}" where X is a hex digit | 68 // "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}" where X is a hex digit |
59 string GuidFromData(const unsigned char data[kGuidDataByteLength]) { | 69 string GuidFromData(const unsigned char data[kGuidDataByteLength]) { |
60 return StringPrintf( | 70 return StringPrintf( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 124 |
115 string OmahaRequestDeviceParams::GetMachineType() const { | 125 string OmahaRequestDeviceParams::GetMachineType() const { |
116 struct utsname buf; | 126 struct utsname buf; |
117 string ret; | 127 string ret; |
118 if (uname(&buf) == 0) | 128 if (uname(&buf) == 0) |
119 ret = buf.machine; | 129 ret = buf.machine; |
120 return ret; | 130 return ret; |
121 } | 131 } |
122 | 132 |
123 } // namespace chromeos_update_engine | 133 } // namespace chromeos_update_engine |
OLD | NEW |