| OLD | NEW |
| 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 "media/blink/buffered_resource_loader.h" | 5 #include "media/blink/buffered_resource_loader.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | |
| 10 #include <limits> | 9 #include <limits> |
| 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bits.h" | 12 #include "base/bits.h" |
| 13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "media/base/media_log.h" | 17 #include "media/base/media_log.h" |
| 18 #include "media/blink/cache_util.h" | 18 #include "media/blink/cache_util.h" |
| 19 #include "net/http/http_byte_range.h" | 19 #include "net/http/http_byte_range.h" |
| 20 #include "net/http/http_request_headers.h" | 20 #include "net/http/http_request_headers.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 frame->setReferrerForRequest(request, blink::WebURL()); | 176 frame->setReferrerForRequest(request, blink::WebURL()); |
| 177 | 177 |
| 178 // Disable compression, compression for audio/video doesn't make sense... | 178 // Disable compression, compression for audio/video doesn't make sense... |
| 179 request.setHTTPHeaderField( | 179 request.setHTTPHeaderField( |
| 180 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), | 180 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), |
| 181 WebString::fromUTF8("identity;q=1, *;q=0")); | 181 WebString::fromUTF8("identity;q=1, *;q=0")); |
| 182 | 182 |
| 183 // Check for our test WebURLLoader. | 183 // Check for our test WebURLLoader. |
| 184 scoped_ptr<WebURLLoader> loader; | 184 scoped_ptr<WebURLLoader> loader; |
| 185 if (test_loader_) { | 185 if (test_loader_) { |
| 186 loader = test_loader_.Pass(); | 186 loader = std::move(test_loader_); |
| 187 } else { | 187 } else { |
| 188 WebURLLoaderOptions options; | 188 WebURLLoaderOptions options; |
| 189 if (cors_mode_ == kUnspecified) { | 189 if (cors_mode_ == kUnspecified) { |
| 190 options.allowCredentials = true; | 190 options.allowCredentials = true; |
| 191 options.crossOriginRequestPolicy = | 191 options.crossOriginRequestPolicy = |
| 192 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; | 192 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; |
| 193 } else { | 193 } else { |
| 194 options.exposeAllResponseHeaders = true; | 194 options.exposeAllResponseHeaders = true; |
| 195 // The author header set is empty, no preflight should go ahead. | 195 // The author header set is empty, no preflight should go ahead. |
| 196 options.preflightPolicy = WebURLLoaderOptions::PreventPreflight; | 196 options.preflightPolicy = WebURLLoaderOptions::PreventPreflight; |
| 197 options.crossOriginRequestPolicy = | 197 options.crossOriginRequestPolicy = |
| 198 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; | 198 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; |
| 199 if (cors_mode_ == kUseCredentials) | 199 if (cors_mode_ == kUseCredentials) |
| 200 options.allowCredentials = true; | 200 options.allowCredentials = true; |
| 201 } | 201 } |
| 202 loader.reset(frame->createAssociatedURLLoader(options)); | 202 loader.reset(frame->createAssociatedURLLoader(options)); |
| 203 } | 203 } |
| 204 | 204 |
| 205 // Start the resource loading. | 205 // Start the resource loading. |
| 206 loader->loadAsynchronously(request, this); | 206 loader->loadAsynchronously(request, this); |
| 207 active_loader_.reset(new ActiveLoader(loader.Pass())); | 207 active_loader_.reset(new ActiveLoader(std::move(loader))); |
| 208 loading_cb_.Run(kLoading); | 208 loading_cb_.Run(kLoading); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void BufferedResourceLoader::Stop() { | 211 void BufferedResourceLoader::Stop() { |
| 212 // Reset callbacks. | 212 // Reset callbacks. |
| 213 start_cb_.Reset(); | 213 start_cb_.Reset(); |
| 214 loading_cb_.Reset(); | 214 loading_cb_.Reset(); |
| 215 progress_cb_.Reset(); | 215 progress_cb_.Reset(); |
| 216 read_cb_.Reset(); | 216 read_cb_.Reset(); |
| 217 | 217 |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 << ", domain=" << error.domain.utf8().data() | 548 << ", domain=" << error.domain.utf8().data() |
| 549 << ", localizedDescription=" | 549 << ", localizedDescription=" |
| 550 << error.localizedDescription.utf8().data(); | 550 << error.localizedDescription.utf8().data(); |
| 551 DCHECK(active_loader_.get()); | 551 DCHECK(active_loader_.get()); |
| 552 MEDIA_LOG(ERROR, media_log_) | 552 MEDIA_LOG(ERROR, media_log_) |
| 553 << "Failed loading buffered resource. Error code=" << error.reason; | 553 << "Failed loading buffered resource. Error code=" << error.reason; |
| 554 | 554 |
| 555 // We don't need to continue loading after failure. | 555 // We don't need to continue loading after failure. |
| 556 // | 556 // |
| 557 // Keep it alive until we exit this method so that |error| remains valid. | 557 // Keep it alive until we exit this method so that |error| remains valid. |
| 558 scoped_ptr<ActiveLoader> active_loader = active_loader_.Pass(); | 558 scoped_ptr<ActiveLoader> active_loader = std::move(active_loader_); |
| 559 loader_failed_ = true; | 559 loader_failed_ = true; |
| 560 loading_cb_.Run(kLoadingFailed); | 560 loading_cb_.Run(kLoadingFailed); |
| 561 | 561 |
| 562 // Don't leave start callbacks hanging around. | 562 // Don't leave start callbacks hanging around. |
| 563 if (!start_cb_.is_null()) { | 563 if (!start_cb_.is_null()) { |
| 564 DCHECK(read_cb_.is_null()) | 564 DCHECK(read_cb_.is_null()) |
| 565 << "Shouldn't have a read callback during start"; | 565 << "Shouldn't have a read callback during start"; |
| 566 DoneStart(kFailed); | 566 DoneStart(kFailed); |
| 567 return; | 567 return; |
| 568 } | 568 } |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 | 823 |
| 824 void BufferedResourceLoader::Log() { | 824 void BufferedResourceLoader::Log() { |
| 825 media_log_->AddEvent( | 825 media_log_->AddEvent( |
| 826 media_log_->CreateBufferedExtentsChangedEvent( | 826 media_log_->CreateBufferedExtentsChangedEvent( |
| 827 offset_ - buffer_.backward_bytes(), | 827 offset_ - buffer_.backward_bytes(), |
| 828 offset_, | 828 offset_, |
| 829 offset_ + buffer_.forward_bytes())); | 829 offset_ + buffer_.forward_bytes())); |
| 830 } | 830 } |
| 831 | 831 |
| 832 } // namespace media | 832 } // namespace media |
| OLD | NEW |