123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- #ifndef UPDATE_ENGINE_UPDATE_ATTEMPTER_H_
- #define UPDATE_ENGINE_UPDATE_ATTEMPTER_H_
- #include <time.h>
- #include <memory>
- #include <set>
- #include <string>
- #include <utility>
- #include <vector>
- #include <base/bind.h>
- #include <base/time/time.h>
- #include <gtest/gtest_prod.h> // for FRIEND_TEST
- #if USE_CHROME_NETWORK_PROXY
- #include "update_engine/chrome_browser_proxy_resolver.h"
- #endif
- #include "update_engine/certificate_checker.h"
- #include "update_engine/client_library/include/update_engine/update_status.h"
- #include "update_engine/common/action_processor.h"
- #include "update_engine/common/cpu_limiter.h"
- #include "update_engine/common/proxy_resolver.h"
- #include "update_engine/omaha_request_params.h"
- #include "update_engine/omaha_response_handler_action.h"
- #include "update_engine/payload_consumer/download_action.h"
- #include "update_engine/payload_consumer/postinstall_runner_action.h"
- #include "update_engine/service_observer_interface.h"
- #include "update_engine/system_state.h"
- #include "update_engine/update_manager/policy.h"
- #include "update_engine/update_manager/staging_utils.h"
- #include "update_engine/update_manager/update_manager.h"
- namespace policy {
- class PolicyProvider;
- }
- namespace chromeos_update_engine {
- class UpdateAttempter : public ActionProcessorDelegate,
- public DownloadActionDelegate,
- public CertificateChecker::Observer,
- public PostinstallRunnerAction::DelegateInterface {
- public:
- using UpdateStatus = update_engine::UpdateStatus;
- using UpdateAttemptFlags = update_engine::UpdateAttemptFlags;
- static const int kMaxDeltaUpdateFailures;
- UpdateAttempter(SystemState* system_state, CertificateChecker* cert_checker);
- ~UpdateAttempter() override;
-
- void Init();
-
-
- virtual bool ScheduleUpdates();
-
-
-
-
-
-
-
- virtual void Update(const std::string& app_version,
- const std::string& omaha_url,
- const std::string& target_channel,
- const std::string& target_version_prefix,
- bool rollback_allowed,
- bool obey_proxies,
- bool interactive);
-
- void ProcessingDone(const ActionProcessor* processor,
- ErrorCode code) override;
- void ProcessingStopped(const ActionProcessor* processor) override;
- void ActionCompleted(ActionProcessor* processor,
- AbstractAction* action,
- ErrorCode code) override;
-
- void ProgressUpdate(double progress) override;
-
-
-
-
-
- virtual bool ResetStatus();
-
- virtual bool GetStatus(update_engine::UpdateEngineStatus* out_status);
- UpdateStatus status() const { return status_; }
- int http_response_code() const { return http_response_code_; }
- void set_http_response_code(int code) { http_response_code_ = code; }
-
-
-
- void SetUpdateAttemptFlags(UpdateAttemptFlags flags) {
- update_attempt_flags_ = flags;
- }
-
-
-
- virtual UpdateAttemptFlags GetCurrentUpdateAttemptFlags() const {
- return current_update_attempt_flags_;
- }
-
-
-
-
-
- virtual bool CheckForUpdate(const std::string& app_version,
- const std::string& omaha_url,
- UpdateAttemptFlags flags);
-
- virtual bool CheckForInstall(const std::vector<std::string>& dlc_module_ids,
- const std::string& omaha_url);
-
-
-
-
- bool Rollback(bool powerwash);
-
- bool CanRollback() const;
-
-
-
- BootControlInterface::Slot GetRollbackSlot() const;
-
-
- bool RebootIfNeeded();
-
- void BytesReceived(uint64_t bytes_progressed,
- uint64_t bytes_received,
- uint64_t total) override;
-
-
- bool ShouldCancel(ErrorCode* cancel_reason) override;
- void DownloadComplete() override;
-
- void BroadcastStatus();
- ErrorCode GetAttemptErrorCode() const { return attempt_error_code_; }
-
- void UpdateEngineStarted();
-
-
-
-
- virtual void RefreshDevicePolicy();
-
-
-
- virtual bool GetBootTimeAtUpdate(base::Time* out_boot_time);
-
-
-
- const std::string& GetPrevVersion() const { return prev_version_; }
-
- virtual unsigned int consecutive_failed_update_checks() const {
- return consecutive_failed_update_checks_;
- }
-
- virtual unsigned int server_dictated_poll_interval() const {
- return server_dictated_poll_interval_;
- }
-
-
-
-
-
-
-
- virtual void set_forced_update_pending_callback(
- base::Callback<void(bool, bool)>* callback) {
- forced_update_pending_callback_.reset(callback);
- }
-
-
-
-
- bool IsAnyUpdateSourceAllowed() const;
-
- void AddObserver(ServiceObserverInterface* observer) {
- service_observers_.insert(observer);
- }
- void RemoveObserver(ServiceObserverInterface* observer) {
- service_observers_.erase(observer);
- }
- const std::set<ServiceObserverInterface*>& service_observers() {
- return service_observers_;
- }
-
- void ClearObservers() { service_observers_.clear(); }
- private:
-
- friend class UpdateAttempterUnderTest;
- friend class UpdateAttempterTest;
- FRIEND_TEST(UpdateAttempterTest, ActionCompletedDownloadTest);
- FRIEND_TEST(UpdateAttempterTest, ActionCompletedErrorTest);
- FRIEND_TEST(UpdateAttempterTest, ActionCompletedOmahaRequestTest);
- FRIEND_TEST(UpdateAttempterTest, BootTimeInUpdateMarkerFile);
- FRIEND_TEST(UpdateAttempterTest, BroadcastCompleteDownloadTest);
- FRIEND_TEST(UpdateAttempterTest, ChangeToDownloadingOnReceivedBytesTest);
- FRIEND_TEST(UpdateAttempterTest, CheckForUpdateAUDlcTest);
- FRIEND_TEST(UpdateAttempterTest, CreatePendingErrorEventTest);
- FRIEND_TEST(UpdateAttempterTest, CreatePendingErrorEventResumedTest);
- FRIEND_TEST(UpdateAttempterTest, DisableDeltaUpdateIfNeededTest);
- FRIEND_TEST(UpdateAttempterTest, DownloadProgressAccumulationTest);
- FRIEND_TEST(UpdateAttempterTest, InstallSetsStatusIdle);
- FRIEND_TEST(UpdateAttempterTest, MarkDeltaUpdateFailureTest);
- FRIEND_TEST(UpdateAttempterTest, PingOmahaTest);
- FRIEND_TEST(UpdateAttempterTest, ReportDailyMetrics);
- FRIEND_TEST(UpdateAttempterTest, RollbackNotAllowed);
- FRIEND_TEST(UpdateAttempterTest, RollbackAfterInstall);
- FRIEND_TEST(UpdateAttempterTest, RollbackAllowed);
- FRIEND_TEST(UpdateAttempterTest, RollbackAllowedSetAndReset);
- FRIEND_TEST(UpdateAttempterTest, RollbackMetricsNotRollbackFailure);
- FRIEND_TEST(UpdateAttempterTest, RollbackMetricsNotRollbackSuccess);
- FRIEND_TEST(UpdateAttempterTest, RollbackMetricsRollbackFailure);
- FRIEND_TEST(UpdateAttempterTest, RollbackMetricsRollbackSuccess);
- FRIEND_TEST(UpdateAttempterTest, ScheduleErrorEventActionNoEventTest);
- FRIEND_TEST(UpdateAttempterTest, ScheduleErrorEventActionTest);
- FRIEND_TEST(UpdateAttempterTest, SetRollbackHappenedNotRollback);
- FRIEND_TEST(UpdateAttempterTest, SetRollbackHappenedRollback);
- FRIEND_TEST(UpdateAttempterTest, TargetVersionPrefixSetAndReset);
- FRIEND_TEST(UpdateAttempterTest, UpdateAfterInstall);
- FRIEND_TEST(UpdateAttempterTest, UpdateAttemptFlagsCachedAtUpdateStart);
- FRIEND_TEST(UpdateAttempterTest, UpdateDeferredByPolicyTest);
- FRIEND_TEST(UpdateAttempterTest, UpdateIsNotRunningWhenUpdateAvailable);
-
-
- uint32_t GetErrorCodeFlags();
-
-
- void CertificateChecked(ServerToCheck server_to_check,
- CertificateCheckResult result) override;
-
-
-
- bool CheckAndReportDailyMetrics();
-
-
- void ReportOSAge();
-
- void SetStatusAndNotify(UpdateStatus status);
-
-
- void CreatePendingErrorEvent(AbstractAction* action, ErrorCode code);
-
-
-
-
- bool ScheduleErrorEventAction();
-
-
- void ScheduleProcessingStart();
-
-
- void DisableDeltaUpdateIfNeeded();
-
-
- void MarkDeltaUpdateFailure();
- ProxyResolver* GetProxyResolver() {
- #if USE_CHROME_NETWORK_PROXY
- if (obeying_proxies_)
- return &chrome_proxy_resolver_;
- #endif
- return &direct_proxy_resolver_;
- }
-
-
-
-
-
- void PingOmaha();
-
-
-
- bool CalculateUpdateParams(const std::string& app_version,
- const std::string& omaha_url,
- const std::string& target_channel,
- const std::string& target_version_prefix,
- bool rollback_allowed,
- bool obey_proxies,
- bool interactive);
-
-
-
-
- void CalculateScatteringParams(bool interactive);
-
-
-
- void GenerateNewWaitingPeriod();
-
-
-
- void BuildUpdateActions(bool interactive);
-
-
- bool DecrementUpdateCheckCount();
-
-
- bool StartP2PAndPerformHousekeeping();
-
-
-
- void CalculateP2PParams(bool interactive);
-
-
-
- bool StartP2PAtStartup();
-
-
- void WriteUpdateCompletedMarker();
-
-
- bool RebootDirectly();
-
-
-
- void OnUpdateScheduled(
- chromeos_update_manager::EvalStatus status,
- const chromeos_update_manager::UpdateCheckParams& params);
-
- void UpdateLastCheckedTime();
-
-
- void UpdateRollbackHappened();
-
- bool IsUpdateRunningOrScheduled();
- void CalculateStagingParams(bool interactive);
-
-
-
- void ReportTimeToUpdateAppliedMetric();
-
-
-
- base::TimeTicks last_notify_time_;
-
- DirectProxyResolver direct_proxy_resolver_;
- #if USE_CHROME_NETWORK_PROXY
- ChromeBrowserProxyResolver chrome_proxy_resolver_;
- #endif
- std::unique_ptr<ActionProcessor> processor_;
-
-
- SystemState* system_state_;
-
- CertificateChecker* cert_checker_;
-
- std::set<ServiceObserverInterface*> service_observers_;
-
- std::unique_ptr<InstallPlan> install_plan_;
-
-
-
- PrefsInterface* prefs_ = nullptr;
-
- std::unique_ptr<OmahaEvent> error_event_;
-
- bool fake_update_success_ = false;
-
- int http_response_code_ = 0;
-
- ErrorCode attempt_error_code_ = ErrorCode::kSuccess;
-
- CPULimiter cpu_limiter_;
-
- UpdateStatus status_{UpdateStatus::IDLE};
- double download_progress_ = 0.0;
- int64_t last_checked_time_ = 0;
- std::string prev_version_;
- std::string new_version_ = "0.0.0.0";
- std::string new_system_version_;
- uint64_t new_payload_size_ = 0;
-
- UpdateAttemptFlags update_attempt_flags_ = UpdateAttemptFlags::kNone;
-
-
- UpdateAttemptFlags current_update_attempt_flags_ = UpdateAttemptFlags::kNone;
-
- OmahaRequestParams* omaha_request_params_ = nullptr;
-
-
- int proxy_manual_checks_ = 0;
-
- bool obeying_proxies_ = true;
-
- std::unique_ptr<policy::PolicyProvider> policy_provider_;
-
- base::TimeDelta scatter_factor_;
-
-
- unsigned int consecutive_failed_update_checks_ = 0;
-
-
- unsigned int server_dictated_poll_interval_ = 0;
-
- bool waiting_for_scheduled_check_ = false;
-
-
-
-
- std::unique_ptr<base::Callback<void(bool, bool)>>
- forced_update_pending_callback_;
-
-
-
- std::string forced_app_version_;
- std::string forced_omaha_url_;
-
- std::vector<std::string> dlc_module_ids_;
-
-
- bool is_install_;
-
- base::TimeDelta staging_wait_time_;
- chromeos_update_manager::StagingSchedule staging_schedule_;
- DISALLOW_COPY_AND_ASSIGN(UpdateAttempter);
- };
- ErrorCode GetErrorCodeForAction(AbstractAction* action, ErrorCode code);
- }
- #endif
|