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

Detect team drive changes that arrive in the default change list.

This CL allows change_list_processor to detect and surface when a
team drive has been added or removed in the incoming change list.

ChangeListLoaderObserver can then surface these changes to any
observers who are interested in new or removed team drives.

Added tests, fixed fake_drive_service so that team drive changes
are delivered as part of the default change list.

Bug: 715355
Change-Id: I26ff29b047ad532f8e02e1ca5b1a171ca301b95d
Reviewed-on: https://chromium-review.googlesource.com/1100369
Commit-Queue: Stuart Langley <slangley@chromium.org>
Reviewed-by: default avatarSasha Morrissey <sashab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567560}
parent 4b82a40b
......@@ -53,6 +53,8 @@ class TestChangeListLoaderObserver : public ChangeListLoaderObserver {
const FileChange& changed_files() const { return changed_files_; }
void clear_changed_files() { changed_files_.ClearForTest(); }
const FileChange& changed_team_drives() const { return changed_team_drives_; }
int load_from_server_complete_count() const {
return load_from_server_complete_count_;
}
......@@ -64,6 +66,9 @@ class TestChangeListLoaderObserver : public ChangeListLoaderObserver {
void OnFileChanged(const FileChange& changed_files) override {
changed_files_.Apply(changed_files);
}
void OnTeamDrivesChanged(const FileChange& changed_team_drives) override {
changed_team_drives_.Apply(changed_team_drives);
}
void OnLoadFromServerComplete() override {
++load_from_server_complete_count_;
}
......@@ -72,6 +77,7 @@ class TestChangeListLoaderObserver : public ChangeListLoaderObserver {
private:
ChangeListLoader* loader_;
FileChange changed_files_;
FileChange changed_team_drives_;
int load_from_server_complete_count_;
int initial_load_complete_count_;
......@@ -81,6 +87,8 @@ class TestChangeListLoaderObserver : public ChangeListLoaderObserver {
class ChangeListLoaderTest : public testing::Test {
protected:
void SetUp() override {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
google_apis::kEnableTeamDrives);
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
BuildTestObjects();
}
......@@ -125,12 +133,6 @@ class ChangeListLoaderTest : public testing::Test {
util::kTeamDriveIdDefaultCorpus, util::GetDriveMyDriveRootPath());
}
void SetUpForTeamDrives() {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
google_apis::kEnableTeamDrives);
BuildTestObjects();
}
// Adds a new file to the root directory of the service.
std::unique_ptr<google_apis::FileResource> AddNewFile(
const std::string& title) {
......@@ -362,5 +364,33 @@ TEST_F(ChangeListLoaderTest, Lock) {
observer.changed_files().CountDirectory(util::GetDriveMyDriveRootPath()));
}
TEST_F(ChangeListLoaderTest, AddTeamDrive) {
FileError error = FILE_ERROR_FAILED;
change_list_loader_->LoadIfNeeded(
google_apis::test_util::CreateCopyResultCallback(&error));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
// Add a new team drive
{
drive_service_->AddTeamDrive("team_drive_id", "team_drive_name");
base::RunLoop().RunUntilIdle();
}
// Start update.
TestChangeListLoaderObserver observer(change_list_loader_.get());
FileError check_for_updates_error = FILE_ERROR_FAILED;
change_list_loader_->CheckForUpdates(
google_apis::test_util::CreateCopyResultCallback(
&check_for_updates_error));
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(observer.changed_files().empty());
EXPECT_FALSE(observer.changed_team_drives().empty());
EXPECT_EQ(1UL, observer.changed_files().CountDirectory(
util::GetDriveTeamDrivesRootPath()));
EXPECT_EQ(1UL, observer.changed_team_drives().CountDirectory(
util::GetDriveTeamDrivesRootPath()));
}
} // namespace internal
} // namespace drive
......@@ -27,6 +27,7 @@
#include "components/drive/chromeos/start_page_token_loader.h"
#include "components/drive/drive_api_util.h"
#include "components/drive/event_logger.h"
#include "components/drive/file_change.h"
#include "components/drive/file_system_core_util.h"
#include "components/drive/job_scheduler.h"
#include "google_apis/drive/drive_api_parser.h"
......@@ -490,6 +491,13 @@ void ChangeListLoader::LoadChangeListFromServerAfterUpdate(
observer.OnFileChanged(change_list_processor->changed_files());
}
if (!change_list_processor->changed_team_drives().empty()) {
for (auto& observer : observers_) {
observer.OnTeamDrivesChanged(
change_list_processor->changed_team_drives());
}
}
OnChangeListLoadComplete(error);
for (auto& observer : observers_)
......
......@@ -25,6 +25,9 @@ class ChangeListLoaderObserver {
// Triggered when content(s) in drive has been changed.
virtual void OnFileChanged(const FileChange& changed_files) {}
// Triggered when the users accessible team drives has changed.
virtual void OnTeamDrivesChanged(const FileChange& changed_team_drives) {}
// Triggered when loading from the server is complete.
virtual void OnLoadFromServerComplete() {}
......
......@@ -143,6 +143,7 @@ ChangeListProcessor::ChangeListProcessor(const std::string& team_drive_id,
: resource_metadata_(resource_metadata),
in_shutdown_(in_shutdown),
changed_files_(new FileChange),
changed_team_drives_(new FileChange),
team_drive_id_(team_drive_id),
root_entry_path_(root_entry_path) {}
......@@ -536,6 +537,10 @@ void ChangeListProcessor::UpdateChangedDirs(const ResourceEntry& entry) {
? FileChange::CHANGE_TYPE_DELETE
: FileChange::CHANGE_TYPE_ADD_OR_UPDATE;
changed_files_->Update(file_path, entry, type);
if (entry.file_info().is_team_drive_root()) {
changed_team_drives_->Update(file_path, entry, type);
}
}
}
......
......@@ -144,6 +144,13 @@ class ChangeListProcessor {
// The set of changed files as a result of change list processing.
const FileChange& changed_files() const { return *changed_files_; }
// The set of team drives changes as a result of change list processing.
// Note that a team drive change will appear in both changed_files() and
// changed_team_drives()
const FileChange& changed_team_drives() const {
return *changed_team_drives_;
}
// Adds or refreshes the child entries from |change_list| to the directory.
static FileError RefreshDirectory(
ResourceMetadata* resource_metadata,
......@@ -196,6 +203,7 @@ class ChangeListProcessor {
ResourceEntryMap entry_map_;
ParentResourceIdMap parent_resource_id_map_;
std::unique_ptr<FileChange> changed_files_;
std::unique_ptr<FileChange> changed_team_drives_;
const std::string team_drive_id_;
const base::FilePath& root_entry_path_;
......
......@@ -19,6 +19,7 @@ message PlatformFileInfoProto {
optional int64 last_modified = 4;
optional int64 last_accessed = 5;
optional int64 creation_time = 6;
optional bool is_team_drive_root = 7;
}
// Represents a property for a file.
......
......@@ -35,6 +35,7 @@ bool ConvertChangeResourceToResourceEntry(
// latter doesn't exist for deleted items.
converted.set_resource_id(input.team_drive_id());
converted.mutable_file_info()->set_is_directory(true);
converted.mutable_file_info()->set_is_team_drive_root(true);
converted.set_parent_local_id(util::kDriveTeamDrivesDirLocalId);
}
} else {
......@@ -158,6 +159,7 @@ void ConvertTeamDriveResourceToResourceEntry(
ResourceEntry* out_entry) {
DCHECK(out_entry);
out_entry->mutable_file_info()->set_is_directory(true);
out_entry->mutable_file_info()->set_is_team_drive_root(true);
out_entry->set_title(input.name());
out_entry->set_base_name(input.name());
out_entry->set_resource_id(input.id());
......
......@@ -1904,7 +1904,7 @@ const FakeDriveService::EntryInfo* FakeDriveService::AddNewTeamDriveEntry(
new_entry->share_url = net::AppendOrReplaceQueryParameter(
share_url_base_, "name", team_drive_name);
AddNewChangestamp(&change, team_drive_id);
AddNewChangestamp(&change, std::string());
change.set_modification_date(base::Time() +
base::TimeDelta::FromMilliseconds(++date_seq_));
......
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