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.
4
5#ifndef CHROME_UTILITY_MEDIA_GALLERIES_MEDIA_METADATA_PARSER_H_
6#define CHROME_UTILITY_MEDIA_GALLERIES_MEDIA_METADATA_PARSER_H_
7
8#include <string>
9#include <vector>
10
11#include "base/callback.h"
12#include "base/memory/scoped_ptr.h"
13#include "chrome/common/extensions/api/media_galleries.h"
14#include "chrome/common/media_galleries/metadata_types.h"
15
16namespace base {
17class Thread;
18}
19
20namespace media {
21class DataSource;
22}
23
24namespace metadata {
25
26// 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,
28// libexif, etc. This class lives and operates on the utility thread of the
29// utility process, as we wish to sandbox potentially dangerous operations
30// on user-provided data.
31class MediaMetadataParser {
32 public:
33  typedef extensions::api::media_galleries::MediaMetadata MediaMetadata;
34  typedef base::Callback<
35      void(const MediaMetadata& metadata,
36           const std::vector<AttachedImage>& attached_images)>
37  MetadataCallback;
38
39  // Does not take ownership of |source|. Caller is responsible for ensuring
40  // that |source| outlives this object.
41  MediaMetadataParser(media::DataSource* source, const std::string& mime_type,
42                      bool get_attached_images);
43
44  ~MediaMetadataParser();
45
46  // |callback| is called on same message loop.
47  void Start(const MetadataCallback& callback);
48
49 private:
50  // Only accessed on |media_thread_| from this class.
51  media::DataSource* const source_;
52
53  const std::string mime_type_;
54
55  bool get_attached_images_;
56
57  // Thread that blocking media parsing operations run on while the main thread
58  // handles messages from the browser process.
59  // TODO(tommycli): Replace with a reference to a WorkerPool if we ever use
60  // this class in batch mode.
61  scoped_ptr<base::Thread> media_thread_;
62
63  DISALLOW_COPY_AND_ASSIGN(MediaMetadataParser);
64};
65
66}  // namespace metadata
67
68#endif  // CHROME_UTILITY_MEDIA_GALLERIES_MEDIA_METADATA_PARSER_H_
69