| 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/bits.h" |
| 7 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 8 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/metrics/histogram.h" |
| 9 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 11 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 12 #include "media/base/media_log.h" | 14 #include "media/base/media_log.h" |
| 13 #include "net/http/http_request_headers.h" | 15 #include "net/http/http_request_headers.h" |
| 16 #include "webkit/media/cache_util.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h
" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h
" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatfo
rmSupport.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatfo
rmSupport.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.
h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.
h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon
se.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon
se.h" |
| 20 | 23 |
| 21 using WebKit::WebFrame; | 24 using WebKit::WebFrame; |
| 22 using WebKit::WebString; | 25 using WebKit::WebString; |
| 23 using WebKit::WebURLError; | 26 using WebKit::WebURLError; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 const GURL& url, | 107 const GURL& url, |
| 105 int64 first_byte_position, | 108 int64 first_byte_position, |
| 106 int64 last_byte_position, | 109 int64 last_byte_position, |
| 107 DeferStrategy strategy, | 110 DeferStrategy strategy, |
| 108 int bitrate, | 111 int bitrate, |
| 109 float playback_rate, | 112 float playback_rate, |
| 110 media::MediaLog* media_log) | 113 media::MediaLog* media_log) |
| 111 : buffer_(kMinBufferCapacity, kMinBufferCapacity), | 114 : buffer_(kMinBufferCapacity, kMinBufferCapacity), |
| 112 loader_failed_(false), | 115 loader_failed_(false), |
| 113 defer_strategy_(strategy), | 116 defer_strategy_(strategy), |
| 117 might_be_reused_from_cache_in_future_(true), |
| 114 range_supported_(false), | 118 range_supported_(false), |
| 115 saved_forward_capacity_(0), | 119 saved_forward_capacity_(0), |
| 116 url_(url), | 120 url_(url), |
| 117 first_byte_position_(first_byte_position), | 121 first_byte_position_(first_byte_position), |
| 118 last_byte_position_(last_byte_position), | 122 last_byte_position_(last_byte_position), |
| 119 single_origin_(true), | 123 single_origin_(true), |
| 120 offset_(0), | 124 offset_(0), |
| 121 content_length_(kPositionNotSpecified), | 125 content_length_(kPositionNotSpecified), |
| 122 instance_size_(kPositionNotSpecified), | 126 instance_size_(kPositionNotSpecified), |
| 123 read_position_(0), | 127 read_position_(0), |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 response.httpVersion() == WebURLResponse::HTTP_1_1 ? "1.1" : | 365 response.httpVersion() == WebURLResponse::HTTP_1_1 ? "1.1" : |
| 362 "Unknown") | 366 "Unknown") |
| 363 << " " << response.httpStatusCode(); | 367 << " " << response.httpStatusCode(); |
| 364 DCHECK(active_loader_.get()); | 368 DCHECK(active_loader_.get()); |
| 365 | 369 |
| 366 // The loader may have been stopped and |start_cb| is destroyed. | 370 // The loader may have been stopped and |start_cb| is destroyed. |
| 367 // In this case we shouldn't do anything. | 371 // In this case we shouldn't do anything. |
| 368 if (start_cb_.is_null()) | 372 if (start_cb_.is_null()) |
| 369 return; | 373 return; |
| 370 | 374 |
| 375 uint32 reasons = GetReasonsForUncacheability(response); |
| 376 might_be_reused_from_cache_in_future_ = reasons == 0; |
| 377 UMA_HISTOGRAM_BOOLEAN("Media.CacheUseful", reasons == 0); |
| 378 int shift = 0; |
| 379 int max_enum = base::bits::Log2Ceiling(kMaxReason); |
| 380 while (reasons) { |
| 381 if (reasons & 0x1) |
| 382 UMA_HISTOGRAM_ENUMERATION("Media.UncacheableReason", shift, max_enum); |
| 383 reasons >>= 1; |
| 384 ++shift; |
| 385 } |
| 386 DCHECK_LT(shift, max_enum); // Sanity check. |
| 387 |
| 371 // Expected content length can be |kPositionNotSpecified|, in that case | 388 // Expected content length can be |kPositionNotSpecified|, in that case |
| 372 // |content_length_| is not specified and this is a streaming response. | 389 // |content_length_| is not specified and this is a streaming response. |
| 373 content_length_ = response.expectedContentLength(); | 390 content_length_ = response.expectedContentLength(); |
| 374 | 391 |
| 375 // We make a strong assumption that when we reach here we have either | 392 // We make a strong assumption that when we reach here we have either |
| 376 // received a response from HTTP/HTTPS protocol or the request was | 393 // received a response from HTTP/HTTPS protocol or the request was |
| 377 // successful (in particular range request). So we only verify the partial | 394 // successful (in particular range request). So we only verify the partial |
| 378 // response for HTTP and HTTPS protocol. | 395 // response for HTTP and HTTPS protocol. |
| 379 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { | 396 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { |
| 380 bool partial_response = (response.httpStatusCode() == kHttpPartialContent); | 397 bool partial_response = (response.httpStatusCode() == kHttpPartialContent); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 } | 550 } |
| 534 } | 551 } |
| 535 | 552 |
| 536 bool BufferedResourceLoader::HasSingleOrigin() const { | 553 bool BufferedResourceLoader::HasSingleOrigin() const { |
| 537 DCHECK(start_cb_.is_null()) | 554 DCHECK(start_cb_.is_null()) |
| 538 << "Start() must complete before calling HasSingleOrigin()"; | 555 << "Start() must complete before calling HasSingleOrigin()"; |
| 539 return single_origin_; | 556 return single_origin_; |
| 540 } | 557 } |
| 541 | 558 |
| 542 void BufferedResourceLoader::UpdateDeferStrategy(DeferStrategy strategy) { | 559 void BufferedResourceLoader::UpdateDeferStrategy(DeferStrategy strategy) { |
| 560 if (!might_be_reused_from_cache_in_future_ && strategy == kNeverDefer) |
| 561 strategy = kThresholdDefer; |
| 543 defer_strategy_ = strategy; | 562 defer_strategy_ = strategy; |
| 544 UpdateDeferBehavior(); | 563 UpdateDeferBehavior(); |
| 545 } | 564 } |
| 546 | 565 |
| 547 void BufferedResourceLoader::SetPlaybackRate(float playback_rate) { | 566 void BufferedResourceLoader::SetPlaybackRate(float playback_rate) { |
| 548 playback_rate_ = playback_rate; | 567 playback_rate_ = playback_rate; |
| 549 | 568 |
| 550 // This is a pause so don't bother updating the buffer window as we'll likely | 569 // This is a pause so don't bother updating the buffer window as we'll likely |
| 551 // get unpaused in the future. | 570 // get unpaused in the future. |
| 552 if (playback_rate_ == 0.0) | 571 if (playback_rate_ == 0.0) |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 | 832 |
| 814 void BufferedResourceLoader::Log() { | 833 void BufferedResourceLoader::Log() { |
| 815 media_log_->AddEvent( | 834 media_log_->AddEvent( |
| 816 media_log_->CreateBufferedExtentsChangedEvent( | 835 media_log_->CreateBufferedExtentsChangedEvent( |
| 817 offset_ - buffer_.backward_bytes(), | 836 offset_ - buffer_.backward_bytes(), |
| 818 offset_, | 837 offset_, |
| 819 offset_ + buffer_.forward_bytes())); | 838 offset_ + buffer_.forward_bytes())); |
| 820 } | 839 } |
| 821 | 840 |
| 822 } // namespace webkit_media | 841 } // namespace webkit_media |
| OLD | NEW |