| 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" |
| 11 | 11 |
| 12 namespace media { | 12 namespace media { |
| 13 | 13 |
| 14 class CompositeDataSourceFactory::BuildRequest | 14 class CompositeDataSourceFactory::BuildRequest |
| 15 : public AsyncDataSourceFactoryBase::BuildRequest { | 15 : public AsyncDataSourceFactoryBase::BuildRequest { |
| 16 public: | 16 public: |
| 17 BuildRequest(const std::string& url, const BuildCallback& callback, | 17 BuildRequest(const std::string& url, const BuildCallback& callback, |
| 18 const FactoryList& factories); | 18 const FactoryList& factories); |
| 19 ~BuildRequest(); | 19 ~BuildRequest(); |
| 20 | 20 |
| 21 protected: | 21 protected: |
| 22 // AsyncDataSourceFactoryBase::BuildRequest method. | 22 // AsyncDataSourceFactoryBase::BuildRequest method. |
| 23 virtual void DoStart(); | 23 virtual void DoStart(); |
| 24 | 24 |
| 25 private: | 25 private: |
| 26 void CallNextFactory(); | 26 void CallNextFactory(); |
| 27 void OnBuildDone(PipelineStatus status, DataSource* data_source); | 27 void OnBuildDone(PipelineStatus status, DataSource* data_source); |
| 28 | 28 |
| 29 FactoryList factories_; | 29 FactoryList factories_; // Not owned by this class. |
| 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().Pass()); |
| 50 } | 52 } |
| 51 | 53 |
| 52 return new_factory; | 54 // TODO(fischman): replace the extra scoped_ptr+release() with Pass() when |
| 55 // http://crbug.com/109026 is fixed. |
| 56 return scoped_ptr<DataSourceFactory>(new_factory.release()); |
| 53 } | 57 } |
| 54 | 58 |
| 55 bool CompositeDataSourceFactory::AllowRequests() const { | 59 bool CompositeDataSourceFactory::AllowRequests() const { |
| 56 return !factories_.empty(); | 60 return !factories_.empty(); |
| 57 } | 61 } |
| 58 | 62 |
| 59 AsyncDataSourceFactoryBase::BuildRequest* | 63 AsyncDataSourceFactoryBase::BuildRequest* |
| 60 CompositeDataSourceFactory::CreateRequest(const std::string& url, | 64 CompositeDataSourceFactory::CreateRequest(const std::string& url, |
| 61 const BuildCallback& callback) { | 65 const BuildCallback& callback) { |
| 62 return new BuildRequest(url, callback, factories_); | 66 return new BuildRequest(url, callback, factories_); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 DCHECK(!data_source); | 104 DCHECK(!data_source); |
| 101 if ((status == DATASOURCE_ERROR_URL_NOT_SUPPORTED) && !factories_.empty()) { | 105 if ((status == DATASOURCE_ERROR_URL_NOT_SUPPORTED) && !factories_.empty()) { |
| 102 CallNextFactory(); | 106 CallNextFactory(); |
| 103 return; | 107 return; |
| 104 } | 108 } |
| 105 | 109 |
| 106 RequestComplete(status, data_source); | 110 RequestComplete(status, data_source); |
| 107 } | 111 } |
| 108 | 112 |
| 109 } // namespace media | 113 } // namespace media |
| OLD | NEW |