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

Side by Side Diff: webkit/media/buffered_data_source.cc

Issue 10698139: Write file:// tests for BufferedDataSource and fix some bugs as a result. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: what the Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « webkit/media/buffered_data_source.h ('k') | webkit/media/buffered_data_source_unittest.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/media/buffered_data_source.h" 5 #include "webkit/media/buffered_data_source.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "media/base/media_log.h" 9 #include "media/base/media_log.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 22 matching lines...) Expand all
33 } 33 }
34 static void NonHttpProgressCallback(int64) {} 34 static void NonHttpProgressCallback(int64) {}
35 35
36 BufferedDataSource::BufferedDataSource( 36 BufferedDataSource::BufferedDataSource(
37 MessageLoop* render_loop, 37 MessageLoop* render_loop,
38 WebFrame* frame, 38 WebFrame* frame,
39 media::MediaLog* media_log, 39 media::MediaLog* media_log,
40 const DownloadingCB& downloading_cb) 40 const DownloadingCB& downloading_cb)
41 : cors_mode_(BufferedResourceLoader::kUnspecified), 41 : cors_mode_(BufferedResourceLoader::kUnspecified),
42 total_bytes_(kPositionNotSpecified), 42 total_bytes_(kPositionNotSpecified),
43 buffered_bytes_(0), 43 assume_fully_buffered_(false),
44 streaming_(false), 44 streaming_(false),
45 frame_(frame), 45 frame_(frame),
46 read_size_(0), 46 read_size_(0),
47 read_buffer_(NULL), 47 read_buffer_(NULL),
48 last_read_start_(0), 48 last_read_start_(0),
49 intermediate_read_buffer_(new uint8[kInitialReadBufferSize]), 49 intermediate_read_buffer_(new uint8[kInitialReadBufferSize]),
50 intermediate_read_buffer_size_(kInitialReadBufferSize), 50 intermediate_read_buffer_size_(kInitialReadBufferSize),
51 render_loop_(render_loop), 51 render_loop_(render_loop),
52 stop_signal_received_(false), 52 stop_signal_received_(false),
53 stopped_on_render_loop_(false), 53 stopped_on_render_loop_(false),
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 loader_.reset( 281 loader_.reset(
282 CreateResourceLoader(last_read_start_, kPositionNotSpecified)); 282 CreateResourceLoader(last_read_start_, kPositionNotSpecified));
283 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { 283 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) {
284 loader_->Start( 284 loader_->Start(
285 base::Bind(&BufferedDataSource::PartialReadStartCallback, this), 285 base::Bind(&BufferedDataSource::PartialReadStartCallback, this),
286 base::Bind(&BufferedDataSource::HttpLoadingStateChangedCallback, this), 286 base::Bind(&BufferedDataSource::HttpLoadingStateChangedCallback, this),
287 base::Bind(&BufferedDataSource::HttpProgressCallback, this), 287 base::Bind(&BufferedDataSource::HttpProgressCallback, this),
288 frame_); 288 frame_);
289 } else { 289 } else {
290 loader_->Start( 290 loader_->Start(
291 base::Bind(&BufferedDataSource::NonHttpInitialStartCallback, this), 291 base::Bind(&BufferedDataSource::PartialReadStartCallback, this),
292 base::Bind(&NonHttpLoadingStateChangedCallback), 292 base::Bind(&NonHttpLoadingStateChangedCallback),
293 base::Bind(&NonHttpProgressCallback), 293 base::Bind(&NonHttpProgressCallback),
294 frame_); 294 frame_);
295 } 295 }
296 } 296 }
297 297
298 void BufferedDataSource::SetPlaybackRateTask(float playback_rate) { 298 void BufferedDataSource::SetPlaybackRateTask(float playback_rate) {
299 DCHECK(MessageLoop::current() == render_loop_); 299 DCHECK(MessageLoop::current() == render_loop_);
300 DCHECK(loader_.get()); 300 DCHECK(loader_.get());
301 301
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 loader_->Stop(); 445 loader_->Stop();
446 return; 446 return;
447 } 447 }
448 448
449 int64 instance_size = loader_->instance_size(); 449 int64 instance_size = loader_->instance_size();
450 bool success = status == BufferedResourceLoader::kOk && 450 bool success = status == BufferedResourceLoader::kOk &&
451 instance_size != kPositionNotSpecified; 451 instance_size != kPositionNotSpecified;
452 452
453 if (success) { 453 if (success) {
454 total_bytes_ = instance_size; 454 total_bytes_ = instance_size;
455 buffered_bytes_ = total_bytes_; 455 assume_fully_buffered_ = true;
456 } else { 456 } else {
457 loader_->Stop(); 457 loader_->Stop();
458 } 458 }
459 459
460 // Reference to prevent destruction while inside the |initialize_cb_| 460 // Reference to prevent destruction while inside the |initialize_cb_|
461 // call. This is a temporary fix to prevent crashes caused by holding the 461 // call. This is a temporary fix to prevent crashes caused by holding the
462 // lock and running the destructor. 462 // lock and running the destructor.
463 // TODO: Review locking in this class and figure out a way to run the callback 463 // TODO: Review locking in this class and figure out a way to run the callback
464 // w/o the lock. 464 // w/o the lock.
465 scoped_refptr<BufferedDataSource> destruction_guard(this); 465 scoped_refptr<BufferedDataSource> destruction_guard(this);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 if (host() && position > last_read_start_) 600 if (host() && position > last_read_start_)
601 host()->AddBufferedByteRange(last_read_start_, position); 601 host()->AddBufferedByteRange(last_read_start_, position);
602 } 602 }
603 603
604 void BufferedDataSource::UpdateHostState_Locked() { 604 void BufferedDataSource::UpdateHostState_Locked() {
605 lock_.AssertAcquired(); 605 lock_.AssertAcquired();
606 606
607 if (!host()) 607 if (!host())
608 return; 608 return;
609 609
610 if (total_bytes_ != kPositionNotSpecified) 610 if (total_bytes_ == kPositionNotSpecified)
611 host()->SetTotalBytes(total_bytes_); 611 return;
612 int64 start = loader_->first_byte_position(); 612
613 if (buffered_bytes_ > start) 613 host()->SetTotalBytes(total_bytes_);
614 host()->AddBufferedByteRange(start, buffered_bytes_); 614
615 if (assume_fully_buffered_)
616 host()->AddBufferedByteRange(0, total_bytes_);
615 } 617 }
616 618
617 } // namespace webkit_media 619 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/buffered_data_source.h ('k') | webkit/media/buffered_data_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698