OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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 SafeMediaMetadataParser::SafeMediaMetadataParser(Profile* profile, | |
18 const std::string& blob_uuid, | |
19 int64 blob_size, | |
20 const std::string& mime_type) | |
21 : profile_(profile), | |
22 blob_uuid_(blob_uuid), | |
23 blob_size_(blob_size), | |
24 mime_type_(mime_type), | |
25 parser_state_(INITIAL_STATE) { | |
26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
27 } | |
28 | |
29 void SafeMediaMetadataParser::Start(const DoneCallback& callback) { | |
30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
31 DCHECK(!callback.is_null()); | |
32 | |
33 callback_ = callback; | |
34 | |
35 BrowserThread::PostTask( | |
36 BrowserThread::IO, | |
37 FROM_HERE, | |
38 base::Bind(&SafeMediaMetadataParser::StartWorkOnIOThread, this)); | |
39 } | |
40 | |
41 SafeMediaMetadataParser::~SafeMediaMetadataParser() { | |
42 } | |
43 | |
44 void SafeMediaMetadataParser::StartWorkOnIOThread() { | |
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
46 DCHECK_EQ(INITIAL_STATE, parser_state_); | |
47 | |
48 utility_process_host_ = content::UtilityProcessHost::Create( | |
49 this, base::MessageLoopProxy::current())->AsWeakPtr(); | |
50 | |
51 utility_process_host_->Send( | |
52 new ChromeUtilityMsg_ParseMediaMetadata(mime_type_, blob_size_)); | |
53 | |
54 parser_state_ = STARTED_PARSING_STATE; | |
55 } | |
56 | |
57 void SafeMediaMetadataParser::OnParseMediaMetadataFinished( | |
58 bool parse_success, | |
59 const base::DictionaryValue& metadata_dictionary) { | |
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
61 DCHECK(!callback_.is_null()); | |
62 | |
63 if (parser_state_ != STARTED_PARSING_STATE) | |
64 return; | |
65 | |
66 scoped_ptr<MediaMetadata> metadata( | |
67 MediaMetadata::FromValue(metadata_dictionary)); | |
vandebo (ex-Chrome)
2014/01/07 18:34:59
Aren't we going to need to turn this back into Val
tommycli
2014/01/07 20:23:31
Done.
| |
68 | |
69 BrowserThread::PostTask( | |
70 BrowserThread::UI, | |
71 FROM_HERE, | |
72 base::Bind(callback_, parse_success, base::Passed(metadata.Pass()))); | |
vandebo (ex-Chrome)
2014/01/07 18:34:59
You said callback_ is only access on the UI thread
tommycli
2014/01/07 20:23:31
I updated the .h comment to read:
// Assigned on t
| |
73 parser_state_ = FINISHED_PARSING_STATE; | |
74 } | |
75 | |
76 void SafeMediaMetadataParser::OnUtilityProcessRequestBlobBytes( | |
77 int64 request_id, | |
78 int64 byte_start, | |
79 int64 length) { | |
80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
81 | |
82 // BlobReader is self-deleting. | |
83 BlobReader* reader = new BlobReader( | |
84 profile_, | |
85 blob_uuid_, | |
86 base::Bind(&SafeMediaMetadataParser::OnBlobReaderDone, | |
87 base::Unretained(this), | |
vandebo (ex-Chrome)
2014/01/07 18:34:59
This concerns me. What if the SafeMediaMetadataPa
tommycli
2014/01/07 20:23:31
Done.
vandebo (ex-Chrome)
2014/01/08 00:26:18
I think bound parameters would be preferred...
ba
tommycli
2014/01/08 01:17:10
Done.
| |
88 request_id)); | |
89 reader->SetByteRange(byte_start, length); | |
90 reader->Start(); | |
91 } | |
92 | |
93 void SafeMediaMetadataParser::OnBlobReaderDone( | |
94 int64 request_id, | |
95 scoped_ptr<std::string> data) { | |
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
97 | |
98 utility_process_host_->Send( | |
99 new ChromeUtilityMsg_ParseMediaMetadata_RequestBlobBytes_Finished( | |
100 request_id, *data)); | |
101 } | |
102 | |
103 void SafeMediaMetadataParser::OnProcessCrashed(int exit_code) { | |
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
105 DCHECK(!callback_.is_null()); | |
106 | |
vandebo (ex-Chrome)
2014/01/07 18:34:59
This should set the state.
tommycli
2014/01/07 20:23:31
Done.
| |
107 BrowserThread::PostTask( | |
108 BrowserThread::UI, | |
109 FROM_HERE, | |
110 base::Bind(callback_, false, | |
111 base::Passed(scoped_ptr<MediaMetadata>().Pass()))); | |
112 } | |
113 | |
114 bool SafeMediaMetadataParser::OnMessageReceived( | |
115 const IPC::Message& message) { | |
116 bool handled = true; | |
117 IPC_BEGIN_MESSAGE_MAP(SafeMediaMetadataParser, message) | |
118 IPC_MESSAGE_HANDLER( | |
119 ChromeUtilityHostMsg_ParseMediaMetadata_Finished, | |
120 OnParseMediaMetadataFinished) | |
121 IPC_MESSAGE_HANDLER( | |
122 ChromeUtilityHostMsg_ParseMediaMetadata_RequestBlobBytes, | |
123 OnUtilityProcessRequestBlobBytes) | |
124 IPC_MESSAGE_UNHANDLED(handled = false) | |
125 IPC_END_MESSAGE_MAP() | |
126 return handled; | |
127 } | |
128 | |
129 } // namespace metadata | |
OLD | NEW |