NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / media_galleries / fileapi / safe_media_metadata_parser.h
blob7aac6ffef57c21e26d94b7bd893c67fab989db6b
1 // Copyright 2014 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_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/common/extensions/api/media_galleries.h"
13 #include "content/public/browser/utility_process_host.h"
14 #include "content/public/browser/utility_process_host_client.h"
16 namespace IPC {
17 class Message;
20 class Profile;
22 namespace metadata {
24 // Parses the media metadata of a Blob safely in a utility process. This class
25 // expects the MIME type of the Blob to be already determined. It spawns a
26 // utility process to do further MIME-type specific metadata extraction.
27 // All public methods and callbacks of this class run on the UI thread.
28 class SafeMediaMetadataParser : public content::UtilityProcessHostClient {
29 public:
30 // |metadata_dictionary| is owned by the callback.
31 typedef base::Callback<
32 void(bool parse_success, base::DictionaryValue* metadata_dictionary)>
33 DoneCallback;
35 SafeMediaMetadataParser(Profile* profile, const std::string& blob_uuid,
36 int64 blob_size, const std::string& mime_type);
38 // Should be called on the UI thread. |callback| also runs on the UI thread.
39 void Start(const DoneCallback& callback);
41 private:
42 enum ParserState {
43 INITIAL_STATE,
44 STARTED_PARSING_STATE,
45 FINISHED_PARSING_STATE,
48 // Private because content::UtilityProcessHostClient is ref-counted.
49 virtual ~SafeMediaMetadataParser();
51 // Launches the utility process. Must run on the IO thread.
52 void StartWorkOnIOThread(const DoneCallback& callback);
54 // Notification from the utility process when it finishes parsing metadata.
55 // Runs on the IO thread.
56 void OnParseMediaMetadataFinished(
57 bool parse_success,
58 const base::DictionaryValue& metadata_dictionary);
60 // Notification when the utility process requests a byte range from the blob.
61 // Runs on the IO thread.
62 void OnUtilityProcessRequestBlobBytes(int64 request_id, int64 byte_start,
63 int64 length);
65 // UtilityProcessHostClient implementation.
66 // Runs on the IO thread.
67 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
68 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
70 // All member variables are only accessed on the IO thread.
71 Profile* const profile_;
72 const std::string blob_uuid_;
73 const int64 blob_size_;
74 const std::string mime_type_;
76 DoneCallback callback_;
78 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
80 // Verifies the messages from the utility process came at the right time.
81 // Initialized on the UI thread, but only accessed on the IO thread.
82 ParserState parser_state_;
84 DISALLOW_COPY_AND_ASSIGN(SafeMediaMetadataParser);
87 } // namespace metadata
89 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_