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

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: Extracted GetReasonsForUncacheability and added tests. 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/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/metrics/histogram.h"
9 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 11 #include "base/string_util.h"
11 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
12 #include "media/base/media_log.h" 13 #include "media/base/media_log.h"
13 #include "net/http/http_request_headers.h" 14 #include "net/http/http_request_headers.h"
15 #include "webkit/media/cache_util.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h " 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h "
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatfo rmSupport.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatfo rmSupport.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError. h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError. h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon se.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon se.h"
20 22
21 using WebKit::WebFrame; 23 using WebKit::WebFrame;
22 using WebKit::WebString; 24 using WebKit::WebString;
23 using WebKit::WebURLError; 25 using WebKit::WebURLError;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 const GURL& url, 106 const GURL& url,
105 int64 first_byte_position, 107 int64 first_byte_position,
106 int64 last_byte_position, 108 int64 last_byte_position,
107 DeferStrategy strategy, 109 DeferStrategy strategy,
108 int bitrate, 110 int bitrate,
109 float playback_rate, 111 float playback_rate,
110 media::MediaLog* media_log) 112 media::MediaLog* media_log)
111 : buffer_(kMinBufferCapacity, kMinBufferCapacity), 113 : buffer_(kMinBufferCapacity, kMinBufferCapacity),
112 loader_failed_(false), 114 loader_failed_(false),
113 defer_strategy_(strategy), 115 defer_strategy_(strategy),
116 might_be_reused_from_cache_in_future_(true),
114 range_supported_(false), 117 range_supported_(false),
115 saved_forward_capacity_(0), 118 saved_forward_capacity_(0),
116 url_(url), 119 url_(url),
117 first_byte_position_(first_byte_position), 120 first_byte_position_(first_byte_position),
118 last_byte_position_(last_byte_position), 121 last_byte_position_(last_byte_position),
119 single_origin_(true), 122 single_origin_(true),
120 offset_(0), 123 offset_(0),
121 content_length_(kPositionNotSpecified), 124 content_length_(kPositionNotSpecified),
122 instance_size_(kPositionNotSpecified), 125 instance_size_(kPositionNotSpecified),
123 read_position_(0), 126 read_position_(0),
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 response.httpVersion() == WebURLResponse::HTTP_1_1 ? "1.1" : 364 response.httpVersion() == WebURLResponse::HTTP_1_1 ? "1.1" :
362 "Unknown") 365 "Unknown")
363 << " " << response.httpStatusCode(); 366 << " " << response.httpStatusCode();
364 DCHECK(active_loader_.get()); 367 DCHECK(active_loader_.get());
365 368
366 // The loader may have been stopped and |start_cb| is destroyed. 369 // The loader may have been stopped and |start_cb| is destroyed.
367 // In this case we shouldn't do anything. 370 // In this case we shouldn't do anything.
368 if (start_cb_.is_null()) 371 if (start_cb_.is_null())
369 return; 372 return;
370 373
374 std::vector<UncacheableReason> reasons =
375 GetReasonsForUncacheability(response);
376 might_be_reused_from_cache_in_future_ = reasons.empty();
377 UMA_HISTOGRAM_BOOLEAN("Media.CacheUseful", reasons.empty());
378 for (size_t i = 0; i < reasons.size(); ++i) {
379 UMA_HISTOGRAM_ENUMERATION(
380 "Media.UncacheableReason", reasons[i], kMaxReason);
scherkus (not reviewing) 2012/05/23 01:16:03 one nit: we would increment counts every time we r
Ami GONE FROM CHROMIUM 2012/05/23 01:27:28 But the whole idea is to classify reusability of i
scherkus (not reviewing) 2012/05/23 01:34:19 I suppose so but how could we answer that out of N
Ami GONE FROM CHROMIUM 2012/05/23 01:38:25 UMA is by its nature not per-site (aggregated alon
scherkus (not reviewing) 2012/05/23 01:43:01 I'm not interested in the domain but setting the s
381 }
382
371 // Expected content length can be |kPositionNotSpecified|, in that case 383 // Expected content length can be |kPositionNotSpecified|, in that case
372 // |content_length_| is not specified and this is a streaming response. 384 // |content_length_| is not specified and this is a streaming response.
373 content_length_ = response.expectedContentLength(); 385 content_length_ = response.expectedContentLength();
374 386
375 // We make a strong assumption that when we reach here we have either 387 // 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 388 // received a response from HTTP/HTTPS protocol or the request was
377 // successful (in particular range request). So we only verify the partial 389 // successful (in particular range request). So we only verify the partial
378 // response for HTTP and HTTPS protocol. 390 // response for HTTP and HTTPS protocol.
379 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { 391 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) {
380 bool partial_response = (response.httpStatusCode() == kHttpPartialContent); 392 bool partial_response = (response.httpStatusCode() == kHttpPartialContent);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 } 545 }
534 } 546 }
535 547
536 bool BufferedResourceLoader::HasSingleOrigin() const { 548 bool BufferedResourceLoader::HasSingleOrigin() const {
537 DCHECK(start_cb_.is_null()) 549 DCHECK(start_cb_.is_null())
538 << "Start() must complete before calling HasSingleOrigin()"; 550 << "Start() must complete before calling HasSingleOrigin()";
539 return single_origin_; 551 return single_origin_;
540 } 552 }
541 553
542 void BufferedResourceLoader::UpdateDeferStrategy(DeferStrategy strategy) { 554 void BufferedResourceLoader::UpdateDeferStrategy(DeferStrategy strategy) {
555 if (!might_be_reused_from_cache_in_future_ && strategy == kNeverDefer)
556 strategy = kThresholdDefer;
543 defer_strategy_ = strategy; 557 defer_strategy_ = strategy;
544 UpdateDeferBehavior(); 558 UpdateDeferBehavior();
545 } 559 }
546 560
547 void BufferedResourceLoader::SetPlaybackRate(float playback_rate) { 561 void BufferedResourceLoader::SetPlaybackRate(float playback_rate) {
548 playback_rate_ = playback_rate; 562 playback_rate_ = playback_rate;
549 563
550 // This is a pause so don't bother updating the buffer window as we'll likely 564 // This is a pause so don't bother updating the buffer window as we'll likely
551 // get unpaused in the future. 565 // get unpaused in the future.
552 if (playback_rate_ == 0.0) 566 if (playback_rate_ == 0.0)
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 827
814 void BufferedResourceLoader::Log() { 828 void BufferedResourceLoader::Log() {
815 media_log_->AddEvent( 829 media_log_->AddEvent(
816 media_log_->CreateBufferedExtentsChangedEvent( 830 media_log_->CreateBufferedExtentsChangedEvent(
817 offset_ - buffer_.backward_bytes(), 831 offset_ - buffer_.backward_bytes(),
818 offset_, 832 offset_,
819 offset_ + buffer_.forward_bytes())); 833 offset_ + buffer_.forward_bytes()));
820 } 834 }
821 835
822 } // namespace webkit_media 836 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698