Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.cc

Issue 250143002: Media Galleries API: Audio/Video attached pictures support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove a stray file Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_images)
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_images_(get_attached_images),
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_images_));
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<AttachedImage>& attached_images) {
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
69 // We need to make a scoped copy of this vector since it will be destroyed
tommycli 2014/05/07 21:39:05 I tried to eliminate all the copies, but could not
70 // at the end of the IPC message handler.
71 scoped_ptr<std::vector<metadata::AttachedImage>> attached_images_scoped =
72 make_scoped_ptr(new std::vector<metadata::AttachedImage>(
73 attached_images));
74
67 BrowserThread::PostTask( 75 BrowserThread::PostTask(
68 BrowserThread::UI, 76 BrowserThread::UI,
69 FROM_HERE, 77 FROM_HERE,
70 base::Bind(callback_, parse_success, 78 base::Bind(callback_, parse_success,
71 base::Owned(metadata_dictionary.DeepCopy()))); 79 base::Passed(make_scoped_ptr(metadata_dictionary.DeepCopy())),
80 base::Passed(&attached_images_scoped)));
72 parser_state_ = FINISHED_PARSING_STATE; 81 parser_state_ = FINISHED_PARSING_STATE;
73 } 82 }
74 83
75 void SafeMediaMetadataParser::OnUtilityProcessRequestBlobBytes( 84 void SafeMediaMetadataParser::OnUtilityProcessRequestBlobBytes(
76 int64 request_id, int64 byte_start, int64 length) { 85 int64 request_id, int64 byte_start, int64 length) {
77 DCHECK_CURRENTLY_ON(BrowserThread::IO); 86 DCHECK_CURRENTLY_ON(BrowserThread::IO);
78 BrowserThread::PostTask( 87 BrowserThread::PostTask(
79 BrowserThread::UI, 88 BrowserThread::UI,
80 FROM_HERE, 89 FROM_HERE,
81 base::Bind(&SafeMediaMetadataParser::StartBlobReaderOnUIThread, this, 90 base::Bind(&SafeMediaMetadataParser::StartBlobReaderOnUIThread, this,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 request_id, *data)); 122 request_id, *data));
114 } 123 }
115 124
116 void SafeMediaMetadataParser::OnProcessCrashed(int exit_code) { 125 void SafeMediaMetadataParser::OnProcessCrashed(int exit_code) {
117 DCHECK_CURRENTLY_ON(BrowserThread::IO); 126 DCHECK_CURRENTLY_ON(BrowserThread::IO);
118 DCHECK(!callback_.is_null()); 127 DCHECK(!callback_.is_null());
119 128
120 BrowserThread::PostTask( 129 BrowserThread::PostTask(
121 BrowserThread::UI, 130 BrowserThread::UI,
122 FROM_HERE, 131 FROM_HERE,
123 base::Bind(callback_, false, base::Owned(new base::DictionaryValue))); 132 base::Bind(callback_, false,
133 base::Passed(scoped_ptr<base::DictionaryValue>()),
134 base::Passed(scoped_ptr<std::vector<AttachedImage>>())));
124 parser_state_ = FINISHED_PARSING_STATE; 135 parser_state_ = FINISHED_PARSING_STATE;
125 } 136 }
126 137
127 bool SafeMediaMetadataParser::OnMessageReceived(const IPC::Message& message) { 138 bool SafeMediaMetadataParser::OnMessageReceived(const IPC::Message& message) {
128 bool handled = true; 139 bool handled = true;
129 IPC_BEGIN_MESSAGE_MAP(SafeMediaMetadataParser, message) 140 IPC_BEGIN_MESSAGE_MAP(SafeMediaMetadataParser, message)
130 IPC_MESSAGE_HANDLER( 141 IPC_MESSAGE_HANDLER(
131 ChromeUtilityHostMsg_ParseMediaMetadata_Finished, 142 ChromeUtilityHostMsg_ParseMediaMetadata_Finished,
132 OnParseMediaMetadataFinished) 143 OnParseMediaMetadataFinished)
133 IPC_MESSAGE_HANDLER( 144 IPC_MESSAGE_HANDLER(
134 ChromeUtilityHostMsg_RequestBlobBytes, 145 ChromeUtilityHostMsg_RequestBlobBytes,
135 OnUtilityProcessRequestBlobBytes) 146 OnUtilityProcessRequestBlobBytes)
136 IPC_MESSAGE_UNHANDLED(handled = false) 147 IPC_MESSAGE_UNHANDLED(handled = false)
137 IPC_END_MESSAGE_MAP() 148 IPC_END_MESSAGE_MAP()
138 return handled; 149 return handled;
139 } 150 }
140 151
141 } // namespace metadata 152 } // namespace metadata
OLDNEW
« no previous file with comments | « chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.h ('k') | chrome/chrome_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698