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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "chrome/common/extensions/api/media_galleries.h" | 18 #include "chrome/common/extensions/api/media_galleries.h" |
| 19 #include "chrome/common/extensions/media_parser.mojom.h" |
19 #include "chrome/common/media_galleries/metadata_types.h" | 20 #include "chrome/common/media_galleries/metadata_types.h" |
20 #include "content/public/browser/utility_process_host.h" | 21 #include "content/public/browser/utility_process_host.h" |
21 #include "content/public/browser/utility_process_host_client.h" | 22 #include "content/public/browser/utility_process_host_client.h" |
22 | 23 |
23 namespace IPC { | 24 namespace IPC { |
24 class Message; | 25 class Message; |
25 } | 26 } |
26 | 27 |
27 class Profile; | 28 class Profile; |
28 | 29 |
(...skipping 27 matching lines...) Expand all Loading... |
56 STARTED_PARSING_STATE, | 57 STARTED_PARSING_STATE, |
57 FINISHED_PARSING_STATE, | 58 FINISHED_PARSING_STATE, |
58 }; | 59 }; |
59 | 60 |
60 // Private because content::UtilityProcessHostClient is ref-counted. | 61 // Private because content::UtilityProcessHostClient is ref-counted. |
61 ~SafeMediaMetadataParser() override; | 62 ~SafeMediaMetadataParser() override; |
62 | 63 |
63 // Launches the utility process. Must run on the IO thread. | 64 // Launches the utility process. Must run on the IO thread. |
64 void StartWorkOnIOThread(const DoneCallback& callback); | 65 void StartWorkOnIOThread(const DoneCallback& callback); |
65 | 66 |
66 // Notification from the utility process when it finishes parsing metadata. | 67 // Mojo callback if the utility process or metadata parse requests fail. |
67 // Runs on the IO thread. | 68 // Runs on the IO thread. |
68 void OnParseMediaMetadataFinished( | 69 void ParseMediaMetadataFailed(); |
69 bool parse_success, const base::DictionaryValue& metadata_dictionary, | 70 |
| 71 // Mojo callback from utility process when it finishes parsing metadata. |
| 72 // Runs on the IO thread. |
| 73 void ParseMediaMetadataDone( |
| 74 bool parse_success, |
| 75 std::unique_ptr<base::DictionaryValue> metadata_dictionary, |
70 const std::vector<AttachedImage>& attached_images); | 76 const std::vector<AttachedImage>& attached_images); |
71 | 77 |
72 // Sequence of functions that bounces from the IO thread to the UI thread to | 78 // Sequence of functions that bounces from the IO thread to the UI thread to |
73 // read the blob data, then sends the data back to the utility process. | 79 // read the blob data, then sends the data back to the utility process. |
74 void OnUtilityProcessRequestBlobBytes(int64_t request_id, | 80 void OnUtilityProcessRequestBlobBytes(int64_t request_id, |
75 int64_t byte_start, | 81 int64_t byte_start, |
76 int64_t length); | 82 int64_t length); |
77 void StartBlobReaderOnUIThread(int64_t request_id, | 83 void StartBlobReaderOnUIThread(int64_t request_id, |
78 int64_t byte_start, | 84 int64_t byte_start, |
79 int64_t length); | 85 int64_t length); |
80 void OnBlobReaderDoneOnUIThread(int64_t request_id, | 86 void OnBlobReaderDoneOnUIThread(int64_t request_id, |
81 std::unique_ptr<std::string> data, | 87 std::unique_ptr<std::string> data, |
82 int64_t /* blob_total_size */); | 88 int64_t /* blob_total_size */); |
83 void FinishRequestBlobBytes(int64_t request_id, | 89 void FinishRequestBlobBytes(int64_t request_id, |
84 std::unique_ptr<std::string> data); | 90 std::unique_ptr<std::string> data); |
85 | 91 |
86 // UtilityProcessHostClient implementation. | 92 // UtilityProcessHostClient implementation. |
87 // Runs on the IO thread. | 93 // Runs on the IO thread. |
88 void OnProcessCrashed(int exit_code) override; | |
89 bool OnMessageReceived(const IPC::Message& message) override; | 94 bool OnMessageReceived(const IPC::Message& message) override; |
90 | 95 |
91 // All member variables are only accessed on the IO thread. | 96 // All member variables are only accessed on the IO thread. |
92 Profile* const profile_; | 97 Profile* const profile_; |
93 const std::string blob_uuid_; | 98 const std::string blob_uuid_; |
94 const int64_t blob_size_; | 99 const int64_t blob_size_; |
95 const std::string mime_type_; | 100 const std::string mime_type_; |
96 bool get_attached_images_; | 101 bool get_attached_images_; |
97 | 102 |
98 DoneCallback callback_; | 103 DoneCallback callback_; |
99 | 104 |
100 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; | 105 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; |
101 | 106 |
| 107 extensions::mojom::MediaParserPtr interface_; |
| 108 |
102 // Verifies the messages from the utility process came at the right time. | 109 // Verifies the messages from the utility process came at the right time. |
103 // Initialized on the UI thread, but only accessed on the IO thread. | 110 // Initialized on the UI thread, but only accessed on the IO thread. |
104 ParserState parser_state_; | 111 ParserState parser_state_; |
105 | 112 |
106 DISALLOW_COPY_AND_ASSIGN(SafeMediaMetadataParser); | 113 DISALLOW_COPY_AND_ASSIGN(SafeMediaMetadataParser); |
107 }; | 114 }; |
108 | 115 |
109 } // namespace metadata | 116 } // namespace metadata |
110 | 117 |
111 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_ | 118 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_ |
OLD | NEW |