chromeos: Add DriveFileSystem::Pin/Unpin

BUG=232450
TEST=unit_tests

Review URL: https://chromiumcodereview.appspot.com/14348016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195235 0039d316-1c4b-4281-b951-d872f2087c98
parent 70e1665c
...@@ -454,6 +454,70 @@ void DriveFileSystem::OnGetEntryInfoForCreateFile( ...@@ -454,6 +454,70 @@ void DriveFileSystem::OnGetEntryInfoForCreateFile(
callback); callback);
} }
void DriveFileSystem::Pin(const base::FilePath& file_path,
const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
GetEntryInfoByPath(file_path,
base::Bind(&DriveFileSystem::PinAfterGetEntryInfoByPath,
weak_ptr_factory_.GetWeakPtr(),
callback));
}
void DriveFileSystem::PinAfterGetEntryInfoByPath(
const FileOperationCallback& callback,
DriveFileError error,
scoped_ptr<DriveEntryProto> entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
// TODO(hashimoto): Support pinning directories. crbug.com/127831
if (entry && entry->file_info().is_directory())
error = DRIVE_FILE_ERROR_NOT_A_FILE;
if (error != DRIVE_FILE_OK) {
callback.Run(error);
return;
}
DCHECK(entry);
cache_->Pin(entry->resource_id(), entry->file_specific_info().file_md5(),
callback);
}
void DriveFileSystem::Unpin(const base::FilePath& file_path,
const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
GetEntryInfoByPath(file_path,
base::Bind(&DriveFileSystem::UnpinAfterGetEntryInfoByPath,
weak_ptr_factory_.GetWeakPtr(),
callback));
}
void DriveFileSystem::UnpinAfterGetEntryInfoByPath(
const FileOperationCallback& callback,
DriveFileError error,
scoped_ptr<DriveEntryProto> entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
// TODO(hashimoto): Support pinning directories. crbug.com/127831
if (entry && entry->file_info().is_directory())
error = DRIVE_FILE_ERROR_NOT_A_FILE;
if (error != DRIVE_FILE_OK) {
callback.Run(error);
return;
}
DCHECK(entry);
cache_->Unpin(entry->resource_id(), entry->file_specific_info().file_md5(),
callback);
}
void DriveFileSystem::GetFileByPath(const base::FilePath& file_path, void DriveFileSystem::GetFileByPath(const base::FilePath& file_path,
const GetFileCallback& callback) { const GetFileCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
......
...@@ -99,6 +99,10 @@ class DriveFileSystem : public DriveFileSystemInterface, ...@@ -99,6 +99,10 @@ class DriveFileSystem : public DriveFileSystemInterface,
virtual void CreateFile(const base::FilePath& file_path, virtual void CreateFile(const base::FilePath& file_path,
bool is_exclusive, bool is_exclusive,
const FileOperationCallback& callback) OVERRIDE; const FileOperationCallback& callback) OVERRIDE;
virtual void Pin(const base::FilePath& file_path,
const FileOperationCallback& callback) OVERRIDE;
virtual void Unpin(const base::FilePath& file_path,
const FileOperationCallback& callback) OVERRIDE;
virtual void GetFileByPath(const base::FilePath& file_path, virtual void GetFileByPath(const base::FilePath& file_path,
const GetFileCallback& callback) OVERRIDE; const GetFileCallback& callback) OVERRIDE;
virtual void GetFileByResourceId( virtual void GetFileByResourceId(
...@@ -203,12 +207,16 @@ class DriveFileSystem : public DriveFileSystemInterface, ...@@ -203,12 +207,16 @@ class DriveFileSystem : public DriveFileSystemInterface,
const FileOperationCallback& callback, const FileOperationCallback& callback,
DriveFileError result, DriveFileError result,
scoped_ptr<DriveEntryProto> entry_proto); scoped_ptr<DriveEntryProto> entry_proto);
void DoUploadForCreateBrandNewFile(const base::FilePath& remote_path,
base::FilePath* local_path, // Used to implement Pin().
const FileOperationCallback& callback); void PinAfterGetEntryInfoByPath(const FileOperationCallback& callback,
void DidUploadForCreateBrandNewFile(const base::FilePath& local_path, DriveFileError error,
const FileOperationCallback& callback, scoped_ptr<DriveEntryProto> entry);
DriveFileError result);
// Used to implement Unpin().
void UnpinAfterGetEntryInfoByPath(const FileOperationCallback& callback,
DriveFileError error,
scoped_ptr<DriveEntryProto> entry);
// Invoked upon completion of GetEntryInfoByPath initiated by // Invoked upon completion of GetEntryInfoByPath initiated by
// GetFileByPath. It then continues to invoke GetResolvedFileByPath. // GetFileByPath. It then continues to invoke GetResolvedFileByPath.
......
...@@ -282,6 +282,18 @@ class DriveFileSystemInterface { ...@@ -282,6 +282,18 @@ class DriveFileSystemInterface {
bool is_exclusive, bool is_exclusive,
const FileOperationCallback& callback) = 0; const FileOperationCallback& callback) = 0;
// Pins a file at |file_path|.
//
// |callback| must not be null.
virtual void Pin(const base::FilePath& file_path,
const FileOperationCallback& callback) = 0;
// Unpins a file at |file_path|.
//
// |callback| must not be null.
virtual void Unpin(const base::FilePath& file_path,
const FileOperationCallback& callback) = 0;
// Gets |file_path| from the file system. The file entry represented by // Gets |file_path| from the file system. The file entry represented by
// |file_path| needs to be present in in-memory representation of the file // |file_path| needs to be present in in-memory representation of the file
// system in order to be retrieved. If the file is not cached, the file // system in order to be retrieved. If the file is not cached, the file
......
...@@ -1532,6 +1532,36 @@ TEST_F(DriveFileSystemTest, CreateDirectoryWithService) { ...@@ -1532,6 +1532,36 @@ TEST_F(DriveFileSystemTest, CreateDirectoryWithService) {
EXPECT_EQ(DRIVE_FILE_OK, error); EXPECT_EQ(DRIVE_FILE_OK, error);
} }
TEST_F(DriveFileSystemTest, PinAndUnpin) {
ASSERT_TRUE(LoadRootFeedDocument());
base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
// Get the file info.
scoped_ptr<DriveEntryProto> entry(GetEntryInfoByPathSync(file_path));
ASSERT_TRUE(entry);
// Pin the file.
DriveFileError error = DRIVE_FILE_ERROR_FAILED;
EXPECT_CALL(*mock_cache_observer_,
OnCachePinned(entry->resource_id(),
entry->file_specific_info().file_md5())).Times(1);
file_system_->Pin(file_path,
google_apis::test_util::CreateCopyResultCallback(&error));
google_apis::test_util::RunBlockingPoolTask();
EXPECT_EQ(DRIVE_FILE_OK, error);
// Unpin the file.
error = DRIVE_FILE_ERROR_FAILED;
EXPECT_CALL(*mock_cache_observer_,
OnCacheUnpinned(entry->resource_id(),
entry->file_specific_info().file_md5())).Times(1);
file_system_->Unpin(file_path,
google_apis::test_util::CreateCopyResultCallback(&error));
google_apis::test_util::RunBlockingPoolTask();
EXPECT_EQ(DRIVE_FILE_OK, error);
}
TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpace) { TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpace) {
ASSERT_TRUE(LoadRootFeedDocument()); ASSERT_TRUE(LoadRootFeedDocument());
......
...@@ -114,6 +114,16 @@ void FakeDriveFileSystem::CreateFile(const base::FilePath& file_path, ...@@ -114,6 +114,16 @@ void FakeDriveFileSystem::CreateFile(const base::FilePath& file_path,
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
} }
void FakeDriveFileSystem::Pin(const base::FilePath& file_path,
const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
void FakeDriveFileSystem::Unpin(const base::FilePath& file_path,
const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
void FakeDriveFileSystem::GetFileByPath(const base::FilePath& file_path, void FakeDriveFileSystem::GetFileByPath(const base::FilePath& file_path,
const GetFileCallback& callback) { const GetFileCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
......
...@@ -77,6 +77,10 @@ class FakeDriveFileSystem : public DriveFileSystemInterface { ...@@ -77,6 +77,10 @@ class FakeDriveFileSystem : public DriveFileSystemInterface {
virtual void CreateFile(const base::FilePath& file_path, virtual void CreateFile(const base::FilePath& file_path,
bool is_exclusive, bool is_exclusive,
const FileOperationCallback& callback) OVERRIDE; const FileOperationCallback& callback) OVERRIDE;
virtual void Pin(const base::FilePath& file_path,
const FileOperationCallback& callback) OVERRIDE;
virtual void Unpin(const base::FilePath& file_path,
const FileOperationCallback& callback) OVERRIDE;
virtual void GetFileByPath(const base::FilePath& file_path, virtual void GetFileByPath(const base::FilePath& file_path,
const GetFileCallback& callback) OVERRIDE; const GetFileCallback& callback) OVERRIDE;
virtual void GetFileByResourceId( virtual void GetFileByResourceId(
......
...@@ -66,6 +66,10 @@ class MockDriveFileSystem : public DriveFileSystemInterface { ...@@ -66,6 +66,10 @@ class MockDriveFileSystem : public DriveFileSystemInterface {
void(const base::FilePath& file_path, void(const base::FilePath& file_path,
bool is_exclusive, bool is_exclusive,
const FileOperationCallback& callback)); const FileOperationCallback& callback));
MOCK_METHOD2(Pin, void(const base::FilePath& file_path,
const FileOperationCallback& callback));
MOCK_METHOD2(Unpin, void(const base::FilePath& file_path,
const FileOperationCallback& callback));
MOCK_METHOD2(GetFileByPath, MOCK_METHOD2(GetFileByPath,
void(const base::FilePath& file_path, void(const base::FilePath& file_path,
const GetFileCallback& callback)); const GetFileCallback& callback));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment