| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "media/blink/resource_multibuffer_data_provider.h" | 5 #include "media/blink/resource_multibuffer_data_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 using blink::WebURLLoader; | 28 using blink::WebURLLoader; |
| 29 using blink::WebURLLoaderOptions; | 29 using blink::WebURLLoaderOptions; |
| 30 using blink::WebURLRequest; | 30 using blink::WebURLRequest; |
| 31 using blink::WebURLResponse; | 31 using blink::WebURLResponse; |
| 32 | 32 |
| 33 namespace media { | 33 namespace media { |
| 34 | 34 |
| 35 // The number of milliseconds to wait before retrying a failed load. | 35 // The number of milliseconds to wait before retrying a failed load. |
| 36 const int kLoaderFailedRetryDelayMs = 250; | 36 const int kLoaderFailedRetryDelayMs = 250; |
| 37 | 37 |
| 38 // Each retry, add this many MS to the delay. |
| 39 const int kAdditionalDelayPerRetryMs = 50; |
| 40 |
| 38 // The number of milliseconds to wait before retrying when the server | 41 // The number of milliseconds to wait before retrying when the server |
| 39 // decides to not give us all the data at once. | 42 // decides to not give us all the data at once. |
| 40 const int kLoaderPartialRetryDelayMs = 25; | 43 const int kLoaderPartialRetryDelayMs = 25; |
| 41 | 44 |
| 42 const int kHttpOK = 200; | 45 const int kHttpOK = 200; |
| 43 const int kHttpPartialContent = 206; | 46 const int kHttpPartialContent = 206; |
| 44 const int kHttpRangeNotSatisfiable = 416; | 47 const int kHttpRangeNotSatisfiable = 416; |
| 45 const int kMaxRetries = 3; | 48 // total delay is: |
| 49 // (kLoaderPartialRetryDelayMs + |
| 50 // kAdditionalDelayPerRetryMs * (kMaxRetries - 1) / 2) * kMaxretries = 29250 ms |
| 51 const int ResourceMultiBufferDataProvider::kMaxRetries = 30; |
| 46 | 52 |
| 47 ResourceMultiBufferDataProvider::ResourceMultiBufferDataProvider( | 53 ResourceMultiBufferDataProvider::ResourceMultiBufferDataProvider( |
| 48 UrlData* url_data, | 54 UrlData* url_data, |
| 49 MultiBufferBlockId pos) | 55 MultiBufferBlockId pos) |
| 50 : pos_(pos), | 56 : pos_(pos), |
| 51 url_data_(url_data), | 57 url_data_(url_data), |
| 52 retries_(0), | 58 retries_(0), |
| 53 cors_mode_(url_data->cors_mode()), | 59 cors_mode_(url_data->cors_mode()), |
| 54 origin_(url_data->url().GetOrigin()), | 60 origin_(url_data->url().GetOrigin()), |
| 55 weak_factory_(this) { | 61 weak_factory_(this) { |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 << ", domain=" << error.domain.utf8().data() | 410 << ", domain=" << error.domain.utf8().data() |
| 405 << ", localizedDescription=" | 411 << ", localizedDescription=" |
| 406 << error.localizedDescription.utf8().data(); | 412 << error.localizedDescription.utf8().data(); |
| 407 DCHECK(active_loader_.get()); | 413 DCHECK(active_loader_.get()); |
| 408 | 414 |
| 409 if (retries_ < kMaxRetries && pos_ != 0) { | 415 if (retries_ < kMaxRetries && pos_ != 0) { |
| 410 retries_++; | 416 retries_++; |
| 411 base::MessageLoop::current()->PostDelayedTask( | 417 base::MessageLoop::current()->PostDelayedTask( |
| 412 FROM_HERE, base::Bind(&ResourceMultiBufferDataProvider::Start, | 418 FROM_HERE, base::Bind(&ResourceMultiBufferDataProvider::Start, |
| 413 weak_factory_.GetWeakPtr()), | 419 weak_factory_.GetWeakPtr()), |
| 414 base::TimeDelta::FromMilliseconds(kLoaderFailedRetryDelayMs)); | 420 base::TimeDelta::FromMilliseconds( |
| 421 kLoaderFailedRetryDelayMs + kAdditionalDelayPerRetryMs * retries_)); |
| 415 } else { | 422 } else { |
| 416 // We don't need to continue loading after failure. | 423 // We don't need to continue loading after failure. |
| 417 // | 424 // Note that calling Fail() will most likely delete this object. |
| 418 // Keep it alive until we exit this method so that |error| remains valid. | |
| 419 scoped_ptr<ActiveLoader> active_loader = std::move(active_loader_); | |
| 420 url_data_->Fail(); | 425 url_data_->Fail(); |
| 421 } | 426 } |
| 422 } | 427 } |
| 423 | 428 |
| 424 bool ResourceMultiBufferDataProvider::ParseContentRange( | 429 bool ResourceMultiBufferDataProvider::ParseContentRange( |
| 425 const std::string& content_range_str, | 430 const std::string& content_range_str, |
| 426 int64_t* first_byte_position, | 431 int64_t* first_byte_position, |
| 427 int64_t* last_byte_position, | 432 int64_t* last_byte_position, |
| 428 int64_t* instance_size) { | 433 int64_t* instance_size) { |
| 429 const std::string kUpThroughBytesUnit = "bytes "; | 434 const std::string kUpThroughBytesUnit = "bytes "; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 } | 497 } |
| 493 | 498 |
| 494 if (byte_pos() != first_byte_position) { | 499 if (byte_pos() != first_byte_position) { |
| 495 return false; | 500 return false; |
| 496 } | 501 } |
| 497 | 502 |
| 498 return true; | 503 return true; |
| 499 } | 504 } |
| 500 | 505 |
| 501 } // namespace media | 506 } // namespace media |
| OLD | NEW |