Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.h" | |
| 6 | |
| 7 #include "chrome/browser/extensions/blob_reader.h" | |
| 8 #include "chrome/common/chrome_utility_messages.h" | |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 #include "content/public/browser/child_process_data.h" | |
| 11 #include "content/public/browser/utility_process_host.h" | |
| 12 | |
| 13 using content::BrowserThread; | |
| 14 | |
| 15 namespace metadata { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 // Completes the Blob byte request by forwarding it to the utility process. | |
| 20 void OnBlobReaderDone( | |
| 21 const base::WeakPtr<content::UtilityProcessHost>& utility_process_host, | |
| 22 int64 request_id, | |
| 23 scoped_ptr<std::string> data) { | |
| 24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 25 | |
| 26 if (!utility_process_host.get()) | |
| 27 return; | |
| 28 utility_process_host->Send(new ChromeUtilityMsg_RequestBlobBytes_Finished( | |
| 29 request_id, *data)); | |
| 30 } | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 SafeMediaMetadataParser::SafeMediaMetadataParser(Profile* profile, | |
| 35 const std::string& blob_uuid, | |
| 36 int64 blob_size, | |
| 37 const std::string& mime_type) | |
| 38 : profile_(profile), | |
| 39 blob_uuid_(blob_uuid), | |
| 40 blob_size_(blob_size), | |
| 41 mime_type_(mime_type), | |
| 42 parser_state_(INITIAL_STATE) { | |
| 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 44 } | |
| 45 | |
| 46 void SafeMediaMetadataParser::Start(const DoneCallback& callback) { | |
| 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 48 | |
| 49 BrowserThread::PostTask( | |
| 50 BrowserThread::IO, | |
| 51 FROM_HERE, | |
| 52 base::Bind(&SafeMediaMetadataParser::StartWorkOnIOThread, this, | |
| 53 callback)); | |
| 54 } | |
| 55 | |
| 56 SafeMediaMetadataParser::~SafeMediaMetadataParser() { | |
| 57 } | |
| 58 | |
| 59 void SafeMediaMetadataParser::StartWorkOnIOThread( | |
| 60 const DoneCallback& callback) { | |
| 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 62 DCHECK_EQ(INITIAL_STATE, parser_state_); | |
| 63 DCHECK(!callback.is_null()); | |
| 64 | |
| 65 callback_ = callback; | |
| 66 | |
| 67 utility_process_host_ = content::UtilityProcessHost::Create( | |
| 68 this, base::MessageLoopProxy::current())->AsWeakPtr(); | |
| 69 | |
| 70 utility_process_host_->Send( | |
| 71 new ChromeUtilityMsg_ParseMediaMetadata(mime_type_, blob_size_)); | |
| 72 | |
| 73 parser_state_ = STARTED_PARSING_STATE; | |
| 74 } | |
| 75 | |
| 76 void SafeMediaMetadataParser::OnParseMediaMetadataFinished( | |
| 77 bool parse_success, const base::DictionaryValue& metadata_dictionary) { | |
| 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 79 DCHECK(!callback_.is_null()); | |
| 80 | |
| 81 if (parser_state_ != STARTED_PARSING_STATE) | |
| 82 return; | |
| 83 | |
| 84 BrowserThread::PostTask( | |
| 85 BrowserThread::UI, | |
| 86 FROM_HERE, | |
| 87 base::Bind(callback_, parse_success, base::Passed( | |
| 88 make_scoped_ptr(metadata_dictionary.DeepCopy())))); | |
|
Lei Zhang
2014/01/10 20:46:09
Given then way its used in SendMediaMetadataToHost
tommycli
2014/01/10 22:41:08
For some reason, changing the callback sig to a ra
Lei Zhang
2014/01/10 22:48:48
Does passing an empty dummy DictionaryValue work?
tommycli
2014/01/10 23:34:00
Yes! That does work. I'm not sure how i feel about
| |
| 89 parser_state_ = FINISHED_PARSING_STATE; | |
| 90 } | |
| 91 | |
| 92 void SafeMediaMetadataParser::OnUtilityProcessRequestBlobBytes( | |
| 93 int64 request_id, int64 byte_start, int64 length) { | |
| 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 95 | |
| 96 // BlobReader is self-deleting. | |
| 97 BlobReader* reader = new BlobReader( | |
| 98 profile_, | |
| 99 blob_uuid_, | |
| 100 base::Bind(&OnBlobReaderDone, utility_process_host_, request_id)); | |
| 101 reader->SetByteRange(byte_start, length); | |
| 102 reader->Start(); | |
| 103 } | |
| 104 | |
| 105 void SafeMediaMetadataParser::OnProcessCrashed(int exit_code) { | |
| 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 107 DCHECK(!callback_.is_null()); | |
| 108 | |
| 109 BrowserThread::PostTask( | |
| 110 BrowserThread::UI, | |
| 111 FROM_HERE, | |
| 112 base::Bind(callback_, false, | |
| 113 base::Passed(scoped_ptr<base::DictionaryValue>()))); | |
| 114 parser_state_ = FINISHED_PARSING_STATE; | |
| 115 } | |
| 116 | |
| 117 bool SafeMediaMetadataParser::OnMessageReceived(const IPC::Message& message) { | |
| 118 bool handled = true; | |
| 119 IPC_BEGIN_MESSAGE_MAP(SafeMediaMetadataParser, message) | |
| 120 IPC_MESSAGE_HANDLER( | |
| 121 ChromeUtilityHostMsg_ParseMediaMetadata_Finished, | |
| 122 OnParseMediaMetadataFinished) | |
| 123 IPC_MESSAGE_HANDLER( | |
| 124 ChromeUtilityHostMsg_RequestBlobBytes, | |
| 125 OnUtilityProcessRequestBlobBytes) | |
| 126 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 127 IPC_END_MESSAGE_MAP() | |
| 128 return handled; | |
| 129 } | |
| 130 | |
| 131 } // namespace metadata | |
| OLD | NEW |