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

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

Issue 306953005: Changing constructor of BufferedDataSource to accept GURL and CORSMode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removing inline Created 6 years, 6 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_data_source.h" 5 #include "content/renderer/media/buffered_data_source.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "content/public/common/url_constants.h" 10 #include "content/public/common/url_constants.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 DCHECK(callback_.is_null()); 72 DCHECK(callback_.is_null());
73 } 73 }
74 74
75 // static 75 // static
76 void BufferedDataSource::ReadOperation::Run( 76 void BufferedDataSource::ReadOperation::Run(
77 scoped_ptr<ReadOperation> read_op, int result) { 77 scoped_ptr<ReadOperation> read_op, int result) {
78 base::ResetAndReturn(&read_op->callback_).Run(result); 78 base::ResetAndReturn(&read_op->callback_).Run(result);
79 } 79 }
80 80
81 BufferedDataSource::BufferedDataSource( 81 BufferedDataSource::BufferedDataSource(
82 const GURL& url,
83 BufferedResourceLoader::CORSMode cors_mode,
82 const scoped_refptr<base::MessageLoopProxy>& render_loop, 84 const scoped_refptr<base::MessageLoopProxy>& render_loop,
83 WebFrame* frame, 85 WebFrame* frame,
84 media::MediaLog* media_log, 86 media::MediaLog* media_log,
85 BufferedDataSourceHost* host, 87 BufferedDataSourceHost* host,
86 const DownloadingCB& downloading_cb) 88 const DownloadingCB& downloading_cb)
87 : cors_mode_(BufferedResourceLoader::kUnspecified), 89 : url_(url),
90 cors_mode_(cors_mode),
88 total_bytes_(kPositionNotSpecified), 91 total_bytes_(kPositionNotSpecified),
89 assume_fully_buffered_(false),
90 streaming_(false), 92 streaming_(false),
91 frame_(frame), 93 frame_(frame),
92 intermediate_read_buffer_(new uint8[kInitialReadBufferSize]), 94 intermediate_read_buffer_(new uint8[kInitialReadBufferSize]),
93 intermediate_read_buffer_size_(kInitialReadBufferSize), 95 intermediate_read_buffer_size_(kInitialReadBufferSize),
94 render_loop_(render_loop), 96 render_loop_(render_loop),
95 stop_signal_received_(false), 97 stop_signal_received_(false),
96 media_has_played_(false), 98 media_has_played_(false),
97 preload_(AUTO), 99 preload_(AUTO),
98 bitrate_(0), 100 bitrate_(0),
99 playback_rate_(0.0), 101 playback_rate_(0.0),
(...skipping 21 matching lines...) Expand all
121 return new BufferedResourceLoader(url_, 123 return new BufferedResourceLoader(url_,
122 cors_mode_, 124 cors_mode_,
123 first_byte_position, 125 first_byte_position,
124 last_byte_position, 126 last_byte_position,
125 strategy, 127 strategy,
126 bitrate_, 128 bitrate_,
127 playback_rate_, 129 playback_rate_,
128 media_log_.get()); 130 media_log_.get());
129 } 131 }
130 132
131 void BufferedDataSource::Initialize( 133 void BufferedDataSource::Initialize(const InitializeCB& init_cb) {
132 const GURL& url,
133 BufferedResourceLoader::CORSMode cors_mode,
134 const InitializeCB& init_cb) {
135 DCHECK(render_loop_->BelongsToCurrentThread()); 134 DCHECK(render_loop_->BelongsToCurrentThread());
136 DCHECK(!init_cb.is_null()); 135 DCHECK(!init_cb.is_null());
137 DCHECK(!loader_.get()); 136 DCHECK(!loader_.get());
138 url_ = url;
139 cors_mode_ = cors_mode;
140 137
141 init_cb_ = init_cb; 138 init_cb_ = init_cb;
142 139
143 if (url_.SchemeIs(url::kHttpScheme) || url_.SchemeIs(url::kHttpsScheme)) { 140 if (url_.SchemeIsHTTPOrHTTPS()) {
144 // Do an unbounded range request starting at the beginning. If the server 141 // Do an unbounded range request starting at the beginning. If the server
145 // responds with 200 instead of 206 we'll fall back into a streaming mode. 142 // responds with 200 instead of 206 we'll fall back into a streaming mode.
146 loader_.reset(CreateResourceLoader(0, kPositionNotSpecified)); 143 loader_.reset(CreateResourceLoader(0, kPositionNotSpecified));
147 } else { 144 } else {
148 // For all other protocols, assume they support range request. We fetch 145 // For all other protocols, assume they support range request. We fetch
149 // the full range of the resource to obtain the instance size because 146 // the full range of the resource to obtain the instance size because
150 // we won't be served HTTP headers. 147 // we won't be served HTTP headers.
151 loader_.reset(CreateResourceLoader(kPositionNotSpecified, 148 loader_.reset(CreateResourceLoader(kPositionNotSpecified,
152 kPositionNotSpecified)); 149 kPositionNotSpecified));
153 assume_fully_buffered_ = true;
154 } 150 }
155 151
156 base::WeakPtr<BufferedDataSource> weak_this = weak_factory_.GetWeakPtr(); 152 base::WeakPtr<BufferedDataSource> weak_this = weak_factory_.GetWeakPtr();
157 loader_->Start( 153 loader_->Start(
158 base::Bind(&BufferedDataSource::StartCallback, weak_this), 154 base::Bind(&BufferedDataSource::StartCallback, weak_this),
159 base::Bind(&BufferedDataSource::LoadingStateChangedCallback, weak_this), 155 base::Bind(&BufferedDataSource::LoadingStateChangedCallback, weak_this),
160 base::Bind(&BufferedDataSource::ProgressCallback, weak_this), 156 base::Bind(&BufferedDataSource::ProgressCallback, weak_this),
161 frame_); 157 frame_);
162 } 158 }
163 159
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 init_cb_is_null = init_cb_.is_null(); 342 init_cb_is_null = init_cb_.is_null();
347 } 343 }
348 if (init_cb_is_null) { 344 if (init_cb_is_null) {
349 loader_->Stop(); 345 loader_->Stop();
350 return; 346 return;
351 } 347 }
352 348
353 // All responses must be successful. Resources that are assumed to be fully 349 // All responses must be successful. Resources that are assumed to be fully
354 // buffered must have a known content length. 350 // buffered must have a known content length.
355 bool success = status == BufferedResourceLoader::kOk && 351 bool success = status == BufferedResourceLoader::kOk &&
356 (!assume_fully_buffered_ || 352 (!assume_fully_buffered() ||
357 loader_->instance_size() != kPositionNotSpecified); 353 loader_->instance_size() != kPositionNotSpecified);
358 354
359 if (success) { 355 if (success) {
360 total_bytes_ = loader_->instance_size(); 356 total_bytes_ = loader_->instance_size();
361 streaming_ = !assume_fully_buffered_ && 357 streaming_ =
358 !assume_fully_buffered() &&
362 (total_bytes_ == kPositionNotSpecified || !loader_->range_supported()); 359 (total_bytes_ == kPositionNotSpecified || !loader_->range_supported());
363 360
364 media_log_->SetDoubleProperty("total_bytes", 361 media_log_->SetDoubleProperty("total_bytes",
365 static_cast<double>(total_bytes_)); 362 static_cast<double>(total_bytes_));
366 media_log_->SetBooleanProperty("streaming", streaming_); 363 media_log_->SetBooleanProperty("streaming", streaming_);
367 } else { 364 } else {
368 loader_->Stop(); 365 loader_->Stop();
369 } 366 }
370 367
371 // TODO(scherkus): we shouldn't have to lock to signal host(), see 368 // TODO(scherkus): we shouldn't have to lock to signal host(), see
372 // http://crbug.com/113712 for details. 369 // http://crbug.com/113712 for details.
373 base::AutoLock auto_lock(lock_); 370 base::AutoLock auto_lock(lock_);
374 if (stop_signal_received_) 371 if (stop_signal_received_)
375 return; 372 return;
376 373
377 if (success) { 374 if (success) {
378 if (total_bytes_ != kPositionNotSpecified) { 375 if (total_bytes_ != kPositionNotSpecified) {
379 host_->SetTotalBytes(total_bytes_); 376 host_->SetTotalBytes(total_bytes_);
380 if (assume_fully_buffered_) 377 if (assume_fully_buffered())
381 host_->AddBufferedByteRange(0, total_bytes_); 378 host_->AddBufferedByteRange(0, total_bytes_);
382 } 379 }
383 380
384 media_log_->SetBooleanProperty("single_origin", loader_->HasSingleOrigin()); 381 media_log_->SetBooleanProperty("single_origin", loader_->HasSingleOrigin());
385 media_log_->SetBooleanProperty("passed_cors_access_check", 382 media_log_->SetBooleanProperty("passed_cors_access_check",
386 loader_->DidPassCORSAccessCheck()); 383 loader_->DidPassCORSAccessCheck());
387 media_log_->SetBooleanProperty("range_header_supported", 384 media_log_->SetBooleanProperty("range_header_supported",
388 loader_->range_supported()); 385 loader_->range_supported());
389 } 386 }
390 387
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 total_bytes_); 463 total_bytes_);
467 } 464 }
468 } 465 }
469 ReadOperation::Run(read_op_.Pass(), bytes_read); 466 ReadOperation::Run(read_op_.Pass(), bytes_read);
470 } 467 }
471 468
472 void BufferedDataSource::LoadingStateChangedCallback( 469 void BufferedDataSource::LoadingStateChangedCallback(
473 BufferedResourceLoader::LoadingState state) { 470 BufferedResourceLoader::LoadingState state) {
474 DCHECK(render_loop_->BelongsToCurrentThread()); 471 DCHECK(render_loop_->BelongsToCurrentThread());
475 472
476 if (assume_fully_buffered_) 473 if (assume_fully_buffered())
477 return; 474 return;
478 475
479 bool is_downloading_data; 476 bool is_downloading_data;
480 switch (state) { 477 switch (state) {
481 case BufferedResourceLoader::kLoading: 478 case BufferedResourceLoader::kLoading:
482 is_downloading_data = true; 479 is_downloading_data = true;
483 break; 480 break;
484 case BufferedResourceLoader::kLoadingDeferred: 481 case BufferedResourceLoader::kLoadingDeferred:
485 case BufferedResourceLoader::kLoadingFinished: 482 case BufferedResourceLoader::kLoadingFinished:
486 is_downloading_data = false; 483 is_downloading_data = false;
487 break; 484 break;
488 485
489 // TODO(scherkus): we don't signal network activity changes when loads 486 // TODO(scherkus): we don't signal network activity changes when loads
490 // fail to preserve existing behaviour when deferring is toggled, however 487 // fail to preserve existing behaviour when deferring is toggled, however
491 // we should consider changing DownloadingCB to also propagate loading 488 // we should consider changing DownloadingCB to also propagate loading
492 // state. For example there isn't any signal today to notify the client that 489 // state. For example there isn't any signal today to notify the client that
493 // loading has failed (we only get errors on subsequent reads). 490 // loading has failed (we only get errors on subsequent reads).
494 case BufferedResourceLoader::kLoadingFailed: 491 case BufferedResourceLoader::kLoadingFailed:
495 return; 492 return;
496 } 493 }
497 494
498 downloading_cb_.Run(is_downloading_data); 495 downloading_cb_.Run(is_downloading_data);
499 } 496 }
500 497
501 void BufferedDataSource::ProgressCallback(int64 position) { 498 void BufferedDataSource::ProgressCallback(int64 position) {
502 DCHECK(render_loop_->BelongsToCurrentThread()); 499 DCHECK(render_loop_->BelongsToCurrentThread());
503 500
504 if (assume_fully_buffered_) 501 if (assume_fully_buffered())
505 return; 502 return;
506 503
507 // TODO(scherkus): we shouldn't have to lock to signal host(), see 504 // TODO(scherkus): we shouldn't have to lock to signal host(), see
508 // http://crbug.com/113712 for details. 505 // http://crbug.com/113712 for details.
509 base::AutoLock auto_lock(lock_); 506 base::AutoLock auto_lock(lock_);
510 if (stop_signal_received_) 507 if (stop_signal_received_)
511 return; 508 return;
512 509
513 host_->AddBufferedByteRange(loader_->first_byte_position(), position); 510 host_->AddBufferedByteRange(loader_->first_byte_position(), position);
514 } 511 }
(...skipping 16 matching lines...) Expand all
531 return; 528 return;
532 } 529 }
533 530
534 // If media is currently playing or the page indicated preload=auto, 531 // If media is currently playing or the page indicated preload=auto,
535 // use threshold strategy to enable/disable deferring when the buffer 532 // use threshold strategy to enable/disable deferring when the buffer
536 // is full/depleted. 533 // is full/depleted.
537 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); 534 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer);
538 } 535 }
539 536
540 } // namespace content 537 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/buffered_data_source.h ('k') | content/renderer/media/buffered_data_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698