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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 stopped_ = true; | 525 stopped_ = true; |
526 resource_loader = buffered_resource_loader_; | 526 resource_loader = buffered_resource_loader_; |
527 // Release the reference to the resource loader. | 527 // Release the reference to the resource loader. |
528 buffered_resource_loader_ = NULL; | 528 buffered_resource_loader_ = NULL; |
529 } | 529 } |
530 // Tell the loader to stop. | 530 // Tell the loader to stop. |
531 if (resource_loader) | 531 if (resource_loader) |
532 resource_loader->Stop(); | 532 resource_loader->Stop(); |
533 } | 533 } |
534 | 534 |
535 bool BufferedDataSource::Initialize(const std::string& url) { | 535 void BufferedDataSource::Initialize(const std::string& url, |
| 536 media::FilterCallback* callback) { |
| 537 DCHECK(callback); |
| 538 initialize_callback_.reset(callback); |
| 539 |
536 // Save the url. | 540 // Save the url. |
537 url_ = GURL(url); | 541 url_ = GURL(url); |
538 | 542 |
539 // Make sure we support the scheme of the URL. | 543 // Make sure we support the scheme of the URL. |
540 if (!IsSchemeSupported(url_)) { | 544 if (!IsSchemeSupported(url_)) { |
541 host()->Error(media::PIPELINE_ERROR_NETWORK); | 545 host()->Error(media::PIPELINE_ERROR_NETWORK); |
542 return false; | 546 initialize_callback_->Run(); |
| 547 initialize_callback_.reset(); |
| 548 return; |
543 } | 549 } |
544 | 550 |
545 media_format_.SetAsString(media::MediaFormat::kMimeType, | 551 media_format_.SetAsString(media::MediaFormat::kMimeType, |
546 media::mime_type::kApplicationOctetStream); | 552 media::mime_type::kApplicationOctetStream); |
547 media_format_.SetAsString(media::MediaFormat::kURL, url); | 553 media_format_.SetAsString(media::MediaFormat::kURL, url); |
548 | 554 |
549 // Setup the BufferedResourceLoader here. | 555 // Setup the BufferedResourceLoader here. |
550 scoped_refptr<BufferedResourceLoader> resource_loader = NULL; | 556 scoped_refptr<BufferedResourceLoader> resource_loader = NULL; |
551 { | 557 { |
552 AutoLock auto_lock(lock_); | 558 AutoLock auto_lock(lock_); |
553 if (!stopped_) { | 559 if (!stopped_) { |
554 buffered_resource_loader_ = new BufferedResourceLoader( | 560 buffered_resource_loader_ = new BufferedResourceLoader( |
555 render_loop_, | 561 render_loop_, |
556 bridge_factory_.get(), | 562 bridge_factory_.get(), |
557 url_, | 563 url_, |
558 kPositionNotSpecified, | 564 kPositionNotSpecified, |
559 kPositionNotSpecified); | 565 kPositionNotSpecified); |
560 resource_loader = buffered_resource_loader_; | 566 resource_loader = buffered_resource_loader_; |
561 } | 567 } |
562 } | 568 } |
563 | 569 |
564 // Use the local reference to start the request. | 570 // Use the local reference to start the request. |
565 if (resource_loader) { | 571 if (!resource_loader) { |
566 if (net::ERR_IO_PENDING != resource_loader->Start( | 572 host()->Error(media::PIPELINE_ERROR_NETWORK); |
567 NewCallback(this, &BufferedDataSource::InitialRequestStarted))) { | 573 initialize_callback_->Run(); |
568 host()->Error(media::PIPELINE_ERROR_NETWORK); | 574 initialize_callback_.reset(); |
569 return false; | 575 return; |
570 } | |
571 return true; | |
572 } | 576 } |
573 host()->Error(media::PIPELINE_ERROR_NETWORK); | 577 |
574 return false; | 578 if (net::ERR_IO_PENDING != resource_loader->Start( |
| 579 NewCallback(this, &BufferedDataSource::InitialRequestStarted))) { |
| 580 host()->Error(media::PIPELINE_ERROR_NETWORK); |
| 581 initialize_callback_->Run(); |
| 582 initialize_callback_.reset(); |
| 583 } |
575 } | 584 } |
576 | 585 |
577 size_t BufferedDataSource::Read(uint8* data, size_t size) { | 586 size_t BufferedDataSource::Read(uint8* data, size_t size) { |
578 // We try two times here: | 587 // We try two times here: |
579 // 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. |
580 // 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 |
581 // starting with a new range. Goto 1. | 590 // starting with a new range. Goto 1. |
582 for (size_t trials = kReadTrials; trials > 0; --trials) { | 591 for (size_t trials = kReadTrials; trials > 0; --trials) { |
583 scoped_refptr<BufferedResourceLoader> resource_loader = NULL; | 592 scoped_refptr<BufferedResourceLoader> resource_loader = NULL; |
584 { | 593 { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 // very likely we are called within a lock in BufferedResourceLoader. | 690 // very likely we are called within a lock in BufferedResourceLoader. |
682 // Acquiring an additional lock here we might have a deadlock situation, | 691 // Acquiring an additional lock here we might have a deadlock situation, |
683 // 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 |
684 // just need to post a task on that thread. | 693 // just need to post a task on that thread. |
685 pipeline_loop_->PostTask(FROM_HERE, | 694 pipeline_loop_->PostTask(FROM_HERE, |
686 NewRunnableMethod(this, | 695 NewRunnableMethod(this, |
687 &BufferedDataSource::OnInitialRequestStarted, error)); | 696 &BufferedDataSource::OnInitialRequestStarted, error)); |
688 } | 697 } |
689 | 698 |
690 void BufferedDataSource::OnInitialRequestStarted(int error) { | 699 void BufferedDataSource::OnInitialRequestStarted(int error) { |
691 // 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 |
692 // 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. |
693 AutoLock auto_lock(lock_); | 702 AutoLock auto_lock(lock_); |
694 if (!stopped_) { | 703 if (!stopped_) { |
695 if (error == net::OK) { | 704 if (error == net::OK) { |
696 total_bytes_ = buffered_resource_loader_->content_length(); | 705 total_bytes_ = buffered_resource_loader_->content_length(); |
697 if (IsSeekable()) { | 706 if (IsSeekable()) { |
698 host()->SetTotalBytes(total_bytes_); | 707 host()->SetTotalBytes(total_bytes_); |
699 // TODO(hclam): report the amount of bytes buffered accurately. | 708 // TODO(hclam): report the amount of bytes buffered accurately. |
700 host()->SetBufferedBytes(total_bytes_); | 709 host()->SetBufferedBytes(total_bytes_); |
701 } | 710 } |
702 host()->InitializationComplete(); | |
703 } else { | 711 } else { |
704 host()->Error(media::PIPELINE_ERROR_NETWORK); | 712 host()->Error(media::PIPELINE_ERROR_NETWORK); |
705 } | 713 } |
706 } | 714 } |
| 715 initialize_callback_->Run(); |
| 716 initialize_callback_.reset(); |
707 } | 717 } |
708 | 718 |
709 const media::MediaFormat& BufferedDataSource::media_format() { | 719 const media::MediaFormat& BufferedDataSource::media_format() { |
710 return media_format_; | 720 return media_format_; |
711 } | 721 } |
OLD | NEW |