| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CHROME_UTILITY_MEDIA_GALLERIES_MEDIA_METADATA_PARSER_H_ | 5 #ifndef CHROME_UTILITY_MEDIA_GALLERIES_MEDIA_METADATA_PARSER_H_ |
| 6 #define CHROME_UTILITY_MEDIA_GALLERIES_MEDIA_METADATA_PARSER_H_ | 6 #define CHROME_UTILITY_MEDIA_GALLERIES_MEDIA_METADATA_PARSER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/common/extensions/api/media_galleries.h" | 10 #include "chrome/common/extensions/api/media_galleries.h" |
| 11 | 11 |
| 12 namespace media { |
| 13 class DataSource; |
| 14 } |
| 15 |
| 12 namespace metadata { | 16 namespace metadata { |
| 13 | 17 |
| 14 // This interface provides bytes needed by MediaMetadataParser. | |
| 15 class DataReader { | |
| 16 public: | |
| 17 typedef base::Callback<void(const std::string& bytes)> ReadBytesCallback; | |
| 18 | |
| 19 virtual ~DataReader() {} | |
| 20 | |
| 21 // Called on the utility thread. | |
| 22 virtual void ReadBytes(int64 offset, int64 length, | |
| 23 const ReadBytesCallback& callback) = 0; | |
| 24 }; | |
| 25 | |
| 26 // This class takes a MIME type and data source and parses its metadata. It | 18 // This class takes a MIME type and data source and parses its metadata. It |
| 27 // handles audio, video, and images. It delegates its operations to FFMPEG, | 19 // handles audio, video, and images. It delegates its operations to FFMPEG, |
| 28 // libexif, etc. This class lives and operates on the utility thread of the | 20 // libexif, etc. This class lives and operates on the utility thread of the |
| 29 // utility process, as we wish to sandbox potentially dangerous operations | 21 // utility process, as we wish to sandbox potentially dangerous operations |
| 30 // on user-provided data. | 22 // on user-provided data. |
| 31 class MediaMetadataParser { | 23 class MediaMetadataParser { |
| 32 public: | 24 public: |
| 33 typedef extensions::api::media_galleries::MediaMetadata MediaMetadata; | 25 typedef extensions::api::media_galleries::MediaMetadata MediaMetadata; |
| 34 typedef base::Callback<void(scoped_ptr<MediaMetadata>)> MetadataCallback; | 26 typedef base::Callback<void(scoped_ptr<MediaMetadata>)> MetadataCallback; |
| 35 | 27 |
| 36 // Takes ownership of |reader|. The MIME type is always sniffed in the browser | 28 // Does not take ownership of |source|. Caller is responsible for ensuring |
| 37 // process, as it's faster (and safe enough) to sniff it there. When the user | 29 // that |source| outlives this object. |
| 38 // wants more metadata than just the MIME type, this class provides it. | 30 MediaMetadataParser(media::DataSource* source, const std::string& mime_type); |
| 39 MediaMetadataParser(DataReader* reader, const std::string& mime_type); | |
| 40 | 31 |
| 41 ~MediaMetadataParser(); | 32 ~MediaMetadataParser(); |
| 42 | 33 |
| 43 // |callback| is called on same message loop. | 34 // |callback| is called on same message loop. |
| 44 void Start(const MetadataCallback& callback); | 35 void Start(const MetadataCallback& callback); |
| 45 | 36 |
| 46 private: | 37 private: |
| 47 scoped_ptr<DataReader> reader_; | 38 media::DataSource* source_; |
| 48 | 39 |
| 49 MetadataCallback callback_; | 40 MetadataCallback callback_; |
| 50 | 41 |
| 51 scoped_ptr<MediaMetadata> metadata_; | 42 scoped_ptr<MediaMetadata> metadata_; |
| 52 | 43 |
| 53 DISALLOW_COPY_AND_ASSIGN(MediaMetadataParser); | 44 DISALLOW_COPY_AND_ASSIGN(MediaMetadataParser); |
| 54 }; | 45 }; |
| 55 | 46 |
| 56 } // namespace metadata | 47 } // namespace metadata |
| 57 | 48 |
| 58 #endif // CHROME_UTILITY_MEDIA_GALLERIES_MEDIA_METADATA_PARSER_H_ | 49 #endif // CHROME_UTILITY_MEDIA_GALLERIES_MEDIA_METADATA_PARSER_H_ |
| OLD | NEW |