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|. The MIME type is sniffed in the |
vandebo (ex-Chrome)
2014/01/07 18:34:59
You should say more explicitly that the caller is
tommycli
2014/01/07 20:23:31
Done.
| |
37 // process, as it's faster (and safe enough) to sniff it there. When the user | 29 // browser process, as it's faster (and safe enough). When the user wants |
vandebo (ex-Chrome)
2014/01/07 18:34:59
I think you can omit the stuff about mime type - t
tommycli
2014/01/07 20:23:31
Done.
| |
38 // wants more metadata than just the MIME type, this class provides it. | 30 // more metadata than just the MIME type, this class provides it. |
39 MediaMetadataParser(DataReader* reader, const std::string& mime_type); | 31 MediaMetadataParser(media::DataSource* source, const std::string& mime_type); |
40 | 32 |
41 ~MediaMetadataParser(); | 33 ~MediaMetadataParser(); |
42 | 34 |
43 // |callback| is called on same message loop. | 35 // |callback| is called on same message loop. |
44 void Start(const MetadataCallback& callback); | 36 void Start(const MetadataCallback& callback); |
45 | 37 |
46 private: | 38 private: |
47 scoped_ptr<DataReader> reader_; | 39 media::DataSource* source_; |
48 | 40 |
49 MetadataCallback callback_; | 41 MetadataCallback callback_; |
50 | 42 |
51 scoped_ptr<MediaMetadata> metadata_; | 43 scoped_ptr<MediaMetadata> metadata_; |
52 | 44 |
53 DISALLOW_COPY_AND_ASSIGN(MediaMetadataParser); | 45 DISALLOW_COPY_AND_ASSIGN(MediaMetadataParser); |
54 }; | 46 }; |
55 | 47 |
56 } // namespace metadata | 48 } // namespace metadata |
57 | 49 |
58 #endif // CHROME_UTILITY_MEDIA_GALLERIES_MEDIA_METADATA_PARSER_H_ | 50 #endif // CHROME_UTILITY_MEDIA_GALLERIES_MEDIA_METADATA_PARSER_H_ |
OLD | NEW |