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 // 16 17 #ifndef UPDATE_ENGINE_CROS_UPDATE_ATTEMPTER_H_ 18 #define UPDATE_ENGINE_CROS_UPDATE_ATTEMPTER_H_ 19 20 #include <time.h> 21 22 #include <memory> 23 #include <set> 24 #include <string> 25 #include <utility> 26 #include <vector> 27 28 #include <base/bind.h> 29 #include <base/guid.h> 30 #include <base/time/time.h> 31 #include <gtest/gtest_prod.h> // for FRIEND_TEST 32 33 #include "update_engine/certificate_checker.h" 34 #include "update_engine/client_library/include/update_engine/update_status.h" 35 #include "update_engine/common/action_processor.h" 36 #include "update_engine/common/cpu_limiter.h" 37 #include "update_engine/common/daemon_state_interface.h" 38 #include "update_engine/common/download_action.h" 39 #include "update_engine/common/excluder_interface.h" 40 #include "update_engine/common/proxy_resolver.h" 41 #include "update_engine/common/service_observer_interface.h" 42 #include "update_engine/common/system_state.h" 43 #include "update_engine/cros/chrome_browser_proxy_resolver.h" 44 #include "update_engine/cros/omaha_request_builder_xml.h" 45 #include "update_engine/cros/omaha_request_params.h" 46 #include "update_engine/cros/omaha_response_handler_action.h" 47 #include "update_engine/payload_consumer/postinstall_runner_action.h" 48 #include "update_engine/update_manager/policy.h" 49 #include "update_engine/update_manager/staging_utils.h" 50 #include "update_engine/update_manager/update_manager.h" 51 52 namespace policy { 53 class PolicyProvider; 54 } 55 56 namespace chromeos_update_engine { 57 58 class UpdateAttempter : public ActionProcessorDelegate, 59 public DownloadActionDelegate, 60 public CertificateChecker::Observer, 61 public PostinstallRunnerAction::DelegateInterface, 62 public DaemonStateInterface { 63 public: 64 using UpdateStatus = update_engine::UpdateStatus; 65 using UpdateAttemptFlags = update_engine::UpdateAttemptFlags; 66 static const int kMaxDeltaUpdateFailures; 67 68 explicit UpdateAttempter(CertificateChecker* cert_checker); 69 ~UpdateAttempter() override; 70 71 // Further initialization to be done post construction. 72 void Init(); 73 74 // Initiates scheduling of update checks. 75 // Returns true if update check is scheduled. 76 virtual bool ScheduleUpdates(); 77 78 // Checks for update and, if a newer version is available, attempts to update 79 // the system. 80 virtual void Update(const chromeos_update_manager::UpdateCheckParams& params); 81 82 // ActionProcessorDelegate methods: 83 void ProcessingDone(const ActionProcessor* processor, 84 ErrorCode code) override; 85 void ProcessingStopped(const ActionProcessor* processor) override; 86 void ActionCompleted(ActionProcessor* processor, 87 AbstractAction* action, 88 ErrorCode code) override; 89 90 // PostinstallRunnerAction::DelegateInterface 91 void ProgressUpdate(double progress) override; 92 93 // Resets the current state to UPDATE_STATUS_IDLE. 94 // Used by update_engine_client for restarting a new update without 95 // having to reboot once the previous update has reached 96 // UPDATE_STATUS_UPDATED_NEED_REBOOT state. This is used only 97 // for testing purposes. 98 virtual bool ResetStatus(); 99 100 // Returns the current status in the out param. Returns true on success. 101 virtual bool GetStatus(update_engine::UpdateEngineStatus* out_status); 102 status()103 UpdateStatus status() const { return status_; } 104 http_response_code()105 int http_response_code() const { return http_response_code_; } set_http_response_code(int code)106 void set_http_response_code(int code) { http_response_code_ = code; } 107 108 // Set flags that influence how updates and checks are performed. These 109 // influence all future checks and updates until changed or the device 110 // reboots. SetUpdateAttemptFlags(UpdateAttemptFlags flags)111 void SetUpdateAttemptFlags(UpdateAttemptFlags flags) { 112 update_attempt_flags_ = flags; 113 } 114 115 // Returns the update attempt flags that are in place for the current update 116 // attempt. These are cached at the start of an update attempt so that they 117 // remain constant throughout the process. GetCurrentUpdateAttemptFlags()118 virtual UpdateAttemptFlags GetCurrentUpdateAttemptFlags() const { 119 return current_update_attempt_flags_; 120 } 121 122 // This is the internal entry point for going through an 123 // update. If the current status is idle invokes Update. 124 // This is called by the DBus implementation. 125 // This returns true if an update check was started, false if a check or an 126 // update was already in progress. 127 virtual bool CheckForUpdate(const std::string& app_version, 128 const std::string& omaha_url, 129 UpdateAttemptFlags flags); 130 131 // This is the version of CheckForUpdate called by AttemptInstall API. 132 virtual bool CheckForInstall(const std::vector<std::string>& dlc_ids, 133 const std::string& omaha_url); 134 135 // This is the internal entry point for going through a rollback. This will 136 // attempt to run the postinstall on the non-active partition and set it as 137 // the partition to boot from. If |powerwash| is True, perform a powerwash 138 // as part of rollback. Returns True on success. 139 bool Rollback(bool powerwash); 140 141 // This is the internal entry point for checking if we can rollback. 142 bool CanRollback() const; 143 144 // This is the internal entry point for getting a rollback partition name, 145 // if one exists. It returns the bootable rollback kernel device partition 146 // name or empty string if none is available. 147 BootControlInterface::Slot GetRollbackSlot() const; 148 149 // Initiates a reboot if the current state is 150 // UPDATED_NEED_REBOOT. Returns true on success, false otherwise. 151 bool RebootIfNeeded(); 152 153 // Sets the DLC as active or inactive. See chromeos/common_service.h 154 virtual bool SetDlcActiveValue(bool is_active, const std::string& dlc_id); 155 156 // DownloadActionDelegate methods: 157 void BytesReceived(uint64_t bytes_progressed, 158 uint64_t bytes_received, 159 uint64_t total) override; 160 161 // Returns that the update should be canceled when the download channel was 162 // changed. 163 bool ShouldCancel(ErrorCode* cancel_reason) override; 164 165 void DownloadComplete() override; 166 167 // Broadcasts the current status to all observers. 168 void BroadcastStatus(); 169 GetAttemptErrorCode()170 ErrorCode GetAttemptErrorCode() const { return attempt_error_code_; } 171 172 // Called at update_engine startup to do various house-keeping. 173 void UpdateEngineStarted(); 174 175 // Returns the |Excluder| that is currently held onto. GetExcluder()176 virtual ExcluderInterface* GetExcluder() const { return excluder_.get(); } 177 178 // Reloads the device policy from libbrillo. Note: This method doesn't 179 // cause a real-time policy fetch from the policy server. It just reloads the 180 // latest value that libbrillo has cached. libbrillo fetches the policies 181 // from the server asynchronously at its own frequency. 182 virtual void RefreshDevicePolicy(); 183 184 // Stores in |out_boot_time| the boottime (CLOCK_BOOTTIME) recorded at the 185 // time of the last successful update in the current boot. Returns false if 186 // there wasn't a successful update in the current boot. 187 virtual bool GetBootTimeAtUpdate(base::Time* out_boot_time); 188 189 // Returns a version OS version that was being used before the last reboot, 190 // and if that reboot happened to be into an update (current version). 191 // This will return an empty string otherwise. GetPrevVersion()192 const std::string& GetPrevVersion() const { return prev_version_; } 193 194 // Returns the number of consecutive failed update checks. consecutive_failed_update_checks()195 virtual unsigned int consecutive_failed_update_checks() const { 196 return consecutive_failed_update_checks_; 197 } 198 199 // Returns the poll interval dictated by Omaha, if provided; zero otherwise. server_dictated_poll_interval()200 virtual unsigned int server_dictated_poll_interval() const { 201 return server_dictated_poll_interval_; 202 } 203 204 // Sets a callback to be used when either a forced update request is received 205 // (first argument set to true) or cleared by an update attempt (first 206 // argument set to false). The callback further encodes whether the forced 207 // check is an interactive one (second argument set to true). Takes ownership 208 // of the callback object. A null value disables callback on these events. 209 // Note that only one callback can be set, so effectively at most one client 210 // can be notified. set_forced_update_pending_callback(base::Callback<void (bool,bool)> * callback)211 virtual void set_forced_update_pending_callback( 212 base::Callback<void(bool, bool)>* callback) { 213 forced_update_pending_callback_.reset(callback); 214 } 215 216 // Returns true if we should allow updates from any source. In official builds 217 // we want to restrict updates to known safe sources, but under certain 218 // conditions it's useful to allow updating from anywhere (e.g. to allow 219 // 'cros flash' to function properly). 220 bool IsAnyUpdateSourceAllowed() const; 221 222 // |DaemonStateInterface| overrides. 223 bool StartUpdater() override; AddObserver(ServiceObserverInterface * observer)224 void AddObserver(ServiceObserverInterface* observer) override { 225 service_observers_.insert(observer); 226 } RemoveObserver(ServiceObserverInterface * observer)227 void RemoveObserver(ServiceObserverInterface* observer) override { 228 service_observers_.erase(observer); 229 } service_observers()230 const std::set<ServiceObserverInterface*>& service_observers() override { 231 return service_observers_; 232 } 233 234 // Remove all the observers. ClearObservers()235 void ClearObservers() { service_observers_.clear(); } 236 237 private: 238 // Friend declarations for testing purposes. 239 friend class UpdateAttempterUnderTest; 240 friend class UpdateAttempterTest; 241 FRIEND_TEST(UpdateAttempterTest, ActionCompletedDownloadTest); 242 FRIEND_TEST(UpdateAttempterTest, ActionCompletedErrorTest); 243 FRIEND_TEST(UpdateAttempterTest, ActionCompletedOmahaRequestTest); 244 FRIEND_TEST(UpdateAttempterTest, BootTimeInUpdateMarkerFile); 245 FRIEND_TEST(UpdateAttempterTest, BroadcastCompleteDownloadTest); 246 FRIEND_TEST(UpdateAttempterTest, CalculateDlcParamsInstallTest); 247 FRIEND_TEST(UpdateAttempterTest, CalculateDlcParamsNoPrefFilesTest); 248 FRIEND_TEST(UpdateAttempterTest, CalculateDlcParamsNonParseableValuesTest); 249 FRIEND_TEST(UpdateAttempterTest, CalculateDlcParamsValidValuesTest); 250 FRIEND_TEST(UpdateAttempterTest, CalculateDlcParamsRemoveStaleMetadata); 251 FRIEND_TEST(UpdateAttempterTest, ChangeToDownloadingOnReceivedBytesTest); 252 FRIEND_TEST(UpdateAttempterTest, CheckForInstallNotIdleFails); 253 FRIEND_TEST(UpdateAttempterTest, CheckForUpdateAUDlcTest); 254 FRIEND_TEST(UpdateAttempterTest, CreatePendingErrorEventTest); 255 FRIEND_TEST(UpdateAttempterTest, CreatePendingErrorEventResumedTest); 256 FRIEND_TEST(UpdateAttempterTest, DisableDeltaUpdateIfNeededTest); 257 FRIEND_TEST(UpdateAttempterTest, DownloadProgressAccumulationTest); 258 FRIEND_TEST(UpdateAttempterTest, InstallSetsStatusIdle); 259 FRIEND_TEST(UpdateAttempterTest, IsEnterpriseRollbackInGetStatusTrue); 260 FRIEND_TEST(UpdateAttempterTest, IsEnterpriseRollbackInGetStatusFalse); 261 FRIEND_TEST(UpdateAttempterTest, 262 PowerwashInGetStatusTrueBecausePowerwashRequired); 263 FRIEND_TEST(UpdateAttempterTest, PowerwashInGetStatusTrueBecauseRollback); 264 FRIEND_TEST(UpdateAttempterTest, MarkDeltaUpdateFailureTest); 265 FRIEND_TEST(UpdateAttempterTest, PingOmahaTest); 266 FRIEND_TEST(UpdateAttempterTest, ProcessingDoneInstallError); 267 FRIEND_TEST(UpdateAttempterTest, ProcessingDoneUpdateError); 268 FRIEND_TEST(UpdateAttempterTest, ReportDailyMetrics); 269 FRIEND_TEST(UpdateAttempterTest, RollbackNotAllowed); 270 FRIEND_TEST(UpdateAttempterTest, RollbackAfterInstall); 271 FRIEND_TEST(UpdateAttempterTest, RollbackAllowed); 272 FRIEND_TEST(UpdateAttempterTest, RollbackAllowedSetAndReset); 273 FRIEND_TEST(UpdateAttempterTest, ChannelDowngradeNoRollback); 274 FRIEND_TEST(UpdateAttempterTest, ChannelDowngradeRollback); 275 FRIEND_TEST(UpdateAttempterTest, RollbackMetricsNotRollbackFailure); 276 FRIEND_TEST(UpdateAttempterTest, RollbackMetricsNotRollbackSuccess); 277 FRIEND_TEST(UpdateAttempterTest, RollbackMetricsRollbackFailure); 278 FRIEND_TEST(UpdateAttempterTest, RollbackMetricsRollbackSuccess); 279 FRIEND_TEST(UpdateAttempterTest, ScheduleErrorEventActionNoEventTest); 280 FRIEND_TEST(UpdateAttempterTest, ScheduleErrorEventActionTest); 281 FRIEND_TEST(UpdateAttempterTest, SessionIdTestEnforceEmptyStrPingOmaha); 282 FRIEND_TEST(UpdateAttempterTest, SessionIdTestOnOmahaRequestActions); 283 FRIEND_TEST(UpdateAttempterTest, SetRollbackHappenedNotRollback); 284 FRIEND_TEST(UpdateAttempterTest, SetRollbackHappenedRollback); 285 FRIEND_TEST(UpdateAttempterTest, TargetChannelHintSetAndReset); 286 FRIEND_TEST(UpdateAttempterTest, TargetVersionPrefixSetAndReset); 287 FRIEND_TEST(UpdateAttempterTest, UpdateAfterInstall); 288 FRIEND_TEST(UpdateAttempterTest, UpdateAttemptFlagsCachedAtUpdateStart); 289 FRIEND_TEST(UpdateAttempterTest, UpdateDeferredByPolicyTest); 290 FRIEND_TEST(UpdateAttempterTest, UpdateIsNotRunningWhenUpdateAvailable); 291 FRIEND_TEST(UpdateAttempterTest, GetSuccessfulDlcIds); 292 FRIEND_TEST(UpdateAttempterTest, QuickFixTokenWhenDeviceIsEnterpriseEnrolled); 293 FRIEND_TEST(UpdateAttempterTest, MoveToPrefs); 294 295 // Returns the special flags to be added to ErrorCode values based on the 296 // parameters used in the current update attempt. 297 uint32_t GetErrorCodeFlags(); 298 299 // ActionProcessorDelegate methods |ProcessingDone()| internal helpers. 300 void ProcessingDoneInternal(const ActionProcessor* processor, ErrorCode code); 301 void ProcessingDoneUpdate(const ActionProcessor* processor, ErrorCode code); 302 void ProcessingDoneInstall(const ActionProcessor* processor, ErrorCode code); 303 304 // CertificateChecker::Observer method. 305 // Report metrics about the certificate being checked. 306 void CertificateChecked(ServerToCheck server_to_check, 307 CertificateCheckResult result) override; 308 309 // Checks if it's more than 24 hours since daily metrics were last 310 // reported and, if so, reports daily metrics. Returns |true| if 311 // metrics were reported, |false| otherwise. 312 bool CheckAndReportDailyMetrics(); 313 314 // Calculates and reports the age of the currently running OS. This 315 // is defined as the age of the /etc/lsb-release file. 316 void ReportOSAge(); 317 318 // Sets the status to the given status and notifies a status update over dbus. 319 void SetStatusAndNotify(UpdateStatus status); 320 321 // Creates an error event object in |error_event_| to be included in an 322 // OmahaRequestAction once the current action processor is done. 323 void CreatePendingErrorEvent(AbstractAction* action, ErrorCode code); 324 325 // If there's a pending error event allocated in |error_event_|, schedules an 326 // OmahaRequestAction with that event in the current processor, clears the 327 // pending event, updates the status and returns true. Returns false 328 // otherwise. 329 bool ScheduleErrorEventAction(); 330 331 // Schedules an event loop callback to start the action processor. This is 332 // scheduled asynchronously to unblock the event loop. 333 void ScheduleProcessingStart(); 334 335 // Checks if a full update is needed and forces it by updating the Omaha 336 // request params. 337 void DisableDeltaUpdateIfNeeded(); 338 339 // If this was a delta update attempt that failed, count it so that a full 340 // update can be tried when needed. 341 void MarkDeltaUpdateFailure(); 342 GetProxyResolver()343 ProxyResolver* GetProxyResolver() { 344 if (obeying_proxies_) 345 return &chrome_proxy_resolver_; 346 return &direct_proxy_resolver_; 347 } 348 349 // Sends a ping to Omaha. 350 // This is used after an update has been applied and we're waiting for the 351 // user to reboot. This ping helps keep the number of actives count 352 // accurate in case a user takes a long time to reboot the device after an 353 // update has been applied. 354 void PingOmaha(); 355 356 // Helper method of Update() to calculate the update-related parameters 357 // from various sources and set the appropriate state. Please refer to 358 // Update() method for the meaning of the parameters. 359 bool CalculateUpdateParams( 360 const chromeos_update_manager::UpdateCheckParams& params); 361 362 // Calculates all the scattering related parameters (such as waiting period, 363 // which type of scattering is enabled, etc.) and also updates/deletes 364 // the corresponding prefs file used in scattering. Should be called 365 // only after the device policy has been loaded and set in the system state. 366 void CalculateScatteringParams(bool interactive); 367 368 // Sets a random value for the waiting period to wait for before downloading 369 // an update, if one available. This value will be upperbounded by the 370 // scatter factor value specified from policy. 371 void GenerateNewWaitingPeriod(); 372 373 // Helper method of Update() to construct the sequence of actions to 374 // be performed for an update check. Please refer to 375 // Update() method for the meaning of the parameters. 376 void BuildUpdateActions(bool interactive); 377 378 // Decrements the count in the kUpdateCheckCountFilePath. 379 // Returns True if successfully decremented, false otherwise. 380 bool DecrementUpdateCheckCount(); 381 382 // Starts p2p and performs housekeeping. Returns true only if p2p is 383 // running and housekeeping was done. 384 bool StartP2PAndPerformHousekeeping(); 385 386 // Calculates whether peer-to-peer should be used. Sets the 387 // |use_p2p_to_download_| and |use_p2p_to_share_| parameters 388 // on the |omaha_request_params_| object. 389 void CalculateP2PParams(bool interactive); 390 391 // For each key, reads value from powerwash safe prefs and adds it to prefs 392 // if key doesnt already exist. Then deletes the powerwash safe keys. 393 void MoveToPrefs(const std::vector<std::string>& keys); 394 395 // Starts P2P if it's enabled and there are files to actually share. 396 // Called only at program startup. Returns true only if p2p was 397 // started and housekeeping was performed. 398 bool StartP2PAtStartup(); 399 400 // Writes to the processing completed marker. Does nothing if 401 // |update_completed_marker_| is empty. 402 void WriteUpdateCompletedMarker(); 403 404 // Reboots the system directly by calling /sbin/shutdown. Returns true on 405 // success. 406 bool RebootDirectly(); 407 408 // Callback for the async UpdateCheckAllowed policy request. If |status| is 409 // |EvalStatus::kSucceeded|, either runs or suppresses periodic update checks, 410 // based on the content of |params|. Otherwise, retries the policy request. 411 void OnUpdateScheduled( 412 chromeos_update_manager::EvalStatus status, 413 const chromeos_update_manager::UpdateCheckParams& params); 414 415 // Updates the time an update was last attempted to the current time. 416 void UpdateLastCheckedTime(); 417 418 // Checks whether we need to clear the rollback-happened preference after 419 // policy is available again. 420 void UpdateRollbackHappened(); 421 422 // Returns if an update is: running, applied and needs reboot, or scheduled. 423 bool IsBusyOrUpdateScheduled(); 424 425 void CalculateStagingParams(bool interactive); 426 427 // Reports a metric that tracks the time from when the update was first seen 428 // to the time when the update was finally downloaded and applied. This metric 429 // will only be reported for enterprise enrolled devices. 430 void ReportTimeToUpdateAppliedMetric(); 431 432 // Resets interactivity and forced update flags. 433 void ResetInteractivityFlags(); 434 435 // Resets all the DLC prefs. 436 bool ResetDlcPrefs(const std::string& dlc_id); 437 438 // Sets given pref key for DLC and platform. 439 void SetPref(const std::string& pref_key, 440 const std::string& pref_value, 441 const std::string& payload_id); 442 443 // Get the integer values from the DLC metadata for |kPrefsPingLastActive| 444 // or |kPrefsPingLastRollcall|. 445 // The value is equal to -2 when the value cannot be read or is not numeric. 446 // The value is equal to -1 the first time it is being sent, which is 447 // when the metadata file doesn't exist. 448 int64_t GetPingMetadata(const std::string& metadata_key) const; 449 450 // Calculates the update parameters for DLCs. Sets the |dlc_ids_| 451 // parameter on the |omaha_request_params_| object. 452 void CalculateDlcParams(); 453 454 // Returns the list of DLC IDs that were installed/updated, excluding the ones 455 // which had "noupdate" in the Omaha response. 456 std::vector<std::string> GetSuccessfulDlcIds(); 457 458 // Last status notification timestamp used for throttling. Use monotonic 459 // TimeTicks to ensure that notifications are sent even if the system clock is 460 // set back in the middle of an update. 461 base::TimeTicks last_notify_time_; 462 463 // Our two proxy resolvers 464 DirectProxyResolver direct_proxy_resolver_; 465 ChromeBrowserProxyResolver chrome_proxy_resolver_; 466 467 std::unique_ptr<ActionProcessor> processor_; 468 469 ActionProcessor aux_processor_; 470 471 // Pointer to the certificate checker instance to use. 472 CertificateChecker* cert_checker_; 473 474 // The list of services observing changes in the updater. 475 std::set<ServiceObserverInterface*> service_observers_; 476 477 // The install plan. 478 std::unique_ptr<InstallPlan> install_plan_; 479 480 // Pointer to the preferences store interface. This is just a cached 481 // copy of SystemState::Get()->prefs() because it's used in many methods and 482 // is convenient this way. 483 PrefsInterface* prefs_ = nullptr; 484 485 // Pending error event, if any. 486 std::unique_ptr<OmahaEvent> error_event_; 487 488 // If we should request a reboot even tho we failed the update 489 bool fake_update_success_ = false; 490 491 // HTTP server response code from the last HTTP request action. 492 int http_response_code_ = 0; 493 494 // The attempt error code when the update attempt finished. 495 ErrorCode attempt_error_code_ = ErrorCode::kSuccess; 496 497 // CPU limiter during the update. 498 CPULimiter cpu_limiter_; 499 500 // For status: 501 UpdateStatus status_{UpdateStatus::IDLE}; 502 double download_progress_ = 0.0; 503 int64_t last_checked_time_ = 0; 504 std::string prev_version_; 505 std::string new_version_ = "0.0.0.0"; 506 uint64_t new_payload_size_ = 0; 507 // Flags influencing all periodic update checks 508 UpdateAttemptFlags update_attempt_flags_ = UpdateAttemptFlags::kNone; 509 // Flags influencing the currently in-progress check (cached at the start of 510 // the update check). 511 UpdateAttemptFlags current_update_attempt_flags_ = UpdateAttemptFlags::kNone; 512 513 // Common parameters for all Omaha requests. 514 OmahaRequestParams* omaha_request_params_ = nullptr; 515 516 // Number of consecutive manual update checks we've had where we obeyed 517 // Chrome's proxy settings. 518 int proxy_manual_checks_ = 0; 519 520 // If true, this update cycle we are obeying proxies 521 bool obeying_proxies_ = true; 522 523 // Used for fetching information about the device policy. 524 std::unique_ptr<policy::PolicyProvider> policy_provider_; 525 526 // The current scatter factor as found in the policy setting. 527 base::TimeDelta scatter_factor_; 528 529 // The number of consecutive failed update checks. Needed for calculating the 530 // next update check interval. 531 unsigned int consecutive_failed_update_checks_ = 0; 532 533 // The poll interval (in seconds) that was dictated by Omaha, if any; zero 534 // otherwise. This is needed for calculating the update check interval. 535 unsigned int server_dictated_poll_interval_ = 0; 536 537 // Tracks whether we have scheduled update checks. 538 bool waiting_for_scheduled_check_ = false; 539 540 // A callback to use when a forced update request is either received (true) or 541 // cleared by an update attempt (false). The second argument indicates whether 542 // this is an interactive update, and its value is significant iff the first 543 // argument is true. 544 std::unique_ptr<base::Callback<void(bool, bool)>> 545 forced_update_pending_callback_; 546 547 // The |app_version| and |omaha_url| parameters received during the latest 548 // forced update request. They are retrieved for use once the update is 549 // actually scheduled. 550 std::string forced_app_version_; 551 std::string forced_omaha_url_; 552 553 // A list of DLC module IDs. 554 std::vector<std::string> dlc_ids_; 555 // Whether the operation is install (write to the current slot not the 556 // inactive slot). 557 bool is_install_; 558 559 // If this is not TimeDelta(), then that means staging is turned on. 560 base::TimeDelta staging_wait_time_; 561 chromeos_update_manager::StagingSchedule staging_schedule_; 562 563 // This is the session ID used to track update flow to Omaha. 564 std::string session_id_; 565 566 // Interface for excluder. 567 std::unique_ptr<ExcluderInterface> excluder_; 568 569 DISALLOW_COPY_AND_ASSIGN(UpdateAttempter); 570 }; 571 572 // Turns a generic ErrorCode::kError to a generic error code specific 573 // to |action| (e.g., ErrorCode::kFilesystemVerifierError). If |code| is 574 // not ErrorCode::kError, or the action is not matched, returns |code| 575 // unchanged. 576 577 ErrorCode GetErrorCodeForAction(AbstractAction* action, ErrorCode code); 578 579 } // namespace chromeos_update_engine 580 581 #endif // UPDATE_ENGINE_CROS_UPDATE_ATTEMPTER_H_ 582