OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/media/buffered_resource_loader.h" | 5 #include "webkit/media/buffered_resource_loader.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "media/base/media_log.h" | 10 #include "media/base/media_log.h" |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 // We make a strong assumption that when we reach here we have either | 372 // We make a strong assumption that when we reach here we have either |
373 // received a response from HTTP/HTTPS protocol or the request was | 373 // received a response from HTTP/HTTPS protocol or the request was |
374 // successful (in particular range request). So we only verify the partial | 374 // successful (in particular range request). So we only verify the partial |
375 // response for HTTP and HTTPS protocol. | 375 // response for HTTP and HTTPS protocol. |
376 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { | 376 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { |
377 int error = net::OK; | 377 int error = net::OK; |
378 | 378 |
379 // Check to see whether the server supports byte ranges. | 379 // Check to see whether the server supports byte ranges. |
380 std::string accept_ranges = | 380 std::string accept_ranges = |
381 response.httpHeaderField("Accept-Ranges").utf8(); | 381 response.httpHeaderField("Accept-Ranges").utf8(); |
382 range_supported_ = (accept_ranges.find("bytes") != std::string::npos); | 382 range_supported_ = (accept_ranges.find("bytes") != std::string::npos); |
acolwell GONE FROM CHROMIUM
2012/03/14 18:24:49
Should this and the line above be moved into the i
Ami GONE FROM CHROMIUM
2012/03/14 19:37:20
Done.
| |
383 | 383 |
384 partial_response = (response.httpStatusCode() == kHttpPartialContent); | 384 partial_response = (response.httpStatusCode() == kHttpPartialContent); |
385 bool ok_response = (response.httpStatusCode() == kHttpOK); | |
385 | 386 |
386 if (range_requested_) { | 387 if (range_requested_) { |
387 // If we have verified the partial response and it is correct, we will | 388 // If we have verified the partial response and it is correct, we will |
388 // return net::OK. It's also possible for a server to support range | 389 // return net::OK. It's also possible for a server to support range |
389 // requests without advertising Accept-Ranges: bytes. | 390 // requests without advertising Accept-Ranges: bytes. |
390 if (partial_response && VerifyPartialResponse(response)) | 391 if (partial_response && VerifyPartialResponse(response)) { |
391 range_supported_ = true; | 392 range_supported_ = true; |
392 else | 393 } else if (ok_response && first_byte_position_ == 0 && |
394 last_byte_position_ == kPositionNotSpecified) { | |
395 // We accept a 200 response for a Range:0- request and down-grade the | |
396 // data source to streaming. | |
397 range_supported_ = false; | |
398 } else { | |
393 error = net::ERR_INVALID_RESPONSE; | 399 error = net::ERR_INVALID_RESPONSE; |
400 } | |
394 } else if (response.httpStatusCode() != kHttpOK) { | 401 } else if (response.httpStatusCode() != kHttpOK) { |
395 // We didn't request a range but server didn't reply with "200 OK". | 402 // We didn't request a range but server didn't reply with "200 OK". |
396 error = net::ERR_FAILED; | 403 error = net::ERR_FAILED; |
397 } | 404 } |
398 | 405 |
399 if (error != net::OK) { | 406 if (error != net::OK) { |
400 DoneStart(error); | 407 DoneStart(error); |
401 return; | 408 return; |
402 } | 409 } |
403 } else { | 410 } else { |
404 // For any protocol other than HTTP and HTTPS, assume range request is | 411 // For any protocol other than HTTP and HTTPS, assume range request is |
405 // always fulfilled. | 412 // always fulfilled. |
406 partial_response = range_requested_; | 413 partial_response = range_requested_; |
acolwell GONE FROM CHROMIUM
2012/03/14 18:24:49
Is this a valid assumption? This code smells a lit
Ami GONE FROM CHROMIUM
2012/03/14 19:37:20
partial_response starts out false and is only used
| |
407 } | 414 } |
408 | 415 |
409 // Expected content length can be |kPositionNotSpecified|, in that case | 416 // Expected content length can be |kPositionNotSpecified|, in that case |
410 // |content_length_| is not specified and this is a streaming response. | 417 // |content_length_| is not specified and this is a streaming response. |
411 content_length_ = response.expectedContentLength(); | 418 content_length_ = response.expectedContentLength(); |
412 | 419 |
413 // If we have not requested a range, then the size of the instance is equal | 420 // If we have not requested a range, then the size of the instance is equal |
414 // to the content length. | 421 // to the content length. |
415 if (!partial_response) | 422 if (!partial_response) |
416 instance_size_ = content_length_; | 423 instance_size_ = content_length_; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
784 if (buffer_.get()) { | 791 if (buffer_.get()) { |
785 media_log_->AddEvent( | 792 media_log_->AddEvent( |
786 media_log_->CreateBufferedExtentsChangedEvent( | 793 media_log_->CreateBufferedExtentsChangedEvent( |
787 offset_ - buffer_->backward_bytes(), | 794 offset_ - buffer_->backward_bytes(), |
788 offset_, | 795 offset_, |
789 offset_ + buffer_->forward_bytes())); | 796 offset_ + buffer_->forward_bytes())); |
790 } | 797 } |
791 } | 798 } |
792 | 799 |
793 } // namespace webkit_media | 800 } // namespace webkit_media |
OLD | NEW |