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

Store the team drive id if the change is an added or removed team drive.

We need to know the team_drive_id so that the FileChange observers can
add or remove team drive change list loaders.

Bug: 715355
Change-Id: Ie6185554c9a8b444913d1edb067530651b436a21
Reviewed-on: https://chromium-review.googlesource.com/1104625
Commit-Queue: Stuart Langley <slangley@chromium.org>
Reviewed-by: default avatarSasha Morrissey <sashab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568323}
parent c45ec0a7
......@@ -16,6 +16,11 @@ FileChange::Change::Change(ChangeType change, FileType file_type)
: change_(change), file_type_(file_type) {
}
FileChange::Change::Change(ChangeType change,
FileType file_type,
const std::string& team_drive_id)
: change_(change), file_type_(file_type), team_drive_id_(team_drive_id) {}
std::string FileChange::Change::DebugString() const {
const char* change_string = nullptr;
switch (change()) {
......@@ -57,6 +62,11 @@ void FileChange::ChangeList::Update(const Change& new_change) {
return;
}
if (last.team_drive_id() != new_change.team_drive_id()) {
list_.push_back(new_change);
return;
}
if (last.change() == new_change.change())
return;
......@@ -114,12 +124,16 @@ void FileChange::Update(const base::FilePath file_path,
void FileChange::Update(const base::FilePath file_path,
const ResourceEntry& entry,
FileChange::ChangeType change) {
FileType type = !entry.has_file_info()
? FILE_TYPE_NO_INFO
: entry.file_info().is_directory() ? FILE_TYPE_DIRECTORY
: FILE_TYPE_FILE;
Update(file_path, type, change);
FileType type = FILE_TYPE_NO_INFO;
std::string team_drive_id;
if (entry.has_file_info()) {
type =
entry.file_info().is_directory() ? FILE_TYPE_DIRECTORY : FILE_TYPE_FILE;
if (entry.file_info().is_team_drive_root()) {
team_drive_id = entry.resource_id();
}
}
Update(file_path, FileChange::Change(change, type, team_drive_id));
}
void FileChange::Apply(const FileChange& new_changed_files) {
......
......@@ -32,6 +32,9 @@ class FileChange {
class Change {
public:
Change(ChangeType change, FileType file_type);
Change(ChangeType change,
FileType file_type,
const std::string& team_drive_id);
bool IsAddOrUpdate() const { return change_ == CHANGE_TYPE_ADD_OR_UPDATE; }
bool IsDelete() const { return change_ == CHANGE_TYPE_DELETE; }
......@@ -42,16 +45,20 @@ class FileChange {
ChangeType change() const { return change_; }
FileType file_type() const { return file_type_; }
const std::string& team_drive_id() const { return team_drive_id_; }
std::string DebugString() const;
bool operator==(const Change& that) const {
return change() == that.change() && file_type() == that.file_type();
return change() == that.change() && file_type() == that.file_type() &&
team_drive_id() == that.team_drive_id();
}
private:
ChangeType change_;
FileType file_type_;
// The team drive id, will be empty if the change is not a team drive root.
std::string team_drive_id_;
};
class ChangeList {
......
......@@ -4,6 +4,7 @@
#include "components/drive/file_change.h"
#include "components/drive/drive.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace drive {
......@@ -57,4 +58,30 @@ TEST(ChangeListTest, FileChange) {
ASSERT_EQ(2u, changed_files.CountDirectory(change_dir));
}
TEST(ChangeListTest, TeamDriveRootChange) {
base::FilePath team_drive1(FILE_PATH_LITERAL("a/b/c"));
base::FilePath team_drive2(FILE_PATH_LITERAL("a/b/d"));
ResourceEntry resource;
resource.mutable_file_info()->set_is_directory(true);
resource.mutable_file_info()->set_is_team_drive_root(true);
FileChange changed_files;
resource.set_resource_id("team_drive_id_1");
changed_files.Update(team_drive1, resource,
FileChange::CHANGE_TYPE_ADD_OR_UPDATE);
resource.set_resource_id("team_drive_id_2");
changed_files.Update(team_drive2, resource,
FileChange::CHANGE_TYPE_ADD_OR_UPDATE);
ASSERT_EQ(2UL, changed_files.size());
const FileChange::Map& change_map = changed_files.map();
ASSERT_EQ("team_drive_id_1",
change_map.at(team_drive1).front().team_drive_id());
ASSERT_EQ("team_drive_id_2",
change_map.at(team_drive2).front().team_drive_id());
}
} // namespace drive
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