| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium 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 #include "net/http/partial_data.h" | 5 #include "net/http/partial_data.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/disk_cache/disk_cache.h" | 10 #include "net/disk_cache/disk_cache.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 return entry->WriteData(kDataStream, static_cast<int>(current_range_start_), | 251 return entry->WriteData(kDataStream, static_cast<int>(current_range_start_), |
| 252 data, data_len, callback, false); | 252 data, data_len, callback, false); |
| 253 } | 253 } |
| 254 } | 254 } |
| 255 | 255 |
| 256 void PartialData::OnCacheReadCompleted(int result) { | 256 void PartialData::OnCacheReadCompleted(int result) { |
| 257 if (result > 0) { | 257 if (result > 0) { |
| 258 current_range_start_ += result; | 258 current_range_start_ += result; |
| 259 cached_min_len_ -= result; | 259 cached_min_len_ -= result; |
| 260 DCHECK(cached_min_len_ >= 0); | 260 DCHECK(cached_min_len_ >= 0); |
| 261 } else if (!result) { | |
| 262 // TODO(rvargas): we can detect this error and make sure that we are not | |
| 263 // in a loop of failure/retry. | |
| 264 } | 261 } |
| 265 } | 262 } |
| 266 | 263 |
| 267 void PartialData::OnNetworkReadCompleted(int result) { | 264 void PartialData::OnNetworkReadCompleted(int result) { |
| 268 if (result > 0) | 265 if (result > 0) |
| 269 current_range_start_ += result; | 266 current_range_start_ += result; |
| 270 } | 267 } |
| 271 | 268 |
| 272 // Static. | 269 // Static. |
| 273 void PartialData::AddRangeHeader(int64 start, int64 end, std::string* headers) { | 270 void PartialData::AddRangeHeader(int64 start, int64 end, std::string* headers) { |
| 274 DCHECK(start >= 0 || end >= 0); | 271 DCHECK(start >= 0 || end >= 0); |
| 275 std::string my_start, my_end; | 272 std::string my_start, my_end; |
| 276 if (start >= 0) | 273 if (start >= 0) |
| 277 my_start = Int64ToString(start); | 274 my_start = Int64ToString(start); |
| 278 if (end >= 0) | 275 if (end >= 0) |
| 279 my_end = Int64ToString(end); | 276 my_end = Int64ToString(end); |
| 280 | 277 |
| 281 headers->append(StringPrintf("Range: bytes=%s-%s\r\n", my_start.c_str(), | 278 headers->append(StringPrintf("Range: bytes=%s-%s\r\n", my_start.c_str(), |
| 282 my_end.c_str())); | 279 my_end.c_str())); |
| 283 } | 280 } |
| 284 | 281 |
| 285 } // namespace net | 282 } // namespace net |
| OLD | NEW |