OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/glue/media/buffered_data_source.h" | 5 #include "webkit/glue/media/buffered_data_source.h" |
6 | 6 |
7 #include "media/base/filter_host.h" | 7 #include "media/base/filter_host.h" |
8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
9 #include "webkit/glue/webkit_glue.h" | 9 #include "webkit/glue/webkit_glue.h" |
10 | 10 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 bool BufferedDataSource::IsUrlSupported(const std::string& url) { | 109 bool BufferedDataSource::IsUrlSupported(const std::string& url) { |
110 GURL gurl(url); | 110 GURL gurl(url); |
111 | 111 |
112 // This data source doesn't support data:// protocol so reject it. | 112 // This data source doesn't support data:// protocol so reject it. |
113 return IsProtocolSupportedForMedia(gurl) && !gurl.SchemeIs(kDataScheme); | 113 return IsProtocolSupportedForMedia(gurl) && !gurl.SchemeIs(kDataScheme); |
114 } | 114 } |
115 | 115 |
116 void BufferedDataSource::Stop(media::FilterCallback* callback) { | 116 void BufferedDataSource::Stop(media::FilterCallback* callback) { |
117 { | 117 { |
118 AutoLock auto_lock(lock_); | 118 base::AutoLock auto_lock(lock_); |
119 stop_signal_received_ = true; | 119 stop_signal_received_ = true; |
120 } | 120 } |
121 if (callback) { | 121 if (callback) { |
122 callback->Run(); | 122 callback->Run(); |
123 delete callback; | 123 delete callback; |
124 } | 124 } |
125 | 125 |
126 render_loop_->PostTask(FROM_HERE, | 126 render_loop_->PostTask(FROM_HERE, |
127 NewRunnableMethod(this, &BufferedDataSource::CleanupTask)); | 127 NewRunnableMethod(this, &BufferedDataSource::CleanupTask)); |
128 } | 128 } |
(...skipping 30 matching lines...) Expand all Loading... |
159 DCHECK(MessageLoop::current() == render_loop_); | 159 DCHECK(MessageLoop::current() == render_loop_); |
160 return single_origin_; | 160 return single_origin_; |
161 } | 161 } |
162 | 162 |
163 void BufferedDataSource::Abort() { | 163 void BufferedDataSource::Abort() { |
164 DCHECK(MessageLoop::current() == render_loop_); | 164 DCHECK(MessageLoop::current() == render_loop_); |
165 | 165 |
166 // If we are told to abort, immediately return from any pending read | 166 // If we are told to abort, immediately return from any pending read |
167 // with an error. | 167 // with an error. |
168 if (read_callback_.get()) { | 168 if (read_callback_.get()) { |
169 AutoLock auto_lock(lock_); | 169 base::AutoLock auto_lock(lock_); |
170 DoneRead_Locked(net::ERR_FAILED); | 170 DoneRead_Locked(net::ERR_FAILED); |
171 } | 171 } |
172 | 172 |
173 CleanupTask(); | 173 CleanupTask(); |
174 frame_ = NULL; | 174 frame_ = NULL; |
175 } | 175 } |
176 | 176 |
177 ///////////////////////////////////////////////////////////////////////////// | 177 ///////////////////////////////////////////////////////////////////////////// |
178 // Render thread tasks. | 178 // Render thread tasks. |
179 void BufferedDataSource::InitializeTask() { | 179 void BufferedDataSource::InitializeTask() { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 } | 407 } |
408 | 408 |
409 // We need to prevent calling to filter host and running the callback if | 409 // We need to prevent calling to filter host and running the callback if |
410 // we have received the stop signal. We need to lock down the whole callback | 410 // we have received the stop signal. We need to lock down the whole callback |
411 // method to prevent bad things from happening. The reason behind this is | 411 // method to prevent bad things from happening. The reason behind this is |
412 // that we cannot guarantee tasks on render thread have completely stopped | 412 // that we cannot guarantee tasks on render thread have completely stopped |
413 // when we receive the Stop() method call. The only way to solve this is to | 413 // when we receive the Stop() method call. The only way to solve this is to |
414 // let tasks on render thread to run but make sure they don't call outside | 414 // let tasks on render thread to run but make sure they don't call outside |
415 // this object when Stop() method is ever called. Locking this method is safe | 415 // this object when Stop() method is ever called. Locking this method is safe |
416 // because |lock_| is only acquired in tasks on render thread. | 416 // because |lock_| is only acquired in tasks on render thread. |
417 AutoLock auto_lock(lock_); | 417 base::AutoLock auto_lock(lock_); |
418 if (stop_signal_received_) | 418 if (stop_signal_received_) |
419 return; | 419 return; |
420 | 420 |
421 if (!success) { | 421 if (!success) { |
422 host()->SetError(media::PIPELINE_ERROR_NETWORK); | 422 host()->SetError(media::PIPELINE_ERROR_NETWORK); |
423 DoneInitialization_Locked(); | 423 DoneInitialization_Locked(); |
424 return; | 424 return; |
425 } | 425 } |
426 | 426 |
427 if (streaming_) { | 427 if (streaming_) { |
(...skipping 30 matching lines...) Expand all Loading... |
458 } | 458 } |
459 | 459 |
460 // We need to prevent calling to filter host and running the callback if | 460 // We need to prevent calling to filter host and running the callback if |
461 // we have received the stop signal. We need to lock down the whole callback | 461 // we have received the stop signal. We need to lock down the whole callback |
462 // method to prevent bad things from happening. The reason behind this is | 462 // method to prevent bad things from happening. The reason behind this is |
463 // that we cannot guarantee tasks on render thread have completely stopped | 463 // that we cannot guarantee tasks on render thread have completely stopped |
464 // when we receive the Stop() method call. The only way to solve this is to | 464 // when we receive the Stop() method call. The only way to solve this is to |
465 // let tasks on render thread to run but make sure they don't call outside | 465 // let tasks on render thread to run but make sure they don't call outside |
466 // this object when Stop() method is ever called. Locking this method is safe | 466 // this object when Stop() method is ever called. Locking this method is safe |
467 // because |lock_| is only acquired in tasks on render thread. | 467 // because |lock_| is only acquired in tasks on render thread. |
468 AutoLock auto_lock(lock_); | 468 base::AutoLock auto_lock(lock_); |
469 if (stop_signal_received_) | 469 if (stop_signal_received_) |
470 return; | 470 return; |
471 | 471 |
472 if (success) { | 472 if (success) { |
473 host()->SetTotalBytes(total_bytes_); | 473 host()->SetTotalBytes(total_bytes_); |
474 host()->SetBufferedBytes(total_bytes_); | 474 host()->SetBufferedBytes(total_bytes_); |
475 host()->SetLoaded(loaded_); | 475 host()->SetLoaded(loaded_); |
476 } else { | 476 } else { |
477 host()->SetError(media::PIPELINE_ERROR_NETWORK); | 477 host()->SetError(media::PIPELINE_ERROR_NETWORK); |
478 } | 478 } |
(...skipping 18 matching lines...) Expand all Loading... |
497 loader_->Stop(); | 497 loader_->Stop(); |
498 | 498 |
499 // We need to prevent calling to filter host and running the callback if | 499 // We need to prevent calling to filter host and running the callback if |
500 // we have received the stop signal. We need to lock down the whole callback | 500 // we have received the stop signal. We need to lock down the whole callback |
501 // method to prevent bad things from happening. The reason behind this is | 501 // method to prevent bad things from happening. The reason behind this is |
502 // that we cannot guarantee tasks on render thread have completely stopped | 502 // that we cannot guarantee tasks on render thread have completely stopped |
503 // when we receive the Stop() method call. So only way to solve this is to | 503 // when we receive the Stop() method call. So only way to solve this is to |
504 // let tasks on render thread to run but make sure they don't call outside | 504 // let tasks on render thread to run but make sure they don't call outside |
505 // this object when Stop() method is ever called. Locking this method is | 505 // this object when Stop() method is ever called. Locking this method is |
506 // safe because |lock_| is only acquired in tasks on render thread. | 506 // safe because |lock_| is only acquired in tasks on render thread. |
507 AutoLock auto_lock(lock_); | 507 base::AutoLock auto_lock(lock_); |
508 if (stop_signal_received_) | 508 if (stop_signal_received_) |
509 return; | 509 return; |
510 DoneRead_Locked(net::ERR_INVALID_RESPONSE); | 510 DoneRead_Locked(net::ERR_INVALID_RESPONSE); |
511 } | 511 } |
512 | 512 |
513 void BufferedDataSource::ReadCallback(int error) { | 513 void BufferedDataSource::ReadCallback(int error) { |
514 DCHECK(MessageLoop::current() == render_loop_); | 514 DCHECK(MessageLoop::current() == render_loop_); |
515 | 515 |
516 if (error < 0) { | 516 if (error < 0) { |
517 DCHECK(loader_.get()); | 517 DCHECK(loader_.get()); |
518 | 518 |
519 // Stop the resource load if it failed. | 519 // Stop the resource load if it failed. |
520 loader_->Stop(); | 520 loader_->Stop(); |
521 | 521 |
522 if (error == net::ERR_CACHE_MISS) { | 522 if (error == net::ERR_CACHE_MISS) { |
523 render_loop_->PostTask(FROM_HERE, | 523 render_loop_->PostTask(FROM_HERE, |
524 NewRunnableMethod(this, &BufferedDataSource::RestartLoadingTask)); | 524 NewRunnableMethod(this, &BufferedDataSource::RestartLoadingTask)); |
525 return; | 525 return; |
526 } | 526 } |
527 } | 527 } |
528 | 528 |
529 // We need to prevent calling to filter host and running the callback if | 529 // We need to prevent calling to filter host and running the callback if |
530 // we have received the stop signal. We need to lock down the whole callback | 530 // we have received the stop signal. We need to lock down the whole callback |
531 // method to prevent bad things from happening. The reason behind this is | 531 // method to prevent bad things from happening. The reason behind this is |
532 // that we cannot guarantee tasks on render thread have completely stopped | 532 // that we cannot guarantee tasks on render thread have completely stopped |
533 // when we receive the Stop() method call. So only way to solve this is to | 533 // when we receive the Stop() method call. So only way to solve this is to |
534 // let tasks on render thread to run but make sure they don't call outside | 534 // let tasks on render thread to run but make sure they don't call outside |
535 // this object when Stop() method is ever called. Locking this method is safe | 535 // this object when Stop() method is ever called. Locking this method is safe |
536 // because |lock_| is only acquired in tasks on render thread. | 536 // because |lock_| is only acquired in tasks on render thread. |
537 AutoLock auto_lock(lock_); | 537 base::AutoLock auto_lock(lock_); |
538 if (stop_signal_received_) | 538 if (stop_signal_received_) |
539 return; | 539 return; |
540 | 540 |
541 if (error > 0) { | 541 if (error > 0) { |
542 // If a position error code is received, read was successful. So copy | 542 // If a position error code is received, read was successful. So copy |
543 // from intermediate read buffer to the target read buffer. | 543 // from intermediate read buffer to the target read buffer. |
544 memcpy(read_buffer_, intermediate_read_buffer_.get(), error); | 544 memcpy(read_buffer_, intermediate_read_buffer_.get(), error); |
545 } | 545 } |
546 DoneRead_Locked(error); | 546 DoneRead_Locked(error); |
547 } | 547 } |
(...skipping 15 matching lines...) Expand all Loading... |
563 return; | 563 return; |
564 | 564 |
565 // We need to prevent calling to filter host and running the callback if | 565 // We need to prevent calling to filter host and running the callback if |
566 // we have received the stop signal. We need to lock down the whole callback | 566 // we have received the stop signal. We need to lock down the whole callback |
567 // method to prevent bad things from happening. The reason behind this is | 567 // method to prevent bad things from happening. The reason behind this is |
568 // that we cannot guarantee tasks on render thread have completely stopped | 568 // that we cannot guarantee tasks on render thread have completely stopped |
569 // when we receive the Stop() method call. So only way to solve this is to | 569 // when we receive the Stop() method call. So only way to solve this is to |
570 // let tasks on render thread to run but make sure they don't call outside | 570 // let tasks on render thread to run but make sure they don't call outside |
571 // this object when Stop() method is ever called. Locking this method is safe | 571 // this object when Stop() method is ever called. Locking this method is safe |
572 // because |lock_| is only acquired in tasks on render thread. | 572 // because |lock_| is only acquired in tasks on render thread. |
573 AutoLock auto_lock(lock_); | 573 base::AutoLock auto_lock(lock_); |
574 if (stop_signal_received_) | 574 if (stop_signal_received_) |
575 return; | 575 return; |
576 | 576 |
577 if (network_activity != network_activity_) { | 577 if (network_activity != network_activity_) { |
578 network_activity_ = network_activity; | 578 network_activity_ = network_activity; |
579 host()->SetNetworkActivity(network_activity); | 579 host()->SetNetworkActivity(network_activity); |
580 } | 580 } |
581 host()->SetBufferedBytes(buffered_position + 1); | 581 host()->SetBufferedBytes(buffered_position + 1); |
582 } | 582 } |
583 | 583 |
584 } // namespace webkit_glue | 584 } // namespace webkit_glue |
OLD | NEW |