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
3 // found in the LICENSE file.
5 #ifndef CHROME_UTILITY_MEDIA_GALLERIES_MEDIA_METADATA_PARSER_H_
6 #define CHROME_UTILITY_MEDIA_GALLERIES_MEDIA_METADATA_PARSER_H_
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/common/extensions/api/media_galleries.h"
22 // This class takes a MIME type and data source and parses its metadata. It
23 // handles audio, video, and images. It delegates its operations to FFMPEG,
24 // libexif, etc. This class lives and operates on the utility thread of the
25 // utility process, as we wish to sandbox potentially dangerous operations
26 // on user-provided data.
27 class MediaMetadataParser
{
29 typedef extensions::api::media_galleries::MediaMetadata MediaMetadata
;
30 typedef base::Callback
<void(scoped_ptr
<MediaMetadata
>)> MetadataCallback
;
32 // Does not take ownership of |source|. Caller is responsible for ensuring
33 // that |source| outlives this object.
34 MediaMetadataParser(media::DataSource
* source
, const std::string
& mime_type
);
36 ~MediaMetadataParser();
38 // |callback| is called on same message loop.
39 void Start(const MetadataCallback
& callback
);
42 // Only accessed on |media_thread_| from this class.
43 media::DataSource
* const source_
;
45 const std::string mime_type_
;
47 // Thread that blocking media parsing operations run on while the main thread
48 // handles messages from the browser process.
49 // TODO(tommycli): Replace with a reference to a WorkerPool if we ever use
50 // this class in batch mode.
51 scoped_ptr
<base::Thread
> media_thread_
;
53 DISALLOW_COPY_AND_ASSIGN(MediaMetadataParser
);
56 } // namespace metadata
58 #endif // CHROME_UTILITY_MEDIA_GALLERIES_MEDIA_METADATA_PARSER_H_