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

Side by Side Diff: chrome/browser/chromeos/drive/file_system.cc

Issue 1036723003: favor DCHECK_CURRENTLY_ON for better logs in chrome/browser/chromeos/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 (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/chromeos/drive/file_system.h" 5 #include "chrome/browser/chromeos/drive/file_system.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/chromeos/drive/change_list_loader.h" 10 #include "chrome/browser/chromeos/drive/change_list_loader.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 return FILE_ERROR_NOT_FOUND; 83 return FILE_ERROR_NOT_FOUND;
84 84
85 entry->mutable_file_info()->set_size(file_info.size); 85 entry->mutable_file_info()->set_size(file_info.size);
86 return FILE_ERROR_OK; 86 return FILE_ERROR_OK;
87 } 87 }
88 88
89 // Runs the callback with parameters. 89 // Runs the callback with parameters.
90 void RunGetResourceEntryCallback(const GetResourceEntryCallback& callback, 90 void RunGetResourceEntryCallback(const GetResourceEntryCallback& callback,
91 scoped_ptr<ResourceEntry> entry, 91 scoped_ptr<ResourceEntry> entry,
92 FileError error) { 92 FileError error) {
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 93 DCHECK_CURRENTLY_ON(BrowserThread::UI);
94 DCHECK(!callback.is_null()); 94 DCHECK(!callback.is_null());
95 95
96 if (error != FILE_ERROR_OK) 96 if (error != FILE_ERROR_OK)
97 entry.reset(); 97 entry.reset();
98 callback.Run(error, entry.Pass()); 98 callback.Run(error, entry.Pass());
99 } 99 }
100 100
101 // Used to implement Pin(). 101 // Used to implement Pin().
102 FileError PinInternal(internal::ResourceMetadata* resource_metadata, 102 FileError PinInternal(internal::ResourceMetadata* resource_metadata,
103 internal::FileCache* cache, 103 internal::FileCache* cache,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 callback.Run(error, *cache_file_path); 153 callback.Run(error, *cache_file_path);
154 } 154 }
155 155
156 // Callback for ResourceMetadata::GetLargestChangestamp. 156 // Callback for ResourceMetadata::GetLargestChangestamp.
157 // |callback| must not be null. 157 // |callback| must not be null.
158 void OnGetLargestChangestamp( 158 void OnGetLargestChangestamp(
159 FileSystemMetadata metadata, // Will be modified. 159 FileSystemMetadata metadata, // Will be modified.
160 const GetFilesystemMetadataCallback& callback, 160 const GetFilesystemMetadataCallback& callback,
161 const int64* largest_changestamp, 161 const int64* largest_changestamp,
162 FileError error) { 162 FileError error) {
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 163 DCHECK_CURRENTLY_ON(BrowserThread::UI);
164 DCHECK(!callback.is_null()); 164 DCHECK(!callback.is_null());
165 165
166 metadata.largest_changestamp = *largest_changestamp; 166 metadata.largest_changestamp = *largest_changestamp;
167 callback.Run(metadata); 167 callback.Run(metadata);
168 } 168 }
169 169
170 // Thin adapter to map GetFileCallback to FileOperationCallback. 170 // Thin adapter to map GetFileCallback to FileOperationCallback.
171 void GetFileCallbackToFileOperationCallbackAdapter( 171 void GetFileCallbackToFileOperationCallbackAdapter(
172 const FileOperationCallback& callback, 172 const FileOperationCallback& callback,
173 FileError error, 173 FileError error,
(...skipping 24 matching lines...) Expand all
198 if (error != FILE_ERROR_OK) 198 if (error != FILE_ERROR_OK)
199 return error; 199 return error;
200 return resource_metadata->GetFilePath(local_id, file_path); 200 return resource_metadata->GetFilePath(local_id, file_path);
201 } 201 }
202 202
203 // Part of GetPathFromResourceId(). 203 // Part of GetPathFromResourceId().
204 // Called when GetPathFromResourceIdInBlockingPool is complete. 204 // Called when GetPathFromResourceIdInBlockingPool is complete.
205 void GetPathFromResourceIdAfterGetPath(base::FilePath* file_path, 205 void GetPathFromResourceIdAfterGetPath(base::FilePath* file_path,
206 const GetFilePathCallback& callback, 206 const GetFilePathCallback& callback,
207 FileError error) { 207 FileError error) {
208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 208 DCHECK_CURRENTLY_ON(BrowserThread::UI);
209 callback.Run(error, *file_path); 209 callback.Run(error, *file_path);
210 } 210 }
211 211
212 bool FreeDiskSpaceIfNeededForOnBlockingPool(internal::FileCache* cache, 212 bool FreeDiskSpaceIfNeededForOnBlockingPool(internal::FileCache* cache,
213 int64 num_bytes) { 213 int64 num_bytes) {
214 return cache->FreeDiskSpaceIfNeededFor(num_bytes); 214 return cache->FreeDiskSpaceIfNeededFor(num_bytes);
215 } 215 }
216 216
217 // Excludes hosted documents from the given entries. 217 // Excludes hosted documents from the given entries.
218 // Used to implement ReadDirectory(). 218 // Used to implement ReadDirectory().
219 void FilterHostedDocuments(const ReadDirectoryEntriesCallback& callback, 219 void FilterHostedDocuments(const ReadDirectoryEntriesCallback& callback,
220 scoped_ptr<ResourceEntryVector> entries) { 220 scoped_ptr<ResourceEntryVector> entries) {
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 221 DCHECK_CURRENTLY_ON(BrowserThread::UI);
222 DCHECK(!callback.is_null()); 222 DCHECK(!callback.is_null());
223 223
224 if (entries) { 224 if (entries) {
225 // TODO(kinaba): Stop handling hide_hosted_docs here. crbug.com/256520. 225 // TODO(kinaba): Stop handling hide_hosted_docs here. crbug.com/256520.
226 scoped_ptr<ResourceEntryVector> filtered(new ResourceEntryVector); 226 scoped_ptr<ResourceEntryVector> filtered(new ResourceEntryVector);
227 for (size_t i = 0; i < entries->size(); ++i) { 227 for (size_t i = 0; i < entries->size(); ++i) {
228 if (entries->at(i).file_specific_info().is_hosted_document()) { 228 if (entries->at(i).file_specific_info().is_hosted_document()) {
229 continue; 229 continue;
230 } 230 }
231 filtered->push_back(entries->at(i)); 231 filtered->push_back(entries->at(i));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 const base::FilePath& temporary_file_directory) 287 const base::FilePath& temporary_file_directory)
288 : pref_service_(pref_service), 288 : pref_service_(pref_service),
289 logger_(logger), 289 logger_(logger),
290 cache_(cache), 290 cache_(cache),
291 scheduler_(scheduler), 291 scheduler_(scheduler),
292 resource_metadata_(resource_metadata), 292 resource_metadata_(resource_metadata),
293 last_update_check_error_(FILE_ERROR_OK), 293 last_update_check_error_(FILE_ERROR_OK),
294 blocking_task_runner_(blocking_task_runner), 294 blocking_task_runner_(blocking_task_runner),
295 temporary_file_directory_(temporary_file_directory), 295 temporary_file_directory_(temporary_file_directory),
296 weak_ptr_factory_(this) { 296 weak_ptr_factory_(this) {
297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 297 DCHECK_CURRENTLY_ON(BrowserThread::UI);
298 298
299 ResetComponents(); 299 ResetComponents();
300 } 300 }
301 301
302 FileSystem::~FileSystem() { 302 FileSystem::~FileSystem() {
303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 303 DCHECK_CURRENTLY_ON(BrowserThread::UI);
304 304
305 directory_loader_->RemoveObserver(this); 305 directory_loader_->RemoveObserver(this);
306 change_list_loader_->RemoveObserver(this); 306 change_list_loader_->RemoveObserver(this);
307 } 307 }
308 308
309 void FileSystem::Reset(const FileOperationCallback& callback) { 309 void FileSystem::Reset(const FileOperationCallback& callback) {
310 // Discard the current loader and operation objects and renew them. This is to 310 // Discard the current loader and operation objects and renew them. This is to
311 // avoid that changes initiated before the metadata reset is applied after the 311 // avoid that changes initiated before the metadata reset is applied after the
312 // reset, which may cause an inconsistent state. 312 // reset, which may cause an inconsistent state.
313 // TODO(kinaba): callbacks held in the subcomponents are discarded. We might 313 // TODO(kinaba): callbacks held in the subcomponents are discarded. We might
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 delegate, 404 delegate,
405 scheduler_, 405 scheduler_,
406 resource_metadata_, 406 resource_metadata_,
407 cache_, 407 cache_,
408 temporary_file_directory_)); 408 temporary_file_directory_));
409 set_property_operation_.reset(new file_system::SetPropertyOperation( 409 set_property_operation_.reset(new file_system::SetPropertyOperation(
410 blocking_task_runner_.get(), delegate, resource_metadata_)); 410 blocking_task_runner_.get(), delegate, resource_metadata_));
411 } 411 }
412 412
413 void FileSystem::CheckForUpdates() { 413 void FileSystem::CheckForUpdates() {
414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 414 DCHECK_CURRENTLY_ON(BrowserThread::UI);
415 DVLOG(1) << "CheckForUpdates"; 415 DVLOG(1) << "CheckForUpdates";
416 416
417 change_list_loader_->CheckForUpdates( 417 change_list_loader_->CheckForUpdates(
418 base::Bind(&FileSystem::OnUpdateChecked, weak_ptr_factory_.GetWeakPtr())); 418 base::Bind(&FileSystem::OnUpdateChecked, weak_ptr_factory_.GetWeakPtr()));
419 } 419 }
420 420
421 void FileSystem::OnUpdateChecked(FileError error) { 421 void FileSystem::OnUpdateChecked(FileError error) {
422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 422 DCHECK_CURRENTLY_ON(BrowserThread::UI);
423 DVLOG(1) << "CheckForUpdates finished: " << FileErrorToString(error); 423 DVLOG(1) << "CheckForUpdates finished: " << FileErrorToString(error);
424 last_update_check_time_ = base::Time::Now(); 424 last_update_check_time_ = base::Time::Now();
425 last_update_check_error_ = error; 425 last_update_check_error_ = error;
426 } 426 }
427 427
428 void FileSystem::AddObserver(FileSystemObserver* observer) { 428 void FileSystem::AddObserver(FileSystemObserver* observer) {
429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 429 DCHECK_CURRENTLY_ON(BrowserThread::UI);
430 observers_.AddObserver(observer); 430 observers_.AddObserver(observer);
431 } 431 }
432 432
433 void FileSystem::RemoveObserver(FileSystemObserver* observer) { 433 void FileSystem::RemoveObserver(FileSystemObserver* observer) {
434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 434 DCHECK_CURRENTLY_ON(BrowserThread::UI);
435 observers_.RemoveObserver(observer); 435 observers_.RemoveObserver(observer);
436 } 436 }
437 437
438 void FileSystem::TransferFileFromLocalToRemote( 438 void FileSystem::TransferFileFromLocalToRemote(
439 const base::FilePath& local_src_file_path, 439 const base::FilePath& local_src_file_path,
440 const base::FilePath& remote_dest_file_path, 440 const base::FilePath& remote_dest_file_path,
441 const FileOperationCallback& callback) { 441 const FileOperationCallback& callback) {
442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 442 DCHECK_CURRENTLY_ON(BrowserThread::UI);
443 DCHECK(!callback.is_null()); 443 DCHECK(!callback.is_null());
444 copy_operation_->TransferFileFromLocalToRemote(local_src_file_path, 444 copy_operation_->TransferFileFromLocalToRemote(local_src_file_path,
445 remote_dest_file_path, 445 remote_dest_file_path,
446 callback); 446 callback);
447 } 447 }
448 448
449 void FileSystem::Copy(const base::FilePath& src_file_path, 449 void FileSystem::Copy(const base::FilePath& src_file_path,
450 const base::FilePath& dest_file_path, 450 const base::FilePath& dest_file_path,
451 bool preserve_last_modified, 451 bool preserve_last_modified,
452 const FileOperationCallback& callback) { 452 const FileOperationCallback& callback) {
453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 453 DCHECK_CURRENTLY_ON(BrowserThread::UI);
454 DCHECK(!callback.is_null()); 454 DCHECK(!callback.is_null());
455 copy_operation_->Copy( 455 copy_operation_->Copy(
456 src_file_path, dest_file_path, preserve_last_modified, callback); 456 src_file_path, dest_file_path, preserve_last_modified, callback);
457 } 457 }
458 458
459 void FileSystem::Move(const base::FilePath& src_file_path, 459 void FileSystem::Move(const base::FilePath& src_file_path,
460 const base::FilePath& dest_file_path, 460 const base::FilePath& dest_file_path,
461 const FileOperationCallback& callback) { 461 const FileOperationCallback& callback) {
462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 462 DCHECK_CURRENTLY_ON(BrowserThread::UI);
463 DCHECK(!callback.is_null()); 463 DCHECK(!callback.is_null());
464 move_operation_->Move(src_file_path, dest_file_path, callback); 464 move_operation_->Move(src_file_path, dest_file_path, callback);
465 } 465 }
466 466
467 void FileSystem::Remove(const base::FilePath& file_path, 467 void FileSystem::Remove(const base::FilePath& file_path,
468 bool is_recursive, 468 bool is_recursive,
469 const FileOperationCallback& callback) { 469 const FileOperationCallback& callback) {
470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 470 DCHECK_CURRENTLY_ON(BrowserThread::UI);
471 DCHECK(!callback.is_null()); 471 DCHECK(!callback.is_null());
472 remove_operation_->Remove(file_path, is_recursive, callback); 472 remove_operation_->Remove(file_path, is_recursive, callback);
473 } 473 }
474 474
475 void FileSystem::CreateDirectory( 475 void FileSystem::CreateDirectory(
476 const base::FilePath& directory_path, 476 const base::FilePath& directory_path,
477 bool is_exclusive, 477 bool is_exclusive,
478 bool is_recursive, 478 bool is_recursive,
479 const FileOperationCallback& callback) { 479 const FileOperationCallback& callback) {
480 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 480 DCHECK_CURRENTLY_ON(BrowserThread::UI);
481 DCHECK(!callback.is_null()); 481 DCHECK(!callback.is_null());
482 482
483 CreateDirectoryParams params; 483 CreateDirectoryParams params;
484 params.directory_path = directory_path; 484 params.directory_path = directory_path;
485 params.is_exclusive = is_exclusive; 485 params.is_exclusive = is_exclusive;
486 params.is_recursive = is_recursive; 486 params.is_recursive = is_recursive;
487 params.callback = callback; 487 params.callback = callback;
488 488
489 // Ensure its parent directory is loaded to the local metadata. 489 // Ensure its parent directory is loaded to the local metadata.
490 ReadDirectory(directory_path.DirName(), 490 ReadDirectory(directory_path.DirName(),
491 ReadDirectoryEntriesCallback(), 491 ReadDirectoryEntriesCallback(),
492 base::Bind(&FileSystem::CreateDirectoryAfterRead, 492 base::Bind(&FileSystem::CreateDirectoryAfterRead,
493 weak_ptr_factory_.GetWeakPtr(), params)); 493 weak_ptr_factory_.GetWeakPtr(), params));
494 } 494 }
495 495
496 void FileSystem::CreateDirectoryAfterRead(const CreateDirectoryParams& params, 496 void FileSystem::CreateDirectoryAfterRead(const CreateDirectoryParams& params,
497 FileError error) { 497 FileError error) {
498 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 498 DCHECK_CURRENTLY_ON(BrowserThread::UI);
499 DCHECK(!params.callback.is_null()); 499 DCHECK(!params.callback.is_null());
500 500
501 DVLOG_IF(1, error != FILE_ERROR_OK) << "ReadDirectory failed. " 501 DVLOG_IF(1, error != FILE_ERROR_OK) << "ReadDirectory failed. "
502 << FileErrorToString(error); 502 << FileErrorToString(error);
503 503
504 create_directory_operation_->CreateDirectory( 504 create_directory_operation_->CreateDirectory(
505 params.directory_path, params.is_exclusive, params.is_recursive, 505 params.directory_path, params.is_exclusive, params.is_recursive,
506 params.callback); 506 params.callback);
507 } 507 }
508 508
509 void FileSystem::CreateFile(const base::FilePath& file_path, 509 void FileSystem::CreateFile(const base::FilePath& file_path,
510 bool is_exclusive, 510 bool is_exclusive,
511 const std::string& mime_type, 511 const std::string& mime_type,
512 const FileOperationCallback& callback) { 512 const FileOperationCallback& callback) {
513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 513 DCHECK_CURRENTLY_ON(BrowserThread::UI);
514 DCHECK(!callback.is_null()); 514 DCHECK(!callback.is_null());
515 create_file_operation_->CreateFile( 515 create_file_operation_->CreateFile(
516 file_path, is_exclusive, mime_type, callback); 516 file_path, is_exclusive, mime_type, callback);
517 } 517 }
518 518
519 void FileSystem::TouchFile(const base::FilePath& file_path, 519 void FileSystem::TouchFile(const base::FilePath& file_path,
520 const base::Time& last_access_time, 520 const base::Time& last_access_time,
521 const base::Time& last_modified_time, 521 const base::Time& last_modified_time,
522 const FileOperationCallback& callback) { 522 const FileOperationCallback& callback) {
523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 523 DCHECK_CURRENTLY_ON(BrowserThread::UI);
524 DCHECK(!callback.is_null()); 524 DCHECK(!callback.is_null());
525 touch_operation_->TouchFile( 525 touch_operation_->TouchFile(
526 file_path, last_access_time, last_modified_time, callback); 526 file_path, last_access_time, last_modified_time, callback);
527 } 527 }
528 528
529 void FileSystem::TruncateFile(const base::FilePath& file_path, 529 void FileSystem::TruncateFile(const base::FilePath& file_path,
530 int64 length, 530 int64 length,
531 const FileOperationCallback& callback) { 531 const FileOperationCallback& callback) {
532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 532 DCHECK_CURRENTLY_ON(BrowserThread::UI);
533 DCHECK(!callback.is_null()); 533 DCHECK(!callback.is_null());
534 truncate_operation_->Truncate(file_path, length, callback); 534 truncate_operation_->Truncate(file_path, length, callback);
535 } 535 }
536 536
537 void FileSystem::Pin(const base::FilePath& file_path, 537 void FileSystem::Pin(const base::FilePath& file_path,
538 const FileOperationCallback& callback) { 538 const FileOperationCallback& callback) {
539 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 539 DCHECK_CURRENTLY_ON(BrowserThread::UI);
540 DCHECK(!callback.is_null()); 540 DCHECK(!callback.is_null());
541 541
542 std::string* local_id = new std::string; 542 std::string* local_id = new std::string;
543 base::PostTaskAndReplyWithResult( 543 base::PostTaskAndReplyWithResult(
544 blocking_task_runner_.get(), 544 blocking_task_runner_.get(),
545 FROM_HERE, 545 FROM_HERE,
546 base::Bind(&PinInternal, resource_metadata_, cache_, file_path, local_id), 546 base::Bind(&PinInternal, resource_metadata_, cache_, file_path, local_id),
547 base::Bind(&FileSystem::FinishPin, 547 base::Bind(&FileSystem::FinishPin,
548 weak_ptr_factory_.GetWeakPtr(), 548 weak_ptr_factory_.GetWeakPtr(),
549 callback, 549 callback,
550 base::Owned(local_id))); 550 base::Owned(local_id)));
551 } 551 }
552 552
553 void FileSystem::FinishPin(const FileOperationCallback& callback, 553 void FileSystem::FinishPin(const FileOperationCallback& callback,
554 const std::string* local_id, 554 const std::string* local_id,
555 FileError error) { 555 FileError error) {
556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 556 DCHECK_CURRENTLY_ON(BrowserThread::UI);
557 DCHECK(!callback.is_null()); 557 DCHECK(!callback.is_null());
558 558
559 if (error == FILE_ERROR_OK) 559 if (error == FILE_ERROR_OK)
560 sync_client_->AddFetchTask(*local_id); 560 sync_client_->AddFetchTask(*local_id);
561 callback.Run(error); 561 callback.Run(error);
562 } 562 }
563 563
564 void FileSystem::Unpin(const base::FilePath& file_path, 564 void FileSystem::Unpin(const base::FilePath& file_path,
565 const FileOperationCallback& callback) { 565 const FileOperationCallback& callback) {
566 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 566 DCHECK_CURRENTLY_ON(BrowserThread::UI);
567 DCHECK(!callback.is_null()); 567 DCHECK(!callback.is_null());
568 568
569 std::string* local_id = new std::string; 569 std::string* local_id = new std::string;
570 base::PostTaskAndReplyWithResult( 570 base::PostTaskAndReplyWithResult(
571 blocking_task_runner_.get(), 571 blocking_task_runner_.get(),
572 FROM_HERE, 572 FROM_HERE,
573 base::Bind( 573 base::Bind(
574 &UnpinInternal, resource_metadata_, cache_, file_path, local_id), 574 &UnpinInternal, resource_metadata_, cache_, file_path, local_id),
575 base::Bind(&FileSystem::FinishUnpin, 575 base::Bind(&FileSystem::FinishUnpin,
576 weak_ptr_factory_.GetWeakPtr(), 576 weak_ptr_factory_.GetWeakPtr(),
577 callback, 577 callback,
578 base::Owned(local_id))); 578 base::Owned(local_id)));
579 } 579 }
580 580
581 void FileSystem::FinishUnpin(const FileOperationCallback& callback, 581 void FileSystem::FinishUnpin(const FileOperationCallback& callback,
582 const std::string* local_id, 582 const std::string* local_id,
583 FileError error) { 583 FileError error) {
584 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 584 DCHECK_CURRENTLY_ON(BrowserThread::UI);
585 DCHECK(!callback.is_null()); 585 DCHECK(!callback.is_null());
586 586
587 if (error == FILE_ERROR_OK) 587 if (error == FILE_ERROR_OK)
588 sync_client_->RemoveFetchTask(*local_id); 588 sync_client_->RemoveFetchTask(*local_id);
589 callback.Run(error); 589 callback.Run(error);
590 } 590 }
591 591
592 void FileSystem::GetFile(const base::FilePath& file_path, 592 void FileSystem::GetFile(const base::FilePath& file_path,
593 const GetFileCallback& callback) { 593 const GetFileCallback& callback) {
594 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 594 DCHECK_CURRENTLY_ON(BrowserThread::UI);
595 DCHECK(!callback.is_null()); 595 DCHECK(!callback.is_null());
596 596
597 download_operation_->EnsureFileDownloadedByPath( 597 download_operation_->EnsureFileDownloadedByPath(
598 file_path, 598 file_path,
599 ClientContext(USER_INITIATED), 599 ClientContext(USER_INITIATED),
600 GetFileContentInitializedCallback(), 600 GetFileContentInitializedCallback(),
601 google_apis::GetContentCallback(), 601 google_apis::GetContentCallback(),
602 callback); 602 callback);
603 } 603 }
604 604
605 void FileSystem::GetFileForSaving(const base::FilePath& file_path, 605 void FileSystem::GetFileForSaving(const base::FilePath& file_path,
606 const GetFileCallback& callback) { 606 const GetFileCallback& callback) {
607 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 607 DCHECK_CURRENTLY_ON(BrowserThread::UI);
608 DCHECK(!callback.is_null()); 608 DCHECK(!callback.is_null());
609 609
610 get_file_for_saving_operation_->GetFileForSaving(file_path, callback); 610 get_file_for_saving_operation_->GetFileForSaving(file_path, callback);
611 } 611 }
612 612
613 base::Closure FileSystem::GetFileContent( 613 base::Closure FileSystem::GetFileContent(
614 const base::FilePath& file_path, 614 const base::FilePath& file_path,
615 const GetFileContentInitializedCallback& initialized_callback, 615 const GetFileContentInitializedCallback& initialized_callback,
616 const google_apis::GetContentCallback& get_content_callback, 616 const google_apis::GetContentCallback& get_content_callback,
617 const FileOperationCallback& completion_callback) { 617 const FileOperationCallback& completion_callback) {
618 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 618 DCHECK_CURRENTLY_ON(BrowserThread::UI);
619 DCHECK(!initialized_callback.is_null()); 619 DCHECK(!initialized_callback.is_null());
620 DCHECK(!get_content_callback.is_null()); 620 DCHECK(!get_content_callback.is_null());
621 DCHECK(!completion_callback.is_null()); 621 DCHECK(!completion_callback.is_null());
622 622
623 return download_operation_->EnsureFileDownloadedByPath( 623 return download_operation_->EnsureFileDownloadedByPath(
624 file_path, 624 file_path,
625 ClientContext(USER_INITIATED), 625 ClientContext(USER_INITIATED),
626 initialized_callback, 626 initialized_callback,
627 get_content_callback, 627 get_content_callback,
628 base::Bind(&GetFileCallbackToFileOperationCallbackAdapter, 628 base::Bind(&GetFileCallbackToFileOperationCallbackAdapter,
629 completion_callback)); 629 completion_callback));
630 } 630 }
631 631
632 void FileSystem::GetResourceEntry( 632 void FileSystem::GetResourceEntry(
633 const base::FilePath& file_path, 633 const base::FilePath& file_path,
634 const GetResourceEntryCallback& callback) { 634 const GetResourceEntryCallback& callback) {
635 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 635 DCHECK_CURRENTLY_ON(BrowserThread::UI);
636 DCHECK(!callback.is_null()); 636 DCHECK(!callback.is_null());
637 637
638 ReadDirectory(file_path.DirName(), 638 ReadDirectory(file_path.DirName(),
639 ReadDirectoryEntriesCallback(), 639 ReadDirectoryEntriesCallback(),
640 base::Bind(&FileSystem::GetResourceEntryAfterRead, 640 base::Bind(&FileSystem::GetResourceEntryAfterRead,
641 weak_ptr_factory_.GetWeakPtr(), 641 weak_ptr_factory_.GetWeakPtr(),
642 file_path, 642 file_path,
643 callback)); 643 callback));
644 } 644 }
645 645
646 void FileSystem::GetResourceEntryAfterRead( 646 void FileSystem::GetResourceEntryAfterRead(
647 const base::FilePath& file_path, 647 const base::FilePath& file_path,
648 const GetResourceEntryCallback& callback, 648 const GetResourceEntryCallback& callback,
649 FileError error) { 649 FileError error) {
650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 650 DCHECK_CURRENTLY_ON(BrowserThread::UI);
651 DCHECK(!callback.is_null()); 651 DCHECK(!callback.is_null());
652 652
653 DVLOG_IF(1, error != FILE_ERROR_OK) << "ReadDirectory failed. " 653 DVLOG_IF(1, error != FILE_ERROR_OK) << "ReadDirectory failed. "
654 << FileErrorToString(error); 654 << FileErrorToString(error);
655 655
656 scoped_ptr<ResourceEntry> entry(new ResourceEntry); 656 scoped_ptr<ResourceEntry> entry(new ResourceEntry);
657 ResourceEntry* entry_ptr = entry.get(); 657 ResourceEntry* entry_ptr = entry.get();
658 base::PostTaskAndReplyWithResult( 658 base::PostTaskAndReplyWithResult(
659 blocking_task_runner_.get(), 659 blocking_task_runner_.get(),
660 FROM_HERE, 660 FROM_HERE,
661 base::Bind(&GetLocallyStoredResourceEntry, 661 base::Bind(&GetLocallyStoredResourceEntry,
662 resource_metadata_, 662 resource_metadata_,
663 cache_, 663 cache_,
664 file_path, 664 file_path,
665 entry_ptr), 665 entry_ptr),
666 base::Bind(&RunGetResourceEntryCallback, callback, base::Passed(&entry))); 666 base::Bind(&RunGetResourceEntryCallback, callback, base::Passed(&entry)));
667 } 667 }
668 668
669 void FileSystem::ReadDirectory( 669 void FileSystem::ReadDirectory(
670 const base::FilePath& directory_path, 670 const base::FilePath& directory_path,
671 const ReadDirectoryEntriesCallback& entries_callback_in, 671 const ReadDirectoryEntriesCallback& entries_callback_in,
672 const FileOperationCallback& completion_callback) { 672 const FileOperationCallback& completion_callback) {
673 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 673 DCHECK_CURRENTLY_ON(BrowserThread::UI);
674 DCHECK(!completion_callback.is_null()); 674 DCHECK(!completion_callback.is_null());
675 675
676 const bool hide_hosted_docs = 676 const bool hide_hosted_docs =
677 pref_service_->GetBoolean(prefs::kDisableDriveHostedFiles); 677 pref_service_->GetBoolean(prefs::kDisableDriveHostedFiles);
678 ReadDirectoryEntriesCallback entries_callback = entries_callback_in; 678 ReadDirectoryEntriesCallback entries_callback = entries_callback_in;
679 if (!entries_callback.is_null() && hide_hosted_docs) 679 if (!entries_callback.is_null() && hide_hosted_docs)
680 entries_callback = base::Bind(&FilterHostedDocuments, entries_callback); 680 entries_callback = base::Bind(&FilterHostedDocuments, entries_callback);
681 681
682 directory_loader_->ReadDirectory( 682 directory_loader_->ReadDirectory(
683 directory_path, entries_callback, completion_callback); 683 directory_path, entries_callback, completion_callback);
684 684
685 // Also start loading all of the user's contents. 685 // Also start loading all of the user's contents.
686 change_list_loader_->LoadIfNeeded( 686 change_list_loader_->LoadIfNeeded(
687 base::Bind(&util::EmptyFileOperationCallback)); 687 base::Bind(&util::EmptyFileOperationCallback));
688 } 688 }
689 689
690 void FileSystem::GetAvailableSpace( 690 void FileSystem::GetAvailableSpace(
691 const GetAvailableSpaceCallback& callback) { 691 const GetAvailableSpaceCallback& callback) {
692 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 692 DCHECK_CURRENTLY_ON(BrowserThread::UI);
693 DCHECK(!callback.is_null()); 693 DCHECK(!callback.is_null());
694 694
695 about_resource_loader_->GetAboutResource( 695 about_resource_loader_->GetAboutResource(
696 base::Bind(&FileSystem::OnGetAboutResource, 696 base::Bind(&FileSystem::OnGetAboutResource,
697 weak_ptr_factory_.GetWeakPtr(), 697 weak_ptr_factory_.GetWeakPtr(),
698 callback)); 698 callback));
699 } 699 }
700 700
701 void FileSystem::OnGetAboutResource( 701 void FileSystem::OnGetAboutResource(
702 const GetAvailableSpaceCallback& callback, 702 const GetAvailableSpaceCallback& callback,
703 google_apis::DriveApiErrorCode status, 703 google_apis::DriveApiErrorCode status,
704 scoped_ptr<google_apis::AboutResource> about_resource) { 704 scoped_ptr<google_apis::AboutResource> about_resource) {
705 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 705 DCHECK_CURRENTLY_ON(BrowserThread::UI);
706 DCHECK(!callback.is_null()); 706 DCHECK(!callback.is_null());
707 707
708 FileError error = GDataToFileError(status); 708 FileError error = GDataToFileError(status);
709 if (error != FILE_ERROR_OK) { 709 if (error != FILE_ERROR_OK) {
710 callback.Run(error, -1, -1); 710 callback.Run(error, -1, -1);
711 return; 711 return;
712 } 712 }
713 DCHECK(about_resource); 713 DCHECK(about_resource);
714 714
715 callback.Run(FILE_ERROR_OK, 715 callback.Run(FILE_ERROR_OK,
716 about_resource->quota_bytes_total(), 716 about_resource->quota_bytes_total(),
717 about_resource->quota_bytes_used()); 717 about_resource->quota_bytes_used());
718 } 718 }
719 719
720 void FileSystem::GetShareUrl(const base::FilePath& file_path, 720 void FileSystem::GetShareUrl(const base::FilePath& file_path,
721 const GURL& embed_origin, 721 const GURL& embed_origin,
722 const GetShareUrlCallback& callback) { 722 const GetShareUrlCallback& callback) {
723 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 723 DCHECK_CURRENTLY_ON(BrowserThread::UI);
724 DCHECK(!callback.is_null()); 724 DCHECK(!callback.is_null());
725 725
726 // Resolve the resource id. 726 // Resolve the resource id.
727 ResourceEntry* entry = new ResourceEntry; 727 ResourceEntry* entry = new ResourceEntry;
728 base::PostTaskAndReplyWithResult( 728 base::PostTaskAndReplyWithResult(
729 blocking_task_runner_.get(), 729 blocking_task_runner_.get(),
730 FROM_HERE, 730 FROM_HERE,
731 base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath, 731 base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath,
732 base::Unretained(resource_metadata_), 732 base::Unretained(resource_metadata_),
733 file_path, 733 file_path,
734 entry), 734 entry),
735 base::Bind(&FileSystem::GetShareUrlAfterGetResourceEntry, 735 base::Bind(&FileSystem::GetShareUrlAfterGetResourceEntry,
736 weak_ptr_factory_.GetWeakPtr(), 736 weak_ptr_factory_.GetWeakPtr(),
737 file_path, 737 file_path,
738 embed_origin, 738 embed_origin,
739 callback, 739 callback,
740 base::Owned(entry))); 740 base::Owned(entry)));
741 } 741 }
742 742
743 void FileSystem::GetShareUrlAfterGetResourceEntry( 743 void FileSystem::GetShareUrlAfterGetResourceEntry(
744 const base::FilePath& file_path, 744 const base::FilePath& file_path,
745 const GURL& embed_origin, 745 const GURL& embed_origin,
746 const GetShareUrlCallback& callback, 746 const GetShareUrlCallback& callback,
747 ResourceEntry* entry, 747 ResourceEntry* entry,
748 FileError error) { 748 FileError error) {
749 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 749 DCHECK_CURRENTLY_ON(BrowserThread::UI);
750 DCHECK(!callback.is_null()); 750 DCHECK(!callback.is_null());
751 751
752 if (error != FILE_ERROR_OK) { 752 if (error != FILE_ERROR_OK) {
753 callback.Run(error, GURL()); 753 callback.Run(error, GURL());
754 return; 754 return;
755 } 755 }
756 if (entry->resource_id().empty()) { 756 if (entry->resource_id().empty()) {
757 // This entry does not exist on the server. Just return. 757 // This entry does not exist on the server. Just return.
758 callback.Run(FILE_ERROR_FAILED, GURL()); 758 callback.Run(FILE_ERROR_FAILED, GURL());
759 return; 759 return;
760 } 760 }
761 761
762 scheduler_->GetShareUrl( 762 scheduler_->GetShareUrl(
763 entry->resource_id(), 763 entry->resource_id(),
764 embed_origin, 764 embed_origin,
765 ClientContext(USER_INITIATED), 765 ClientContext(USER_INITIATED),
766 base::Bind(&FileSystem::OnGetResourceEntryForGetShareUrl, 766 base::Bind(&FileSystem::OnGetResourceEntryForGetShareUrl,
767 weak_ptr_factory_.GetWeakPtr(), 767 weak_ptr_factory_.GetWeakPtr(),
768 callback)); 768 callback));
769 } 769 }
770 770
771 void FileSystem::OnGetResourceEntryForGetShareUrl( 771 void FileSystem::OnGetResourceEntryForGetShareUrl(
772 const GetShareUrlCallback& callback, 772 const GetShareUrlCallback& callback,
773 google_apis::DriveApiErrorCode status, 773 google_apis::DriveApiErrorCode status,
774 const GURL& share_url) { 774 const GURL& share_url) {
775 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 775 DCHECK_CURRENTLY_ON(BrowserThread::UI);
776 DCHECK(!callback.is_null()); 776 DCHECK(!callback.is_null());
777 777
778 FileError error = GDataToFileError(status); 778 FileError error = GDataToFileError(status);
779 if (error != FILE_ERROR_OK) { 779 if (error != FILE_ERROR_OK) {
780 callback.Run(error, GURL()); 780 callback.Run(error, GURL());
781 return; 781 return;
782 } 782 }
783 783
784 if (share_url.is_empty()) { 784 if (share_url.is_empty()) {
785 callback.Run(FILE_ERROR_FAILED, GURL()); 785 callback.Run(FILE_ERROR_FAILED, GURL());
786 return; 786 return;
787 } 787 }
788 788
789 callback.Run(FILE_ERROR_OK, share_url); 789 callback.Run(FILE_ERROR_OK, share_url);
790 } 790 }
791 791
792 void FileSystem::Search(const std::string& search_query, 792 void FileSystem::Search(const std::string& search_query,
793 const GURL& next_link, 793 const GURL& next_link,
794 const SearchCallback& callback) { 794 const SearchCallback& callback) {
795 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 795 DCHECK_CURRENTLY_ON(BrowserThread::UI);
796 DCHECK(!callback.is_null()); 796 DCHECK(!callback.is_null());
797 search_operation_->Search(search_query, next_link, callback); 797 search_operation_->Search(search_query, next_link, callback);
798 } 798 }
799 799
800 void FileSystem::SearchMetadata(const std::string& query, 800 void FileSystem::SearchMetadata(const std::string& query,
801 int options, 801 int options,
802 int at_most_num_matches, 802 int at_most_num_matches,
803 const SearchMetadataCallback& callback) { 803 const SearchMetadataCallback& callback) {
804 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 804 DCHECK_CURRENTLY_ON(BrowserThread::UI);
805 805
806 // TODO(satorux): Stop handling hide_hosted_docs here. crbug.com/256520. 806 // TODO(satorux): Stop handling hide_hosted_docs here. crbug.com/256520.
807 if (pref_service_->GetBoolean(prefs::kDisableDriveHostedFiles)) 807 if (pref_service_->GetBoolean(prefs::kDisableDriveHostedFiles))
808 options |= SEARCH_METADATA_EXCLUDE_HOSTED_DOCUMENTS; 808 options |= SEARCH_METADATA_EXCLUDE_HOSTED_DOCUMENTS;
809 809
810 drive::internal::SearchMetadata( 810 drive::internal::SearchMetadata(
811 blocking_task_runner_, resource_metadata_, query, 811 blocking_task_runner_, resource_metadata_, query,
812 base::Bind(&drive::internal::MatchesType, options), at_most_num_matches, 812 base::Bind(&drive::internal::MatchesType, options), at_most_num_matches,
813 callback); 813 callback);
814 } 814 }
815 815
816 void FileSystem::SearchByHashes(const std::set<std::string>& hashes, 816 void FileSystem::SearchByHashes(const std::set<std::string>& hashes,
817 const SearchByHashesCallback& callback) { 817 const SearchByHashesCallback& callback) {
818 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 818 DCHECK_CURRENTLY_ON(BrowserThread::UI);
819 drive::internal::SearchMetadata( 819 drive::internal::SearchMetadata(
820 blocking_task_runner_, resource_metadata_, 820 blocking_task_runner_, resource_metadata_,
821 /* any file name */ "", base::Bind(&CheckHashes, hashes), 821 /* any file name */ "", base::Bind(&CheckHashes, hashes),
822 std::numeric_limits<size_t>::max(), 822 std::numeric_limits<size_t>::max(),
823 base::Bind(&RunSearchByHashesCallback, callback)); 823 base::Bind(&RunSearchByHashesCallback, callback));
824 } 824 }
825 825
826 void FileSystem::OnFileChangedByOperation(const FileChange& changed_files) { 826 void FileSystem::OnFileChangedByOperation(const FileChange& changed_files) {
827 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 827 DCHECK_CURRENTLY_ON(BrowserThread::UI);
828 828
829 FOR_EACH_OBSERVER( 829 FOR_EACH_OBSERVER(
830 FileSystemObserver, observers_, OnFileChanged(changed_files)); 830 FileSystemObserver, observers_, OnFileChanged(changed_files));
831 } 831 }
832 832
833 void FileSystem::OnEntryUpdatedByOperation(const ClientContext& context, 833 void FileSystem::OnEntryUpdatedByOperation(const ClientContext& context,
834 const std::string& local_id) { 834 const std::string& local_id) {
835 sync_client_->AddUpdateTask(context, local_id); 835 sync_client_->AddUpdateTask(context, local_id);
836 } 836 }
837 837
(...skipping 23 matching lines...) Expand all
861 observers_, 861 observers_,
862 OnDriveSyncError(type, *file_path)); 862 OnDriveSyncError(type, *file_path));
863 } 863 }
864 864
865 bool FileSystem::WaitForSyncComplete(const std::string& local_id, 865 bool FileSystem::WaitForSyncComplete(const std::string& local_id,
866 const FileOperationCallback& callback) { 866 const FileOperationCallback& callback) {
867 return sync_client_->WaitForUpdateTaskToComplete(local_id, callback); 867 return sync_client_->WaitForUpdateTaskToComplete(local_id, callback);
868 } 868 }
869 869
870 void FileSystem::OnDirectoryReloaded(const base::FilePath& directory_path) { 870 void FileSystem::OnDirectoryReloaded(const base::FilePath& directory_path) {
871 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 871 DCHECK_CURRENTLY_ON(BrowserThread::UI);
872 872
873 FOR_EACH_OBSERVER( 873 FOR_EACH_OBSERVER(
874 FileSystemObserver, observers_, OnDirectoryChanged(directory_path)); 874 FileSystemObserver, observers_, OnDirectoryChanged(directory_path));
875 } 875 }
876 876
877 void FileSystem::OnFileChanged(const FileChange& changed_files) { 877 void FileSystem::OnFileChanged(const FileChange& changed_files) {
878 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 878 DCHECK_CURRENTLY_ON(BrowserThread::UI);
879 879
880 FOR_EACH_OBSERVER( 880 FOR_EACH_OBSERVER(
881 FileSystemObserver, observers_, OnFileChanged(changed_files)); 881 FileSystemObserver, observers_, OnFileChanged(changed_files));
882 } 882 }
883 883
884 void FileSystem::OnLoadFromServerComplete() { 884 void FileSystem::OnLoadFromServerComplete() {
885 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 885 DCHECK_CURRENTLY_ON(BrowserThread::UI);
886 886
887 sync_client_->StartCheckingExistingPinnedFiles(); 887 sync_client_->StartCheckingExistingPinnedFiles();
888 } 888 }
889 889
890 void FileSystem::OnInitialLoadComplete() { 890 void FileSystem::OnInitialLoadComplete() {
891 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 891 DCHECK_CURRENTLY_ON(BrowserThread::UI);
892 892
893 blocking_task_runner_->PostTask(FROM_HERE, 893 blocking_task_runner_->PostTask(FROM_HERE,
894 base::Bind(&internal::RemoveStaleCacheFiles, 894 base::Bind(&internal::RemoveStaleCacheFiles,
895 cache_, 895 cache_,
896 resource_metadata_)); 896 resource_metadata_));
897 sync_client_->StartProcessingBacklog(); 897 sync_client_->StartProcessingBacklog();
898 } 898 }
899 899
900 void FileSystem::GetMetadata( 900 void FileSystem::GetMetadata(
901 const GetFilesystemMetadataCallback& callback) { 901 const GetFilesystemMetadataCallback& callback) {
902 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 902 DCHECK_CURRENTLY_ON(BrowserThread::UI);
903 DCHECK(!callback.is_null()); 903 DCHECK(!callback.is_null());
904 904
905 FileSystemMetadata metadata; 905 FileSystemMetadata metadata;
906 metadata.refreshing = change_list_loader_->IsRefreshing(); 906 metadata.refreshing = change_list_loader_->IsRefreshing();
907 907
908 // Metadata related to delta update. 908 // Metadata related to delta update.
909 metadata.last_update_check_time = last_update_check_time_; 909 metadata.last_update_check_time = last_update_check_time_;
910 metadata.last_update_check_error = last_update_check_error_; 910 metadata.last_update_check_error = last_update_check_error_;
911 911
912 int64* largest_changestamp = new int64(0); 912 int64* largest_changestamp = new int64(0);
913 base::PostTaskAndReplyWithResult( 913 base::PostTaskAndReplyWithResult(
914 blocking_task_runner_.get(), 914 blocking_task_runner_.get(),
915 FROM_HERE, 915 FROM_HERE,
916 base::Bind(&internal::ResourceMetadata::GetLargestChangestamp, 916 base::Bind(&internal::ResourceMetadata::GetLargestChangestamp,
917 base::Unretained(resource_metadata_), 917 base::Unretained(resource_metadata_),
918 largest_changestamp), 918 largest_changestamp),
919 base::Bind(&OnGetLargestChangestamp, 919 base::Bind(&OnGetLargestChangestamp,
920 metadata, 920 metadata,
921 callback, 921 callback,
922 base::Owned(largest_changestamp))); 922 base::Owned(largest_changestamp)));
923 } 923 }
924 924
925 void FileSystem::MarkCacheFileAsMounted( 925 void FileSystem::MarkCacheFileAsMounted(
926 const base::FilePath& drive_file_path, 926 const base::FilePath& drive_file_path,
927 const MarkMountedCallback& callback) { 927 const MarkMountedCallback& callback) {
928 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 928 DCHECK_CURRENTLY_ON(BrowserThread::UI);
929 DCHECK(!callback.is_null()); 929 DCHECK(!callback.is_null());
930 930
931 base::FilePath* cache_file_path = new base::FilePath; 931 base::FilePath* cache_file_path = new base::FilePath;
932 base::PostTaskAndReplyWithResult( 932 base::PostTaskAndReplyWithResult(
933 blocking_task_runner_.get(), 933 blocking_task_runner_.get(),
934 FROM_HERE, 934 FROM_HERE,
935 base::Bind(&MarkCacheFileAsMountedInternal, 935 base::Bind(&MarkCacheFileAsMountedInternal,
936 resource_metadata_, 936 resource_metadata_,
937 cache_, 937 cache_,
938 drive_file_path, 938 drive_file_path,
939 cache_file_path), 939 cache_file_path),
940 base::Bind( 940 base::Bind(
941 &RunMarkMountedCallback, callback, base::Owned(cache_file_path))); 941 &RunMarkMountedCallback, callback, base::Owned(cache_file_path)));
942 } 942 }
943 943
944 void FileSystem::MarkCacheFileAsUnmounted( 944 void FileSystem::MarkCacheFileAsUnmounted(
945 const base::FilePath& cache_file_path, 945 const base::FilePath& cache_file_path,
946 const FileOperationCallback& callback) { 946 const FileOperationCallback& callback) {
947 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 947 DCHECK_CURRENTLY_ON(BrowserThread::UI);
948 DCHECK(!callback.is_null()); 948 DCHECK(!callback.is_null());
949 949
950 if (!cache_->IsUnderFileCacheDirectory(cache_file_path)) { 950 if (!cache_->IsUnderFileCacheDirectory(cache_file_path)) {
951 callback.Run(FILE_ERROR_FAILED); 951 callback.Run(FILE_ERROR_FAILED);
952 return; 952 return;
953 } 953 }
954 954
955 base::PostTaskAndReplyWithResult( 955 base::PostTaskAndReplyWithResult(
956 blocking_task_runner_.get(), 956 blocking_task_runner_.get(),
957 FROM_HERE, 957 FROM_HERE,
958 base::Bind(&internal::FileCache::MarkAsUnmounted, 958 base::Bind(&internal::FileCache::MarkAsUnmounted,
959 base::Unretained(cache_), 959 base::Unretained(cache_),
960 cache_file_path), 960 cache_file_path),
961 callback); 961 callback);
962 } 962 }
963 963
964 void FileSystem::AddPermission(const base::FilePath& drive_file_path, 964 void FileSystem::AddPermission(const base::FilePath& drive_file_path,
965 const std::string& email, 965 const std::string& email,
966 google_apis::drive::PermissionRole role, 966 google_apis::drive::PermissionRole role,
967 const FileOperationCallback& callback) { 967 const FileOperationCallback& callback) {
968 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 968 DCHECK_CURRENTLY_ON(BrowserThread::UI);
969 DCHECK(!callback.is_null()); 969 DCHECK(!callback.is_null());
970 970
971 // Resolve the resource id. 971 // Resolve the resource id.
972 ResourceEntry* const entry = new ResourceEntry; 972 ResourceEntry* const entry = new ResourceEntry;
973 base::PostTaskAndReplyWithResult( 973 base::PostTaskAndReplyWithResult(
974 blocking_task_runner_.get(), 974 blocking_task_runner_.get(),
975 FROM_HERE, 975 FROM_HERE,
976 base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath, 976 base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath,
977 base::Unretained(resource_metadata_), 977 base::Unretained(resource_metadata_),
978 drive_file_path, 978 drive_file_path,
979 entry), 979 entry),
980 base::Bind(&FileSystem::AddPermissionAfterGetResourceEntry, 980 base::Bind(&FileSystem::AddPermissionAfterGetResourceEntry,
981 weak_ptr_factory_.GetWeakPtr(), 981 weak_ptr_factory_.GetWeakPtr(),
982 email, 982 email,
983 role, 983 role,
984 callback, 984 callback,
985 base::Owned(entry))); 985 base::Owned(entry)));
986 } 986 }
987 987
988 void FileSystem::AddPermissionAfterGetResourceEntry( 988 void FileSystem::AddPermissionAfterGetResourceEntry(
989 const std::string& email, 989 const std::string& email,
990 google_apis::drive::PermissionRole role, 990 google_apis::drive::PermissionRole role,
991 const FileOperationCallback& callback, 991 const FileOperationCallback& callback,
992 ResourceEntry* entry, 992 ResourceEntry* entry,
993 FileError error) { 993 FileError error) {
994 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 994 DCHECK_CURRENTLY_ON(BrowserThread::UI);
995 995
996 if (error != FILE_ERROR_OK) { 996 if (error != FILE_ERROR_OK) {
997 callback.Run(error); 997 callback.Run(error);
998 return; 998 return;
999 } 999 }
1000 1000
1001 scheduler_->AddPermission( 1001 scheduler_->AddPermission(
1002 entry->resource_id(), 1002 entry->resource_id(),
1003 email, 1003 email,
1004 role, 1004 role,
1005 base::Bind(&RunFileOperationCallbackAsEntryActionCallback, callback)); 1005 base::Bind(&RunFileOperationCallbackAsEntryActionCallback, callback));
1006 } 1006 }
1007 1007
1008 void FileSystem::SetProperty( 1008 void FileSystem::SetProperty(
1009 const base::FilePath& drive_file_path, 1009 const base::FilePath& drive_file_path,
1010 google_apis::drive::Property::Visibility visibility, 1010 google_apis::drive::Property::Visibility visibility,
1011 const std::string& key, 1011 const std::string& key,
1012 const std::string& value, 1012 const std::string& value,
1013 const FileOperationCallback& callback) { 1013 const FileOperationCallback& callback) {
1014 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1014 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1015 DCHECK(!callback.is_null()); 1015 DCHECK(!callback.is_null());
1016 1016
1017 set_property_operation_->SetProperty(drive_file_path, visibility, key, value, 1017 set_property_operation_->SetProperty(drive_file_path, visibility, key, value,
1018 callback); 1018 callback);
1019 } 1019 }
1020 1020
1021 void FileSystem::OpenFile(const base::FilePath& file_path, 1021 void FileSystem::OpenFile(const base::FilePath& file_path,
1022 OpenMode open_mode, 1022 OpenMode open_mode,
1023 const std::string& mime_type, 1023 const std::string& mime_type,
1024 const OpenFileCallback& callback) { 1024 const OpenFileCallback& callback) {
1025 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1025 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1026 DCHECK(!callback.is_null()); 1026 DCHECK(!callback.is_null());
1027 1027
1028 open_file_operation_->OpenFile(file_path, open_mode, mime_type, callback); 1028 open_file_operation_->OpenFile(file_path, open_mode, mime_type, callback);
1029 } 1029 }
1030 1030
1031 void FileSystem::GetPathFromResourceId(const std::string& resource_id, 1031 void FileSystem::GetPathFromResourceId(const std::string& resource_id,
1032 const GetFilePathCallback& callback) { 1032 const GetFilePathCallback& callback) {
1033 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1033 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1034 DCHECK(!callback.is_null()); 1034 DCHECK(!callback.is_null());
1035 1035
1036 base::FilePath* const file_path = new base::FilePath(); 1036 base::FilePath* const file_path = new base::FilePath();
1037 base::PostTaskAndReplyWithResult( 1037 base::PostTaskAndReplyWithResult(
1038 blocking_task_runner_.get(), 1038 blocking_task_runner_.get(),
1039 FROM_HERE, 1039 FROM_HERE,
1040 base::Bind(&GetPathFromResourceIdOnBlockingPool, 1040 base::Bind(&GetPathFromResourceIdOnBlockingPool,
1041 resource_metadata_, 1041 resource_metadata_,
1042 resource_id, 1042 resource_id,
1043 file_path), 1043 file_path),
1044 base::Bind(&GetPathFromResourceIdAfterGetPath, 1044 base::Bind(&GetPathFromResourceIdAfterGetPath,
1045 base::Owned(file_path), 1045 base::Owned(file_path),
1046 callback)); 1046 callback));
1047 } 1047 }
1048 1048
1049 void FileSystem::FreeDiskSpaceIfNeededFor( 1049 void FileSystem::FreeDiskSpaceIfNeededFor(
1050 int64 num_bytes, 1050 int64 num_bytes,
1051 const FreeDiskSpaceCallback& callback) { 1051 const FreeDiskSpaceCallback& callback) {
1052 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1052 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1053 DCHECK(!callback.is_null()); 1053 DCHECK(!callback.is_null());
1054 base::PostTaskAndReplyWithResult( 1054 base::PostTaskAndReplyWithResult(
1055 blocking_task_runner_.get(), FROM_HERE, 1055 blocking_task_runner_.get(), FROM_HERE,
1056 base::Bind(&FreeDiskSpaceIfNeededForOnBlockingPool, cache_, num_bytes), 1056 base::Bind(&FreeDiskSpaceIfNeededForOnBlockingPool, cache_, num_bytes),
1057 callback); 1057 callback);
1058 } 1058 }
1059 } // namespace drive 1059 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_cache.cc ('k') | chrome/browser/chromeos/drive/file_system/copy_operation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698