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 #include "chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.h" | 5 #include "chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
12 #include "chrome/browser/extensions/blob_reader.h" | 12 #include "chrome/browser/extensions/blob_reader.h" |
13 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" | 13 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" |
14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/child_process_data.h" | 16 #include "content/public/browser/child_process_data.h" |
17 #include "content/public/browser/utility_process_host.h" | 17 #include "content/public/browser/utility_process_host.h" |
18 #include "services/service_manager/public/cpp/interface_provider.h" | |
18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
19 | 20 |
20 using content::BrowserThread; | 21 using content::BrowserThread; |
21 | 22 |
22 namespace metadata { | 23 namespace metadata { |
23 | 24 |
24 SafeMediaMetadataParser::SafeMediaMetadataParser(Profile* profile, | 25 SafeMediaMetadataParser::SafeMediaMetadataParser(Profile* profile, |
25 const std::string& blob_uuid, | 26 const std::string& blob_uuid, |
26 int64_t blob_size, | 27 int64_t blob_size, |
27 const std::string& mime_type, | 28 const std::string& mime_type, |
(...skipping 25 matching lines...) Expand all Loading... | |
53 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 54 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
54 DCHECK_EQ(INITIAL_STATE, parser_state_); | 55 DCHECK_EQ(INITIAL_STATE, parser_state_); |
55 DCHECK(!callback.is_null()); | 56 DCHECK(!callback.is_null()); |
56 | 57 |
57 callback_ = callback; | 58 callback_ = callback; |
58 | 59 |
59 utility_process_host_ = content::UtilityProcessHost::Create( | 60 utility_process_host_ = content::UtilityProcessHost::Create( |
60 this, base::ThreadTaskRunnerHandle::Get())->AsWeakPtr(); | 61 this, base::ThreadTaskRunnerHandle::Get())->AsWeakPtr(); |
61 utility_process_host_->SetName(l10n_util::GetStringUTF16( | 62 utility_process_host_->SetName(l10n_util::GetStringUTF16( |
62 IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME)); | 63 IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME)); |
63 | 64 utility_process_host_->Start(); |
64 utility_process_host_->Send( | |
65 new ChromeUtilityMsg_ParseMediaMetadata(mime_type_, blob_size_, | |
66 get_attached_images_)); | |
67 | 65 |
68 parser_state_ = STARTED_PARSING_STATE; | 66 parser_state_ = STARTED_PARSING_STATE; |
67 | |
68 utility_process_host_->GetRemoteInterfaces()->GetInterface(&interface_); | |
69 | |
70 interface_.set_connection_error_handler( | |
71 base::Bind(&SafeMediaMetadataParser::ParseMediaMetadataFailed, this)); | |
72 | |
73 interface_->ParseMediaMetadata( | |
74 mime_type_, blob_size_, get_attached_images_, | |
75 base::Bind(&SafeMediaMetadataParser::ParseMediaMetadataDone, this)); | |
69 } | 76 } |
70 | 77 |
71 void SafeMediaMetadataParser::OnParseMediaMetadataFinished( | 78 void SafeMediaMetadataParser::ParseMediaMetadataFailed() { |
72 bool parse_success, const base::DictionaryValue& metadata_dictionary, | 79 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
80 DCHECK_EQ(parser_state_, STARTED_PARSING_STATE); | |
81 DCHECK(!callback_.is_null()); | |
82 | |
83 interface_.reset(); | |
84 | |
85 BrowserThread::PostTask( | |
86 BrowserThread::UI, FROM_HERE, | |
87 base::Bind(callback_, false, | |
88 base::Passed(std::unique_ptr<base::DictionaryValue>()), | |
89 base::Passed(std::unique_ptr<std::vector<AttachedImage>>()))); | |
90 | |
91 parser_state_ = FINISHED_PARSING_STATE; | |
92 } | |
93 | |
94 void SafeMediaMetadataParser::ParseMediaMetadataDone( | |
95 bool parse_success, | |
96 std::unique_ptr<base::DictionaryValue> metadata_dictionary, | |
73 const std::vector<AttachedImage>& attached_images) { | 97 const std::vector<AttachedImage>& attached_images) { |
74 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 98 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
99 DCHECK_EQ(parser_state_, STARTED_PARSING_STATE); | |
75 DCHECK(!callback_.is_null()); | 100 DCHECK(!callback_.is_null()); |
76 | 101 |
77 if (parser_state_ != STARTED_PARSING_STATE) | 102 interface_.reset(); |
78 return; | |
79 | 103 |
80 // We need to make a scoped copy of this vector since it will be destroyed | 104 // We need to make a scoped copy of this vector since it will be destroyed |
81 // at the end of the IPC message handler. | 105 // at the end of the handler. |
82 std::unique_ptr<std::vector<metadata::AttachedImage>> attached_images_copy = | 106 std::unique_ptr<std::vector<metadata::AttachedImage>> attached_images_copy = |
83 base::MakeUnique<std::vector<metadata::AttachedImage>>(attached_images); | 107 base::MakeUnique<std::vector<metadata::AttachedImage>>(attached_images); |
84 | 108 |
85 BrowserThread::PostTask( | 109 BrowserThread::PostTask( |
86 BrowserThread::UI, FROM_HERE, | 110 BrowserThread::UI, FROM_HERE, |
87 base::Bind(callback_, parse_success, | 111 base::Bind(callback_, parse_success, |
88 base::Passed(base::WrapUnique(metadata_dictionary.DeepCopy())), | 112 base::Passed(metadata_dictionary->CreateDeepCopy()), |
Sam McNally
2017/01/10 06:55:14
base::Passed(&metadata_dictionary)
Noel Gordon
2017/01/10 22:52:36
Done.
| |
89 base::Passed(&attached_images_copy))); | 113 base::Passed(&attached_images_copy))); |
114 | |
90 parser_state_ = FINISHED_PARSING_STATE; | 115 parser_state_ = FINISHED_PARSING_STATE; |
91 } | 116 } |
92 | 117 |
93 void SafeMediaMetadataParser::OnUtilityProcessRequestBlobBytes( | 118 void SafeMediaMetadataParser::OnUtilityProcessRequestBlobBytes( |
94 int64_t request_id, | 119 int64_t request_id, |
95 int64_t byte_start, | 120 int64_t byte_start, |
96 int64_t length) { | 121 int64_t length) { |
97 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 122 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
98 BrowserThread::PostTask( | 123 BrowserThread::PostTask( |
99 BrowserThread::UI, | 124 BrowserThread::UI, |
(...skipping 28 matching lines...) Expand all Loading... | |
128 void SafeMediaMetadataParser::FinishRequestBlobBytes( | 153 void SafeMediaMetadataParser::FinishRequestBlobBytes( |
129 int64_t request_id, | 154 int64_t request_id, |
130 std::unique_ptr<std::string> data) { | 155 std::unique_ptr<std::string> data) { |
131 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 156 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
132 if (!utility_process_host_.get()) | 157 if (!utility_process_host_.get()) |
133 return; | 158 return; |
134 utility_process_host_->Send(new ChromeUtilityMsg_RequestBlobBytes_Finished( | 159 utility_process_host_->Send(new ChromeUtilityMsg_RequestBlobBytes_Finished( |
135 request_id, *data)); | 160 request_id, *data)); |
136 } | 161 } |
137 | 162 |
138 void SafeMediaMetadataParser::OnProcessCrashed(int exit_code) { | |
139 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
140 DCHECK(!callback_.is_null()); | |
141 | |
142 BrowserThread::PostTask( | |
143 BrowserThread::UI, FROM_HERE, | |
144 base::Bind(callback_, false, | |
145 base::Passed(std::unique_ptr<base::DictionaryValue>()), | |
146 base::Passed(std::unique_ptr<std::vector<AttachedImage>>()))); | |
147 parser_state_ = FINISHED_PARSING_STATE; | |
148 } | |
149 | |
150 bool SafeMediaMetadataParser::OnMessageReceived(const IPC::Message& message) { | 163 bool SafeMediaMetadataParser::OnMessageReceived(const IPC::Message& message) { |
151 bool handled = true; | 164 bool handled = true; |
152 IPC_BEGIN_MESSAGE_MAP(SafeMediaMetadataParser, message) | 165 IPC_BEGIN_MESSAGE_MAP(SafeMediaMetadataParser, message) |
153 IPC_MESSAGE_HANDLER( | 166 IPC_MESSAGE_HANDLER( |
154 ChromeUtilityHostMsg_ParseMediaMetadata_Finished, | |
155 OnParseMediaMetadataFinished) | |
156 IPC_MESSAGE_HANDLER( | |
157 ChromeUtilityHostMsg_RequestBlobBytes, | 167 ChromeUtilityHostMsg_RequestBlobBytes, |
158 OnUtilityProcessRequestBlobBytes) | 168 OnUtilityProcessRequestBlobBytes) |
159 IPC_MESSAGE_UNHANDLED(handled = false) | 169 IPC_MESSAGE_UNHANDLED(handled = false) |
160 IPC_END_MESSAGE_MAP() | 170 IPC_END_MESSAGE_MAP() |
161 return handled; | 171 return handled; |
162 } | 172 } |
163 | 173 |
164 } // namespace metadata | 174 } // namespace metadata |
OLD | NEW |