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

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

Issue 14348016: chromeos: Add DriveFileSystem::Pin/Unpin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use GetEntryInfoByPathSync Created 7 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 | Annotate | Revision Log
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/drive_file_system.h" 5 #include "chrome/browser/chromeos/drive/drive_file_system.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/json/json_file_value_serializer.h" 9 #include "base/json/json_file_value_serializer.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 } 458 }
459 459
460 // No entry found at |file_path|. Let's create a brand new file. 460 // No entry found at |file_path|. Let's create a brand new file.
461 // For now, it is implemented by uploading an empty file (/dev/null). 461 // For now, it is implemented by uploading an empty file (/dev/null).
462 // TODO(kinaba): http://crbug.com/135143. Implement in a nicer way. 462 // TODO(kinaba): http://crbug.com/135143. Implement in a nicer way.
463 drive_operations_.TransferRegularFile(base::FilePath(kEmptyFilePath), 463 drive_operations_.TransferRegularFile(base::FilePath(kEmptyFilePath),
464 file_path, 464 file_path,
465 callback); 465 callback);
466 } 466 }
467 467
468 void DriveFileSystem::Pin(const base::FilePath& file_path,
469 const FileOperationCallback& callback) {
470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
471 DCHECK(!callback.is_null());
472
473 GetEntryInfoByPath(file_path,
474 base::Bind(&DriveFileSystem::PinAfterGetEntryInfoByPath,
475 weak_ptr_factory_.GetWeakPtr(),
476 callback));
477 }
478
479 void DriveFileSystem::PinAfterGetEntryInfoByPath(
480 const FileOperationCallback& callback,
481 DriveFileError error,
482 scoped_ptr<DriveEntryProto> entry) {
483 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
484 DCHECK(!callback.is_null());
485
486 // TODO(hashimoto): Support pinning directories. crbug.com/127831
487 if (entry && entry->file_info().is_directory())
488 error = DRIVE_FILE_ERROR_NOT_A_FILE;
489
490 if (error != DRIVE_FILE_OK) {
491 callback.Run(error);
492 return;
493 }
494 DCHECK(entry);
495
496 cache_->Pin(entry->resource_id(), entry->file_specific_info().file_md5(),
497 callback);
498 }
499
500 void DriveFileSystem::Unpin(const base::FilePath& file_path,
501 const FileOperationCallback& callback) {
502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
503 DCHECK(!callback.is_null());
504
505 GetEntryInfoByPath(file_path,
506 base::Bind(&DriveFileSystem::UnpinAfterGetEntryInfoByPath,
507 weak_ptr_factory_.GetWeakPtr(),
508 callback));
509 }
510
511 void DriveFileSystem::UnpinAfterGetEntryInfoByPath(
512 const FileOperationCallback& callback,
513 DriveFileError error,
514 scoped_ptr<DriveEntryProto> entry) {
515 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
516 DCHECK(!callback.is_null());
517
518 // TODO(hashimoto): Support pinning directories. crbug.com/127831
519 if (entry && entry->file_info().is_directory())
520 error = DRIVE_FILE_ERROR_NOT_A_FILE;
521
522 if (error != DRIVE_FILE_OK) {
523 callback.Run(error);
524 return;
525 }
526 DCHECK(entry);
527
528 cache_->Unpin(entry->resource_id(), entry->file_specific_info().file_md5(),
529 callback);
530 }
531
468 void DriveFileSystem::GetFileByPath(const base::FilePath& file_path, 532 void DriveFileSystem::GetFileByPath(const base::FilePath& file_path,
469 const GetFileCallback& callback) { 533 const GetFileCallback& callback) {
470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
471 DCHECK(!callback.is_null()); 535 DCHECK(!callback.is_null());
472 536
473 resource_metadata_->GetEntryInfoByPath( 537 resource_metadata_->GetEntryInfoByPath(
474 file_path, 538 file_path,
475 base::Bind(&DriveFileSystem::OnGetEntryInfoCompleteForGetFileByPath, 539 base::Bind(&DriveFileSystem::OnGetEntryInfoCompleteForGetFileByPath,
476 weak_ptr_factory_.GetWeakPtr(), 540 weak_ptr_factory_.GetWeakPtr(),
477 file_path, 541 file_path,
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 return; 1746 return;
1683 } 1747 }
1684 1748
1685 PlatformFileInfoProto entry_file_info; 1749 PlatformFileInfoProto entry_file_info;
1686 util::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 1750 util::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
1687 *entry_proto->mutable_file_info() = entry_file_info; 1751 *entry_proto->mutable_file_info() = entry_file_info;
1688 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); 1752 callback.Run(DRIVE_FILE_OK, entry_proto.Pass());
1689 } 1753 }
1690 1754
1691 } // namespace drive 1755 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_file_system.h ('k') | chrome/browser/chromeos/drive/drive_file_system_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698