123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- #ifndef UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H_
- #define UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H_
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <map>
- #include <memory>
- #include <string>
- #include <vector>
- #include <gtest/gtest_prod.h> // for FRIEND_TEST
- #include <brillo/secure_blob.h>
- #include <curl/curl.h>
- #include "update_engine/common/action.h"
- #include "update_engine/common/http_fetcher.h"
- #include "update_engine/omaha_response.h"
- #include "update_engine/system_state.h"
- namespace policy {
- class PolicyProvider;
- }
- namespace chromeos_update_engine {
- std::string XmlEncodeWithDefault(const std::string& input,
- const std::string& default_value);
- bool XmlEncode(const std::string& input, std::string* output);
- struct OmahaEvent {
-
- enum Type {
- kTypeUnknown = 0,
- kTypeDownloadComplete = 1,
- kTypeInstallComplete = 2,
- kTypeUpdateComplete = 3,
- kTypeUpdateDownloadStarted = 13,
- kTypeUpdateDownloadFinished = 14,
-
-
- kTypeRebootedAfterUpdate = 54,
- };
-
- enum Result {
- kResultError = 0,
- kResultSuccess = 1,
- kResultUpdateDeferred = 9,
- };
- OmahaEvent()
- : type(kTypeUnknown),
- result(kResultError),
- error_code(ErrorCode::kError) {}
- explicit OmahaEvent(Type in_type)
- : type(in_type),
- result(kResultSuccess),
- error_code(ErrorCode::kSuccess) {}
- OmahaEvent(Type in_type, Result in_result, ErrorCode in_error_code)
- : type(in_type), result(in_result), error_code(in_error_code) {}
- Type type;
- Result result;
- ErrorCode error_code;
- };
- class NoneType;
- class OmahaRequestAction;
- class OmahaRequestParams;
- class PrefsInterface;
- struct OmahaParserData;
- template <>
- class ActionTraits<OmahaRequestAction> {
- public:
-
- typedef NoneType InputObjectType;
-
-
- typedef OmahaResponse OutputObjectType;
- };
- class OmahaRequestAction : public Action<OmahaRequestAction>,
- public HttpFetcherDelegate {
- public:
- static const int kNeverPinged = -1;
- static const int kPingTimeJump = -2;
-
-
-
-
-
- static const int kDefaultMaxFailureCountPerUrl = 10;
-
-
- static const int kMaxWaitTimeStagingInDays = 28;
-
-
- enum WallClockWaitResult {
- kWallClockWaitNotSatisfied,
- kWallClockWaitDoneButUpdateCheckWaitRequired,
- kWallClockWaitDoneAndUpdateCheckWaitNotRequired,
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- OmahaRequestAction(SystemState* system_state,
- OmahaEvent* event,
- std::unique_ptr<HttpFetcher> http_fetcher,
- bool ping_only);
- ~OmahaRequestAction() override;
- typedef ActionTraits<OmahaRequestAction>::InputObjectType InputObjectType;
- typedef ActionTraits<OmahaRequestAction>::OutputObjectType OutputObjectType;
- void PerformAction() override;
- void TerminateProcessing() override;
- void ActionCompleted(ErrorCode code) override;
- int GetHTTPResponseCode() { return http_fetcher_->http_response_code(); }
-
- static std::string StaticType() { return "OmahaRequestAction"; }
- std::string Type() const override { return StaticType(); }
-
- bool ReceivedBytes(HttpFetcher* fetcher,
- const void* bytes,
- size_t length) override;
- void TransferComplete(HttpFetcher* fetcher, bool successful) override;
-
- bool IsEvent() const { return event_.get() != nullptr; }
- private:
- friend class OmahaRequestActionTest;
- friend class OmahaRequestActionTestProcessorDelegate;
- FRIEND_TEST(OmahaRequestActionTest, GetInstallDateWhenNoPrefsNorOOBE);
- FRIEND_TEST(OmahaRequestActionTest,
- GetInstallDateWhenOOBECompletedWithInvalidDate);
- FRIEND_TEST(OmahaRequestActionTest,
- GetInstallDateWhenOOBECompletedWithValidDate);
- FRIEND_TEST(OmahaRequestActionTest,
- GetInstallDateWhenOOBECompletedDateChanges);
-
- enum InstallDateProvisioningSource {
- kProvisionedFromOmahaResponse,
- kProvisionedFromOOBEMarker,
-
-
- kProvisionedMax
- };
-
-
-
- static int GetInstallDate(SystemState* system_state);
-
-
-
-
- static bool ParseInstallDate(OmahaParserData* parser_data,
- OmahaResponse* output_object);
-
-
- static bool HasInstallDate(SystemState* system_state);
-
-
-
- static bool PersistInstallDate(SystemState* system_state,
- int install_date_days,
- InstallDateProvisioningSource source);
-
-
-
-
- bool PersistCohortData(const std::string& prefs_key,
- const std::string& new_value);
-
-
- bool PersistEolStatus(const std::map<std::string, std::string>& attrs);
-
-
-
- void InitPingDays();
-
-
- int CalculatePingDays(const std::string& key);
-
-
- bool ShouldPing() const;
-
-
- bool ShouldDeferDownload(OmahaResponse* output_object);
-
-
-
-
- WallClockWaitResult IsWallClockBasedWaitingSatisfied(
- OmahaResponse* output_object);
-
-
- bool IsUpdateCheckCountBasedWaitingSatisfied();
-
-
-
-
- bool ParseResponse(OmahaParserData* parser_data,
- OmahaResponse* output_object,
- ScopedActionCompleter* completer);
-
-
-
- bool ParseStatus(OmahaParserData* parser_data,
- OmahaResponse* output_object,
- ScopedActionCompleter* completer);
-
-
-
- bool ParseUrls(OmahaParserData* parser_data,
- OmahaResponse* output_object,
- ScopedActionCompleter* completer);
-
-
-
- bool ParseParams(OmahaParserData* parser_data,
- OmahaResponse* output_object,
- ScopedActionCompleter* completer);
-
-
- void CompleteProcessing();
-
- void LookupPayloadViaP2P(const OmahaResponse& response);
-
- void OnLookupPayloadViaP2PCompleted(const std::string& url);
-
- bool ShouldIgnoreUpdate(const OmahaResponse& response,
- ErrorCode* error) const;
-
- bool IsUpdateAllowedOverCellularByPrefs(const OmahaResponse& response) const;
-
-
- bool IsUpdateAllowedOverCurrentConnection(
- ErrorCode* error, const OmahaResponse& response) const;
-
-
- bool IsRollbackEnabled() const;
-
-
- void SetMaxKernelKeyVersionForRollback() const;
-
-
-
- base::Time LoadOrPersistUpdateFirstSeenAtPref() const;
-
- SystemState* system_state_;
-
- OmahaRequestParams* params_;
-
- std::unique_ptr<OmahaEvent> event_;
-
- std::unique_ptr<HttpFetcher> http_fetcher_;
-
- std::unique_ptr<policy::PolicyProvider> policy_provider_;
-
- bool ping_only_;
-
- brillo::Blob response_buffer_;
-
-
-
- int ping_active_days_;
- int ping_roll_call_days_;
- DISALLOW_COPY_AND_ASSIGN(OmahaRequestAction);
- };
- }
- #endif
|