Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.h

Issue 103283003: Media Galleries API Metadata: SafeMediaMetadataParser and IPCTunnelDataReader. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_
7
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"
15
16 namespace IPC {
17 class Message;
18 }
19
20 class Profile;
21
22 namespace metadata {
23
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 typedef extensions::api::media_galleries::MediaMetadata MediaMetadata;
31
32 // Callback function should take ownership of |metadata|.
33 typedef base::Callback<
34 void(bool parse_success,
35 scoped_ptr<base::DictionaryValue> metadata_dictionary)>
36 DoneCallback;
37
38 SafeMediaMetadataParser(Profile* profile, const std::string& blob_uuid,
39 int64 blob_size, const std::string& mime_type);
40
41 // Should be called on the UI thread. |callback| also runs on the UI thread.
42 void Start(const DoneCallback& callback);
43
44 private:
45 enum ParserState {
46 INITIAL_STATE,
47 STARTED_PARSING_STATE,
48 FINISHED_PARSING_STATE,
49 };
50
51 // Private because content::UtilityProcessHostClient is ref-counted.
52 virtual ~SafeMediaMetadataParser();
53
54 // Launches the utility process. Must run on the IO thread.
55 void StartWorkOnIOThread();
56
57 // Notification from the utility process when it finishes parsing metadata.
58 // Runs on the IO thread.
59 void OnParseMediaMetadataFinished(
60 bool parse_success,
61 const base::DictionaryValue& metadata_dictionary);
62
63 // Notification when the utility process requests a byte range from the blob.
64 // Runs on the IO thread.
65 void OnUtilityProcessRequestBlobBytes(int64 request_id, int64 byte_start,
66 int64 length);
67 // Completes the Blob byte request.
68 void OnBlobReaderDone(int64 request_id, scoped_ptr<std::string> data);
69
70 // UtilityProcessHostClient implementation.
71 // Runs on the IO thread.
72 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
73 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
74
75 // Only accessed on the IO thread.
76 Profile* const profile_;
77 const std::string blob_uuid_;
78 const int64 blob_size_;
79 const std::string mime_type_;
80
81 // Assigned on the UI thread, then accessed on the IO thread only.
vandebo (ex-Chrome) 2014/01/08 00:26:18 I think you can just assign this on the IO thread.
tommycli 2014/01/08 01:17:10 Done.
82 DoneCallback callback_;
83
84 // Only accessed on the IO thread.
85 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
86
87 // Verifies the messages from the utility process came at the right time.
88 // Initialized on the UI thread, but only accessed on the IO thread.
89 ParserState parser_state_;
90
91 base::WeakPtrFactory<SafeMediaMetadataParser> weak_factory_;
92
93 DISALLOW_COPY_AND_ASSIGN(SafeMediaMetadataParser);
94 };
95
96 } // namespace metadata
97
98 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698