| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_MULTI_HTTP_FETCHER_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_MULTI_HTTP_FETCHER_H__ |
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_MULTI_HTTP_FETCHER_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_MULTI_HTTP_FETCHER_H__ |
| 7 | 7 |
| 8 #include <tr1/memory> | 8 #include <tr1/memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 } | 115 } |
| 116 | 116 |
| 117 void StartTransfer() { | 117 void StartTransfer() { |
| 118 if (current_index_ >= ranges_.size()) { | 118 if (current_index_ >= ranges_.size()) { |
| 119 return; | 119 return; |
| 120 } | 120 } |
| 121 LOG(INFO) << "Starting a transfer @" << ranges_[current_index_].first << "(" | 121 LOG(INFO) << "Starting a transfer @" << ranges_[current_index_].first << "(" |
| 122 << ranges_[current_index_].second << ")"; | 122 << ranges_[current_index_].second << ")"; |
| 123 bytes_received_this_fetcher_ = 0; | 123 bytes_received_this_fetcher_ = 0; |
| 124 fetchers_[current_index_]->SetOffset(ranges_[current_index_].first); | 124 fetchers_[current_index_]->SetOffset(ranges_[current_index_].first); |
| 125 if (delegate_) |
| 126 delegate_->SeekToOffset(ranges_[current_index_].first); |
| 125 fetchers_[current_index_]->BeginTransfer(url_); | 127 fetchers_[current_index_]->BeginTransfer(url_); |
| 126 } | 128 } |
| 127 | 129 |
| 128 void ReceivedBytes(HttpFetcher* fetcher, | 130 void ReceivedBytes(HttpFetcher* fetcher, |
| 129 const char* bytes, | 131 const char* bytes, |
| 130 int length) { | 132 int length) { |
| 131 if (current_index_ >= ranges_.size()) | 133 if (current_index_ >= ranges_.size()) |
| 132 return; | 134 return; |
| 133 if (fetcher != fetchers_[current_index_].get()) { | 135 if (fetcher != fetchers_[current_index_].get()) { |
| 134 LOG(WARNING) << "Received bytes from invalid fetcher"; | 136 LOG(WARNING) << "Received bytes from invalid fetcher"; |
| 135 return; | 137 return; |
| 136 } | 138 } |
| 137 off_t next_size = length; | 139 off_t next_size = length; |
| 138 if (ranges_[current_index_].second >= 0) { | 140 if (ranges_[current_index_].second >= 0) { |
| 139 next_size = std::min(next_size, | 141 next_size = std::min(next_size, |
| 140 ranges_[current_index_].second - | 142 ranges_[current_index_].second - |
| 141 bytes_received_this_fetcher_); | 143 bytes_received_this_fetcher_); |
| 142 } | 144 } |
| 143 LOG_IF(WARNING, next_size <= 0) << "Asked to write length <= 0"; | 145 LOG_IF(WARNING, next_size <= 0) << "Asked to write length <= 0"; |
| 144 if (delegate_) | 146 if (delegate_) { |
| 145 delegate_->ReceivedBytes(this, bytes, next_size); | 147 delegate_->ReceivedBytes(this, bytes, next_size); |
| 148 } |
| 146 bytes_received_this_fetcher_ += length; | 149 bytes_received_this_fetcher_ += length; |
| 147 if (ranges_[current_index_].second >= 0 && | 150 if (ranges_[current_index_].second >= 0 && |
| 148 bytes_received_this_fetcher_ >= ranges_[current_index_].second) { | 151 bytes_received_this_fetcher_ >= ranges_[current_index_].second) { |
| 149 fetchers_[current_index_]->TerminateTransfer(); | 152 fetchers_[current_index_]->TerminateTransfer(); |
| 150 current_index_++; | 153 current_index_++; |
| 151 if (current_index_ == ranges_.size()) { | 154 if (current_index_ == ranges_.size()) { |
| 152 SendTransferComplete(fetchers_[current_index_ - 1].get(), true); | 155 SendTransferComplete(fetchers_[current_index_ - 1].get(), true); |
| 153 } else { | 156 } else { |
| 154 StartTransfer(); | 157 StartTransfer(); |
| 155 } | 158 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 RangesVect::size_type current_index_; // index into ranges_, fetchers_ | 197 RangesVect::size_type current_index_; // index into ranges_, fetchers_ |
| 195 off_t bytes_received_this_fetcher_; | 198 off_t bytes_received_this_fetcher_; |
| 196 | 199 |
| 197 private: | 200 private: |
| 198 DISALLOW_COPY_AND_ASSIGN(MultiHttpFetcher); | 201 DISALLOW_COPY_AND_ASSIGN(MultiHttpFetcher); |
| 199 }; | 202 }; |
| 200 | 203 |
| 201 } // namespace chromeos_update_engine | 204 } // namespace chromeos_update_engine |
| 202 | 205 |
| 203 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MULTI_HTTP_FETCHER_H__ | 206 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MULTI_HTTP_FETCHER_H__ |
| OLD | NEW |