| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // | 
|  | 2 | // Copyright (C) 2012 The Android Open Source Project | 
|  | 3 | // | 
|  | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | // you may not use this file except in compliance with the License. | 
|  | 6 | // You may obtain a copy of the License at | 
|  | 7 | // | 
|  | 8 | //      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | // | 
|  | 10 | // Unless required by applicable law or agreed to in writing, software | 
|  | 11 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | // See the License for the specific language governing permissions and | 
|  | 14 | // limitations under the License. | 
|  | 15 | // | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 16 |  | 
| Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H_ | 
|  | 18 | #define UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H_ | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 19 |  | 
| Alex Vakulenko | 44cab30 | 2014-07-23 13:12:15 -0700 | [diff] [blame] | 20 | #include <fcntl.h> | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 21 | #include <sys/stat.h> | 
| Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 22 | #include <sys/types.h> | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 23 |  | 
| Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 24 | #include <map> | 
| Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 25 | #include <memory> | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 26 | #include <string> | 
| Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 27 | #include <vector> | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 28 |  | 
| Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 29 | #include <gtest/gtest_prod.h>  // for FRIEND_TEST | 
|  | 30 |  | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 31 | #include <brillo/secure_blob.h> | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 32 | #include <curl/curl.h> | 
|  | 33 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 34 | #include "update_engine/common/action.h" | 
|  | 35 | #include "update_engine/common/http_fetcher.h" | 
| Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 36 | #include "update_engine/omaha_response.h" | 
| Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 37 | #include "update_engine/system_state.h" | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 38 |  | 
| Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 39 | // The Omaha Request action makes a request to Omaha and can output | 
|  | 40 | // the response on the output ActionPipe. | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 41 |  | 
| Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 42 | namespace policy { | 
|  | 43 | class PolicyProvider; | 
|  | 44 | } | 
|  | 45 |  | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 46 | namespace chromeos_update_engine { | 
|  | 47 |  | 
| Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 48 | // Encodes XML entities in a given string. Input must be ASCII-7 valid. If | 
|  | 49 | // the input is invalid, the default value is used instead. | 
|  | 50 | std::string XmlEncodeWithDefault(const std::string& input, | 
|  | 51 | const std::string& default_value); | 
|  | 52 |  | 
|  | 53 | // Escapes text so it can be included as character data and attribute | 
|  | 54 | // values. The |input| string must be valid ASCII-7, no UTF-8 supported. | 
|  | 55 | // Returns whether the |input| was valid and escaped properly in |output|. | 
|  | 56 | bool XmlEncode(const std::string& input, std::string* output); | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 57 |  | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 58 | // This struct encapsulates the Omaha event information. For a | 
|  | 59 | // complete list of defined event types and results, see | 
|  | 60 | // http://code.google.com/p/omaha/wiki/ServerProtocol#event | 
|  | 61 | struct OmahaEvent { | 
| Jay Srinivasan | 56d5aa4 | 2012-03-26 14:27:59 -0700 | [diff] [blame] | 62 | // The Type values correspond to EVENT_TYPE values of Omaha. | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 63 | enum Type { | 
|  | 64 | kTypeUnknown = 0, | 
|  | 65 | kTypeDownloadComplete = 1, | 
|  | 66 | kTypeInstallComplete = 2, | 
|  | 67 | kTypeUpdateComplete = 3, | 
| Darin Petkov | 8c2980e | 2010-07-16 15:16:49 -0700 | [diff] [blame] | 68 | kTypeUpdateDownloadStarted = 13, | 
|  | 69 | kTypeUpdateDownloadFinished = 14, | 
| Alex Deymo | 9fded1e | 2015-11-05 12:31:19 -0800 | [diff] [blame] | 70 | // Chromium OS reserved type sent after the first reboot following an update | 
|  | 71 | // completed. | 
|  | 72 | kTypeRebootedAfterUpdate = 54, | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 73 | }; | 
|  | 74 |  | 
| Jay Srinivasan | 56d5aa4 | 2012-03-26 14:27:59 -0700 | [diff] [blame] | 75 | // The Result values correspond to EVENT_RESULT values of Omaha. | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 76 | enum Result { | 
|  | 77 | kResultError = 0, | 
|  | 78 | kResultSuccess = 1, | 
| Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 79 | kResultUpdateDeferred = 9,  // When we ignore/defer updates due to policy. | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 80 | }; | 
|  | 81 |  | 
|  | 82 | OmahaEvent() | 
|  | 83 | : type(kTypeUnknown), | 
|  | 84 | result(kResultError), | 
| Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 85 | error_code(ErrorCode::kError) {} | 
| Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 86 | explicit OmahaEvent(Type in_type) | 
|  | 87 | : type(in_type), | 
|  | 88 | result(kResultSuccess), | 
| Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 89 | error_code(ErrorCode::kSuccess) {} | 
| David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 90 | OmahaEvent(Type in_type, Result in_result, ErrorCode in_error_code) | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 91 | : type(in_type), | 
|  | 92 | result(in_result), | 
|  | 93 | error_code(in_error_code) {} | 
|  | 94 |  | 
|  | 95 | Type type; | 
|  | 96 | Result result; | 
| David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 97 | ErrorCode error_code; | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 98 | }; | 
|  | 99 |  | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 100 | class NoneType; | 
| Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 101 | class OmahaRequestAction; | 
| Yunlian Jiang | a178e5e | 2013-04-05 14:41:56 -0700 | [diff] [blame] | 102 | class OmahaRequestParams; | 
| Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 103 | class PrefsInterface; | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 104 |  | 
| David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 105 | // This struct is declared in the .cc file. | 
|  | 106 | struct OmahaParserData; | 
|  | 107 |  | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 108 | template<> | 
| Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 109 | class ActionTraits<OmahaRequestAction> { | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 110 | public: | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 111 | // Takes parameters on the input pipe. | 
| Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 112 | typedef NoneType InputObjectType; | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 113 | // On UpdateCheck success, puts the Omaha response on output. Event | 
|  | 114 | // requests do not have an output pipe. | 
| Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 115 | typedef OmahaResponse OutputObjectType; | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 116 | }; | 
|  | 117 |  | 
| Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 118 | class OmahaRequestAction : public Action<OmahaRequestAction>, | 
|  | 119 | public HttpFetcherDelegate { | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 120 | public: | 
| Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 121 | static const int kNeverPinged = -1; | 
|  | 122 | static const int kPingTimeJump = -2; | 
| Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 123 | // We choose this value of 10 as a heuristic for a work day in trying | 
|  | 124 | // each URL, assuming we check roughly every 45 mins. This is a good time to | 
|  | 125 | // wait - neither too long nor too little - so we don't give up the preferred | 
|  | 126 | // URLs that appear earlier in list too quickly before moving on to the | 
|  | 127 | // fallback ones. | 
|  | 128 | static const int kDefaultMaxFailureCountPerUrl = 10; | 
| Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 129 |  | 
| Adolfo Victoria | 497044c | 2018-07-18 07:51:42 -0700 | [diff] [blame] | 130 | // If staging is enabled, set the maximum wait time to 28 days, since that is | 
|  | 131 | // the predetermined wait time for staging. | 
|  | 132 | static const int kMaxWaitTimeStagingInDays = 28; | 
|  | 133 |  | 
| Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 134 | // These are the possible outcome upon checking whether we satisfied | 
|  | 135 | // the wall-clock-based-wait. | 
|  | 136 | enum WallClockWaitResult { | 
|  | 137 | kWallClockWaitNotSatisfied, | 
|  | 138 | kWallClockWaitDoneButUpdateCheckWaitRequired, | 
|  | 139 | kWallClockWaitDoneAndUpdateCheckWaitNotRequired, | 
|  | 140 | }; | 
|  | 141 |  | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 142 | // The ctor takes in all the parameters that will be used for making | 
|  | 143 | // the request to Omaha. For some of them we have constants that | 
|  | 144 | // should be used. | 
|  | 145 | // | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 146 | // Takes ownership of the passed in HttpFetcher. Useful for testing. | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 147 | // | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 148 | // Takes ownership of the passed in OmahaEvent. If |event| is null, | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 149 | // this is an UpdateCheck request, otherwise it's an Event request. | 
|  | 150 | // Event requests always succeed. | 
|  | 151 | // | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 152 | // A good calling pattern is: | 
| Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 153 | // OmahaRequestAction(..., new OmahaEvent(...), new WhateverHttpFetcher); | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 154 | // or | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 155 | // OmahaRequestAction(..., nullptr, new WhateverHttpFetcher); | 
| Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 156 | OmahaRequestAction(SystemState* system_state, | 
| Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 157 | OmahaEvent* event, | 
| Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 158 | std::unique_ptr<HttpFetcher> http_fetcher, | 
| Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 159 | bool ping_only); | 
| Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 160 | ~OmahaRequestAction() override; | 
| Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 161 | typedef ActionTraits<OmahaRequestAction>::InputObjectType InputObjectType; | 
|  | 162 | typedef ActionTraits<OmahaRequestAction>::OutputObjectType OutputObjectType; | 
| Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 163 | void PerformAction() override; | 
|  | 164 | void TerminateProcessing() override; | 
|  | 165 | void ActionCompleted(ErrorCode code) override; | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 166 |  | 
| Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 167 | int GetHTTPResponseCode() { return http_fetcher_->http_response_code(); } | 
|  | 168 |  | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 169 | // Debugging/logging | 
| Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 170 | static std::string StaticType() { return "OmahaRequestAction"; } | 
| Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 171 | std::string Type() const override { return StaticType(); } | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 172 |  | 
|  | 173 | // Delegate methods (see http_fetcher.h) | 
| Amin Hassani | 0cd9d77 | 2018-07-31 23:55:43 -0700 | [diff] [blame] | 174 | bool ReceivedBytes(HttpFetcher* fetcher, | 
|  | 175 | const void* bytes, | 
|  | 176 | size_t length) override; | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 177 |  | 
| Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 178 | void TransferComplete(HttpFetcher *fetcher, bool successful) override; | 
|  | 179 |  | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 180 | // Returns true if this is an Event request, false if it's an UpdateCheck. | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 181 | bool IsEvent() const { return event_.get() != nullptr; } | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 182 |  | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 183 | private: | 
| Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 184 | friend class OmahaRequestActionTest; | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 185 | friend class OmahaRequestActionTestProcessorDelegate; | 
| Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 186 | FRIEND_TEST(OmahaRequestActionTest, GetInstallDateWhenNoPrefsNorOOBE); | 
|  | 187 | FRIEND_TEST(OmahaRequestActionTest, | 
|  | 188 | GetInstallDateWhenOOBECompletedWithInvalidDate); | 
|  | 189 | FRIEND_TEST(OmahaRequestActionTest, | 
|  | 190 | GetInstallDateWhenOOBECompletedWithValidDate); | 
|  | 191 | FRIEND_TEST(OmahaRequestActionTest, | 
|  | 192 | GetInstallDateWhenOOBECompletedDateChanges); | 
| David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 193 |  | 
|  | 194 | // Enumeration used in PersistInstallDate(). | 
|  | 195 | enum InstallDateProvisioningSource { | 
|  | 196 | kProvisionedFromOmahaResponse, | 
|  | 197 | kProvisionedFromOOBEMarker, | 
|  | 198 |  | 
|  | 199 | // kProvisionedMax is the count of the number of enums above. Add | 
|  | 200 | // any new enums above this line only. | 
|  | 201 | kProvisionedMax | 
|  | 202 | }; | 
|  | 203 |  | 
|  | 204 | // Gets the install date, expressed as the number of PST8PDT | 
|  | 205 | // calendar weeks since January 1st 2007, times seven. Returns -1 if | 
|  | 206 | // unknown. See http://crbug.com/336838 for details about this value. | 
|  | 207 | static int GetInstallDate(SystemState* system_state); | 
|  | 208 |  | 
|  | 209 | // Parses the Omaha Response in |doc| and sets the | 
|  | 210 | // |install_date_days| field of |output_object| to the value of the | 
|  | 211 | // elapsed_days attribute of the daystart element. Returns True if | 
|  | 212 | // the value was set, False if it wasn't found. | 
| David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 213 | static bool ParseInstallDate(OmahaParserData* parser_data, | 
| David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 214 | OmahaResponse* output_object); | 
|  | 215 |  | 
|  | 216 | // Returns True if the kPrefsInstallDateDays state variable is set, | 
|  | 217 | // False otherwise. | 
|  | 218 | static bool HasInstallDate(SystemState *system_state); | 
|  | 219 |  | 
|  | 220 | // Writes |install_date_days| into the kPrefsInstallDateDays state | 
|  | 221 | // variable and emits an UMA stat for the |source| used. Returns | 
|  | 222 | // True if the value was written, False if an error occurred. | 
|  | 223 | static bool PersistInstallDate(SystemState *system_state, | 
|  | 224 | int install_date_days, | 
|  | 225 | InstallDateProvisioningSource source); | 
|  | 226 |  | 
| Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 227 | // Persist the new cohort* value received in the XML file in the |prefs_key| | 
|  | 228 | // preference file. If the |new_value| is empty, the currently stored value | 
|  | 229 | // will be deleted. Don't call this function with an empty |new_value| if the | 
|  | 230 | // value was not set in the XML, since that would delete the stored value. | 
|  | 231 | bool PersistCohortData(const std::string& prefs_key, | 
|  | 232 | const std::string& new_value); | 
|  | 233 |  | 
| Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 234 | // Parse and persist the end-of-life status flag sent back in the updatecheck | 
|  | 235 | // tag attributes. The flag will be validated and stored in the Prefs. | 
|  | 236 | bool PersistEolStatus(const std::map<std::string, std::string>& attrs); | 
|  | 237 |  | 
| Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 238 | // If this is an update check request, initializes | 
|  | 239 | // |ping_active_days_| and |ping_roll_call_days_| to values that may | 
|  | 240 | // be sent as pings to Omaha. | 
|  | 241 | void InitPingDays(); | 
|  | 242 |  | 
| Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 243 | // Based on the persistent preference store values, calculates the | 
| Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 244 | // number of days since the last ping sent for |key|. | 
|  | 245 | int CalculatePingDays(const std::string& key); | 
|  | 246 |  | 
| Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 247 | // Returns whether we have "active_days" or "roll_call_days" ping values to | 
|  | 248 | // send to Omaha and thus we should include them in the response. | 
|  | 249 | bool ShouldPing() const; | 
|  | 250 |  | 
| Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 251 | // Returns true if the download of a new update should be deferred. | 
|  | 252 | // False if the update can be downloaded. | 
| Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 253 | bool ShouldDeferDownload(OmahaResponse* output_object); | 
| Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 254 |  | 
|  | 255 | // Returns true if the basic wall-clock-based waiting period has been | 
|  | 256 | // satisfied based on the scattering policy setting. False otherwise. | 
|  | 257 | // If true, it also indicates whether the additional update-check-count-based | 
|  | 258 | // waiting period also needs to be satisfied before the download can begin. | 
|  | 259 | WallClockWaitResult IsWallClockBasedWaitingSatisfied( | 
| Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 260 | OmahaResponse* output_object); | 
| Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 261 |  | 
|  | 262 | // Returns true if the update-check-count-based waiting period has been | 
|  | 263 | // satisfied. False otherwise. | 
| Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 264 | bool IsUpdateCheckCountBasedWaitingSatisfied(); | 
|  | 265 |  | 
|  | 266 | // Parses the response from Omaha that's available in |doc| using the other | 
|  | 267 | // helper methods below and populates the |output_object| with the relevant | 
|  | 268 | // values. Returns true if we should continue the parsing.  False otherwise, | 
|  | 269 | // in which case it sets any error code using |completer|. | 
| David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 270 | bool ParseResponse(OmahaParserData* parser_data, | 
| Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 271 | OmahaResponse* output_object, | 
|  | 272 | ScopedActionCompleter* completer); | 
|  | 273 |  | 
|  | 274 | // Parses the status property in the given update_check_node and populates | 
|  | 275 | // |output_object| if valid. Returns true if we should continue the parsing. | 
|  | 276 | // False otherwise, in which case it sets any error code using |completer|. | 
| David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 277 | bool ParseStatus(OmahaParserData* parser_data, | 
| Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 278 | OmahaResponse* output_object, | 
|  | 279 | ScopedActionCompleter* completer); | 
|  | 280 |  | 
|  | 281 | // Parses the URL nodes in the given XML document and populates | 
|  | 282 | // |output_object| if valid. Returns true if we should continue the parsing. | 
|  | 283 | // False otherwise, in which case it sets any error code using |completer|. | 
| David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 284 | bool ParseUrls(OmahaParserData* parser_data, | 
| Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 285 | OmahaResponse* output_object, | 
|  | 286 | ScopedActionCompleter* completer); | 
|  | 287 |  | 
| Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 288 | // Parses the other parameters in the given XML document and populates | 
|  | 289 | // |output_object| if valid. Returns true if we should continue the parsing. | 
|  | 290 | // False otherwise, in which case it sets any error code using |completer|. | 
| David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 291 | bool ParseParams(OmahaParserData* parser_data, | 
| Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 292 | OmahaResponse* output_object, | 
|  | 293 | ScopedActionCompleter* completer); | 
| Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 294 |  | 
| David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 295 | // Called by TransferComplete() to complete processing, either | 
|  | 296 | // asynchronously after looking up resources via p2p or directly. | 
|  | 297 | void CompleteProcessing(); | 
|  | 298 |  | 
|  | 299 | // Helper to asynchronously look up payload on the LAN. | 
|  | 300 | void LookupPayloadViaP2P(const OmahaResponse& response); | 
|  | 301 |  | 
|  | 302 | // Callback used by LookupPayloadViaP2P(). | 
|  | 303 | void OnLookupPayloadViaP2PCompleted(const std::string& url); | 
|  | 304 |  | 
| Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 305 | // Returns true if the current update should be ignored. | 
| Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 306 | bool ShouldIgnoreUpdate(ErrorCode* error, | 
|  | 307 | const OmahaResponse& response) const; | 
|  | 308 |  | 
|  | 309 | // Return true if updates are allowed by user preferences. | 
|  | 310 | bool IsUpdateAllowedOverCellularByPrefs(const OmahaResponse& response) const; | 
| Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 311 |  | 
|  | 312 | // Returns true if updates are allowed over the current type of connection. | 
|  | 313 | // False otherwise. | 
| Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 314 | bool IsUpdateAllowedOverCurrentConnection( | 
|  | 315 | ErrorCode* error, const OmahaResponse& response) const; | 
| Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 316 |  | 
| Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 317 | // Returns true if rollback is enabled. Always returns false for consumer | 
|  | 318 | // devices. | 
|  | 319 | bool IsRollbackEnabled() const; | 
|  | 320 |  | 
|  | 321 | // Sets the appropriate max kernel key version based on whether rollback is | 
|  | 322 | // enabled. | 
|  | 323 | void SetMaxKernelKeyVersionForRollback() const; | 
|  | 324 |  | 
| Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 325 | // Global system context. | 
|  | 326 | SystemState* system_state_; | 
| Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 327 |  | 
| Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 328 | // Contains state that is relevant in the processing of the Omaha request. | 
|  | 329 | OmahaRequestParams* params_; | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 330 |  | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 331 | // Pointer to the OmahaEvent info. This is an UpdateCheck request if null. | 
| Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 332 | std::unique_ptr<OmahaEvent> event_; | 
| Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 333 |  | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 334 | // pointer to the HttpFetcher that does the http work | 
| Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 335 | std::unique_ptr<HttpFetcher> http_fetcher_; | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 336 |  | 
| Zentaro Kavanagh | 1f899d5 | 2018-02-27 15:02:47 -0800 | [diff] [blame] | 337 | // Used for fetching information about the device policy. | 
|  | 338 | std::unique_ptr<policy::PolicyProvider> policy_provider_; | 
|  | 339 |  | 
| Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 340 | // If true, only include the <ping> element in the request. | 
|  | 341 | bool ping_only_; | 
|  | 342 |  | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 343 | // Stores the response from the omaha server | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 344 | brillo::Blob response_buffer_; | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 345 |  | 
| Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 346 | // Initialized by InitPingDays to values that may be sent to Omaha | 
|  | 347 | // as part of a ping message. Note that only positive values and -1 | 
|  | 348 | // are sent to Omaha. | 
|  | 349 | int ping_active_days_; | 
|  | 350 | int ping_roll_call_days_; | 
|  | 351 |  | 
| Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 352 | DISALLOW_COPY_AND_ASSIGN(OmahaRequestAction); | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 353 | }; | 
|  | 354 |  | 
|  | 355 | }  // namespace chromeos_update_engine | 
|  | 356 |  | 
| Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 357 | #endif  // UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H_ |