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

Side by Side Diff: content/renderer/media/buffered_resource_loader.cc

Issue 78343004: Net: Standardize HttpByteRange printing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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
« no previous file with comments | « content/renderer/media/buffered_resource_loader.h ('k') | net/http/http_byte_range.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/renderer/media/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/format_macros.h"
10 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
11 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h"
14 #include "content/renderer/media/cache_util.h" 12 #include "content/renderer/media/cache_util.h"
15 #include "media/base/media_log.h" 13 #include "media/base/media_log.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;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 offset_ = first_byte_position_; 157 offset_ = first_byte_position_;
159 } 158 }
160 159
161 // Prepare the request. 160 // Prepare the request.
162 WebURLRequest request(url_); 161 WebURLRequest request(url_);
163 request.setTargetType(WebURLRequest::TargetIsMedia); 162 request.setTargetType(WebURLRequest::TargetIsMedia);
164 163
165 if (IsRangeRequest()) { 164 if (IsRangeRequest()) {
166 request.setHTTPHeaderField( 165 request.setHTTPHeaderField(
167 WebString::fromUTF8(net::HttpRequestHeaders::kRange), 166 WebString::fromUTF8(net::HttpRequestHeaders::kRange),
168 WebString::fromUTF8(GenerateHeaders(first_byte_position_, 167 WebString::fromUTF8(net::HttpByteRange::Bounded(
169 last_byte_position_))); 168 first_byte_position_, last_byte_position_).GetHeaderValue()));
170 } 169 }
171 170
172 frame->setReferrerForRequest(request, blink::WebURL()); 171 frame->setReferrerForRequest(request, blink::WebURL());
173 172
174 // Disable compression, compression for audio/video doesn't make sense... 173 // Disable compression, compression for audio/video doesn't make sense...
175 request.setHTTPHeaderField( 174 request.setHTTPHeaderField(
176 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), 175 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding),
177 WebString::fromUTF8("identity;q=1, *;q=0")); 176 WebString::fromUTF8("identity;q=1, *;q=0"));
178 177
179 // Check for our test WebURLLoader. 178 // Check for our test WebURLLoader.
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 if (first_byte_position_ != kPositionNotSpecified && 742 if (first_byte_position_ != kPositionNotSpecified &&
744 first_byte_position_ != first_byte_position) { 743 first_byte_position_ != first_byte_position) {
745 return false; 744 return false;
746 } 745 }
747 746
748 // TODO(hclam): I should also check |last_byte_position|, but since 747 // TODO(hclam): I should also check |last_byte_position|, but since
749 // we will never make such a request that it is ok to leave it unimplemented. 748 // we will never make such a request that it is ok to leave it unimplemented.
750 return true; 749 return true;
751 } 750 }
752 751
753 std::string BufferedResourceLoader::GenerateHeaders(
754 int64 first_byte_position,
755 int64 last_byte_position) {
756 // Construct the value for the range header.
757 std::string header;
758 if (first_byte_position > kPositionNotSpecified &&
759 last_byte_position > kPositionNotSpecified) {
760 if (first_byte_position <= last_byte_position) {
761 header = base::StringPrintf("bytes=%" PRId64 "-%" PRId64,
762 first_byte_position,
763 last_byte_position);
764 }
765 } else if (first_byte_position > kPositionNotSpecified) {
766 header = base::StringPrintf("bytes=%" PRId64 "-",
767 first_byte_position);
768 } else if (last_byte_position > kPositionNotSpecified) {
769 NOTIMPLEMENTED() << "Suffix range not implemented";
770 }
771 return header;
772 }
773
774 void BufferedResourceLoader::DoneRead(Status status, int bytes_read) { 752 void BufferedResourceLoader::DoneRead(Status status, int bytes_read) {
775 if (saved_forward_capacity_) { 753 if (saved_forward_capacity_) {
776 buffer_.set_forward_capacity(saved_forward_capacity_); 754 buffer_.set_forward_capacity(saved_forward_capacity_);
777 saved_forward_capacity_ = 0; 755 saved_forward_capacity_ = 0;
778 } 756 }
779 read_position_ = 0; 757 read_position_ = 0;
780 read_size_ = 0; 758 read_size_ = 0;
781 read_buffer_ = NULL; 759 read_buffer_ = NULL;
782 first_offset_ = 0; 760 first_offset_ = 0;
783 last_offset_ = 0; 761 last_offset_ = 0;
(...skipping 13 matching lines...) Expand all
797 775
798 void BufferedResourceLoader::Log() { 776 void BufferedResourceLoader::Log() {
799 media_log_->AddEvent( 777 media_log_->AddEvent(
800 media_log_->CreateBufferedExtentsChangedEvent( 778 media_log_->CreateBufferedExtentsChangedEvent(
801 offset_ - buffer_.backward_bytes(), 779 offset_ - buffer_.backward_bytes(),
802 offset_, 780 offset_,
803 offset_ + buffer_.forward_bytes())); 781 offset_ + buffer_.forward_bytes()));
804 } 782 }
805 783
806 } // namespace content 784 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/buffered_resource_loader.h ('k') | net/http/http_byte_range.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698