| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "media/base/composite_data_source_factory.h" | 5 #include "media/base/composite_data_source_factory.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 FactoryList factories_; | 29 FactoryList factories_; |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 CompositeDataSourceFactory::CompositeDataSourceFactory() {} | 32 CompositeDataSourceFactory::CompositeDataSourceFactory() {} |
| 33 | 33 |
| 34 CompositeDataSourceFactory::~CompositeDataSourceFactory() { | 34 CompositeDataSourceFactory::~CompositeDataSourceFactory() { |
| 35 STLDeleteElements(&factories_); | 35 STLDeleteElements(&factories_); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void CompositeDataSourceFactory::AddFactory(DataSourceFactory* factory) { | 38 void CompositeDataSourceFactory::AddFactory( |
| 39 DCHECK(factory); | 39 scoped_ptr<DataSourceFactory> factory) { |
| 40 factories_.push_back(factory); | 40 DCHECK(factory.get()); |
| 41 factories_.push_back(factory.release()); |
| 41 } | 42 } |
| 42 | 43 |
| 43 DataSourceFactory* CompositeDataSourceFactory::Clone() const { | 44 scoped_ptr<DataSourceFactory> CompositeDataSourceFactory::Clone() const { |
| 44 CompositeDataSourceFactory* new_factory = new CompositeDataSourceFactory(); | 45 scoped_ptr<CompositeDataSourceFactory> new_factory( |
| 46 new CompositeDataSourceFactory()); |
| 45 | 47 |
| 46 for (FactoryList::const_iterator itr = factories_.begin(); | 48 for (FactoryList::const_iterator itr = factories_.begin(); |
| 47 itr != factories_.end(); | 49 itr != factories_.end(); |
| 48 ++itr) { | 50 ++itr) { |
| 49 new_factory->AddFactory((*itr)->Clone()); | 51 new_factory->AddFactory((*itr)->Clone()); |
| 50 } | 52 } |
| 51 | 53 |
| 52 return new_factory; | 54 // TODO(fischman): hopefully the extra scoped_ptr<m::DSF>() will be |
| 55 // unnecessary once http://codereview.chromium.org/8968032/ lands |
| 56 // properly. |
| 57 return scoped_ptr<DataSourceFactory>(new_factory.Pass()); |
| 53 } | 58 } |
| 54 | 59 |
| 55 bool CompositeDataSourceFactory::AllowRequests() const { | 60 bool CompositeDataSourceFactory::AllowRequests() const { |
| 56 return !factories_.empty(); | 61 return !factories_.empty(); |
| 57 } | 62 } |
| 58 | 63 |
| 59 AsyncDataSourceFactoryBase::BuildRequest* | 64 AsyncDataSourceFactoryBase::BuildRequest* |
| 60 CompositeDataSourceFactory::CreateRequest(const std::string& url, | 65 CompositeDataSourceFactory::CreateRequest(const std::string& url, |
| 61 const BuildCallback& callback) { | 66 const BuildCallback& callback) { |
| 62 return new BuildRequest(url, callback, factories_); | 67 return new BuildRequest(url, callback, factories_); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 73 | 78 |
| 74 CompositeDataSourceFactory::BuildRequest::~BuildRequest() {} | 79 CompositeDataSourceFactory::BuildRequest::~BuildRequest() {} |
| 75 | 80 |
| 76 void CompositeDataSourceFactory::BuildRequest::DoStart() { | 81 void CompositeDataSourceFactory::BuildRequest::DoStart() { |
| 77 CallNextFactory(); | 82 CallNextFactory(); |
| 78 } | 83 } |
| 79 | 84 |
| 80 void CompositeDataSourceFactory::BuildRequest::CallNextFactory() { | 85 void CompositeDataSourceFactory::BuildRequest::CallNextFactory() { |
| 81 DCHECK(!factories_.empty()); | 86 DCHECK(!factories_.empty()); |
| 82 | 87 |
| 83 DataSourceFactory* factory = factories_.front(); | 88 scoped_ptr<DataSourceFactory> factory(factories_.front()); |
| 84 factories_.pop_front(); | 89 factories_.pop_front(); |
| 85 | 90 |
| 86 factory->Build(url(), base::Bind(&BuildRequest::OnBuildDone, | 91 factory->Build(url(), base::Bind(&BuildRequest::OnBuildDone, |
| 87 base::Unretained(this))); | 92 base::Unretained(this))); |
| 88 } | 93 } |
| 89 | 94 |
| 90 void CompositeDataSourceFactory::BuildRequest::OnBuildDone( | 95 void CompositeDataSourceFactory::BuildRequest::OnBuildDone( |
| 91 PipelineStatus status, | 96 PipelineStatus status, |
| 92 DataSource* data_source) { | 97 DataSource* data_source) { |
| 93 | 98 |
| 94 if (status == PIPELINE_OK) { | 99 if (status == PIPELINE_OK) { |
| 95 DCHECK(data_source); | 100 DCHECK(data_source); |
| 96 RequestComplete(status, data_source); | 101 RequestComplete(status, data_source); |
| 97 return; | 102 return; |
| 98 } | 103 } |
| 99 | 104 |
| 100 DCHECK(!data_source); | 105 DCHECK(!data_source); |
| 101 if ((status == DATASOURCE_ERROR_URL_NOT_SUPPORTED) && !factories_.empty()) { | 106 if ((status == DATASOURCE_ERROR_URL_NOT_SUPPORTED) && !factories_.empty()) { |
| 102 CallNextFactory(); | 107 CallNextFactory(); |
| 103 return; | 108 return; |
| 104 } | 109 } |
| 105 | 110 |
| 106 RequestComplete(status, data_source); | 111 RequestComplete(status, data_source); |
| 107 } | 112 } |
| 108 | 113 |
| 109 } // namespace media | 114 } // namespace media |
| OLD | NEW |