| 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<AttachedPicture>& attached_pictures) { |
| 61 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 63 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 62 DCHECK(!callback_.is_null()); | 64 DCHECK(!callback_.is_null()); |
| 63 | 65 |
| 64 if (parser_state_ != STARTED_PARSING_STATE) | 66 if (parser_state_ != STARTED_PARSING_STATE) |
| 65 return; | 67 return; |
| 66 | 68 |
| 67 BrowserThread::PostTask( | 69 BrowserThread::PostTask( |
| 68 BrowserThread::UI, | 70 BrowserThread::UI, |
| 69 FROM_HERE, | 71 FROM_HERE, |
| 70 base::Bind(callback_, parse_success, | 72 base::Bind(callback_, parse_success, |
| 71 base::Owned(metadata_dictionary.DeepCopy()))); | 73 base::Owned(metadata_dictionary.DeepCopy()), |
| 74 attached_pictures)); |
| 72 parser_state_ = FINISHED_PARSING_STATE; | 75 parser_state_ = FINISHED_PARSING_STATE; |
| 73 } | 76 } |
| 74 | 77 |
| 75 void SafeMediaMetadataParser::OnUtilityProcessRequestBlobBytes( | 78 void SafeMediaMetadataParser::OnUtilityProcessRequestBlobBytes( |
| 76 int64 request_id, int64 byte_start, int64 length) { | 79 int64 request_id, int64 byte_start, int64 length) { |
| 77 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 80 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 78 BrowserThread::PostTask( | 81 BrowserThread::PostTask( |
| 79 BrowserThread::UI, | 82 BrowserThread::UI, |
| 80 FROM_HERE, | 83 FROM_HERE, |
| 81 base::Bind(&SafeMediaMetadataParser::StartBlobReaderOnUIThread, this, | 84 base::Bind(&SafeMediaMetadataParser::StartBlobReaderOnUIThread, this, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 request_id, *data)); | 116 request_id, *data)); |
| 114 } | 117 } |
| 115 | 118 |
| 116 void SafeMediaMetadataParser::OnProcessCrashed(int exit_code) { | 119 void SafeMediaMetadataParser::OnProcessCrashed(int exit_code) { |
| 117 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 120 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 118 DCHECK(!callback_.is_null()); | 121 DCHECK(!callback_.is_null()); |
| 119 | 122 |
| 120 BrowserThread::PostTask( | 123 BrowserThread::PostTask( |
| 121 BrowserThread::UI, | 124 BrowserThread::UI, |
| 122 FROM_HERE, | 125 FROM_HERE, |
| 123 base::Bind(callback_, false, base::Owned(new base::DictionaryValue))); | 126 base::Bind(callback_, false, base::Owned(new base::DictionaryValue), |
| 127 std::vector<AttachedPicture>())); |
| 124 parser_state_ = FINISHED_PARSING_STATE; | 128 parser_state_ = FINISHED_PARSING_STATE; |
| 125 } | 129 } |
| 126 | 130 |
| 127 bool SafeMediaMetadataParser::OnMessageReceived(const IPC::Message& message) { | 131 bool SafeMediaMetadataParser::OnMessageReceived(const IPC::Message& message) { |
| 128 bool handled = true; | 132 bool handled = true; |
| 129 IPC_BEGIN_MESSAGE_MAP(SafeMediaMetadataParser, message) | 133 IPC_BEGIN_MESSAGE_MAP(SafeMediaMetadataParser, message) |
| 130 IPC_MESSAGE_HANDLER( | 134 IPC_MESSAGE_HANDLER( |
| 131 ChromeUtilityHostMsg_ParseMediaMetadata_Finished, | 135 ChromeUtilityHostMsg_ParseMediaMetadata_Finished, |
| 132 OnParseMediaMetadataFinished) | 136 OnParseMediaMetadataFinished) |
| 133 IPC_MESSAGE_HANDLER( | 137 IPC_MESSAGE_HANDLER( |
| 134 ChromeUtilityHostMsg_RequestBlobBytes, | 138 ChromeUtilityHostMsg_RequestBlobBytes, |
| 135 OnUtilityProcessRequestBlobBytes) | 139 OnUtilityProcessRequestBlobBytes) |
| 136 IPC_MESSAGE_UNHANDLED(handled = false) | 140 IPC_MESSAGE_UNHANDLED(handled = false) |
| 137 IPC_END_MESSAGE_MAP() | 141 IPC_END_MESSAGE_MAP() |
| 138 return handled; | 142 return handled; |
| 139 } | 143 } |
| 140 | 144 |
| 141 } // namespace metadata | 145 } // namespace metadata |
| OLD | NEW |