| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/process_util.h" | 7 #include "base/process_util.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/common/extensions/url_pattern.h" | 10 #include "chrome/common/extensions/url_pattern.h" |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 void BufferedDataSource::Initialize(const std::string& url, | 535 void BufferedDataSource::Initialize(const std::string& url, |
| 536 media::FilterCallback* callback) { | 536 media::FilterCallback* callback) { |
| 537 DCHECK(callback); | 537 DCHECK(callback); |
| 538 initialize_callback_.reset(callback); | 538 initialize_callback_.reset(callback); |
| 539 | 539 |
| 540 // Save the url. | 540 // Save the url. |
| 541 url_ = GURL(url); | 541 url_ = GURL(url); |
| 542 | 542 |
| 543 // Make sure we support the scheme of the URL. | 543 // Make sure we support the scheme of the URL. |
| 544 if (!IsSchemeSupported(url_)) { | 544 if (!IsSchemeSupported(url_)) { |
| 545 host()->Error(media::PIPELINE_ERROR_NETWORK); | 545 host()->SetError(media::PIPELINE_ERROR_NETWORK); |
| 546 initialize_callback_->Run(); | 546 initialize_callback_->Run(); |
| 547 initialize_callback_.reset(); | 547 initialize_callback_.reset(); |
| 548 return; | 548 return; |
| 549 } | 549 } |
| 550 | 550 |
| 551 media_format_.SetAsString(media::MediaFormat::kMimeType, | 551 media_format_.SetAsString(media::MediaFormat::kMimeType, |
| 552 media::mime_type::kApplicationOctetStream); | 552 media::mime_type::kApplicationOctetStream); |
| 553 media_format_.SetAsString(media::MediaFormat::kURL, url); | 553 media_format_.SetAsString(media::MediaFormat::kURL, url); |
| 554 | 554 |
| 555 // Setup the BufferedResourceLoader here. | 555 // Setup the BufferedResourceLoader here. |
| 556 scoped_refptr<BufferedResourceLoader> resource_loader = NULL; | 556 scoped_refptr<BufferedResourceLoader> resource_loader = NULL; |
| 557 { | 557 { |
| 558 AutoLock auto_lock(lock_); | 558 AutoLock auto_lock(lock_); |
| 559 if (!stopped_) { | 559 if (!stopped_) { |
| 560 buffered_resource_loader_ = new BufferedResourceLoader( | 560 buffered_resource_loader_ = new BufferedResourceLoader( |
| 561 render_loop_, | 561 render_loop_, |
| 562 bridge_factory_.get(), | 562 bridge_factory_.get(), |
| 563 url_, | 563 url_, |
| 564 kPositionNotSpecified, | 564 kPositionNotSpecified, |
| 565 kPositionNotSpecified); | 565 kPositionNotSpecified); |
| 566 resource_loader = buffered_resource_loader_; | 566 resource_loader = buffered_resource_loader_; |
| 567 } | 567 } |
| 568 } | 568 } |
| 569 | 569 |
| 570 // Use the local reference to start the request. | 570 // Use the local reference to start the request. |
| 571 if (!resource_loader) { | 571 if (!resource_loader) { |
| 572 host()->Error(media::PIPELINE_ERROR_NETWORK); | 572 host()->SetError(media::PIPELINE_ERROR_NETWORK); |
| 573 initialize_callback_->Run(); | 573 initialize_callback_->Run(); |
| 574 initialize_callback_.reset(); | 574 initialize_callback_.reset(); |
| 575 return; | 575 return; |
| 576 } | 576 } |
| 577 | 577 |
| 578 if (net::ERR_IO_PENDING != resource_loader->Start( | 578 if (net::ERR_IO_PENDING != resource_loader->Start( |
| 579 NewCallback(this, &BufferedDataSource::InitialRequestStarted))) { | 579 NewCallback(this, &BufferedDataSource::InitialRequestStarted))) { |
| 580 host()->Error(media::PIPELINE_ERROR_NETWORK); | 580 host()->SetError(media::PIPELINE_ERROR_NETWORK); |
| 581 initialize_callback_->Run(); | 581 initialize_callback_->Run(); |
| 582 initialize_callback_.reset(); | 582 initialize_callback_.reset(); |
| 583 } | 583 } |
| 584 } | 584 } |
| 585 | 585 |
| 586 size_t BufferedDataSource::Read(uint8* data, size_t size) { | 586 size_t BufferedDataSource::Read(uint8* data, size_t size) { |
| 587 // We try two times here: | 587 // We try two times here: |
| 588 // 1. Use the existing resource loader to seek and read from it. | 588 // 1. Use the existing resource loader to seek and read from it. |
| 589 // 2. If any of the above operations failed, we create a new resource loader | 589 // 2. If any of the above operations failed, we create a new resource loader |
| 590 // starting with a new range. Goto 1. | 590 // starting with a new range. Goto 1. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 return false; | 673 return false; |
| 674 } | 674 } |
| 675 | 675 |
| 676 bool BufferedDataSource::IsSeekable() { | 676 bool BufferedDataSource::IsSeekable() { |
| 677 return total_bytes_ != kPositionNotSpecified; | 677 return total_bytes_ != kPositionNotSpecified; |
| 678 } | 678 } |
| 679 | 679 |
| 680 void BufferedDataSource::HandleError(media::PipelineError error) { | 680 void BufferedDataSource::HandleError(media::PipelineError error) { |
| 681 AutoLock auto_lock(lock_); | 681 AutoLock auto_lock(lock_); |
| 682 if (!stopped_) { | 682 if (!stopped_) { |
| 683 host()->Error(error); | 683 host()->SetError(error); |
| 684 } | 684 } |
| 685 } | 685 } |
| 686 | 686 |
| 687 void BufferedDataSource::InitialRequestStarted(int error) { | 687 void BufferedDataSource::InitialRequestStarted(int error) { |
| 688 // Don't take any lock and call to |host_| here, this method is called from | 688 // Don't take any lock and call to |host_| here, this method is called from |
| 689 // BufferedResourceLoader after the response has started or failed, it is | 689 // BufferedResourceLoader after the response has started or failed, it is |
| 690 // very likely we are called within a lock in BufferedResourceLoader. | 690 // very likely we are called within a lock in BufferedResourceLoader. |
| 691 // Acquiring an additional lock here we might have a deadlock situation, | 691 // Acquiring an additional lock here we might have a deadlock situation, |
| 692 // but one thing very sure is that pipeline thread is still alive, so we | 692 // but one thing very sure is that pipeline thread is still alive, so we |
| 693 // just need to post a task on that thread. | 693 // just need to post a task on that thread. |
| 694 pipeline_loop_->PostTask(FROM_HERE, | 694 pipeline_loop_->PostTask(FROM_HERE, |
| 695 NewRunnableMethod(this, | 695 NewRunnableMethod(this, |
| 696 &BufferedDataSource::OnInitialRequestStarted, error)); | 696 &BufferedDataSource::OnInitialRequestStarted, error)); |
| 697 } | 697 } |
| 698 | 698 |
| 699 void BufferedDataSource::OnInitialRequestStarted(int error) { | 699 void BufferedDataSource::OnInitialRequestStarted(int error) { |
| 700 // Acquiring a lock should not be needed because |stopped_| is only written | 700 // Acquiring a lock should not be needed because |stopped_| is only written |
| 701 // on pipeline thread and we are on pipeline thread but just to be safe. | 701 // on pipeline thread and we are on pipeline thread but just to be safe. |
| 702 AutoLock auto_lock(lock_); | 702 AutoLock auto_lock(lock_); |
| 703 if (!stopped_) { | 703 if (!stopped_) { |
| 704 if (error == net::OK) { | 704 if (error == net::OK) { |
| 705 total_bytes_ = buffered_resource_loader_->content_length(); | 705 total_bytes_ = buffered_resource_loader_->content_length(); |
| 706 if (IsSeekable()) { | 706 if (IsSeekable()) { |
| 707 host()->SetTotalBytes(total_bytes_); | 707 host()->SetTotalBytes(total_bytes_); |
| 708 // TODO(hclam): report the amount of bytes buffered accurately. | 708 // TODO(hclam): report the amount of bytes buffered accurately. |
| 709 host()->SetBufferedBytes(total_bytes_); | 709 host()->SetBufferedBytes(total_bytes_); |
| 710 } | 710 } |
| 711 } else { | 711 } else { |
| 712 host()->Error(media::PIPELINE_ERROR_NETWORK); | 712 host()->SetError(media::PIPELINE_ERROR_NETWORK); |
| 713 } | 713 } |
| 714 } | 714 } |
| 715 initialize_callback_->Run(); | 715 initialize_callback_->Run(); |
| 716 initialize_callback_.reset(); | 716 initialize_callback_.reset(); |
| 717 } | 717 } |
| 718 | 718 |
| 719 const media::MediaFormat& BufferedDataSource::media_format() { | 719 const media::MediaFormat& BufferedDataSource::media_format() { |
| 720 return media_format_; | 720 return media_format_; |
| 721 } | 721 } |
| OLD | NEW |