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

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

Issue 495353003: Move WebMediaPlayerImpl and its dependencies to media/blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Exclude media/blink from Android GN builds for now like cc/blink does. Created 6 years, 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/renderer/media/buffered_resource_loader.h" 5 #include "media/blink/buffered_resource_loader.h"
6 6
7 #include "base/bits.h" 7 #include "base/bits.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "content/public/common/url_constants.h"
13 #include "content/renderer/media/cache_util.h"
14 #include "media/base/media_log.h" 12 #include "media/base/media_log.h"
13 #include "media/blink/cache_util.h"
15 #include "net/http/http_byte_range.h" 14 #include "net/http/http_byte_range.h"
16 #include "net/http/http_request_headers.h" 15 #include "net/http/http_request_headers.h"
17 #include "third_party/WebKit/public/platform/WebString.h" 16 #include "third_party/WebKit/public/platform/WebString.h"
18 #include "third_party/WebKit/public/platform/WebURLError.h" 17 #include "third_party/WebKit/public/platform/WebURLError.h"
19 #include "third_party/WebKit/public/platform/WebURLResponse.h" 18 #include "third_party/WebKit/public/platform/WebURLResponse.h"
20 #include "third_party/WebKit/public/web/WebKit.h" 19 #include "third_party/WebKit/public/web/WebKit.h"
21 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" 20 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h"
22 21
23 using blink::WebFrame; 22 using blink::WebFrame;
24 using blink::WebString; 23 using blink::WebString;
25 using blink::WebURLError; 24 using blink::WebURLError;
26 using blink::WebURLLoader; 25 using blink::WebURLLoader;
27 using blink::WebURLLoaderOptions; 26 using blink::WebURLLoaderOptions;
28 using blink::WebURLRequest; 27 using blink::WebURLRequest;
29 using blink::WebURLResponse; 28 using blink::WebURLResponse;
30 29
31 namespace content { 30 namespace media {
32 31
33 static const int kHttpOK = 200; 32 static const int kHttpOK = 200;
34 static const int kHttpPartialContent = 206; 33 static const int kHttpPartialContent = 206;
35 34
36 // Define the number of bytes in a megabyte. 35 // Define the number of bytes in a megabyte.
37 static const int kMegabyte = 1024 * 1024; 36 static const int kMegabyte = 1024 * 1024;
38 37
39 // Minimum capacity of the buffer in forward or backward direction. 38 // Minimum capacity of the buffer in forward or backward direction.
40 // 39 //
41 // 2MB is an arbitrary limit; it just seems to be "good enough" in practice. 40 // 2MB is an arbitrary limit; it just seems to be "good enough" in practice.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 95 }
97 96
98 BufferedResourceLoader::BufferedResourceLoader( 97 BufferedResourceLoader::BufferedResourceLoader(
99 const GURL& url, 98 const GURL& url,
100 CORSMode cors_mode, 99 CORSMode cors_mode,
101 int64 first_byte_position, 100 int64 first_byte_position,
102 int64 last_byte_position, 101 int64 last_byte_position,
103 DeferStrategy strategy, 102 DeferStrategy strategy,
104 int bitrate, 103 int bitrate,
105 float playback_rate, 104 float playback_rate,
106 media::MediaLog* media_log) 105 MediaLog* media_log)
107 : buffer_(kMinBufferCapacity, kMinBufferCapacity), 106 : buffer_(kMinBufferCapacity, kMinBufferCapacity),
108 loader_failed_(false), 107 loader_failed_(false),
109 defer_strategy_(strategy), 108 defer_strategy_(strategy),
110 might_be_reused_from_cache_in_future_(true), 109 might_be_reused_from_cache_in_future_(true),
111 range_supported_(false), 110 range_supported_(false),
112 saved_forward_capacity_(0), 111 saved_forward_capacity_(0),
113 url_(url), 112 url_(url),
114 cors_mode_(cors_mode), 113 cors_mode_(cors_mode),
115 first_byte_position_(first_byte_position), 114 first_byte_position_(first_byte_position),
116 last_byte_position_(last_byte_position), 115 last_byte_position_(last_byte_position),
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 if (start_cb_.is_null()) 368 if (start_cb_.is_null())
370 return; 369 return;
371 370
372 uint32 reasons = GetReasonsForUncacheability(response); 371 uint32 reasons = GetReasonsForUncacheability(response);
373 might_be_reused_from_cache_in_future_ = reasons == 0; 372 might_be_reused_from_cache_in_future_ = reasons == 0;
374 UMA_HISTOGRAM_BOOLEAN("Media.CacheUseful", reasons == 0); 373 UMA_HISTOGRAM_BOOLEAN("Media.CacheUseful", reasons == 0);
375 int shift = 0; 374 int shift = 0;
376 int max_enum = base::bits::Log2Ceiling(kMaxReason); 375 int max_enum = base::bits::Log2Ceiling(kMaxReason);
377 while (reasons) { 376 while (reasons) {
378 DCHECK_LT(shift, max_enum); // Sanity check. 377 DCHECK_LT(shift, max_enum); // Sanity check.
379 if (reasons & 0x1) 378 if (reasons & 0x1) {
380 UMA_HISTOGRAM_ENUMERATION("Media.UncacheableReason", shift, max_enum); 379 UMA_HISTOGRAM_ENUMERATION("Media.UncacheableReason",
380 shift,
381 max_enum); // PRESUBMIT_IGNORE_UMA_MAX
382 }
383
381 reasons >>= 1; 384 reasons >>= 1;
382 ++shift; 385 ++shift;
383 } 386 }
384 387
385 // Expected content length can be |kPositionNotSpecified|, in that case 388 // Expected content length can be |kPositionNotSpecified|, in that case
386 // |content_length_| is not specified and this is a streaming response. 389 // |content_length_| is not specified and this is a streaming response.
387 content_length_ = response.expectedContentLength(); 390 content_length_ = response.expectedContentLength();
388 391
389 // 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
390 // received a response from HTTP/HTTPS protocol or the request was 393 // received a response from HTTP/HTTPS protocol or the request was
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 } 780 }
778 781
779 void BufferedResourceLoader::Log() { 782 void BufferedResourceLoader::Log() {
780 media_log_->AddEvent( 783 media_log_->AddEvent(
781 media_log_->CreateBufferedExtentsChangedEvent( 784 media_log_->CreateBufferedExtentsChangedEvent(
782 offset_ - buffer_.backward_bytes(), 785 offset_ - buffer_.backward_bytes(),
783 offset_, 786 offset_,
784 offset_ + buffer_.forward_bytes())); 787 offset_ + buffer_.forward_bytes()));
785 } 788 }
786 789
787 } // namespace content 790 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698