| 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 "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
| 8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
| 9 #include "chrome/browser/extensions/blob_reader.h" | 9 #include "chrome/browser/extensions/blob_reader.h" |
| 10 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" | 10 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" |
| 11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/child_process_data.h" | 13 #include "content/public/browser/child_process_data.h" |
| 14 #include "content/public/browser/utility_process_host.h" | 14 #include "content/public/browser/utility_process_host.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 | 16 |
| 17 using content::BrowserThread; | 17 using content::BrowserThread; |
| 18 | 18 |
| 19 namespace metadata { | 19 namespace metadata { |
| 20 | 20 |
| 21 SafeMediaMetadataParser::SafeMediaMetadataParser( | 21 SafeMediaMetadataParser::SafeMediaMetadataParser(Profile* profile, |
| 22 Profile* profile, const std::string& blob_uuid, int64 blob_size, | 22 const std::string& blob_uuid, |
| 23 const std::string& mime_type, bool get_attached_images) | 23 int64_t blob_size, |
| 24 const std::string& mime_type, |
| 25 bool get_attached_images) |
| 24 : profile_(profile), | 26 : profile_(profile), |
| 25 blob_uuid_(blob_uuid), | 27 blob_uuid_(blob_uuid), |
| 26 blob_size_(blob_size), | 28 blob_size_(blob_size), |
| 27 mime_type_(mime_type), | 29 mime_type_(mime_type), |
| 28 get_attached_images_(get_attached_images), | 30 get_attached_images_(get_attached_images), |
| 29 parser_state_(INITIAL_STATE) { | 31 parser_state_(INITIAL_STATE) { |
| 30 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 31 } | 33 } |
| 32 | 34 |
| 33 void SafeMediaMetadataParser::Start(const DoneCallback& callback) { | 35 void SafeMediaMetadataParser::Start(const DoneCallback& callback) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 BrowserThread::PostTask( | 83 BrowserThread::PostTask( |
| 82 BrowserThread::UI, | 84 BrowserThread::UI, |
| 83 FROM_HERE, | 85 FROM_HERE, |
| 84 base::Bind(callback_, parse_success, | 86 base::Bind(callback_, parse_success, |
| 85 base::Passed(make_scoped_ptr(metadata_dictionary.DeepCopy())), | 87 base::Passed(make_scoped_ptr(metadata_dictionary.DeepCopy())), |
| 86 base::Passed(&attached_images_copy))); | 88 base::Passed(&attached_images_copy))); |
| 87 parser_state_ = FINISHED_PARSING_STATE; | 89 parser_state_ = FINISHED_PARSING_STATE; |
| 88 } | 90 } |
| 89 | 91 |
| 90 void SafeMediaMetadataParser::OnUtilityProcessRequestBlobBytes( | 92 void SafeMediaMetadataParser::OnUtilityProcessRequestBlobBytes( |
| 91 int64 request_id, int64 byte_start, int64 length) { | 93 int64_t request_id, |
| 94 int64_t byte_start, |
| 95 int64_t length) { |
| 92 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 96 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 93 BrowserThread::PostTask( | 97 BrowserThread::PostTask( |
| 94 BrowserThread::UI, | 98 BrowserThread::UI, |
| 95 FROM_HERE, | 99 FROM_HERE, |
| 96 base::Bind(&SafeMediaMetadataParser::StartBlobReaderOnUIThread, this, | 100 base::Bind(&SafeMediaMetadataParser::StartBlobReaderOnUIThread, this, |
| 97 request_id, byte_start, length)); | 101 request_id, byte_start, length)); |
| 98 } | 102 } |
| 99 | 103 |
| 100 void SafeMediaMetadataParser::StartBlobReaderOnUIThread( | 104 void SafeMediaMetadataParser::StartBlobReaderOnUIThread(int64_t request_id, |
| 101 int64 request_id, int64 byte_start, int64 length) { | 105 int64_t byte_start, |
| 106 int64_t length) { |
| 102 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 107 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 103 | 108 |
| 104 // BlobReader is self-deleting. | 109 // BlobReader is self-deleting. |
| 105 BlobReader* reader = new BlobReader(profile_, blob_uuid_, base::Bind( | 110 BlobReader* reader = new BlobReader(profile_, blob_uuid_, base::Bind( |
| 106 &SafeMediaMetadataParser::OnBlobReaderDoneOnUIThread, this, request_id)); | 111 &SafeMediaMetadataParser::OnBlobReaderDoneOnUIThread, this, request_id)); |
| 107 reader->SetByteRange(byte_start, length); | 112 reader->SetByteRange(byte_start, length); |
| 108 reader->Start(); | 113 reader->Start(); |
| 109 } | 114 } |
| 110 | 115 |
| 111 void SafeMediaMetadataParser::OnBlobReaderDoneOnUIThread( | 116 void SafeMediaMetadataParser::OnBlobReaderDoneOnUIThread( |
| 112 int64 request_id, scoped_ptr<std::string> data, | 117 int64_t request_id, |
| 113 int64 /* blob_total_size */) { | 118 scoped_ptr<std::string> data, |
| 119 int64_t /* blob_total_size */) { |
| 114 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 120 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 115 BrowserThread::PostTask( | 121 BrowserThread::PostTask( |
| 116 BrowserThread::IO, | 122 BrowserThread::IO, |
| 117 FROM_HERE, | 123 FROM_HERE, |
| 118 base::Bind(&SafeMediaMetadataParser::FinishRequestBlobBytes, this, | 124 base::Bind(&SafeMediaMetadataParser::FinishRequestBlobBytes, this, |
| 119 request_id, base::Passed(data.Pass()))); | 125 request_id, base::Passed(data.Pass()))); |
| 120 } | 126 } |
| 121 | 127 |
| 122 void SafeMediaMetadataParser::FinishRequestBlobBytes( | 128 void SafeMediaMetadataParser::FinishRequestBlobBytes( |
| 123 int64 request_id, scoped_ptr<std::string> data) { | 129 int64_t request_id, |
| 130 scoped_ptr<std::string> data) { |
| 124 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 131 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 125 if (!utility_process_host_.get()) | 132 if (!utility_process_host_.get()) |
| 126 return; | 133 return; |
| 127 utility_process_host_->Send(new ChromeUtilityMsg_RequestBlobBytes_Finished( | 134 utility_process_host_->Send(new ChromeUtilityMsg_RequestBlobBytes_Finished( |
| 128 request_id, *data)); | 135 request_id, *data)); |
| 129 } | 136 } |
| 130 | 137 |
| 131 void SafeMediaMetadataParser::OnProcessCrashed(int exit_code) { | 138 void SafeMediaMetadataParser::OnProcessCrashed(int exit_code) { |
| 132 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 139 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 133 DCHECK(!callback_.is_null()); | 140 DCHECK(!callback_.is_null()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 149 OnParseMediaMetadataFinished) | 156 OnParseMediaMetadataFinished) |
| 150 IPC_MESSAGE_HANDLER( | 157 IPC_MESSAGE_HANDLER( |
| 151 ChromeUtilityHostMsg_RequestBlobBytes, | 158 ChromeUtilityHostMsg_RequestBlobBytes, |
| 152 OnUtilityProcessRequestBlobBytes) | 159 OnUtilityProcessRequestBlobBytes) |
| 153 IPC_MESSAGE_UNHANDLED(handled = false) | 160 IPC_MESSAGE_UNHANDLED(handled = false) |
| 154 IPC_END_MESSAGE_MAP() | 161 IPC_END_MESSAGE_MAP() |
| 155 return handled; | 162 return handled; |
| 156 } | 163 } |
| 157 | 164 |
| 158 } // namespace metadata | 165 } // namespace metadata |
| OLD | NEW |