Commit 25f22440 authored by Austin Tankiang's avatar Austin Tankiang Committed by Commit Bot

Remove legacy drive file system (part 1)

Bug: 1003238
Change-Id: I7dd421fd8d8e91fd37289df898f6481d51aad9ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1896488Reviewed-by: default avatarSergei Datsenko <dats@chromium.org>
Reviewed-by: default avatarStuart Langley <slangley@chromium.org>
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713739}
parent 9a49df51
......@@ -2938,7 +2938,6 @@ source_set("unit_tests") {
"//components/drive/drive_file_util_unittest.cc",
"//components/drive/drive_notification_manager_unittest.cc",
"//components/drive/drive_operation_queue_unittest.cc",
"//components/drive/fake_file_system_unittest.cc",
"//components/drive/file_change_unittest.cc",
"//components/drive/file_system/copy_operation_unittest.cc",
"//components/drive/file_system/create_directory_operation_unittest.cc",
......@@ -2955,7 +2954,6 @@ source_set("unit_tests") {
"//components/drive/file_system/touch_operation_unittest.cc",
"//components/drive/file_system/truncate_operation_unittest.cc",
"//components/drive/file_system_core_util_unittest.cc",
"//components/drive/file_system_unittest.cc",
"//components/drive/file_write_watcher_unittest.cc",
"//components/drive/job_queue_unittest.cc",
"//components/drive/job_scheduler_unittest.cc",
......
......@@ -116,8 +116,6 @@ if (is_chromeos) {
"chromeos/drive_operation_queue.h",
"chromeos/file_cache.cc",
"chromeos/file_cache.h",
"chromeos/file_system.cc",
"chromeos/file_system.h",
"chromeos/file_system/copy_operation.cc",
"chromeos/file_system/copy_operation.h",
"chromeos/file_system/create_directory_operation.cc",
......@@ -192,10 +190,6 @@ if (is_chromeos) {
sources = [
"chromeos/drive_test_util.cc",
"chromeos/drive_test_util.h",
"chromeos/dummy_file_system.cc",
"chromeos/dummy_file_system.h",
"chromeos/fake_file_system.cc",
"chromeos/fake_file_system.h",
"chromeos/fake_free_disk_space_getter.cc",
"chromeos/fake_free_disk_space_getter.h",
]
......
......@@ -43,10 +43,8 @@ specific_include_rules = {
r"|change_list_processor_unittest\.cc"
r"|directory_loader_unittest\.cc"
r"|drive_file_util_unittest\.cc"
r"|fake_file_system_unittest\.cc"
r"|file_cache_unittest\.cc"
r"|file_system_core_util_unittest\.cc"
r"|file_system_unittest\.cc"
r"|file_write_watcher_unittest\.cc"
r"|job_scheduler_unittest\.cc"
r"|operation_test_base\.h"
......@@ -65,8 +63,6 @@ specific_include_rules = {
# The following test dependencies should be removed to fully componentize this
# directory. crbug.com/498951
r"(drive_uploader\.cc"
r"|fake_file_system\.cc"
r"|file_system_unittest\.cc"
r"|file_write_watcher_unittest\.cc"
r"|get_file_for_saving_operation_unittest\.cc"
r"|operation_test_base\.cc"
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/drive/chromeos/dummy_file_system.h"
#include "base/bind_helpers.h"
namespace drive {
base::Closure DummyFileSystem::GetFileContent(
const base::FilePath& file_path,
GetFileContentInitializedCallback initialized_callback,
const google_apis::GetContentCallback& get_content_callback,
const FileOperationCallback& completion_callback) {
return base::DoNothing();
}
} // namespace drive
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_DRIVE_CHROMEOS_DUMMY_FILE_SYSTEM_H_
#define COMPONENTS_DRIVE_CHROMEOS_DUMMY_FILE_SYSTEM_H_
#include <stdint.h>
#include <set>
#include <string>
#include "components/drive/chromeos/file_system_interface.h"
namespace drive {
// Dummy implementation of FileSystemInterface. All functions do nothing.
class DummyFileSystem : public FileSystemInterface {
public:
~DummyFileSystem() override = default;
void AddObserver(FileSystemObserver* observer) override {}
void RemoveObserver(FileSystemObserver* observer) override {}
void CheckForUpdates() override {}
void CheckForUpdates(const std::set<std::string>& ids) override {}
void TransferFileFromLocalToRemote(
const base::FilePath& local_src_file_path,
const base::FilePath& remote_dest_file_path,
const FileOperationCallback& callback) override {}
void OpenFile(const base::FilePath& file_path,
OpenMode open_mode,
const std::string& mime_type,
OpenFileCallback callback) override {}
void Copy(const base::FilePath& src_file_path,
const base::FilePath& dest_file_path,
bool preserve_last_modified,
const FileOperationCallback& callback) override {}
void Move(const base::FilePath& src_file_path,
const base::FilePath& dest_file_path,
const FileOperationCallback& callback) override {}
void Remove(const base::FilePath& file_path,
bool is_recursive,
const FileOperationCallback& callback) override {}
void CreateDirectory(const base::FilePath& directory_path,
bool is_exclusive,
bool is_recursive,
const FileOperationCallback& callback) override {}
void CreateFile(const base::FilePath& file_path,
bool is_exclusive,
const std::string& mime_type,
const FileOperationCallback& callback) override {}
void TouchFile(const base::FilePath& file_path,
const base::Time& last_access_time,
const base::Time& last_modified_time,
const FileOperationCallback& callback) override {}
void TruncateFile(const base::FilePath& file_path,
int64_t length,
const FileOperationCallback& callback) override {}
void Pin(const base::FilePath& file_path,
const FileOperationCallback& callback) override {}
void Unpin(const base::FilePath& file_path,
const FileOperationCallback& callback) override {}
void GetFile(const base::FilePath& file_path,
GetFileCallback callback) override {}
void GetFileForSaving(const base::FilePath& file_path,
GetFileCallback callback) override {}
base::Closure GetFileContent(
const base::FilePath& file_path,
GetFileContentInitializedCallback initialized_callback,
const google_apis::GetContentCallback& get_content_callback,
const FileOperationCallback& completion_callback) override;
void GetResourceEntry(const base::FilePath& file_path,
GetResourceEntryCallback callback) override {}
void ReadDirectory(
const base::FilePath& file_path,
ReadDirectoryEntriesCallback entries_callback,
const FileOperationCallback& completion_callback) override {}
void Search(const std::string& search_query,
const GURL& next_link,
SearchCallback callback) override {}
void SearchMetadata(const std::string& query,
int options,
int at_most_num_matches,
MetadataSearchOrder order,
SearchMetadataCallback callback) override {}
void SearchByHashes(const std::set<std::string>& hashes,
SearchByHashesCallback callback) override {}
void GetAvailableSpace(GetAvailableSpaceCallback callback) override {}
void GetMetadata(GetFilesystemMetadataCallback callback) override {}
void MarkCacheFileAsMounted(const base::FilePath& drive_file_path,
MarkMountedCallback callback) override {}
void MarkCacheFileAsUnmounted(
const base::FilePath& cache_file_path,
const FileOperationCallback& callback) override {}
void IsCacheFileMarkedAsMounted(const base::FilePath& drive_file_path,
IsMountedCallback callback) override {}
void AddPermission(const base::FilePath& drive_file_path,
const std::string& email,
google_apis::drive::PermissionRole role,
const FileOperationCallback& callback) override {}
void SetProperty(const base::FilePath& drive_file_path,
google_apis::drive::Property::Visibility visibility,
const std::string& key,
const std::string& value,
const FileOperationCallback& callback) override {}
void Reset(const FileOperationCallback& callback) override {}
void GetPathFromResourceId(const std::string& resource_id,
const GetFilePathCallback& callback) override {}
void FreeDiskSpaceIfNeededFor(
int64_t num_bytes,
const FreeDiskSpaceCallback& callback) override {}
void CalculateCacheSize(const CacheSizeCallback& callback) override {}
void CalculateEvictableCacheSize(
const CacheSizeCallback& callback) override {}
};
} // namespace drive
#endif // COMPONENTS_DRIVE_CHROMEOS_DUMMY_FILE_SYSTEM_H_
This diff is collapsed.
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_DRIVE_CHROMEOS_FAKE_FILE_SYSTEM_H_
#define COMPONENTS_DRIVE_CHROMEOS_FAKE_FILE_SYSTEM_H_
#include <stdint.h>
#include <memory>
#include <set>
#include <string>
#include "base/callback_forward.h"
#include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
#include "components/drive/chromeos/file_system_interface.h"
#include "components/drive/file_errors.h"
#include "google_apis/drive/drive_api_error_codes.h"
namespace google_apis {
class AboutResource;
class FileResource;
} // namespace google_apis
namespace drive {
class DriveServiceInterface;
class FileSystemObserver;
class ResourceEntry;
namespace test_util {
// This class implements a fake FileSystem which acts like a real Drive
// file system with FakeDriveService, for testing purpose.
// Note that this class doesn't support "caching" at the moment, so the number
// of interactions to the FakeDriveService may be bigger than the real
// implementation.
// Currently most methods are empty (not implemented).
class FakeFileSystem : public FileSystemInterface {
public:
explicit FakeFileSystem(DriveServiceInterface* drive_service);
~FakeFileSystem() override;
// FileSystemInterface Overrides.
void AddObserver(FileSystemObserver* observer) override;
void RemoveObserver(FileSystemObserver* observer) override;
void CheckForUpdates() override;
void CheckForUpdates(const std::set<std::string>& ids) override;
void TransferFileFromLocalToRemote(
const base::FilePath& local_src_file_path,
const base::FilePath& remote_dest_file_path,
const FileOperationCallback& callback) override;
void OpenFile(const base::FilePath& file_path,
OpenMode open_mode,
const std::string& mime_type,
OpenFileCallback callback) override;
void Copy(const base::FilePath& src_file_path,
const base::FilePath& dest_file_path,
bool preserve_last_modified,
const FileOperationCallback& callback) override;
void Move(const base::FilePath& src_file_path,
const base::FilePath& dest_file_path,
const FileOperationCallback& callback) override;
void Remove(const base::FilePath& file_path,
bool is_recursive,
const FileOperationCallback& callback) override;
void CreateDirectory(const base::FilePath& directory_path,
bool is_exclusive,
bool is_recursive,
const FileOperationCallback& callback) override;
void CreateFile(const base::FilePath& file_path,
bool is_exclusive,
const std::string& mime_type,
const FileOperationCallback& callback) override;
void TouchFile(const base::FilePath& file_path,
const base::Time& last_access_time,
const base::Time& last_modified_time,
const FileOperationCallback& callback) override;
void TruncateFile(const base::FilePath& file_path,
int64_t length,
const FileOperationCallback& callback) override;
void Pin(const base::FilePath& file_path,
const FileOperationCallback& callback) override;
void Unpin(const base::FilePath& file_path,
const FileOperationCallback& callback) override;
void GetFile(const base::FilePath& file_path,
GetFileCallback callback) override;
void GetFileForSaving(const base::FilePath& file_path,
GetFileCallback callback) override;
base::Closure GetFileContent(
const base::FilePath& file_path,
GetFileContentInitializedCallback initialized_callback,
const google_apis::GetContentCallback& get_content_callback,
const FileOperationCallback& completion_callback) override;
void GetResourceEntry(const base::FilePath& file_path,
GetResourceEntryCallback callback) override;
void ReadDirectory(const base::FilePath& file_path,
ReadDirectoryEntriesCallback entries_callback,
const FileOperationCallback& completion_callback) override;
void Search(const std::string& search_query,
const GURL& next_link,
SearchCallback callback) override;
void SearchMetadata(const std::string& query,
int options,
int at_most_num_matches,
MetadataSearchOrder order,
SearchMetadataCallback callback) override;
void SearchByHashes(const std::set<std::string>& hashes,
SearchByHashesCallback callback) override;
void GetAvailableSpace(GetAvailableSpaceCallback callback) override;
void GetMetadata(GetFilesystemMetadataCallback callback) override;
void MarkCacheFileAsMounted(const base::FilePath& drive_file_path,
MarkMountedCallback callback) override;
void MarkCacheFileAsUnmounted(const base::FilePath& cache_file_path,
const FileOperationCallback& callback) override;
void IsCacheFileMarkedAsMounted(const base::FilePath& drive_file_path,
IsMountedCallback callback) override;
void AddPermission(const base::FilePath& drive_file_path,
const std::string& email,
google_apis::drive::PermissionRole role,
const FileOperationCallback& callback) override;
void SetProperty(const base::FilePath& drive_file_path,
google_apis::drive::Property::Visibility visibility,
const std::string& key,
const std::string& value,
const FileOperationCallback& callback) override;
void Reset(const FileOperationCallback& callback) override;
void GetPathFromResourceId(const std::string& resource_id,
const GetFilePathCallback& callback) override;
void FreeDiskSpaceIfNeededFor(int64_t num_bytes,
const FreeDiskSpaceCallback& callback) override;
void CalculateCacheSize(const CacheSizeCallback& callback) override;
void CalculateEvictableCacheSize(const CacheSizeCallback& callback) override;
private:
// Helpers of GetFileContent.
// How the method works:
// 1) Gets ResourceEntry of the path.
// 2) Look at if there is a cache file or not. If found return it.
// 3) Otherwise start DownloadFile.
// 4) Runs the |completion_callback| upon the download completion.
void GetFileContentAfterGetResourceEntry(
GetFileContentInitializedCallback initialized_callback,
const google_apis::GetContentCallback& get_content_callback,
const FileOperationCallback& completion_callback,
FileError error,
std::unique_ptr<ResourceEntry> entry);
void GetFileContentAfterGetFileResource(
GetFileContentInitializedCallback initialized_callback,
const google_apis::GetContentCallback& get_content_callback,
const FileOperationCallback& completion_callback,
google_apis::DriveApiErrorCode gdata_error,
std::unique_ptr<google_apis::FileResource> gdata_entry);
void GetFileContentAfterDownloadFile(
const FileOperationCallback& completion_callback,
google_apis::DriveApiErrorCode gdata_error,
const base::FilePath& temp_file);
// Helpers of GetResourceEntry.
// How the method works:
// 1) If the path is root, gets AboutResrouce from the drive service
// and create ResourceEntry.
// 2-1) Otherwise, gets the parent's ResourceEntry by recursive call.
// 2-2) Then, gets the resource list by restricting the parent with its id.
// 2-3) Search the results based on title, and return the ResourceEntry.
// Note that adding suffix (e.g. " (2)") for files sharing a same name is
// not supported in FakeFileSystem. Thus, even if the server has
// files sharing the same name under a directory, the second (or later)
// file cannot be taken with the suffixed name.
void GetResourceEntryAfterGetAboutResource(
GetResourceEntryCallback callback,
google_apis::DriveApiErrorCode gdata_error,
std::unique_ptr<google_apis::AboutResource> about_resource);
void GetResourceEntryAfterGetParentEntryInfo(
const base::FilePath& base_name,
GetResourceEntryCallback callback,
FileError error,
std::unique_ptr<ResourceEntry> parent_entry);
void GetResourceEntryAfterGetFileList(
const base::FilePath& base_name,
GetResourceEntryCallback callback,
google_apis::DriveApiErrorCode gdata_error,
std::unique_ptr<google_apis::FileList> file_list);
DriveServiceInterface* drive_service_; // Not owned.
base::ScopedTempDir cache_dir_;
// Note: This should remain the last member so it'll be destroyed and
// invalidate the weak pointers before any other members are destroyed.
base::WeakPtrFactory<FakeFileSystem> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(FakeFileSystem);
};
} // namespace test_util
} // namespace drive
#endif // COMPONENTS_DRIVE_CHROMEOS_FAKE_FILE_SYSTEM_H_
This diff is collapsed.
This diff is collapsed.
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/drive/chromeos/fake_file_system.h"
#include <memory>
#include "base/files/file_util.h"
#include "base/run_loop.h"
#include "components/drive/file_system_core_util.h"
#include "components/drive/service/fake_drive_service.h"
#include "components/drive/service/test_util.h"
#include "content/public/test/browser_task_environment.h"
#include "google_apis/drive/test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace drive {
namespace test_util {
class FakeFileSystemTest : public ::testing::Test {
protected:
void SetUp() override {
// Initialize FakeDriveService.
fake_drive_service_ = std::make_unique<FakeDriveService>();
ASSERT_TRUE(SetUpTestEntries(fake_drive_service_.get()));
// Create a testee instance.
fake_file_system_ =
std::make_unique<FakeFileSystem>(fake_drive_service_.get());
}
content::BrowserTaskEnvironment task_environment_;
std::unique_ptr<FakeDriveService> fake_drive_service_;
std::unique_ptr<FakeFileSystem> fake_file_system_;
};
TEST_F(FakeFileSystemTest, GetFileContent) {
FileError initialize_error = FILE_ERROR_FAILED;
std::unique_ptr<ResourceEntry> entry;
base::FilePath cache_file_path;
google_apis::test_util::TestGetContentCallback get_content_callback;
FileError completion_error = FILE_ERROR_FAILED;
const base::FilePath kDriveFile =
util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt");
// For the first time, the file should be downloaded from the service.
base::Closure cancel_download = fake_file_system_->GetFileContent(
kDriveFile,
google_apis::test_util::CreateCopyResultCallback(
&initialize_error, &cache_file_path, &entry),
get_content_callback.callback(),
google_apis::test_util::CreateCopyResultCallback(&completion_error));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, initialize_error);
EXPECT_TRUE(entry);
// No cache file is available yet.
EXPECT_TRUE(cache_file_path.empty());
// The download should be happened so the |get_content_callback|
// should have the actual data.
std::string content = get_content_callback.GetConcatenatedData();
EXPECT_EQ(26U, content.size());
EXPECT_EQ(FILE_ERROR_OK, completion_error);
initialize_error = FILE_ERROR_FAILED;
entry.reset();
get_content_callback.mutable_data()->clear();
completion_error = FILE_ERROR_FAILED;
// For the second time, the cache file should be found.
cancel_download = fake_file_system_->GetFileContent(
kDriveFile,
google_apis::test_util::CreateCopyResultCallback(
&initialize_error, &cache_file_path, &entry),
get_content_callback.callback(),
google_apis::test_util::CreateCopyResultCallback(&completion_error));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, initialize_error);
EXPECT_TRUE(entry);
// Cache file should be available.
ASSERT_FALSE(cache_file_path.empty());
// There should be a cache file so no data should be downloaded.
EXPECT_TRUE(get_content_callback.data().empty());
EXPECT_EQ(FILE_ERROR_OK, completion_error);
// Make sure the cached file's content.
std::string cache_file_content;
ASSERT_TRUE(
base::ReadFileToString(cache_file_path, &cache_file_content));
EXPECT_EQ(content, cache_file_content);
}
TEST_F(FakeFileSystemTest, GetFileContent_Directory) {
FileError initialize_error = FILE_ERROR_FAILED;
std::unique_ptr<ResourceEntry> entry;
base::FilePath cache_file_path;
google_apis::test_util::TestGetContentCallback get_content_callback;
FileError completion_error = FILE_ERROR_FAILED;
base::Closure cancel_download = fake_file_system_->GetFileContent(
util::GetDriveMyDriveRootPath(),
google_apis::test_util::CreateCopyResultCallback(
&initialize_error, &cache_file_path, &entry),
get_content_callback.callback(),
google_apis::test_util::CreateCopyResultCallback(&completion_error));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(FILE_ERROR_NOT_A_FILE, completion_error);
}
TEST_F(FakeFileSystemTest, GetResourceEntry) {
FileError error = FILE_ERROR_FAILED;
std::unique_ptr<ResourceEntry> entry;
fake_file_system_->GetResourceEntry(
util::GetDriveMyDriveRootPath().AppendASCII(
"Directory 1/Sub Directory Folder"),
google_apis::test_util::CreateCopyResultCallback(&error, &entry));
base::RunLoop().RunUntilIdle();
ASSERT_EQ(FILE_ERROR_OK, error);
ASSERT_TRUE(entry);
EXPECT_EQ("sub_dir_folder_resource_id", entry->resource_id());
}
TEST_F(FakeFileSystemTest, GetResourceEntry_Root) {
FileError error = FILE_ERROR_FAILED;
std::unique_ptr<ResourceEntry> entry;
fake_file_system_->GetResourceEntry(
util::GetDriveMyDriveRootPath(),
google_apis::test_util::CreateCopyResultCallback(&error, &entry));
base::RunLoop().RunUntilIdle();
ASSERT_EQ(FILE_ERROR_OK, error);
ASSERT_TRUE(entry);
EXPECT_TRUE(entry->file_info().is_directory());
EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id());
EXPECT_EQ(util::kDriveMyDriveRootDirName, entry->title());
}
TEST_F(FakeFileSystemTest, GetResourceEntry_Invalid) {
FileError error = FILE_ERROR_FAILED;
std::unique_ptr<ResourceEntry> entry;
fake_file_system_->GetResourceEntry(
util::GetDriveMyDriveRootPath().AppendASCII("Invalid File Name"),
google_apis::test_util::CreateCopyResultCallback(&error, &entry));
base::RunLoop().RunUntilIdle();
ASSERT_EQ(FILE_ERROR_NOT_FOUND, error);
ASSERT_FALSE(entry);
}
} // namespace test_util
} // namespace drive
This diff is collapsed.
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