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

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

Issue 250143002: Media Galleries API: Audio/Video attached pictures support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_ 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_ 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_
7 7
8 #include <string>
9 #include <vector>
10
8 #include "base/callback.h" 11 #include "base/callback.h"
9 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
12 #include "chrome/common/extensions/api/media_galleries.h" 15 #include "chrome/common/extensions/api/media_galleries.h"
13 #include "content/public/browser/utility_process_host.h" 16 #include "content/public/browser/utility_process_host.h"
14 #include "content/public/browser/utility_process_host_client.h" 17 #include "content/public/browser/utility_process_host_client.h"
15 18
16 namespace IPC { 19 namespace IPC {
17 class Message; 20 class Message;
18 } 21 }
19 22
20 class Profile; 23 class Profile;
21 24
22 namespace metadata { 25 namespace metadata {
23 26
24 // Parses the media metadata of a Blob safely in a utility process. This class 27 // 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 28 // 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. 29 // utility process to do further MIME-type specific metadata extraction.
27 // All public methods and callbacks of this class run on the UI thread. 30 // All public methods and callbacks of this class run on the UI thread.
28 class SafeMediaMetadataParser : public content::UtilityProcessHostClient { 31 class SafeMediaMetadataParser : public content::UtilityProcessHostClient {
29 public: 32 public:
30 // |metadata_dictionary| is owned by the callback. 33 // |metadata_dictionary| is owned by the callback.
31 typedef base::Callback< 34 typedef base::Callback<
32 void(bool parse_success, base::DictionaryValue* metadata_dictionary)> 35 void(bool parse_success, base::DictionaryValue* metadata_dictionary,
36 const std::vector<std::string>& attached_pictures_bytes,
37 const std::vector<std::string>& attached_pictures_types)>
33 DoneCallback; 38 DoneCallback;
34 39
35 SafeMediaMetadataParser(Profile* profile, const std::string& blob_uuid, 40 SafeMediaMetadataParser(Profile* profile, const std::string& blob_uuid,
36 int64 blob_size, const std::string& mime_type); 41 int64 blob_size, const std::string& mime_type,
42 bool get_attached_pictures);
37 43
38 // Should be called on the UI thread. |callback| also runs on the UI thread. 44 // Should be called on the UI thread. |callback| also runs on the UI thread.
39 void Start(const DoneCallback& callback); 45 void Start(const DoneCallback& callback);
40 46
41 private: 47 private:
42 enum ParserState { 48 enum ParserState {
43 INITIAL_STATE, 49 INITIAL_STATE,
44 STARTED_PARSING_STATE, 50 STARTED_PARSING_STATE,
45 FINISHED_PARSING_STATE, 51 FINISHED_PARSING_STATE,
46 }; 52 };
47 53
48 // Private because content::UtilityProcessHostClient is ref-counted. 54 // Private because content::UtilityProcessHostClient is ref-counted.
49 virtual ~SafeMediaMetadataParser(); 55 virtual ~SafeMediaMetadataParser();
50 56
51 // Launches the utility process. Must run on the IO thread. 57 // Launches the utility process. Must run on the IO thread.
52 void StartWorkOnIOThread(const DoneCallback& callback); 58 void StartWorkOnIOThread(const DoneCallback& callback);
53 59
54 // Notification from the utility process when it finishes parsing metadata. 60 // Notification from the utility process when it finishes parsing metadata.
55 // Runs on the IO thread. 61 // Runs on the IO thread.
56 void OnParseMediaMetadataFinished( 62 void OnParseMediaMetadataFinished(
57 bool parse_success, 63 bool parse_success, const base::DictionaryValue& metadata_dictionary,
58 const base::DictionaryValue& metadata_dictionary); 64 const std::vector<std::string>& attached_pictures_bytes,
65 const std::vector<std::string>& attached_pictures_types);
59 66
60 // Sequence of functions that bounces from the IO thread to the UI thread to 67 // Sequence of functions that bounces from the IO thread to the UI thread to
61 // read the blob data, then sends the data back to the utility process. 68 // read the blob data, then sends the data back to the utility process.
62 void OnUtilityProcessRequestBlobBytes(int64 request_id, int64 byte_start, 69 void OnUtilityProcessRequestBlobBytes(int64 request_id, int64 byte_start,
63 int64 length); 70 int64 length);
64 void StartBlobReaderOnUIThread(int64 request_id, int64 byte_start, 71 void StartBlobReaderOnUIThread(int64 request_id, int64 byte_start,
65 int64 length); 72 int64 length);
66 void OnBlobReaderDoneOnUIThread(int64 request_id, 73 void OnBlobReaderDoneOnUIThread(int64 request_id,
67 scoped_ptr<std::string> data, 74 scoped_ptr<std::string> data,
68 int64 /* blob_total_size */); 75 int64 /* blob_total_size */);
69 void FinishRequestBlobBytes(int64 request_id, scoped_ptr<std::string> data); 76 void FinishRequestBlobBytes(int64 request_id, scoped_ptr<std::string> data);
70 77
71 // UtilityProcessHostClient implementation. 78 // UtilityProcessHostClient implementation.
72 // Runs on the IO thread. 79 // Runs on the IO thread.
73 virtual void OnProcessCrashed(int exit_code) OVERRIDE; 80 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
74 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 81 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
75 82
76 // All member variables are only accessed on the IO thread. 83 // All member variables are only accessed on the IO thread.
77 Profile* const profile_; 84 Profile* const profile_;
78 const std::string blob_uuid_; 85 const std::string blob_uuid_;
79 const int64 blob_size_; 86 const int64 blob_size_;
80 const std::string mime_type_; 87 const std::string mime_type_;
88 bool get_attached_pictures_;
81 89
82 DoneCallback callback_; 90 DoneCallback callback_;
83 91
84 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; 92 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
85 93
86 // Verifies the messages from the utility process came at the right time. 94 // Verifies the messages from the utility process came at the right time.
87 // Initialized on the UI thread, but only accessed on the IO thread. 95 // Initialized on the UI thread, but only accessed on the IO thread.
88 ParserState parser_state_; 96 ParserState parser_state_;
89 97
90 DISALLOW_COPY_AND_ASSIGN(SafeMediaMetadataParser); 98 DISALLOW_COPY_AND_ASSIGN(SafeMediaMetadataParser);
91 }; 99 };
92 100
93 } // namespace metadata 101 } // namespace metadata
94 102
95 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_ 103 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698