Merge remote-tracking branch 'aosp/upstream-master' into merge
It's a merge from chrome OS with some reverts.
1. the fd watcher change, because the libbrillo version isn't
compatible in aosp.
commit 6955bcc4ffe4cc9d62a88186b9a7e75d095a7897
commit 493fecb3f48c8478fd3ef244d631d857730dd14d
2. two libcurl unittest. Because the RunOnce() of the fake message
loop seems to have different behavior in aosp.
commit d3d84218cafbc1a95e7d6bbb775b495d1bebf4d2
Put preprocessor guards to use the old code in aosp. And we can
switch to the new code in the other path after adopting the new
libbrillo & libchrome.
Test: unit tests pass, apply an OTA
Change-Id: Id613599834b0f44f92841dbeae6303601db5490d
diff --git a/libcurl_http_fetcher.h b/libcurl_http_fetcher.h
index 25a2df3..4854f40 100644
--- a/libcurl_http_fetcher.h
+++ b/libcurl_http_fetcher.h
@@ -24,6 +24,7 @@
#include <curl/curl.h>
+#include <base/files/file_descriptor_watcher_posix.h>
#include <base/logging.h>
#include <base/macros.h>
#include <brillo/message_loops/message_loop.h>
@@ -37,6 +38,48 @@
namespace chromeos_update_engine {
+// |UnresolvedHostStateMachine| is a representation of internal state machine of
+// |LibcurlHttpFetcher|.
+class UnresolvedHostStateMachine {
+ public:
+ UnresolvedHostStateMachine() = default;
+ enum class State {
+ kInit = 0,
+ kRetry = 1,
+ kRetriedSuccess = 2,
+ kNotRetry = 3,
+ };
+
+ State GetState() { return state_; }
+
+ // Updates the following internal state machine:
+ //
+ // |kInit|
+ // |
+ // |
+ // \/
+ // (Try, host Unresolved)
+ // |
+ // |
+ // \/
+ // |kRetry| --> (Retry, host resolved)
+ // | |
+ // | |
+ // \/ \/
+ // (Retry, host Unresolved) |kRetriedSuccess|
+ // |
+ // |
+ // \/
+ // |kNotRetry|
+ //
+ void UpdateState(bool failed_to_resolve_host);
+
+ private:
+ State state_ = {State::kInit};
+
+ DISALLOW_COPY_AND_ASSIGN(UnresolvedHostStateMachine);
+};
+
class LibcurlHttpFetcher : public HttpFetcher {
public:
LibcurlHttpFetcher(ProxyResolver* proxy_resolver,
@@ -61,6 +104,9 @@
void SetHeader(const std::string& header_name,
const std::string& header_value) override;
+ bool GetHeader(const std::string& header_name,
+ std::string* header_value) const override;
+
// Suspend the transfer by calling curl_easy_pause(CURLPAUSE_ALL).
void Pause() override;
@@ -85,6 +131,8 @@
no_network_max_retries_ = retries;
}
+ int get_no_network_max_retries() { return no_network_max_retries_; }
+
void set_server_to_check(ServerToCheck server_to_check) {
server_to_check_ = server_to_check;
}
@@ -106,7 +154,13 @@
max_retry_count_ = max_retry_count;
}
+ void set_is_update_check(bool is_update_check) {
+ is_update_check_ = is_update_check;
+ }
+
private:
+ FRIEND_TEST(LibcurlHttpFetcherTest, HostResolvedTest);
+
// libcurl's CURLOPT_CLOSESOCKETFUNCTION callback function. Called when
// closing a socket created with the CURLOPT_OPENSOCKETFUNCTION callback.
static int LibcurlCloseSocketCallback(void* clientp, curl_socket_t item);
@@ -116,7 +170,10 @@
void ProxiesResolved();
// Asks libcurl for the http response code and stores it in the object.
- void GetHttpResponseCode();
+ virtual void GetHttpResponseCode();
+
+ // Returns the last |CURLcode|.
+ CURLcode GetCurlCode();
// Checks whether stored HTTP response is within the success range.
inline bool IsHttpResponseSuccess() {
@@ -161,7 +218,7 @@
}
// Cleans up the following if they are non-null:
- // curl(m) handles, fd_task_maps_, timeout_id_.
+ // curl(m) handles, fd_controller_maps_(fd_task_maps_), timeout_id_.
void CleanUp();
// Force terminate the transfer. This will invoke the delegate's (if any)
@@ -198,7 +255,12 @@
// the message loop. libcurl may open/close descriptors and switch their
// directions so maintain two separate lists so that watch conditions can be
// set appropriately.
+#ifdef __ANDROID__
std::map<int, brillo::MessageLoop::TaskId> fd_task_maps_[2];
+#else
+ std::map<int, std::unique_ptr<base::FileDescriptorWatcher::Controller>>
+ fd_controller_maps_[2];
+#endif // __ANDROID__
// The TaskId of the timer we're waiting on. kTaskIdNull if we are not waiting
// on it.
@@ -265,6 +327,12 @@
// ServerToCheck::kNone.
ServerToCheck server_to_check_{ServerToCheck::kNone};
+ // True if this object is for update check.
+ bool is_update_check_{false};
+
+ // Internal state machine.
+ UnresolvedHostStateMachine unresolved_host_state_machine_;
+
int low_speed_limit_bps_{kDownloadLowSpeedLimitBps};
int low_speed_time_seconds_{kDownloadLowSpeedTimeSeconds};
int connect_timeout_seconds_{kDownloadConnectTimeoutSeconds};