| 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 // total delay is: |
| 40 // (kLoaderPartialRetryDelayMs + |
| 41 // kAdditionalDelayPerRetryMs * (kMaxRetries - 1) / 2) * kMaxretries = 29250 ms |
| 42 const int kAdditionalDelayPerRetryMs = 50; |
| 43 |
| 38 // The number of milliseconds to wait before retrying when the server | 44 // The number of milliseconds to wait before retrying when the server |
| 39 // decides to not give us all the data at once. | 45 // decides to not give us all the data at once. |
| 40 const int kLoaderPartialRetryDelayMs = 25; | 46 const int kLoaderPartialRetryDelayMs = 25; |
| 41 | 47 |
| 42 const int kHttpOK = 200; | 48 const int kHttpOK = 200; |
| 43 const int kHttpPartialContent = 206; | 49 const int kHttpPartialContent = 206; |
| 44 const int kHttpRangeNotSatisfiable = 416; | 50 const int kHttpRangeNotSatisfiable = 416; |
| 45 const int kMaxRetries = 3; | |
| 46 | 51 |
| 47 ResourceMultiBufferDataProvider::ResourceMultiBufferDataProvider( | 52 ResourceMultiBufferDataProvider::ResourceMultiBufferDataProvider( |
| 48 UrlData* url_data, | 53 UrlData* url_data, |
| 49 MultiBufferBlockId pos) | 54 MultiBufferBlockId pos) |
| 50 : pos_(pos), | 55 : pos_(pos), |
| 51 url_data_(url_data), | 56 url_data_(url_data), |
| 52 retries_(0), | 57 retries_(0), |
| 53 cors_mode_(url_data->cors_mode()), | 58 cors_mode_(url_data->cors_mode()), |
| 54 origin_(url_data->url().GetOrigin()), | 59 origin_(url_data->url().GetOrigin()), |
| 55 weak_factory_(this) { | 60 weak_factory_(this) { |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 << ", domain=" << error.domain.utf8().data() | 409 << ", domain=" << error.domain.utf8().data() |
| 405 << ", localizedDescription=" | 410 << ", localizedDescription=" |
| 406 << error.localizedDescription.utf8().data(); | 411 << error.localizedDescription.utf8().data(); |
| 407 DCHECK(active_loader_.get()); | 412 DCHECK(active_loader_.get()); |
| 408 | 413 |
| 409 if (retries_ < kMaxRetries && pos_ != 0) { | 414 if (retries_ < kMaxRetries && pos_ != 0) { |
| 410 retries_++; | 415 retries_++; |
| 411 base::MessageLoop::current()->PostDelayedTask( | 416 base::MessageLoop::current()->PostDelayedTask( |
| 412 FROM_HERE, base::Bind(&ResourceMultiBufferDataProvider::Start, | 417 FROM_HERE, base::Bind(&ResourceMultiBufferDataProvider::Start, |
| 413 weak_factory_.GetWeakPtr()), | 418 weak_factory_.GetWeakPtr()), |
| 414 base::TimeDelta::FromMilliseconds(kLoaderFailedRetryDelayMs)); | 419 base::TimeDelta::FromMilliseconds( |
| 420 kLoaderFailedRetryDelayMs + kAdditionalDelayPerRetryMs * retries_)); |
| 415 } else { | 421 } else { |
| 416 // We don't need to continue loading after failure. | 422 // We don't need to continue loading after failure. |
| 417 // | 423 // 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(); | 424 url_data_->Fail(); |
| 421 } | 425 } |
| 422 } | 426 } |
| 423 | 427 |
| 424 bool ResourceMultiBufferDataProvider::ParseContentRange( | 428 bool ResourceMultiBufferDataProvider::ParseContentRange( |
| 425 const std::string& content_range_str, | 429 const std::string& content_range_str, |
| 426 int64_t* first_byte_position, | 430 int64_t* first_byte_position, |
| 427 int64_t* last_byte_position, | 431 int64_t* last_byte_position, |
| 428 int64_t* instance_size) { | 432 int64_t* instance_size) { |
| 429 const std::string kUpThroughBytesUnit = "bytes "; | 433 const std::string kUpThroughBytesUnit = "bytes "; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 } | 496 } |
| 493 | 497 |
| 494 if (byte_pos() != first_byte_position) { | 498 if (byte_pos() != first_byte_position) { |
| 495 return false; | 499 return false; |
| 496 } | 500 } |
| 497 | 501 |
| 498 return true; | 502 return true; |
| 499 } | 503 } |
| 500 | 504 |
| 501 } // namespace media | 505 } // namespace media |
| OLD | NEW |