OLD | NEW |
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" |
| 16 #include "chrome/common/media_galleries/metadata_types.h" |
13 #include "content/public/browser/utility_process_host.h" | 17 #include "content/public/browser/utility_process_host.h" |
14 #include "content/public/browser/utility_process_host_client.h" | 18 #include "content/public/browser/utility_process_host_client.h" |
15 | 19 |
16 namespace IPC { | 20 namespace IPC { |
17 class Message; | 21 class Message; |
18 } | 22 } |
19 | 23 |
20 class Profile; | 24 class Profile; |
21 | 25 |
22 namespace metadata { | 26 namespace metadata { |
23 | 27 |
24 // Parses the media metadata of a Blob safely in a utility process. This class | 28 // 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 | 29 // 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. | 30 // utility process to do further MIME-type specific metadata extraction. |
27 // All public methods and callbacks of this class run on the UI thread. | 31 // All public methods and callbacks of this class run on the UI thread. |
28 class SafeMediaMetadataParser : public content::UtilityProcessHostClient { | 32 class SafeMediaMetadataParser : public content::UtilityProcessHostClient { |
29 public: | 33 public: |
30 // |metadata_dictionary| is owned by the callback. | 34 // |metadata_dictionary| is owned by the callback. |
31 typedef base::Callback< | 35 typedef base::Callback< |
32 void(bool parse_success, base::DictionaryValue* metadata_dictionary)> | 36 void(bool parse_success, base::DictionaryValue* metadata_dictionary, |
| 37 const std::vector<AttachedImage>& attached_images)> |
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_images); |
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<AttachedImage>& attached_images); |
59 | 65 |
60 // Sequence of functions that bounces from the IO thread to the UI thread to | 66 // 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. | 67 // read the blob data, then sends the data back to the utility process. |
62 void OnUtilityProcessRequestBlobBytes(int64 request_id, int64 byte_start, | 68 void OnUtilityProcessRequestBlobBytes(int64 request_id, int64 byte_start, |
63 int64 length); | 69 int64 length); |
64 void StartBlobReaderOnUIThread(int64 request_id, int64 byte_start, | 70 void StartBlobReaderOnUIThread(int64 request_id, int64 byte_start, |
65 int64 length); | 71 int64 length); |
66 void OnBlobReaderDoneOnUIThread(int64 request_id, | 72 void OnBlobReaderDoneOnUIThread(int64 request_id, |
67 scoped_ptr<std::string> data, | 73 scoped_ptr<std::string> data, |
68 int64 /* blob_total_size */); | 74 int64 /* blob_total_size */); |
69 void FinishRequestBlobBytes(int64 request_id, scoped_ptr<std::string> data); | 75 void FinishRequestBlobBytes(int64 request_id, scoped_ptr<std::string> data); |
70 | 76 |
71 // UtilityProcessHostClient implementation. | 77 // UtilityProcessHostClient implementation. |
72 // Runs on the IO thread. | 78 // Runs on the IO thread. |
73 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | 79 virtual void OnProcessCrashed(int exit_code) OVERRIDE; |
74 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 80 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
75 | 81 |
76 // All member variables are only accessed on the IO thread. | 82 // All member variables are only accessed on the IO thread. |
77 Profile* const profile_; | 83 Profile* const profile_; |
78 const std::string blob_uuid_; | 84 const std::string blob_uuid_; |
79 const int64 blob_size_; | 85 const int64 blob_size_; |
80 const std::string mime_type_; | 86 const std::string mime_type_; |
| 87 bool get_attached_images_; |
81 | 88 |
82 DoneCallback callback_; | 89 DoneCallback callback_; |
83 | 90 |
84 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; | 91 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; |
85 | 92 |
86 // Verifies the messages from the utility process came at the right time. | 93 // 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. | 94 // Initialized on the UI thread, but only accessed on the IO thread. |
88 ParserState parser_state_; | 95 ParserState parser_state_; |
89 | 96 |
90 DISALLOW_COPY_AND_ASSIGN(SafeMediaMetadataParser); | 97 DISALLOW_COPY_AND_ASSIGN(SafeMediaMetadataParser); |
91 }; | 98 }; |
92 | 99 |
93 } // namespace metadata | 100 } // namespace metadata |
94 | 101 |
95 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_ | 102 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_ |
OLD | NEW |