diff options
author | Sen Jiang <senj@google.com> | 2018-03-01 01:24:26 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-03-01 01:24:26 +0000 |
commit | 0366795070b8b723c3449b80e6b9165efa89d8f7 (patch) | |
tree | 07e91178e5b5dfd0b773747a574ac2ebb0264352 | |
parent | 5bf2c2927fad189c4f0d427cb43c601ef550880d (diff) | |
parent | c72bc8708544c44fa0268e826e5b36946cfc7732 (diff) | |
download | update_engine-0366795070b8b723c3449b80e6b9165efa89d8f7.tar.gz |
Fix P2PDownloadActionTest. am: ba2213a53e am: 0a735f14cb
am: c72bc87085
Change-Id: I2bc5ebbbcb890a5a1f05385d30b7506e9856fa05
-rw-r--r-- | common/multi_range_http_fetcher.cc | 23 | ||||
-rw-r--r-- | common/multi_range_http_fetcher.h | 2 | ||||
-rw-r--r-- | payload_consumer/download_action_unittest.cc | 3 |
3 files changed, 26 insertions, 2 deletions
diff --git a/common/multi_range_http_fetcher.cc b/common/multi_range_http_fetcher.cc index e696c361..1189fdec 100644 --- a/common/multi_range_http_fetcher.cc +++ b/common/multi_range_http_fetcher.cc @@ -188,4 +188,27 @@ std::string MultiRangeHttpFetcher::Range::ToString() const { return range_str; } +void MultiRangeHttpFetcher::SetOffset(off_t offset) { + current_index_ = 0; + for (const Range& range : ranges_) { + if (!range.HasLength() || static_cast<size_t>(offset) < range.length()) { + bytes_received_this_range_ = offset; + + base_fetcher_->SetOffset(range.offset() + offset); + if (range.HasLength()) + base_fetcher_->SetLength(range.length()); + else + base_fetcher_->UnsetLength(); + if (delegate_) + delegate_->SeekToOffset(range.offset() + offset); + return; + } + current_index_++; + offset -= range.length(); + } + if (offset > 0) { + LOG(ERROR) << "Offset too large."; + } +} + } // namespace chromeos_update_engine diff --git a/common/multi_range_http_fetcher.h b/common/multi_range_http_fetcher.h index 8a91eadf..54ddfbc6 100644 --- a/common/multi_range_http_fetcher.h +++ b/common/multi_range_http_fetcher.h @@ -67,7 +67,7 @@ class MultiRangeHttpFetcher : public HttpFetcher, public HttpFetcherDelegate { } // HttpFetcher overrides. - void SetOffset(off_t offset) override {} // for now, doesn't support this + void SetOffset(off_t offset) override; void SetLength(size_t length) override {} // unsupported void UnsetLength() override {} diff --git a/payload_consumer/download_action_unittest.cc b/payload_consumer/download_action_unittest.cc index 21ce4610..7ec7e0e0 100644 --- a/payload_consumer/download_action_unittest.cc +++ b/payload_consumer/download_action_unittest.cc @@ -22,6 +22,7 @@ #include <memory> #include <string> #include <utility> +#include <vector> #include <base/bind.h> #include <base/files/file_path.h> @@ -603,7 +604,7 @@ class P2PDownloadActionTest : public testing::Test { // Callback used in StartDownload() method. void StartProcessorInRunLoopForP2P() { processor_.StartProcessing(); - http_fetcher_->SetOffset(start_at_offset_); + download_action_->http_fetcher()->SetOffset(start_at_offset_); } // The requested starting offset passed to SetupDownload(). |