OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/extensions/api/webrtc_logging_private/webrtc_logging_pr
ivate_api.h" | 5 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr
ivate_api.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/hash.h" | 10 #include "base/hash.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 WebRtcLoggingHandlerHost::GenericDoneCallback callback; | 166 WebRtcLoggingHandlerHost::GenericDoneCallback callback; |
167 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = | 167 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = |
168 PrepareTask(params->request, params->security_origin, &callback); | 168 PrepareTask(params->request, params->security_origin, &callback); |
169 if (!webrtc_logging_handler_host.get()) | 169 if (!webrtc_logging_handler_host.get()) |
170 return false; | 170 return false; |
171 | 171 |
172 std::unique_ptr<MetaDataMap> meta_data(new MetaDataMap()); | 172 std::unique_ptr<MetaDataMap> meta_data(new MetaDataMap()); |
173 for (const MetaDataEntry& entry : params->meta_data) | 173 for (const MetaDataEntry& entry : params->meta_data) |
174 (*meta_data)[entry.key] = entry.value; | 174 (*meta_data)[entry.key] = entry.value; |
175 | 175 |
176 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 176 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
177 &WebRtcLoggingHandlerHost::SetMetaData, webrtc_logging_handler_host, | 177 base::BindOnce(&WebRtcLoggingHandlerHost::SetMetaData, |
178 base::Passed(&meta_data), callback)); | 178 webrtc_logging_handler_host, |
| 179 base::Passed(&meta_data), callback)); |
179 | 180 |
180 return true; | 181 return true; |
181 } | 182 } |
182 | 183 |
183 bool WebrtcLoggingPrivateStartFunction::RunAsync() { | 184 bool WebrtcLoggingPrivateStartFunction::RunAsync() { |
184 std::unique_ptr<Start::Params> params(Start::Params::Create(*args_)); | 185 std::unique_ptr<Start::Params> params(Start::Params::Create(*args_)); |
185 EXTENSION_FUNCTION_VALIDATE(params.get()); | 186 EXTENSION_FUNCTION_VALIDATE(params.get()); |
186 | 187 |
187 WebRtcLoggingHandlerHost::GenericDoneCallback callback; | 188 WebRtcLoggingHandlerHost::GenericDoneCallback callback; |
188 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = | 189 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = |
189 PrepareTask(params->request, params->security_origin, &callback); | 190 PrepareTask(params->request, params->security_origin, &callback); |
190 if (!webrtc_logging_handler_host.get()) | 191 if (!webrtc_logging_handler_host.get()) |
191 return false; | 192 return false; |
192 | 193 |
193 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 194 BrowserThread::PostTask( |
194 &WebRtcLoggingHandlerHost::StartLogging, webrtc_logging_handler_host, | 195 BrowserThread::IO, FROM_HERE, |
195 callback)); | 196 base::BindOnce(&WebRtcLoggingHandlerHost::StartLogging, |
| 197 webrtc_logging_handler_host, callback)); |
196 | 198 |
197 return true; | 199 return true; |
198 } | 200 } |
199 | 201 |
200 bool WebrtcLoggingPrivateSetUploadOnRenderCloseFunction::RunAsync() { | 202 bool WebrtcLoggingPrivateSetUploadOnRenderCloseFunction::RunAsync() { |
201 std::unique_ptr<SetUploadOnRenderClose::Params> params( | 203 std::unique_ptr<SetUploadOnRenderClose::Params> params( |
202 SetUploadOnRenderClose::Params::Create(*args_)); | 204 SetUploadOnRenderClose::Params::Create(*args_)); |
203 EXTENSION_FUNCTION_VALIDATE(params.get()); | 205 EXTENSION_FUNCTION_VALIDATE(params.get()); |
204 | 206 |
205 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | 207 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
206 LoggingHandlerFromRequest(params->request, params->security_origin)); | 208 LoggingHandlerFromRequest(params->request, params->security_origin)); |
207 if (!webrtc_logging_handler_host.get()) | 209 if (!webrtc_logging_handler_host.get()) |
208 return false; | 210 return false; |
209 | 211 |
210 webrtc_logging_handler_host->set_upload_log_on_render_close( | 212 webrtc_logging_handler_host->set_upload_log_on_render_close( |
211 params->should_upload); | 213 params->should_upload); |
212 | 214 |
213 // Post a task since this is an asynchronous extension function. | 215 // Post a task since this is an asynchronous extension function. |
214 // TODO(devlin): This is unneccessary; this should just be a | 216 // TODO(devlin): This is unneccessary; this should just be a |
215 // UIThreadExtensionFunction. Fix this. | 217 // UIThreadExtensionFunction. Fix this. |
216 BrowserThread::PostTask( | 218 BrowserThread::PostTask( |
217 BrowserThread::UI, FROM_HERE, | 219 BrowserThread::UI, FROM_HERE, |
218 base::Bind( | 220 base::BindOnce( |
219 &WebrtcLoggingPrivateSetUploadOnRenderCloseFunction::SendResponse, | 221 &WebrtcLoggingPrivateSetUploadOnRenderCloseFunction::SendResponse, |
220 this, true)); | 222 this, true)); |
221 return true; | 223 return true; |
222 } | 224 } |
223 | 225 |
224 bool WebrtcLoggingPrivateStopFunction::RunAsync() { | 226 bool WebrtcLoggingPrivateStopFunction::RunAsync() { |
225 std::unique_ptr<Stop::Params> params(Stop::Params::Create(*args_)); | 227 std::unique_ptr<Stop::Params> params(Stop::Params::Create(*args_)); |
226 EXTENSION_FUNCTION_VALIDATE(params.get()); | 228 EXTENSION_FUNCTION_VALIDATE(params.get()); |
227 | 229 |
228 WebRtcLoggingHandlerHost::GenericDoneCallback callback; | 230 WebRtcLoggingHandlerHost::GenericDoneCallback callback; |
229 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = | 231 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = |
230 PrepareTask(params->request, params->security_origin, &callback); | 232 PrepareTask(params->request, params->security_origin, &callback); |
231 if (!webrtc_logging_handler_host.get()) | 233 if (!webrtc_logging_handler_host.get()) |
232 return false; | 234 return false; |
233 | 235 |
234 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 236 BrowserThread::PostTask( |
235 &WebRtcLoggingHandlerHost::StopLogging, webrtc_logging_handler_host, | 237 BrowserThread::IO, FROM_HERE, |
236 callback)); | 238 base::BindOnce(&WebRtcLoggingHandlerHost::StopLogging, |
| 239 webrtc_logging_handler_host, callback)); |
237 | 240 |
238 return true; | 241 return true; |
239 } | 242 } |
240 | 243 |
241 bool WebrtcLoggingPrivateStoreFunction::RunAsync() { | 244 bool WebrtcLoggingPrivateStoreFunction::RunAsync() { |
242 std::unique_ptr<Store::Params> params(Store::Params::Create(*args_)); | 245 std::unique_ptr<Store::Params> params(Store::Params::Create(*args_)); |
243 EXTENSION_FUNCTION_VALIDATE(params.get()); | 246 EXTENSION_FUNCTION_VALIDATE(params.get()); |
244 | 247 |
245 WebRtcLoggingHandlerHost::GenericDoneCallback callback; | 248 WebRtcLoggingHandlerHost::GenericDoneCallback callback; |
246 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = | 249 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = |
247 PrepareTask(params->request, params->security_origin, &callback); | 250 PrepareTask(params->request, params->security_origin, &callback); |
248 if (!webrtc_logging_handler_host.get()) | 251 if (!webrtc_logging_handler_host.get()) |
249 return false; | 252 return false; |
250 | 253 |
251 const std::string local_log_id(HashIdWithOrigin(params->security_origin, | 254 const std::string local_log_id(HashIdWithOrigin(params->security_origin, |
252 params->log_id)); | 255 params->log_id)); |
253 | 256 |
254 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 257 BrowserThread::PostTask( |
255 &WebRtcLoggingHandlerHost::StoreLog, | 258 BrowserThread::IO, FROM_HERE, |
256 webrtc_logging_handler_host, local_log_id, callback)); | 259 base::BindOnce(&WebRtcLoggingHandlerHost::StoreLog, |
| 260 webrtc_logging_handler_host, local_log_id, callback)); |
257 | 261 |
258 return true; | 262 return true; |
259 } | 263 } |
260 | 264 |
261 bool WebrtcLoggingPrivateUploadStoredFunction::RunAsync() { | 265 bool WebrtcLoggingPrivateUploadStoredFunction::RunAsync() { |
262 std::unique_ptr<UploadStored::Params> params( | 266 std::unique_ptr<UploadStored::Params> params( |
263 UploadStored::Params::Create(*args_)); | 267 UploadStored::Params::Create(*args_)); |
264 EXTENSION_FUNCTION_VALIDATE(params.get()); | 268 EXTENSION_FUNCTION_VALIDATE(params.get()); |
265 | 269 |
266 scoped_refptr<WebRtcLoggingHandlerHost> logging_handler( | 270 scoped_refptr<WebRtcLoggingHandlerHost> logging_handler( |
267 LoggingHandlerFromRequest(params->request, params->security_origin)); | 271 LoggingHandlerFromRequest(params->request, params->security_origin)); |
268 if (!logging_handler.get()) | 272 if (!logging_handler.get()) |
269 return false; | 273 return false; |
270 | 274 |
271 WebRtcLoggingHandlerHost::UploadDoneCallback callback = base::Bind( | 275 WebRtcLoggingHandlerHost::UploadDoneCallback callback = base::Bind( |
272 &WebrtcLoggingPrivateUploadStoredFunction::FireCallback, this); | 276 &WebrtcLoggingPrivateUploadStoredFunction::FireCallback, this); |
273 | 277 |
274 const std::string local_log_id(HashIdWithOrigin(params->security_origin, | 278 const std::string local_log_id(HashIdWithOrigin(params->security_origin, |
275 params->log_id)); | 279 params->log_id)); |
276 | 280 |
277 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 281 BrowserThread::PostTask( |
278 &WebRtcLoggingHandlerHost::UploadStoredLog, logging_handler, local_log_id, | 282 BrowserThread::IO, FROM_HERE, |
279 callback)); | 283 base::BindOnce(&WebRtcLoggingHandlerHost::UploadStoredLog, |
| 284 logging_handler, local_log_id, callback)); |
280 | 285 |
281 return true; | 286 return true; |
282 } | 287 } |
283 | 288 |
284 bool WebrtcLoggingPrivateUploadFunction::RunAsync() { | 289 bool WebrtcLoggingPrivateUploadFunction::RunAsync() { |
285 std::unique_ptr<Upload::Params> params(Upload::Params::Create(*args_)); | 290 std::unique_ptr<Upload::Params> params(Upload::Params::Create(*args_)); |
286 EXTENSION_FUNCTION_VALIDATE(params.get()); | 291 EXTENSION_FUNCTION_VALIDATE(params.get()); |
287 | 292 |
288 scoped_refptr<WebRtcLoggingHandlerHost> logging_handler( | 293 scoped_refptr<WebRtcLoggingHandlerHost> logging_handler( |
289 LoggingHandlerFromRequest(params->request, params->security_origin)); | 294 LoggingHandlerFromRequest(params->request, params->security_origin)); |
290 if (!logging_handler.get()) | 295 if (!logging_handler.get()) |
291 return false; | 296 return false; |
292 | 297 |
293 WebRtcLoggingHandlerHost::UploadDoneCallback callback = base::Bind( | 298 WebRtcLoggingHandlerHost::UploadDoneCallback callback = base::Bind( |
294 &WebrtcLoggingPrivateUploadFunction::FireCallback, this); | 299 &WebrtcLoggingPrivateUploadFunction::FireCallback, this); |
295 | 300 |
296 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 301 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
297 &WebRtcLoggingHandlerHost::UploadLog, logging_handler, callback)); | 302 base::BindOnce(&WebRtcLoggingHandlerHost::UploadLog, |
| 303 logging_handler, callback)); |
298 | 304 |
299 return true; | 305 return true; |
300 } | 306 } |
301 | 307 |
302 bool WebrtcLoggingPrivateDiscardFunction::RunAsync() { | 308 bool WebrtcLoggingPrivateDiscardFunction::RunAsync() { |
303 std::unique_ptr<Discard::Params> params(Discard::Params::Create(*args_)); | 309 std::unique_ptr<Discard::Params> params(Discard::Params::Create(*args_)); |
304 EXTENSION_FUNCTION_VALIDATE(params.get()); | 310 EXTENSION_FUNCTION_VALIDATE(params.get()); |
305 | 311 |
306 WebRtcLoggingHandlerHost::GenericDoneCallback callback; | 312 WebRtcLoggingHandlerHost::GenericDoneCallback callback; |
307 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = | 313 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = |
308 PrepareTask(params->request, params->security_origin, &callback); | 314 PrepareTask(params->request, params->security_origin, &callback); |
309 if (!webrtc_logging_handler_host.get()) | 315 if (!webrtc_logging_handler_host.get()) |
310 return false; | 316 return false; |
311 | 317 |
312 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 318 BrowserThread::PostTask( |
313 &WebRtcLoggingHandlerHost::DiscardLog, webrtc_logging_handler_host, | 319 BrowserThread::IO, FROM_HERE, |
314 callback)); | 320 base::BindOnce(&WebRtcLoggingHandlerHost::DiscardLog, |
| 321 webrtc_logging_handler_host, callback)); |
315 | 322 |
316 return true; | 323 return true; |
317 } | 324 } |
318 | 325 |
319 bool WebrtcLoggingPrivateStartRtpDumpFunction::RunAsync() { | 326 bool WebrtcLoggingPrivateStartRtpDumpFunction::RunAsync() { |
320 std::unique_ptr<StartRtpDump::Params> params( | 327 std::unique_ptr<StartRtpDump::Params> params( |
321 StartRtpDump::Params::Create(*args_)); | 328 StartRtpDump::Params::Create(*args_)); |
322 EXTENSION_FUNCTION_VALIDATE(params.get()); | 329 EXTENSION_FUNCTION_VALIDATE(params.get()); |
323 | 330 |
324 if (!params->incoming && !params->outgoing) { | 331 if (!params->incoming && !params->outgoing) { |
(...skipping 18 matching lines...) Expand all Loading... |
343 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | 350 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( |
344 &WebrtcLoggingPrivateStartRtpDumpFunction::FireCallback, this); | 351 &WebrtcLoggingPrivateStartRtpDumpFunction::FireCallback, this); |
345 | 352 |
346 // This call cannot fail. | 353 // This call cannot fail. |
347 content::RenderProcessHost::WebRtcStopRtpDumpCallback stop_callback = | 354 content::RenderProcessHost::WebRtcStopRtpDumpCallback stop_callback = |
348 host->StartRtpDump(params->incoming, | 355 host->StartRtpDump(params->incoming, |
349 params->outgoing, | 356 params->outgoing, |
350 base::Bind(&WebRtcLoggingHandlerHost::OnRtpPacket, | 357 base::Bind(&WebRtcLoggingHandlerHost::OnRtpPacket, |
351 webrtc_logging_handler_host)); | 358 webrtc_logging_handler_host)); |
352 | 359 |
353 BrowserThread::PostTask(BrowserThread::IO, | 360 BrowserThread::PostTask( |
354 FROM_HERE, | 361 BrowserThread::IO, FROM_HERE, |
355 base::Bind(&WebRtcLoggingHandlerHost::StartRtpDump, | 362 base::BindOnce(&WebRtcLoggingHandlerHost::StartRtpDump, |
356 webrtc_logging_handler_host, | 363 webrtc_logging_handler_host, type, callback, |
357 type, | 364 stop_callback)); |
358 callback, | |
359 stop_callback)); | |
360 return true; | 365 return true; |
361 } | 366 } |
362 | 367 |
363 bool WebrtcLoggingPrivateStopRtpDumpFunction::RunAsync() { | 368 bool WebrtcLoggingPrivateStopRtpDumpFunction::RunAsync() { |
364 std::unique_ptr<StopRtpDump::Params> params( | 369 std::unique_ptr<StopRtpDump::Params> params( |
365 StopRtpDump::Params::Create(*args_)); | 370 StopRtpDump::Params::Create(*args_)); |
366 EXTENSION_FUNCTION_VALIDATE(params.get()); | 371 EXTENSION_FUNCTION_VALIDATE(params.get()); |
367 | 372 |
368 if (!params->incoming && !params->outgoing) { | 373 if (!params->incoming && !params->outgoing) { |
369 FireCallback(false, "Either incoming or outgoing must be true."); | 374 FireCallback(false, "Either incoming or outgoing must be true."); |
(...skipping 10 matching lines...) Expand all Loading... |
380 if (!host) | 385 if (!host) |
381 return false; | 386 return false; |
382 | 387 |
383 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | 388 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
384 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get( | 389 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get( |
385 host, WebRtcLoggingHandlerHost::kWebRtcLoggingHandlerHostKey)); | 390 host, WebRtcLoggingHandlerHost::kWebRtcLoggingHandlerHostKey)); |
386 | 391 |
387 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | 392 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( |
388 &WebrtcLoggingPrivateStopRtpDumpFunction::FireCallback, this); | 393 &WebrtcLoggingPrivateStopRtpDumpFunction::FireCallback, this); |
389 | 394 |
390 BrowserThread::PostTask(BrowserThread::IO, | 395 BrowserThread::PostTask( |
391 FROM_HERE, | 396 BrowserThread::IO, FROM_HERE, |
392 base::Bind(&WebRtcLoggingHandlerHost::StopRtpDump, | 397 base::BindOnce(&WebRtcLoggingHandlerHost::StopRtpDump, |
393 webrtc_logging_handler_host, | 398 webrtc_logging_handler_host, type, callback)); |
394 type, | |
395 callback)); | |
396 return true; | 399 return true; |
397 } | 400 } |
398 | 401 |
399 bool WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::RunAsync() { | 402 bool WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::RunAsync() { |
400 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 403 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
401 switches::kEnableAudioDebugRecordingsFromExtension)) { | 404 switches::kEnableAudioDebugRecordingsFromExtension)) { |
402 return false; | 405 return false; |
403 } | 406 } |
404 | 407 |
405 std::unique_ptr<StartAudioDebugRecordings::Params> params( | 408 std::unique_ptr<StartAudioDebugRecordings::Params> params( |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 &WebrtcLoggingPrivateStopWebRtcEventLoggingFunction::FireCallback, | 515 &WebrtcLoggingPrivateStopWebRtcEventLoggingFunction::FireCallback, |
513 this), | 516 this), |
514 base::Bind(&WebrtcLoggingPrivateStopWebRtcEventLoggingFunction:: | 517 base::Bind(&WebrtcLoggingPrivateStopWebRtcEventLoggingFunction:: |
515 FireErrorCallback, | 518 FireErrorCallback, |
516 this)); | 519 this)); |
517 | 520 |
518 return true; | 521 return true; |
519 } | 522 } |
520 | 523 |
521 } // namespace extensions | 524 } // namespace extensions |
OLD | NEW |