Commit b00b1ee5 authored by Stuart Langley's avatar Stuart Langley Committed by Commit Bot

Add/remove a team drive list loader when observed in the default change.

Bug: 715355
Change-Id: I246fe81e0d51d27f53135a9664e8a1bbf5f84bfa
Reviewed-on: https://chromium-review.googlesource.com/1105197
Commit-Queue: Stuart Langley <slangley@chromium.org>
Reviewed-by: default avatarSasha Morrissey <sashab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568504}
parent 62222ed9
...@@ -910,6 +910,33 @@ void FileSystem::OnFileChanged(const FileChange& changed_files) { ...@@ -910,6 +910,33 @@ void FileSystem::OnFileChanged(const FileChange& changed_files) {
observer.OnFileChanged(changed_files); observer.OnFileChanged(changed_files);
} }
void FileSystem::OnTeamDrivesChanged(const FileChange& changed_team_drives) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
for (const auto& entry : changed_team_drives.map()) {
for (const auto& change : entry.second.list()) {
DCHECK(!change.team_drive_id().empty());
if (change.IsDelete()) {
const auto it =
team_drive_change_list_loaders_.find(change.team_drive_id());
DCHECK(it != team_drive_change_list_loaders_.end());
team_drive_change_list_loaders_.erase(it);
} else if (change.IsAddOrUpdate()) {
DCHECK(team_drive_change_list_loaders_.count(change.team_drive_id()) ==
0);
auto loader = std::make_unique<internal::TeamDriveChangeListLoader>(
change.team_drive_id(), entry.first, logger_,
blocking_task_runner_.get(), resource_metadata_, scheduler_,
loader_controller_.get());
loader->AddChangeListLoaderObserver(this);
loader->LoadIfNeeded(base::DoNothing());
team_drive_change_list_loaders_.emplace(change.team_drive_id(),
std::move(loader));
}
}
}
}
void FileSystem::OnLoadFromServerComplete() { void FileSystem::OnLoadFromServerComplete() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
sync_client_->StartCheckingExistingPinnedFiles(); sync_client_->StartCheckingExistingPinnedFiles();
......
...@@ -186,6 +186,7 @@ class FileSystem : public FileSystemInterface, ...@@ -186,6 +186,7 @@ class FileSystem : public FileSystemInterface,
// Used to propagate events from ChangeListLoader. // Used to propagate events from ChangeListLoader.
void OnDirectoryReloaded(const base::FilePath& directory_path) override; void OnDirectoryReloaded(const base::FilePath& directory_path) override;
void OnFileChanged(const FileChange& changed_files) override; void OnFileChanged(const FileChange& changed_files) override;
void OnTeamDrivesChanged(const FileChange& changed_team_drives) override;
void OnLoadFromServerComplete() override; void OnLoadFromServerComplete() override;
void OnInitialLoadComplete() override; void OnInitialLoadComplete() override;
......
...@@ -882,6 +882,61 @@ TEST_F(FileSystemTest, ReadDirectory_TeamDriveFolder) { ...@@ -882,6 +882,61 @@ TEST_F(FileSystemTest, ReadDirectory_TeamDriveFolder) {
EXPECT_EQ(1U, found.count(base::FilePath::FromUTF8Unsafe("TestFile"))); EXPECT_EQ(1U, found.count(base::FilePath::FromUTF8Unsafe("TestFile")));
} }
TEST_F(FileSystemTest, AddTeamDriveInChangeList) {
ASSERT_TRUE(SetupTeamDrives());
// The first load trigger the loading of team drives.
ReadDirectorySync(base::FilePath::FromUTF8Unsafe("."));
// Add a new team drive to the fake file system.
{
fake_drive_service_->AddTeamDrive("td_id_3", "team_drive_3");
base::RunLoop().RunUntilIdle();
}
// Notify the update to the file system, which will add the team drive
file_system_->CheckForUpdates();
std::unique_ptr<ResourceEntryVector> entries(
ReadDirectorySync(base::FilePath::FromUTF8Unsafe("drive/team_drives/")));
// The root directory should be read correctly.
ASSERT_TRUE(entries);
std::set<base::FilePath> found;
for (size_t i = 0; i < entries->size(); ++i) {
found.insert(base::FilePath::FromUTF8Unsafe((*entries)[i].title()));
}
EXPECT_EQ(3U, found.size());
EXPECT_EQ(1U, found.count(base::FilePath::FromUTF8Unsafe("team_drive_3")));
// Add a new entry to drive/team_drives/team_drive_3
// Create a file in the test directory.
std::unique_ptr<google_apis::FileResource> entry;
{
google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
fake_drive_service_->AddNewFile(
"text/plain", "(dummy data)", "td_id_3", "TestFile",
false, // shared_with_me
google_apis::test_util::CreateCopyResultCallback(&error, &entry));
base::RunLoop().RunUntilIdle();
ASSERT_EQ(google_apis::HTTP_CREATED, error);
}
// Notify the update to the file system.
file_system_->CheckForUpdates();
entries = ReadDirectorySync(
base::FilePath::FromUTF8Unsafe("drive/team_drives/team_drive_3"));
// The root directory should be read correctly.
ASSERT_TRUE(entries);
found.clear();
for (size_t i = 0; i < entries->size(); ++i) {
found.insert(base::FilePath::FromUTF8Unsafe((*entries)[i].title()));
}
EXPECT_EQ(1U, found.size());
EXPECT_EQ(1U, found.count(base::FilePath::FromUTF8Unsafe("TestFile")));
}
TEST_F(FileSystemTest, ReadDirectory_NonRootDirectory) { TEST_F(FileSystemTest, ReadDirectory_NonRootDirectory) {
// ReadDirectory() should kick off the resource list loading. // ReadDirectory() should kick off the resource list loading.
std::unique_ptr<ResourceEntryVector> entries(ReadDirectorySync( std::unique_ptr<ResourceEntryVector> entries(ReadDirectorySync(
......
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