summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-19 18:05:18 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-19 18:05:18 +0000
commit378b61365a77c7788e6fd4e11fb681c303a3e65d (patch)
tree073ffe57365fbf92b507823dde601cc5bf774342 /chrome/browser/chromeos
parent70e1665c6c1c2c4b5d0777583afd1d1ba438668a (diff)
downloadchromium_src-378b61365a77c7788e6fd4e11fb681c303a3e65d.zip
chromium_src-378b61365a77c7788e6fd4e11fb681c303a3e65d.tar.gz
chromium_src-378b61365a77c7788e6fd4e11fb681c303a3e65d.tar.bz2
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
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r--chrome/browser/chromeos/drive/drive_file_system.cc64
-rw-r--r--chrome/browser/chromeos/drive/drive_file_system.h20
-rw-r--r--chrome/browser/chromeos/drive/drive_file_system_interface.h12
-rw-r--r--chrome/browser/chromeos/drive/drive_file_system_unittest.cc30
-rw-r--r--chrome/browser/chromeos/drive/fake_drive_file_system.cc10
-rw-r--r--chrome/browser/chromeos/drive/fake_drive_file_system.h4
-rw-r--r--chrome/browser/chromeos/drive/mock_drive_file_system.h4
7 files changed, 138 insertions, 6 deletions
diff --git a/chrome/browser/chromeos/drive/drive_file_system.cc b/chrome/browser/chromeos/drive/drive_file_system.cc
index 5932f87..bc98186 100644
--- a/chrome/browser/chromeos/drive/drive_file_system.cc
+++ b/chrome/browser/chromeos/drive/drive_file_system.cc
@@ -454,6 +454,70 @@ void DriveFileSystem::OnGetEntryInfoForCreateFile(
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,
const GetFileCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
diff --git a/chrome/browser/chromeos/drive/drive_file_system.h b/chrome/browser/chromeos/drive/drive_file_system.h
index ea74e61..f5010b3 100644
--- a/chrome/browser/chromeos/drive/drive_file_system.h
+++ b/chrome/browser/chromeos/drive/drive_file_system.h
@@ -99,6 +99,10 @@ class DriveFileSystem : public DriveFileSystemInterface,
virtual void CreateFile(const base::FilePath& file_path,
bool is_exclusive,
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,
const GetFileCallback& callback) OVERRIDE;
virtual void GetFileByResourceId(
@@ -203,12 +207,16 @@ class DriveFileSystem : public DriveFileSystemInterface,
const FileOperationCallback& callback,
DriveFileError result,
scoped_ptr<DriveEntryProto> entry_proto);
- void DoUploadForCreateBrandNewFile(const base::FilePath& remote_path,
- base::FilePath* local_path,
- const FileOperationCallback& callback);
- void DidUploadForCreateBrandNewFile(const base::FilePath& local_path,
- const FileOperationCallback& callback,
- DriveFileError result);
+
+ // Used to implement Pin().
+ void PinAfterGetEntryInfoByPath(const FileOperationCallback& callback,
+ DriveFileError error,
+ scoped_ptr<DriveEntryProto> entry);
+
+ // Used to implement Unpin().
+ void UnpinAfterGetEntryInfoByPath(const FileOperationCallback& callback,
+ DriveFileError error,
+ scoped_ptr<DriveEntryProto> entry);
// Invoked upon completion of GetEntryInfoByPath initiated by
// GetFileByPath. It then continues to invoke GetResolvedFileByPath.
diff --git a/chrome/browser/chromeos/drive/drive_file_system_interface.h b/chrome/browser/chromeos/drive/drive_file_system_interface.h
index 7ae18dd..354b7da 100644
--- a/chrome/browser/chromeos/drive/drive_file_system_interface.h
+++ b/chrome/browser/chromeos/drive/drive_file_system_interface.h
@@ -282,6 +282,18 @@ class DriveFileSystemInterface {
bool is_exclusive,
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
// |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
diff --git a/chrome/browser/chromeos/drive/drive_file_system_unittest.cc b/chrome/browser/chromeos/drive/drive_file_system_unittest.cc
index 6671679..17fab9e 100644
--- a/chrome/browser/chromeos/drive/drive_file_system_unittest.cc
+++ b/chrome/browser/chromeos/drive/drive_file_system_unittest.cc
@@ -1532,6 +1532,36 @@ TEST_F(DriveFileSystemTest, CreateDirectoryWithService) {
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) {
ASSERT_TRUE(LoadRootFeedDocument());
diff --git a/chrome/browser/chromeos/drive/fake_drive_file_system.cc b/chrome/browser/chromeos/drive/fake_drive_file_system.cc
index 87f1852..deed368 100644
--- a/chrome/browser/chromeos/drive/fake_drive_file_system.cc
+++ b/chrome/browser/chromeos/drive/fake_drive_file_system.cc
@@ -114,6 +114,16 @@ void FakeDriveFileSystem::CreateFile(const base::FilePath& file_path,
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,
const GetFileCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
diff --git a/chrome/browser/chromeos/drive/fake_drive_file_system.h b/chrome/browser/chromeos/drive/fake_drive_file_system.h
index 1a83782..7158fb1 100644
--- a/chrome/browser/chromeos/drive/fake_drive_file_system.h
+++ b/chrome/browser/chromeos/drive/fake_drive_file_system.h
@@ -77,6 +77,10 @@ class FakeDriveFileSystem : public DriveFileSystemInterface {
virtual void CreateFile(const base::FilePath& file_path,
bool is_exclusive,
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,
const GetFileCallback& callback) OVERRIDE;
virtual void GetFileByResourceId(
diff --git a/chrome/browser/chromeos/drive/mock_drive_file_system.h b/chrome/browser/chromeos/drive/mock_drive_file_system.h
index 9b0e81f..0cceaa0 100644
--- a/chrome/browser/chromeos/drive/mock_drive_file_system.h
+++ b/chrome/browser/chromeos/drive/mock_drive_file_system.h
@@ -66,6 +66,10 @@ class MockDriveFileSystem : public DriveFileSystemInterface {
void(const base::FilePath& file_path,
bool is_exclusive,
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,
void(const base::FilePath& file_path,
const GetFileCallback& callback));