Commit 95c21505 authored by Stuart Langley's avatar Stuart Langley Committed by Commit Bot

Pass the team drive id and root path to loaders so the can support team drives.

Currently change_list_loader and directory_loader only work for the users
default corpus. We can fix this by passing the team_drive_id and the
root_entry_path as parameters during construction rather then just assuming
the users default corpus root.

With this change we can not use directory_loader and change_list_loader to also
processes changes from team drives by passing the appropriate team_drive_id and
root_entry_path.

Bug: 835703, 833690

Change-Id: I5ba3ed8fa3323dfd520c9e1837934eeef79a30a7
Reviewed-on: https://chromium-review.googlesource.com/1068642
Commit-Queue: Stuart Langley <slangley@chromium.org>
Reviewed-by: default avatarSasha Morrissey <sashab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561767}
parent d6a8b825
......@@ -120,7 +120,8 @@ class ChangeListLoaderTest : public testing::Test {
change_list_loader_.reset(new ChangeListLoader(
logger_.get(), base::ThreadTaskRunnerHandle::Get().get(),
metadata_.get(), scheduler_.get(), root_folder_id_loader_.get(),
start_page_token_loader_.get(), loader_controller_.get()));
start_page_token_loader_.get(), loader_controller_.get(),
util::kTeamDriveIdDefaultCorpus, util::GetDriveMyDriveRootPath()));
}
void SetUpForTeamDrives() {
......@@ -265,7 +266,8 @@ TEST_F(ChangeListLoaderTest, Load_LocalMetadataAvailable) {
change_list_loader_.reset(new ChangeListLoader(
logger_.get(), base::ThreadTaskRunnerHandle::Get().get(), metadata_.get(),
scheduler_.get(), root_folder_id_loader_.get(),
start_page_token_loader_.get(), loader_controller_.get()));
start_page_token_loader_.get(), loader_controller_.get(),
util::kTeamDriveIdDefaultCorpus, util::GetDriveMyDriveRootPath()));
// Add a file to the service.
std::unique_ptr<google_apis::FileResource> gdata_entry =
......
......@@ -131,7 +131,9 @@ class ChangeListProcessorTest : public testing::Test {
// start page token |kBaseStartPageToken|.
FileError ApplyFullResourceList(
std::vector<std::unique_ptr<ChangeList>> changes) {
ChangeListProcessor processor(metadata_.get(), nullptr);
ChangeListProcessor processor(util::kTeamDriveIdDefaultCorpus,
util::GetDriveMyDriveRootPath(),
metadata_.get(), nullptr);
return processor.ApplyUserChangeList(kBaseStartPageToken, kRootId,
std::move(changes),
false /* is_delta_update */);
......@@ -143,7 +145,9 @@ class ChangeListProcessorTest : public testing::Test {
FileError ApplyUserChangeList(
std::vector<std::unique_ptr<ChangeList>> changes,
FileChange* changed_files) {
ChangeListProcessor processor(metadata_.get(), nullptr);
ChangeListProcessor processor(util::kTeamDriveIdDefaultCorpus,
util::GetDriveMyDriveRootPath(),
metadata_.get(), nullptr);
FileError error = processor.ApplyUserChangeList(kBaseStartPageToken,
kRootId, std::move(changes),
true /* is_delta_update */);
......
......@@ -238,7 +238,9 @@ ChangeListLoader::ChangeListLoader(
JobScheduler* scheduler,
RootFolderIdLoader* root_folder_id_loader,
StartPageTokenLoader* start_page_token_loader,
LoaderController* loader_controller)
LoaderController* loader_controller,
const std::string& team_drive_id,
const base::FilePath& root_entry_path)
: logger_(logger),
blocking_task_runner_(blocking_task_runner),
in_shutdown_(new base::CancellationFlag),
......@@ -248,6 +250,8 @@ ChangeListLoader::ChangeListLoader(
start_page_token_loader_(start_page_token_loader),
loader_controller_(loader_controller),
loaded_(false),
team_drive_id_(team_drive_id),
root_entry_path_(root_entry_path),
weak_ptr_factory_(this) {}
ChangeListLoader::~ChangeListLoader() {
......@@ -525,8 +529,8 @@ void ChangeListLoader::LoadChangeListFromServerAfterLoadChangeList(
std::make_move_iterator(change_lists.begin()),
std::make_move_iterator(change_lists.end()));
ChangeListProcessor* change_list_processor =
new ChangeListProcessor(resource_metadata_, in_shutdown_.get());
ChangeListProcessor* change_list_processor = new ChangeListProcessor(
team_drive_id_, root_entry_path_, resource_metadata_, in_shutdown_.get());
// Don't send directory content change notification while performing
// the initial content retrieval.
const bool should_notify_changed_directories = is_delta_update;
......
......@@ -65,7 +65,9 @@ class ChangeListLoader {
JobScheduler* scheduler,
RootFolderIdLoader* root_folder_id_loader,
StartPageTokenLoader* start_page_token_loader,
LoaderController* apply_task_controller);
LoaderController* apply_task_controller,
const std::string& team_drive_id,
const base::FilePath& root_entry_path);
~ChangeListLoader();
// Indicates whether there is a request for full resource list or change
......@@ -175,6 +177,14 @@ class ChangeListLoader {
// stored locally).
bool loaded_;
// The team drive id for the changes being loaded by this change list loader.
const std::string team_drive_id_;
// The root entry path for changes being loaded by this change list loader.
// Can be a team drive root entry or for the users default corpus will be the
// drive root entry.
const base::FilePath root_entry_path_;
THREAD_CHECKER(thread_checker_);
// Note: This should remain the last member so it'll be destroyed and
......
......@@ -13,6 +13,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/cancellation_flag.h"
#include "components/drive/chromeos/drive_file_util.h"
#include "components/drive/chromeos/resource_metadata.h"
#include "components/drive/drive.pb.h"
#include "components/drive/drive_api_util.h"
......@@ -118,11 +119,15 @@ class ChangeListProcessor::ChangeListToEntryMapUMAStats {
int num_hosted_documents_;
};
ChangeListProcessor::ChangeListProcessor(ResourceMetadata* resource_metadata,
ChangeListProcessor::ChangeListProcessor(const std::string& team_drive_id,
const base::FilePath& root_entry_path,
ResourceMetadata* resource_metadata,
base::CancellationFlag* in_shutdown)
: resource_metadata_(resource_metadata),
in_shutdown_(in_shutdown),
changed_files_(new FileChange) {}
changed_files_(new FileChange),
team_drive_id_(team_drive_id),
root_entry_path_(root_entry_path) {}
ChangeListProcessor::~ChangeListProcessor() = default;
......@@ -143,8 +148,8 @@ FileError ChangeListProcessor::ApplyUserChangeList(
ResourceEntry root;
// Update the resource ID of the entry for "My Drive" directory.
FileError error = resource_metadata_->GetResourceEntryByPath(
util::GetDriveMyDriveRootPath(), &root);
FileError error =
resource_metadata_->GetResourceEntryByPath(root_entry_path_, &root);
if (error != FILE_ERROR_OK) {
LOG(ERROR) << "Failed to get root entry: " << FileErrorToString(error);
return error;
......@@ -163,7 +168,8 @@ FileError ChangeListProcessor::ApplyUserChangeList(
return error;
// Update start_page_token in the metadata header.
error = resource_metadata_->SetStartPageToken(new_start_page_token);
error = SetStartPageToken(resource_metadata_, team_drive_id_,
new_start_page_token);
if (error != FILE_ERROR_OK) {
DLOG(ERROR) << "SetStartPageToken failed: " << FileErrorToString(error);
return error;
......
......@@ -113,7 +113,9 @@ class ChangeList {
// updates the resource metadata stored locally.
class ChangeListProcessor {
public:
ChangeListProcessor(ResourceMetadata* resource_metadata,
ChangeListProcessor(const std::string& team_drive_id,
const base::FilePath& root_entry_path,
ResourceMetadata* resource_metadata,
base::CancellationFlag* in_shutdown);
~ChangeListProcessor();
......@@ -124,6 +126,10 @@ class ChangeListProcessor {
// it is full resource lists (false) or change lists (true).
//
// Must be run on the same task runner as |resource_metadata_| uses.
// |start_page_token| is the start page token used to retrieve the change
// list.
// |root_resource_id| is the resource id to lookup the root folder of the
// changeslists in resource metadata.
FileError ApplyUserChangeList(
const std::string& start_page_token,
const std::string& root_resource_id,
......@@ -185,6 +191,8 @@ class ChangeListProcessor {
ResourceEntryMap entry_map_;
ParentResourceIdMap parent_resource_id_map_;
std::unique_ptr<FileChange> changed_files_;
const std::string team_drive_id_;
const base::FilePath& root_entry_path_;
DISALLOW_COPY_AND_ASSIGN(ChangeListProcessor);
};
......
......@@ -33,12 +33,13 @@ DefaultCorpusChangeListLoader::DefaultCorpusChangeListLoader(
change_list_loader_ = std::make_unique<ChangeListLoader>(
logger_, blocking_task_runner_.get(), resource_metadata_, scheduler_,
root_folder_id_loader_.get(), start_page_token_loader_.get(),
loader_controller_);
loader_controller_, util::kTeamDriveIdDefaultCorpus,
util::GetDriveMyDriveRootPath());
directory_loader_ = std::make_unique<DirectoryLoader>(
logger_, blocking_task_runner_.get(), resource_metadata_, scheduler_,
root_folder_id_loader_.get(), start_page_token_loader_.get(),
loader_controller_);
loader_controller_, util::GetDriveMyDriveRootPath());
}
DefaultCorpusChangeListLoader::~DefaultCorpusChangeListLoader() = default;
......
......@@ -38,6 +38,7 @@ namespace {
constexpr int kMinimumChangestampGap = 50;
FileError CheckLocalState(ResourceMetadata* resource_metadata,
const base::FilePath& root_entry_path,
const std::string& root_folder_id,
const std::string& local_id,
ResourceEntry* entry,
......@@ -45,8 +46,8 @@ FileError CheckLocalState(ResourceMetadata* resource_metadata,
DCHECK(start_page_token);
// Fill My Drive resource ID.
ResourceEntry mydrive;
FileError error = resource_metadata->GetResourceEntryByPath(
util::GetDriveMyDriveRootPath(), &mydrive);
FileError error =
resource_metadata->GetResourceEntryByPath(root_entry_path, &mydrive);
if (error != FILE_ERROR_OK)
return error;
......@@ -204,7 +205,8 @@ DirectoryLoader::DirectoryLoader(
JobScheduler* scheduler,
RootFolderIdLoader* root_folder_id_loader,
StartPageTokenLoader* start_page_token_loader,
LoaderController* loader_controller)
LoaderController* loader_controller,
const base::FilePath& root_entry_path)
: logger_(logger),
blocking_task_runner_(blocking_task_runner),
resource_metadata_(resource_metadata),
......@@ -212,6 +214,7 @@ DirectoryLoader::DirectoryLoader(
root_folder_id_loader_(root_folder_id_loader),
start_page_token_loader_(start_page_token_loader),
loader_controller_(loader_controller),
root_entry_path_(root_entry_path),
weak_ptr_factory_(this) {}
DirectoryLoader::~DirectoryLoader() = default;
......@@ -371,8 +374,8 @@ void DirectoryLoader::ReadDirectoryAfterGetStartPageToken(
std::string* local_start_page_token = new std::string();
base::PostTaskAndReplyWithResult(
blocking_task_runner_.get(), FROM_HERE,
base::BindOnce(&CheckLocalState, resource_metadata_, root_folder_id,
local_id, entry, local_start_page_token),
base::BindOnce(&CheckLocalState, resource_metadata_, root_entry_path_,
root_folder_id, local_id, entry, local_start_page_token),
base::BindOnce(&DirectoryLoader::ReadDirectoryAfterCheckLocalState,
weak_ptr_factory_.GetWeakPtr(),
start_page_token->start_page_token(), local_id,
......
......@@ -51,7 +51,8 @@ class DirectoryLoader {
JobScheduler* scheduler,
RootFolderIdLoader* root_folder_id_loader,
StartPageTokenLoader* start_page_token_loader,
LoaderController* apply_task_controller);
LoaderController* apply_task_controller,
const base::FilePath& root_entry_path);
~DirectoryLoader();
// Adds and removes the observer.
......@@ -145,6 +146,11 @@ class DirectoryLoader {
// Set of the running feed fetcher for the fast fetch.
std::set<std::unique_ptr<FeedFetcher>> fast_fetch_feed_fetcher_set_;
// The root entry path for changes being loaded by this directory loader.
// Can be a team drive root entry or for the users default corpus will be the
// drive root entry.
const base::FilePath root_entry_path_;
THREAD_CHECKER(thread_checker_);
// Note: This should remain the last member so it'll be destroyed and
......
......@@ -109,7 +109,8 @@ class DirectoryLoaderTest : public testing::Test {
directory_loader_.reset(new DirectoryLoader(
logger_.get(), base::ThreadTaskRunnerHandle::Get().get(),
metadata_.get(), scheduler_.get(), root_folder_id_loader_.get(),
start_page_token_loader_.get(), loader_controller_.get()));
start_page_token_loader_.get(), loader_controller_.get(),
util::GetDriveMyDriveRootPath()));
}
// Adds a new file to the root directory of the service.
......
......@@ -132,7 +132,8 @@ void OperationTestBase::SetUp() {
change_list_loader_.reset(new internal::ChangeListLoader(
logger_.get(), blocking_task_runner_.get(), metadata_.get(),
scheduler_.get(), root_folder_id_loader_.get(),
start_page_token_loader_.get(), loader_controller_.get()));
start_page_token_loader_.get(), loader_controller_.get(),
util::kTeamDriveIdDefaultCorpus, util::GetDriveMyDriveRootPath()));
change_list_loader_->LoadIfNeeded(
google_apis::test_util::CreateCopyResultCallback(&error));
content::RunAllTasksUntilIdle();
......
......@@ -148,7 +148,8 @@ class SyncClientTest : public testing::Test {
change_list_loader_.reset(new ChangeListLoader(
logger_.get(), base::ThreadTaskRunnerHandle::Get().get(),
metadata_.get(), scheduler_.get(), root_folder_id_loader_.get(),
start_page_token_loader_.get(), loader_controller_.get()));
start_page_token_loader_.get(), loader_controller_.get(),
util::kTeamDriveIdDefaultCorpus, util::GetDriveMyDriveRootPath()));
ASSERT_NO_FATAL_FAILURE(SetUpTestData());
sync_client_.reset(
......
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