Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Side by Side Diff: webkit/media/buffered_resource_loader.cc

Issue 10387200: Suppress pause-and-buffer behavior when the HTTP response won't satisfy future requests via cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bitfield for reasons and fix typo picking out the Date header. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 std::vector<UncacheableReason> reasons =
376 GetReasonsForUncacheability(response);
377 might_be_reused_from_cache_in_future_ = reasons.empty();
378 UMA_HISTOGRAM_BOOLEAN("Media.CacheUseful", reasons.empty());
379 for (size_t i = 0; i < reasons.size(); ++i) {
380 UMA_HISTOGRAM_ENUMERATION("Media.UncacheableReason",
381 base::bits::Log2Floor(reasons[i]),
382 base::bits::Log2Ceiling(kMaxReason));
383 }
384
371 // Expected content length can be |kPositionNotSpecified|, in that case 385 // Expected content length can be |kPositionNotSpecified|, in that case
372 // |content_length_| is not specified and this is a streaming response. 386 // |content_length_| is not specified and this is a streaming response.
373 content_length_ = response.expectedContentLength(); 387 content_length_ = response.expectedContentLength();
374 388
375 // We make a strong assumption that when we reach here we have either 389 // 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 390 // received a response from HTTP/HTTPS protocol or the request was
377 // successful (in particular range request). So we only verify the partial 391 // successful (in particular range request). So we only verify the partial
378 // response for HTTP and HTTPS protocol. 392 // response for HTTP and HTTPS protocol.
379 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { 393 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) {
380 bool partial_response = (response.httpStatusCode() == kHttpPartialContent); 394 bool partial_response = (response.httpStatusCode() == kHttpPartialContent);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 } 547 }
534 } 548 }
535 549
536 bool BufferedResourceLoader::HasSingleOrigin() const { 550 bool BufferedResourceLoader::HasSingleOrigin() const {
537 DCHECK(start_cb_.is_null()) 551 DCHECK(start_cb_.is_null())
538 << "Start() must complete before calling HasSingleOrigin()"; 552 << "Start() must complete before calling HasSingleOrigin()";
539 return single_origin_; 553 return single_origin_;
540 } 554 }
541 555
542 void BufferedResourceLoader::UpdateDeferStrategy(DeferStrategy strategy) { 556 void BufferedResourceLoader::UpdateDeferStrategy(DeferStrategy strategy) {
557 if (!might_be_reused_from_cache_in_future_ && strategy == kNeverDefer)
558 strategy = kThresholdDefer;
543 defer_strategy_ = strategy; 559 defer_strategy_ = strategy;
544 UpdateDeferBehavior(); 560 UpdateDeferBehavior();
545 } 561 }
546 562
547 void BufferedResourceLoader::SetPlaybackRate(float playback_rate) { 563 void BufferedResourceLoader::SetPlaybackRate(float playback_rate) {
548 playback_rate_ = playback_rate; 564 playback_rate_ = playback_rate;
549 565
550 // This is a pause so don't bother updating the buffer window as we'll likely 566 // This is a pause so don't bother updating the buffer window as we'll likely
551 // get unpaused in the future. 567 // get unpaused in the future.
552 if (playback_rate_ == 0.0) 568 if (playback_rate_ == 0.0)
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 829
814 void BufferedResourceLoader::Log() { 830 void BufferedResourceLoader::Log() {
815 media_log_->AddEvent( 831 media_log_->AddEvent(
816 media_log_->CreateBufferedExtentsChangedEvent( 832 media_log_->CreateBufferedExtentsChangedEvent(
817 offset_ - buffer_.backward_bytes(), 833 offset_ - buffer_.backward_bytes(),
818 offset_, 834 offset_,
819 offset_ + buffer_.forward_bytes())); 835 offset_ + buffer_.forward_bytes()));
820 } 836 }
821 837
822 } // namespace webkit_media 838 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698