OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/resource_multibuffer_data_provider.h" | 5 #include "media/blink/resource_multibuffer_data_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/bits.h" | 11 #include "base/bits.h" |
11 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "media/blink/active_loader.h" | 16 #include "media/blink/active_loader.h" |
16 #include "media/blink/cache_util.h" | 17 #include "media/blink/cache_util.h" |
17 #include "media/blink/media_blink_export.h" | 18 #include "media/blink/media_blink_export.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 url_data_->frame()->setReferrerForRequest(request, blink::WebURL()); | 76 url_data_->frame()->setReferrerForRequest(request, blink::WebURL()); |
76 | 77 |
77 // Disable compression, compression for audio/video doesn't make sense... | 78 // Disable compression, compression for audio/video doesn't make sense... |
78 request.setHTTPHeaderField( | 79 request.setHTTPHeaderField( |
79 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), | 80 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), |
80 WebString::fromUTF8("identity;q=1, *;q=0")); | 81 WebString::fromUTF8("identity;q=1, *;q=0")); |
81 | 82 |
82 // Check for our test WebURLLoader. | 83 // Check for our test WebURLLoader. |
83 scoped_ptr<WebURLLoader> loader; | 84 scoped_ptr<WebURLLoader> loader; |
84 if (test_loader_) { | 85 if (test_loader_) { |
85 loader = test_loader_.Pass(); | 86 loader = std::move(test_loader_); |
86 } else { | 87 } else { |
87 WebURLLoaderOptions options; | 88 WebURLLoaderOptions options; |
88 if (url_data_->cors_mode() == UrlData::CORS_UNSPECIFIED) { | 89 if (url_data_->cors_mode() == UrlData::CORS_UNSPECIFIED) { |
89 options.allowCredentials = true; | 90 options.allowCredentials = true; |
90 options.crossOriginRequestPolicy = | 91 options.crossOriginRequestPolicy = |
91 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; | 92 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; |
92 } else { | 93 } else { |
93 options.exposeAllResponseHeaders = true; | 94 options.exposeAllResponseHeaders = true; |
94 // The author header set is empty, no preflight should go ahead. | 95 // The author header set is empty, no preflight should go ahead. |
95 options.preflightPolicy = WebURLLoaderOptions::PreventPreflight; | 96 options.preflightPolicy = WebURLLoaderOptions::PreventPreflight; |
96 options.crossOriginRequestPolicy = | 97 options.crossOriginRequestPolicy = |
97 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; | 98 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; |
98 if (url_data_->cors_mode() == UrlData::CORS_USE_CREDENTIALS) | 99 if (url_data_->cors_mode() == UrlData::CORS_USE_CREDENTIALS) |
99 options.allowCredentials = true; | 100 options.allowCredentials = true; |
100 } | 101 } |
101 loader.reset(url_data_->frame()->createAssociatedURLLoader(options)); | 102 loader.reset(url_data_->frame()->createAssociatedURLLoader(options)); |
102 } | 103 } |
103 | 104 |
104 // Start the resource loading. | 105 // Start the resource loading. |
105 loader->loadAsynchronously(request, this); | 106 loader->loadAsynchronously(request, this); |
106 active_loader_.reset(new ActiveLoader(loader.Pass())); | 107 active_loader_.reset(new ActiveLoader(std::move(loader))); |
107 } | 108 } |
108 | 109 |
109 ResourceMultiBufferDataProvider::~ResourceMultiBufferDataProvider() {} | 110 ResourceMultiBufferDataProvider::~ResourceMultiBufferDataProvider() {} |
110 | 111 |
111 ///////////////////////////////////////////////////////////////////////////// | 112 ///////////////////////////////////////////////////////////////////////////// |
112 // MultiBuffer::DataProvider implementation. | 113 // MultiBuffer::DataProvider implementation. |
113 MultiBufferBlockId ResourceMultiBufferDataProvider::Tell() const { | 114 MultiBufferBlockId ResourceMultiBufferDataProvider::Tell() const { |
114 return pos_; | 115 return pos_; |
115 } | 116 } |
116 | 117 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 292 |
292 // First, let's take a ref on the current url data. | 293 // First, let's take a ref on the current url data. |
293 scoped_refptr<UrlData> old_url_data(url_data_); | 294 scoped_refptr<UrlData> old_url_data(url_data_); |
294 destination_url_data->Use(); | 295 destination_url_data->Use(); |
295 | 296 |
296 // Take ownership of ourselves. (From the multibuffer) | 297 // Take ownership of ourselves. (From the multibuffer) |
297 scoped_ptr<DataProvider> self( | 298 scoped_ptr<DataProvider> self( |
298 url_data_->multibuffer()->RemoveProvider(this)); | 299 url_data_->multibuffer()->RemoveProvider(this)); |
299 url_data_ = destination_url_data.get(); | 300 url_data_ = destination_url_data.get(); |
300 // Give the ownership to our new owner. | 301 // Give the ownership to our new owner. |
301 url_data_->multibuffer()->AddProvider(self.Pass()); | 302 url_data_->multibuffer()->AddProvider(std::move(self)); |
302 | 303 |
303 // Call callback to let upstream users know about the transfer. | 304 // Call callback to let upstream users know about the transfer. |
304 // This will merge the data from the two multibuffers and | 305 // This will merge the data from the two multibuffers and |
305 // cause clients to start using the new UrlData. | 306 // cause clients to start using the new UrlData. |
306 old_url_data->RedirectTo(destination_url_data); | 307 old_url_data->RedirectTo(destination_url_data); |
307 } | 308 } |
308 } | 309 } |
309 | 310 |
310 void ResourceMultiBufferDataProvider::didReceiveData(WebURLLoader* loader, | 311 void ResourceMultiBufferDataProvider::didReceiveData(WebURLLoader* loader, |
311 const char* data, | 312 const char* data, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 size < url_data_->length()) { | 375 size < url_data_->length()) { |
375 if (retries_ < kMaxRetries) { | 376 if (retries_ < kMaxRetries) { |
376 DVLOG(1) << " Partial data received.... @ pos = " << size; | 377 DVLOG(1) << " Partial data received.... @ pos = " << size; |
377 retries_++; | 378 retries_++; |
378 base::MessageLoop::current()->PostDelayedTask( | 379 base::MessageLoop::current()->PostDelayedTask( |
379 FROM_HERE, base::Bind(&ResourceMultiBufferDataProvider::Start, | 380 FROM_HERE, base::Bind(&ResourceMultiBufferDataProvider::Start, |
380 weak_factory_.GetWeakPtr()), | 381 weak_factory_.GetWeakPtr()), |
381 base::TimeDelta::FromMilliseconds(kLoaderPartialRetryDelayMs)); | 382 base::TimeDelta::FromMilliseconds(kLoaderPartialRetryDelayMs)); |
382 return; | 383 return; |
383 } else { | 384 } else { |
384 scoped_ptr<ActiveLoader> active_loader = active_loader_.Pass(); | 385 scoped_ptr<ActiveLoader> active_loader = std::move(active_loader_); |
385 url_data_->Fail(); | 386 url_data_->Fail(); |
386 return; | 387 return; |
387 } | 388 } |
388 } | 389 } |
389 | 390 |
390 url_data_->set_length(size); | 391 url_data_->set_length(size); |
391 fifo_.push_back(DataBuffer::CreateEOSBuffer()); | 392 fifo_.push_back(DataBuffer::CreateEOSBuffer()); |
392 | 393 |
393 DCHECK(Available()); | 394 DCHECK(Available()); |
394 url_data_->multibuffer()->OnDataProviderEvent(this); | 395 url_data_->multibuffer()->OnDataProviderEvent(this); |
(...skipping 13 matching lines...) Expand all Loading... |
408 if (retries_ < kMaxRetries && pos_ != 0) { | 409 if (retries_ < kMaxRetries && pos_ != 0) { |
409 retries_++; | 410 retries_++; |
410 base::MessageLoop::current()->PostDelayedTask( | 411 base::MessageLoop::current()->PostDelayedTask( |
411 FROM_HERE, base::Bind(&ResourceMultiBufferDataProvider::Start, | 412 FROM_HERE, base::Bind(&ResourceMultiBufferDataProvider::Start, |
412 weak_factory_.GetWeakPtr()), | 413 weak_factory_.GetWeakPtr()), |
413 base::TimeDelta::FromMilliseconds(kLoaderFailedRetryDelayMs)); | 414 base::TimeDelta::FromMilliseconds(kLoaderFailedRetryDelayMs)); |
414 } else { | 415 } else { |
415 // We don't need to continue loading after failure. | 416 // We don't need to continue loading after failure. |
416 // | 417 // |
417 // Keep it alive until we exit this method so that |error| remains valid. | 418 // Keep it alive until we exit this method so that |error| remains valid. |
418 scoped_ptr<ActiveLoader> active_loader = active_loader_.Pass(); | 419 scoped_ptr<ActiveLoader> active_loader = std::move(active_loader_); |
419 url_data_->Fail(); | 420 url_data_->Fail(); |
420 } | 421 } |
421 } | 422 } |
422 | 423 |
423 bool ResourceMultiBufferDataProvider::ParseContentRange( | 424 bool ResourceMultiBufferDataProvider::ParseContentRange( |
424 const std::string& content_range_str, | 425 const std::string& content_range_str, |
425 int64_t* first_byte_position, | 426 int64_t* first_byte_position, |
426 int64_t* last_byte_position, | 427 int64_t* last_byte_position, |
427 int64_t* instance_size) { | 428 int64_t* instance_size) { |
428 const std::string kUpThroughBytesUnit = "bytes "; | 429 const std::string kUpThroughBytesUnit = "bytes "; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 } | 492 } |
492 | 493 |
493 if (byte_pos() != first_byte_position) { | 494 if (byte_pos() != first_byte_position) { |
494 return false; | 495 return false; |
495 } | 496 } |
496 | 497 |
497 return true; | 498 return true; |
498 } | 499 } |
499 | 500 |
500 } // namespace media | 501 } // namespace media |
OLD | NEW |