Chromium Code Reviews| 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 "chrome/browser/extensions/blob_reader.h" | 7 #include "chrome/browser/extensions/blob_reader.h" |
| 8 #include "chrome/common/chrome_utility_messages.h" | 8 #include "chrome/common/chrome_utility_messages.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/child_process_data.h" | 10 #include "content/public/browser/child_process_data.h" |
| 11 #include "content/public/browser/utility_process_host.h" | 11 #include "content/public/browser/utility_process_host.h" |
| 12 | 12 |
| 13 using content::BrowserThread; | 13 using content::BrowserThread; |
| 14 | 14 |
| 15 namespace metadata { | 15 namespace metadata { |
| 16 | 16 |
| 17 SafeMediaMetadataParser::SafeMediaMetadataParser(Profile* profile, | 17 SafeMediaMetadataParser::SafeMediaMetadataParser( |
| 18 const std::string& blob_uuid, | 18 Profile* profile, const std::string& blob_uuid, int64 blob_size, |
| 19 int64 blob_size, | 19 const std::string& mime_type, bool get_attached_pictures) |
| 20 const std::string& mime_type) | |
| 21 : profile_(profile), | 20 : profile_(profile), |
| 22 blob_uuid_(blob_uuid), | 21 blob_uuid_(blob_uuid), |
| 23 blob_size_(blob_size), | 22 blob_size_(blob_size), |
| 24 mime_type_(mime_type), | 23 mime_type_(mime_type), |
| 24 get_attached_pictures_(get_attached_pictures), | |
| 25 parser_state_(INITIAL_STATE) { | 25 parser_state_(INITIAL_STATE) { |
| 26 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 26 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void SafeMediaMetadataParser::Start(const DoneCallback& callback) { | 29 void SafeMediaMetadataParser::Start(const DoneCallback& callback) { |
| 30 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 30 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 31 | 31 |
| 32 BrowserThread::PostTask( | 32 BrowserThread::PostTask( |
| 33 BrowserThread::IO, | 33 BrowserThread::IO, |
| 34 FROM_HERE, | 34 FROM_HERE, |
| 35 base::Bind(&SafeMediaMetadataParser::StartWorkOnIOThread, this, | 35 base::Bind(&SafeMediaMetadataParser::StartWorkOnIOThread, this, |
| 36 callback)); | 36 callback)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 SafeMediaMetadataParser::~SafeMediaMetadataParser() { | 39 SafeMediaMetadataParser::~SafeMediaMetadataParser() { |
| 40 } | 40 } |
| 41 | 41 |
| 42 void SafeMediaMetadataParser::StartWorkOnIOThread( | 42 void SafeMediaMetadataParser::StartWorkOnIOThread( |
| 43 const DoneCallback& callback) { | 43 const DoneCallback& callback) { |
| 44 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 44 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 45 DCHECK_EQ(INITIAL_STATE, parser_state_); | 45 DCHECK_EQ(INITIAL_STATE, parser_state_); |
| 46 DCHECK(!callback.is_null()); | 46 DCHECK(!callback.is_null()); |
| 47 | 47 |
| 48 callback_ = callback; | 48 callback_ = callback; |
| 49 | 49 |
| 50 utility_process_host_ = content::UtilityProcessHost::Create( | 50 utility_process_host_ = content::UtilityProcessHost::Create( |
| 51 this, base::MessageLoopProxy::current())->AsWeakPtr(); | 51 this, base::MessageLoopProxy::current())->AsWeakPtr(); |
| 52 | 52 |
| 53 utility_process_host_->Send( | 53 utility_process_host_->Send( |
| 54 new ChromeUtilityMsg_ParseMediaMetadata(mime_type_, blob_size_)); | 54 new ChromeUtilityMsg_ParseMediaMetadata(mime_type_, blob_size_, |
| 55 get_attached_pictures_)); | |
| 55 | 56 |
| 56 parser_state_ = STARTED_PARSING_STATE; | 57 parser_state_ = STARTED_PARSING_STATE; |
| 57 } | 58 } |
| 58 | 59 |
| 59 void SafeMediaMetadataParser::OnParseMediaMetadataFinished( | 60 void SafeMediaMetadataParser::OnParseMediaMetadataFinished( |
| 60 bool parse_success, const base::DictionaryValue& metadata_dictionary) { | 61 bool parse_success, const base::DictionaryValue& metadata_dictionary, |
| 62 const std::vector<std::string>& attached_pictures_bytes, | |
| 63 const std::vector<std::string>& attached_pictures_types) { | |
| 61 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 64 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 62 DCHECK(!callback_.is_null()); | 65 DCHECK(!callback_.is_null()); |
| 63 | 66 |
| 64 if (parser_state_ != STARTED_PARSING_STATE) | 67 if (parser_state_ != STARTED_PARSING_STATE) |
| 65 return; | 68 return; |
| 66 | 69 |
| 70 if (attached_pictures_bytes.size() != attached_pictures_types.size()) { | |
|
vandebo (ex-Chrome)
2014/04/23 23:22:45
nit: no {} Should this be a DCHECK ?
tommycli
2014/04/29 00:15:51
Done. Moving to a struct eliminated the need for t
| |
| 71 DLOG(ERROR) << "Media metadata parser gave malformed attached picture data"; | |
| 72 } | |
| 73 | |
| 67 BrowserThread::PostTask( | 74 BrowserThread::PostTask( |
| 68 BrowserThread::UI, | 75 BrowserThread::UI, |
| 69 FROM_HERE, | 76 FROM_HERE, |
| 70 base::Bind(callback_, parse_success, | 77 base::Bind(callback_, parse_success, |
| 71 base::Owned(metadata_dictionary.DeepCopy()))); | 78 base::Owned(metadata_dictionary.DeepCopy()), |
| 79 attached_pictures_bytes, attached_pictures_types)); | |
| 72 parser_state_ = FINISHED_PARSING_STATE; | 80 parser_state_ = FINISHED_PARSING_STATE; |
| 73 } | 81 } |
| 74 | 82 |
| 75 void SafeMediaMetadataParser::OnUtilityProcessRequestBlobBytes( | 83 void SafeMediaMetadataParser::OnUtilityProcessRequestBlobBytes( |
| 76 int64 request_id, int64 byte_start, int64 length) { | 84 int64 request_id, int64 byte_start, int64 length) { |
| 77 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 85 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 78 BrowserThread::PostTask( | 86 BrowserThread::PostTask( |
| 79 BrowserThread::UI, | 87 BrowserThread::UI, |
| 80 FROM_HERE, | 88 FROM_HERE, |
| 81 base::Bind(&SafeMediaMetadataParser::StartBlobReaderOnUIThread, this, | 89 base::Bind(&SafeMediaMetadataParser::StartBlobReaderOnUIThread, this, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 request_id, *data)); | 121 request_id, *data)); |
| 114 } | 122 } |
| 115 | 123 |
| 116 void SafeMediaMetadataParser::OnProcessCrashed(int exit_code) { | 124 void SafeMediaMetadataParser::OnProcessCrashed(int exit_code) { |
| 117 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 125 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 118 DCHECK(!callback_.is_null()); | 126 DCHECK(!callback_.is_null()); |
| 119 | 127 |
| 120 BrowserThread::PostTask( | 128 BrowserThread::PostTask( |
| 121 BrowserThread::UI, | 129 BrowserThread::UI, |
| 122 FROM_HERE, | 130 FROM_HERE, |
| 123 base::Bind(callback_, false, base::Owned(new base::DictionaryValue))); | 131 base::Bind(callback_, false, base::Owned(new base::DictionaryValue), |
| 132 std::vector<std::string>(), std::vector<std::string>())); | |
| 124 parser_state_ = FINISHED_PARSING_STATE; | 133 parser_state_ = FINISHED_PARSING_STATE; |
| 125 } | 134 } |
| 126 | 135 |
| 127 bool SafeMediaMetadataParser::OnMessageReceived(const IPC::Message& message) { | 136 bool SafeMediaMetadataParser::OnMessageReceived(const IPC::Message& message) { |
| 128 bool handled = true; | 137 bool handled = true; |
| 129 IPC_BEGIN_MESSAGE_MAP(SafeMediaMetadataParser, message) | 138 IPC_BEGIN_MESSAGE_MAP(SafeMediaMetadataParser, message) |
| 130 IPC_MESSAGE_HANDLER( | 139 IPC_MESSAGE_HANDLER( |
| 131 ChromeUtilityHostMsg_ParseMediaMetadata_Finished, | 140 ChromeUtilityHostMsg_ParseMediaMetadata_Finished, |
| 132 OnParseMediaMetadataFinished) | 141 OnParseMediaMetadataFinished) |
| 133 IPC_MESSAGE_HANDLER( | 142 IPC_MESSAGE_HANDLER( |
| 134 ChromeUtilityHostMsg_RequestBlobBytes, | 143 ChromeUtilityHostMsg_RequestBlobBytes, |
| 135 OnUtilityProcessRequestBlobBytes) | 144 OnUtilityProcessRequestBlobBytes) |
| 136 IPC_MESSAGE_UNHANDLED(handled = false) | 145 IPC_MESSAGE_UNHANDLED(handled = false) |
| 137 IPC_END_MESSAGE_MAP() | 146 IPC_END_MESSAGE_MAP() |
| 138 return handled; | 147 return handled; |
| 139 } | 148 } |
| 140 | 149 |
| 141 } // namespace metadata | 150 } // namespace metadata |
| OLD | NEW |