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

Side by Side Diff: chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.cc

Issue 397743003: Media Galleries: Another round of MTPDeviceDelegateImplLinux cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: grammar Created 6 years, 5 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
« no previous file with comments | « chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/linux/mtp_device_delegate_impl_linux.h" 5 #include "chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 success_callback, 252 success_callback,
253 error_callback), 253 error_callback),
254 base::Bind(&MTPDeviceDelegateImplLinux::HandleDeviceFileError, 254 base::Bind(&MTPDeviceDelegateImplLinux::HandleDeviceFileError,
255 weak_ptr_factory_.GetWeakPtr(), 255 weak_ptr_factory_.GetWeakPtr(),
256 error_callback)); 256 error_callback));
257 EnsureInitAndRunTask(PendingTaskInfo(FROM_HERE, call_closure)); 257 EnsureInitAndRunTask(PendingTaskInfo(FROM_HERE, call_closure));
258 } 258 }
259 259
260 void MTPDeviceDelegateImplLinux::CreateSnapshotFile( 260 void MTPDeviceDelegateImplLinux::CreateSnapshotFile(
261 const base::FilePath& device_file_path, 261 const base::FilePath& device_file_path,
262 const base::FilePath& snapshot_file_path, 262 const base::FilePath& local_path,
263 const CreateSnapshotFileSuccessCallback& success_callback, 263 const CreateSnapshotFileSuccessCallback& success_callback,
264 const ErrorCallback& error_callback) { 264 const ErrorCallback& error_callback) {
265 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 265 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
266 DCHECK(!device_file_path.empty()); 266 DCHECK(!device_file_path.empty());
267 DCHECK(!snapshot_file_path.empty()); 267 DCHECK(!local_path.empty());
268 std::string device_file_relative_path = 268 std::string device_file_relative_path =
269 GetDeviceRelativePath(device_path_, device_file_path); 269 GetDeviceRelativePath(device_path_, device_file_path);
270 scoped_ptr<SnapshotRequestInfo> request_info( 270 scoped_ptr<SnapshotRequestInfo> request_info(
271 new SnapshotRequestInfo(device_file_relative_path, 271 new SnapshotRequestInfo(device_file_relative_path,
272 snapshot_file_path, 272 local_path,
273 success_callback, 273 success_callback,
274 error_callback)); 274 error_callback));
275 base::Closure call_closure = 275 base::Closure call_closure =
276 base::Bind( 276 base::Bind(
277 &GetFileInfoOnUIThread, 277 &GetFileInfoOnUIThread,
278 storage_name_, 278 storage_name_,
279 device_file_relative_path, 279 device_file_relative_path,
280 base::Bind( 280 base::Bind(
281 &MTPDeviceDelegateImplLinux::OnDidGetFileInfoToCreateSnapshotFile, 281 &MTPDeviceDelegateImplLinux::OnDidGetFileInfoToCreateSnapshotFile,
282 weak_ptr_factory_.GetWeakPtr(), 282 weak_ptr_factory_.GetWeakPtr(),
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 base::Bind(&MTPDeviceDelegateImplLinux::OnInitCompleted, 346 base::Bind(&MTPDeviceDelegateImplLinux::OnInitCompleted,
347 weak_ptr_factory_.GetWeakPtr()))); 347 weak_ptr_factory_.GetWeakPtr())));
348 } 348 }
349 } 349 }
350 350
351 void MTPDeviceDelegateImplLinux::WriteDataIntoSnapshotFile( 351 void MTPDeviceDelegateImplLinux::WriteDataIntoSnapshotFile(
352 const base::File::Info& file_info) { 352 const base::File::Info& file_info) {
353 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 353 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
354 DCHECK(current_snapshot_request_info_.get()); 354 DCHECK(current_snapshot_request_info_.get());
355 DCHECK_GT(file_info.size, 0); 355 DCHECK_GT(file_info.size, 0);
356 task_in_progress_ = true; 356 DCHECK(task_in_progress_);
357 SnapshotRequestInfo request_info( 357 SnapshotRequestInfo request_info(
358 current_snapshot_request_info_->device_file_path, 358 current_snapshot_request_info_->device_file_path,
359 current_snapshot_request_info_->snapshot_file_path, 359 current_snapshot_request_info_->snapshot_file_path,
360 base::Bind( 360 base::Bind(
361 &MTPDeviceDelegateImplLinux::OnDidWriteDataIntoSnapshotFile, 361 &MTPDeviceDelegateImplLinux::OnDidWriteDataIntoSnapshotFile,
362 weak_ptr_factory_.GetWeakPtr()), 362 weak_ptr_factory_.GetWeakPtr()),
363 base::Bind( 363 base::Bind(
364 &MTPDeviceDelegateImplLinux::OnWriteDataIntoSnapshotFileError, 364 &MTPDeviceDelegateImplLinux::OnWriteDataIntoSnapshotFileError,
365 weak_ptr_factory_.GetWeakPtr())); 365 weak_ptr_factory_.GetWeakPtr()));
366 366
367 base::Closure task_closure = base::Bind(&WriteDataIntoSnapshotFileOnUIThread, 367 base::Closure task_closure = base::Bind(&WriteDataIntoSnapshotFileOnUIThread,
368 storage_name_, 368 storage_name_,
369 request_info, 369 request_info,
370 file_info); 370 file_info);
371 content::BrowserThread::PostTask(content::BrowserThread::UI, 371 content::BrowserThread::PostTask(content::BrowserThread::UI,
372 FROM_HERE, 372 FROM_HERE,
373 task_closure); 373 task_closure);
374 } 374 }
375 375
376 void MTPDeviceDelegateImplLinux::PendingRequestDone() {
377 DCHECK(task_in_progress_);
378 task_in_progress_ = false;
379 ProcessNextPendingRequest();
380 }
381
376 void MTPDeviceDelegateImplLinux::ProcessNextPendingRequest() { 382 void MTPDeviceDelegateImplLinux::ProcessNextPendingRequest() {
377 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 383 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
378 DCHECK(!task_in_progress_); 384 DCHECK(!task_in_progress_);
379 if (pending_tasks_.empty()) 385 if (pending_tasks_.empty())
380 return; 386 return;
381 387
382 task_in_progress_ = true; 388 task_in_progress_ = true;
383 const PendingTaskInfo& task_info = pending_tasks_.front(); 389 const PendingTaskInfo& task_info = pending_tasks_.front();
384 content::BrowserThread::PostTask(content::BrowserThread::UI, 390 content::BrowserThread::PostTask(content::BrowserThread::UI,
385 task_info.location, 391 task_info.location,
386 task_info.task); 392 task_info.task);
387 pending_tasks_.pop(); 393 pending_tasks_.pop();
388 } 394 }
389 395
390 void MTPDeviceDelegateImplLinux::OnInitCompleted(bool succeeded) { 396 void MTPDeviceDelegateImplLinux::OnInitCompleted(bool succeeded) {
391 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 397 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
392 init_state_ = succeeded ? INITIALIZED : UNINITIALIZED; 398 init_state_ = succeeded ? INITIALIZED : UNINITIALIZED;
393 task_in_progress_ = false; 399 PendingRequestDone();
394 ProcessNextPendingRequest();
395 } 400 }
396 401
397 void MTPDeviceDelegateImplLinux::OnDidGetFileInfo( 402 void MTPDeviceDelegateImplLinux::OnDidGetFileInfo(
398 const GetFileInfoSuccessCallback& success_callback, 403 const GetFileInfoSuccessCallback& success_callback,
399 const base::File::Info& file_info) { 404 const base::File::Info& file_info) {
400 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 405 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
401 success_callback.Run(file_info); 406 success_callback.Run(file_info);
402 task_in_progress_ = false; 407 PendingRequestDone();
403 ProcessNextPendingRequest();
404 } 408 }
405 409
406 void MTPDeviceDelegateImplLinux::OnDidGetFileInfoToReadDirectory( 410 void MTPDeviceDelegateImplLinux::OnDidGetFileInfoToReadDirectory(
407 const std::string& root, 411 const std::string& root,
408 const ReadDirectorySuccessCallback& success_callback, 412 const ReadDirectorySuccessCallback& success_callback,
409 const ErrorCallback& error_callback, 413 const ErrorCallback& error_callback,
410 const base::File::Info& file_info) { 414 const base::File::Info& file_info) {
411 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 415 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
412 DCHECK(task_in_progress_); 416 DCHECK(task_in_progress_);
413 if (!file_info.is_directory) { 417 if (!file_info.is_directory) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 snapshot_file_info, current_snapshot_request_info_->snapshot_file_path); 462 snapshot_file_info, current_snapshot_request_info_->snapshot_file_path);
459 } 463 }
460 WriteDataIntoSnapshotFile(snapshot_file_info); 464 WriteDataIntoSnapshotFile(snapshot_file_info);
461 } 465 }
462 466
463 void MTPDeviceDelegateImplLinux::OnDidReadDirectory( 467 void MTPDeviceDelegateImplLinux::OnDidReadDirectory(
464 const ReadDirectorySuccessCallback& success_callback, 468 const ReadDirectorySuccessCallback& success_callback,
465 const fileapi::AsyncFileUtil::EntryList& file_list) { 469 const fileapi::AsyncFileUtil::EntryList& file_list) {
466 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 470 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
467 success_callback.Run(file_list, false /*no more entries*/); 471 success_callback.Run(file_list, false /*no more entries*/);
468 task_in_progress_ = false; 472 PendingRequestDone();
469 ProcessNextPendingRequest();
470 } 473 }
471 474
472 void MTPDeviceDelegateImplLinux::OnDidWriteDataIntoSnapshotFile( 475 void MTPDeviceDelegateImplLinux::OnDidWriteDataIntoSnapshotFile(
473 const base::File::Info& file_info, 476 const base::File::Info& file_info,
474 const base::FilePath& snapshot_file_path) { 477 const base::FilePath& snapshot_file_path) {
475 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 478 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
476 DCHECK(current_snapshot_request_info_.get()); 479 DCHECK(current_snapshot_request_info_.get());
477 DCHECK(task_in_progress_);
478 current_snapshot_request_info_->success_callback.Run( 480 current_snapshot_request_info_->success_callback.Run(
479 file_info, snapshot_file_path); 481 file_info, snapshot_file_path);
480 task_in_progress_ = false;
481 current_snapshot_request_info_.reset(); 482 current_snapshot_request_info_.reset();
482 ProcessNextPendingRequest(); 483 PendingRequestDone();
483 } 484 }
484 485
485 void MTPDeviceDelegateImplLinux::OnWriteDataIntoSnapshotFileError( 486 void MTPDeviceDelegateImplLinux::OnWriteDataIntoSnapshotFileError(
486 base::File::Error error) { 487 base::File::Error error) {
487 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 488 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
488 DCHECK(current_snapshot_request_info_.get()); 489 DCHECK(current_snapshot_request_info_.get());
489 DCHECK(task_in_progress_);
490 current_snapshot_request_info_->error_callback.Run(error); 490 current_snapshot_request_info_->error_callback.Run(error);
491 task_in_progress_ = false;
492 current_snapshot_request_info_.reset(); 491 current_snapshot_request_info_.reset();
493 ProcessNextPendingRequest(); 492 PendingRequestDone();
494 } 493 }
495 494
496 void MTPDeviceDelegateImplLinux::OnDidReadBytes( 495 void MTPDeviceDelegateImplLinux::OnDidReadBytes(
497 const ReadBytesSuccessCallback& success_callback, 496 const ReadBytesSuccessCallback& success_callback,
498 const base::File::Info& file_info, int bytes_read) { 497 const base::File::Info& file_info, int bytes_read) {
499 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 498 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
500 DCHECK(task_in_progress_);
501 success_callback.Run(file_info, bytes_read); 499 success_callback.Run(file_info, bytes_read);
502 task_in_progress_ = false; 500 PendingRequestDone();
503 ProcessNextPendingRequest();
504 } 501 }
505 502
506 void MTPDeviceDelegateImplLinux::HandleDeviceFileError( 503 void MTPDeviceDelegateImplLinux::HandleDeviceFileError(
507 const ErrorCallback& error_callback, 504 const ErrorCallback& error_callback,
508 base::File::Error error) { 505 base::File::Error error) {
509 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 506 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
510 DCHECK(task_in_progress_);
511 error_callback.Run(error); 507 error_callback.Run(error);
512 task_in_progress_ = false; 508 PendingRequestDone();
513 ProcessNextPendingRequest();
514 } 509 }
515 510
516 void CreateMTPDeviceAsyncDelegate( 511 void CreateMTPDeviceAsyncDelegate(
517 const std::string& device_location, 512 const std::string& device_location,
518 const CreateMTPDeviceAsyncDelegateCallback& callback) { 513 const CreateMTPDeviceAsyncDelegateCallback& callback) {
519 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 514 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
520 callback.Run(new MTPDeviceDelegateImplLinux(device_location)); 515 callback.Run(new MTPDeviceDelegateImplLinux(device_location));
521 } 516 }
OLDNEW
« no previous file with comments | « chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698