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

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

Issue 2827853003: Rewrite base::Bind to base::BindOnce with base_bind_rewriters in //chrome/browser/media_galleries (Closed)
Patch Set: Created 3 years, 8 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
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 <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "chrome/browser/extensions/blob_reader.h" 10 #include "chrome/browser/extensions/blob_reader.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 mime_type_(mime_type), 51 mime_type_(mime_type),
52 get_attached_images_(get_attached_images) { 52 get_attached_images_(get_attached_images) {
53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
54 } 54 }
55 55
56 void SafeMediaMetadataParser::Start(const DoneCallback& callback) { 56 void SafeMediaMetadataParser::Start(const DoneCallback& callback) {
57 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 57 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
58 58
59 content::BrowserThread::PostTask( 59 content::BrowserThread::PostTask(
60 content::BrowserThread::IO, FROM_HERE, 60 content::BrowserThread::IO, FROM_HERE,
61 base::Bind(&SafeMediaMetadataParser::StartOnIOThread, this, callback)); 61 base::BindOnce(&SafeMediaMetadataParser::StartOnIOThread, this,
62 callback));
62 } 63 }
63 64
64 SafeMediaMetadataParser::~SafeMediaMetadataParser() = default; 65 SafeMediaMetadataParser::~SafeMediaMetadataParser() = default;
65 66
66 void SafeMediaMetadataParser::StartOnIOThread(const DoneCallback& callback) { 67 void SafeMediaMetadataParser::StartOnIOThread(const DoneCallback& callback) {
67 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 68 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
68 DCHECK(!utility_process_mojo_client_); 69 DCHECK(!utility_process_mojo_client_);
69 DCHECK(callback); 70 DCHECK(callback);
70 71
71 callback_ = callback; 72 callback_ = callback;
(...skipping 20 matching lines...) Expand all
92 utility_process_mojo_client_.reset(); // Terminate the utility process. 93 utility_process_mojo_client_.reset(); // Terminate the utility process.
93 media_data_source_.reset(); 94 media_data_source_.reset();
94 95
95 std::unique_ptr<base::DictionaryValue> metadata_dictionary = 96 std::unique_ptr<base::DictionaryValue> metadata_dictionary =
96 base::MakeUnique<base::DictionaryValue>(); 97 base::MakeUnique<base::DictionaryValue>();
97 std::unique_ptr<std::vector<metadata::AttachedImage>> attached_images = 98 std::unique_ptr<std::vector<metadata::AttachedImage>> attached_images =
98 base::MakeUnique<std::vector<metadata::AttachedImage>>(); 99 base::MakeUnique<std::vector<metadata::AttachedImage>>();
99 100
100 content::BrowserThread::PostTask( 101 content::BrowserThread::PostTask(
101 content::BrowserThread::UI, FROM_HERE, 102 content::BrowserThread::UI, FROM_HERE,
102 base::Bind(callback_, false, base::Passed(&metadata_dictionary), 103 base::BindOnce(callback_, false, base::Passed(&metadata_dictionary),
103 base::Passed(&attached_images))); 104 base::Passed(&attached_images)));
104 } 105 }
105 106
106 void SafeMediaMetadataParser::ParseMediaMetadataDone( 107 void SafeMediaMetadataParser::ParseMediaMetadataDone(
107 bool parse_success, 108 bool parse_success,
108 std::unique_ptr<base::DictionaryValue> metadata_dictionary, 109 std::unique_ptr<base::DictionaryValue> metadata_dictionary,
109 const std::vector<AttachedImage>& attached_images) { 110 const std::vector<AttachedImage>& attached_images) {
110 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 111 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
111 112
112 utility_process_mojo_client_.reset(); // Terminate the utility process. 113 utility_process_mojo_client_.reset(); // Terminate the utility process.
113 media_data_source_.reset(); 114 media_data_source_.reset();
114 115
115 // We need to make a scoped copy of this vector since it will be destroyed 116 // We need to make a scoped copy of this vector since it will be destroyed
116 // at the end of the handler. 117 // at the end of the handler.
117 std::unique_ptr<std::vector<metadata::AttachedImage>> attached_images_copy = 118 std::unique_ptr<std::vector<metadata::AttachedImage>> attached_images_copy =
118 base::MakeUnique<std::vector<metadata::AttachedImage>>(attached_images); 119 base::MakeUnique<std::vector<metadata::AttachedImage>>(attached_images);
119 120
120 content::BrowserThread::PostTask( 121 content::BrowserThread::PostTask(
121 content::BrowserThread::UI, FROM_HERE, 122 content::BrowserThread::UI, FROM_HERE,
122 base::Bind(callback_, parse_success, base::Passed(&metadata_dictionary), 123 base::BindOnce(callback_, parse_success,
123 base::Passed(&attached_images_copy))); 124 base::Passed(&metadata_dictionary),
125 base::Passed(&attached_images_copy)));
124 } 126 }
125 127
126 void SafeMediaMetadataParser::StartBlobRequest( 128 void SafeMediaMetadataParser::StartBlobRequest(
127 const extensions::mojom::MediaDataSource::ReadBlobCallback& callback, 129 const extensions::mojom::MediaDataSource::ReadBlobCallback& callback,
128 int64_t position, 130 int64_t position,
129 int64_t length) { 131 int64_t length) {
130 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 132 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
131 133
132 content::BrowserThread::PostTask( 134 content::BrowserThread::PostTask(
133 content::BrowserThread::UI, FROM_HERE, 135 content::BrowserThread::UI, FROM_HERE,
134 base::Bind(&SafeMediaMetadataParser::StartBlobReaderOnUIThread, this, 136 base::BindOnce(&SafeMediaMetadataParser::StartBlobReaderOnUIThread, this,
135 callback, position, length)); 137 callback, position, length));
136 } 138 }
137 139
138 void SafeMediaMetadataParser::StartBlobReaderOnUIThread( 140 void SafeMediaMetadataParser::StartBlobReaderOnUIThread(
139 const extensions::mojom::MediaDataSource::ReadBlobCallback& callback, 141 const extensions::mojom::MediaDataSource::ReadBlobCallback& callback,
140 int64_t position, 142 int64_t position,
141 int64_t length) { 143 int64_t length) {
142 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 144 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
143 145
144 BlobReader* reader = new BlobReader( // BlobReader is self-deleting. 146 BlobReader* reader = new BlobReader( // BlobReader is self-deleting.
145 profile_, blob_uuid_, 147 profile_, blob_uuid_,
146 base::Bind(&SafeMediaMetadataParser::BlobReaderDoneOnUIThread, this, 148 base::Bind(&SafeMediaMetadataParser::BlobReaderDoneOnUIThread, this,
147 callback)); 149 callback));
148 reader->SetByteRange(position, length); 150 reader->SetByteRange(position, length);
149 reader->Start(); 151 reader->Start();
150 } 152 }
151 153
152 void SafeMediaMetadataParser::BlobReaderDoneOnUIThread( 154 void SafeMediaMetadataParser::BlobReaderDoneOnUIThread(
153 const extensions::mojom::MediaDataSource::ReadBlobCallback& callback, 155 const extensions::mojom::MediaDataSource::ReadBlobCallback& callback,
154 std::unique_ptr<std::string> data, 156 std::unique_ptr<std::string> data,
155 int64_t /* blob_total_size */) { 157 int64_t /* blob_total_size */) {
156 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 158 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
157 159
158 content::BrowserThread::PostTask( 160 content::BrowserThread::PostTask(
159 content::BrowserThread::IO, FROM_HERE, 161 content::BrowserThread::IO, FROM_HERE,
160 base::Bind(&SafeMediaMetadataParser::FinishBlobRequest, this, callback, 162 base::BindOnce(&SafeMediaMetadataParser::FinishBlobRequest, this,
161 base::Passed(std::move(data)))); 163 callback, base::Passed(std::move(data))));
162 } 164 }
163 165
164 void SafeMediaMetadataParser::FinishBlobRequest( 166 void SafeMediaMetadataParser::FinishBlobRequest(
165 const extensions::mojom::MediaDataSource::ReadBlobCallback& callback, 167 const extensions::mojom::MediaDataSource::ReadBlobCallback& callback,
166 std::unique_ptr<std::string> data) { 168 std::unique_ptr<std::string> data) {
167 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 169 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
168 170
169 if (utility_process_mojo_client_) 171 if (utility_process_mojo_client_)
170 callback.Run(std::vector<uint8_t>(data->begin(), data->end())); 172 callback.Run(std::vector<uint8_t>(data->begin(), data->end()));
171 } 173 }
172 174
173 } // namespace metadata 175 } // namespace metadata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698