Commit 65234c47 authored by Stuart Langley's avatar Stuart Langley Committed by Commit Bot

ResourceMetadata for supporting StartPageToken in the header and directories.

This cl adds start_page_token to ResourceMetadataHeader and
DirectorySpecificInfo for supporting change list retrival based on
startPageToken instead of largestChangeId.

Bug: 840211
Change-Id: Ib498276b48b28dc1876fc9a70a4a1356b60ddeb9
Reviewed-on: https://chromium-review.googlesource.com/1050052Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Commit-Queue: Stuart Langley <slangley@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557137}
parent f0137029
...@@ -103,6 +103,10 @@ FileError ResourceMetadata::Reset() { ...@@ -103,6 +103,10 @@ FileError ResourceMetadata::Reset() {
if (error != FILE_ERROR_OK) if (error != FILE_ERROR_OK)
return error; return error;
error = storage_->SetStartPageToken(std::string());
if (error != FILE_ERROR_OK)
return error;
// Remove all root entries. // Remove all root entries.
std::unique_ptr<Iterator> it = GetIterator(); std::unique_ptr<Iterator> it = GetIterator();
for (; !it->IsAtEnd(); it->Advance()) { for (; !it->IsAtEnd(); it->Advance()) {
...@@ -245,6 +249,20 @@ FileError ResourceMetadata::SetLargestChangestamp(int64_t value) { ...@@ -245,6 +249,20 @@ FileError ResourceMetadata::SetLargestChangestamp(int64_t value) {
return storage_->SetLargestChangestamp(value); return storage_->SetLargestChangestamp(value);
} }
FileError ResourceMetadata::GetStartPageToken(std::string* out_value) {
DCHECK(blocking_task_runner_->RunsTasksInCurrentSequence());
return storage_->GetStartPageToken(out_value);
}
FileError ResourceMetadata::SetStartPageToken(const std::string& value) {
DCHECK(blocking_task_runner_->RunsTasksInCurrentSequence());
if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path()))
return FILE_ERROR_NO_LOCAL_SPACE;
return storage_->SetStartPageToken(value);
}
FileError ResourceMetadata::AddEntry(const ResourceEntry& entry, FileError ResourceMetadata::AddEntry(const ResourceEntry& entry,
std::string* out_id) { std::string* out_id) {
DCHECK(blocking_task_runner_->RunsTasksInCurrentSequence()); DCHECK(blocking_task_runner_->RunsTasksInCurrentSequence());
......
...@@ -62,6 +62,12 @@ class ResourceMetadata { ...@@ -62,6 +62,12 @@ class ResourceMetadata {
// Sets the largest changestamp. // Sets the largest changestamp.
FileError SetLargestChangestamp(int64_t value); FileError SetLargestChangestamp(int64_t value);
// Returns the start page token for the users default corpus.
FileError GetStartPageToken(std::string* out_value);
// Sets the start page token for the users default corpus.
FileError SetStartPageToken(const std::string& value);
// Adds |entry| to the metadata tree based on its parent_local_id. // Adds |entry| to the metadata tree based on its parent_local_id.
FileError AddEntry(const ResourceEntry& entry, std::string* out_id); FileError AddEntry(const ResourceEntry& entry, std::string* out_id);
......
...@@ -79,7 +79,12 @@ message DirectorySpecificInfo { ...@@ -79,7 +79,12 @@ message DirectorySpecificInfo {
// changestamp of ResourceMetadata, if this directory was // changestamp of ResourceMetadata, if this directory was
// "fast-fetched". See crbug.com/178348 for details about the "fast-fetch" // "fast-fetched". See crbug.com/178348 for details about the "fast-fetch"
// feature. // feature.
// TODO(slangley): Deprecate and remove changestamp.
optional int64 changestamp = 1; optional int64 changestamp = 1;
// The start page token of this directory. This value may not match the
// start_page_token of ResourceMetadata if the directory was "fast-fetched".
optional string start_page_token = 2;
} }
// Represents metadata of a resource (file or directory) on Drive. // Represents metadata of a resource (file or directory) on Drive.
...@@ -162,11 +167,16 @@ message ResourceMetadataHeader { ...@@ -162,11 +167,16 @@ message ResourceMetadataHeader {
// incompatible change is made to the DB format. kDBVersion in // incompatible change is made to the DB format. kDBVersion in
// drive_resource_metadata_storage.h defines the current version. // drive_resource_metadata_storage.h defines the current version.
optional int32 version = 1; optional int32 version = 1;
// TODO(slangley): Deprecate and remove changestamp.
optional int64 largest_changestamp = 2; optional int64 largest_changestamp = 2;
// The argument with ID 3 (starred_property_initialized) had been used, but // The argument with ID 3 (starred_property_initialized) had been used, but
// got deleted. // got deleted.
reserved 3; reserved 3;
// The start_page_token for the users default corpus changelist.
optional string start_page_token = 4;
} }
// Message to store information of an existing cache file. // Message to store information of an existing cache file.
......
...@@ -767,6 +767,33 @@ FileError ResourceMetadataStorage::GetLargestChangestamp( ...@@ -767,6 +767,33 @@ FileError ResourceMetadataStorage::GetLargestChangestamp(
return FILE_ERROR_OK; return FILE_ERROR_OK;
} }
FileError ResourceMetadataStorage::GetStartPageToken(
std::string* start_page_token) {
base::AssertBlockingAllowed();
ResourceMetadataHeader header;
FileError error = GetHeader(&header);
if (error != FILE_ERROR_OK) {
DLOG(ERROR) << "Failed to get the header.";
return error;
}
*start_page_token = header.start_page_token();
return FILE_ERROR_OK;
}
FileError ResourceMetadataStorage::SetStartPageToken(
const std::string& start_page_token) {
base::AssertBlockingAllowed();
ResourceMetadataHeader header;
FileError error = GetHeader(&header);
if (error != FILE_ERROR_OK) {
DLOG(ERROR) << "Failed to get the header.";
return error;
}
header.set_start_page_token(start_page_token);
return PutHeader(header);
}
FileError ResourceMetadataStorage::PutEntry(const ResourceEntry& entry) { FileError ResourceMetadataStorage::PutEntry(const ResourceEntry& entry) {
base::AssertBlockingAllowed(); base::AssertBlockingAllowed();
......
...@@ -109,6 +109,10 @@ class ResourceMetadataStorage { ...@@ -109,6 +109,10 @@ class ResourceMetadataStorage {
// Gets the largest changestamp. // Gets the largest changestamp.
FileError GetLargestChangestamp(int64_t* largest_changestamp); FileError GetLargestChangestamp(int64_t* largest_changestamp);
FileError GetStartPageToken(std::string* out_value);
FileError SetStartPageToken(const std::string& value);
// Puts the entry to this storage. // Puts the entry to this storage.
FileError PutEntry(const ResourceEntry& entry); FileError PutEntry(const ResourceEntry& entry);
......
...@@ -27,9 +27,8 @@ namespace drive { ...@@ -27,9 +27,8 @@ namespace drive {
namespace internal { namespace internal {
namespace { namespace {
// The changestamp of the resource metadata used in // The start page token of the resource metadata used in ResourceMetadataTest.
// ResourceMetadataTest. constexpr char kTestStartPageToken[] = "a token";
const int64_t kTestChangestamp = 100;
// Returns the sorted base names from |entries|. // Returns the sorted base names from |entries|.
std::vector<std::string> GetSortedBaseNames( std::vector<std::string> GetSortedBaseNames(
...@@ -52,7 +51,8 @@ ResourceEntry CreateDirectoryEntryWithResourceId( ...@@ -52,7 +51,8 @@ ResourceEntry CreateDirectoryEntryWithResourceId(
entry.set_resource_id(resource_id); entry.set_resource_id(resource_id);
entry.set_parent_local_id(parent_local_id); entry.set_parent_local_id(parent_local_id);
entry.mutable_file_info()->set_is_directory(true); entry.mutable_file_info()->set_is_directory(true);
entry.mutable_directory_specific_info()->set_changestamp(kTestChangestamp); entry.mutable_directory_specific_info()->set_start_page_token(
kTestStartPageToken);
return entry; return entry;
} }
...@@ -131,7 +131,7 @@ void SetUpEntries(ResourceMetadata* resource_metadata) { ...@@ -131,7 +131,7 @@ void SetUpEntries(ResourceMetadata* resource_metadata) {
CreateFileEntry("file10", local_id_dir3), &local_id)); CreateFileEntry("file10", local_id_dir3), &local_id));
ASSERT_EQ(FILE_ERROR_OK, ASSERT_EQ(FILE_ERROR_OK,
resource_metadata->SetLargestChangestamp(kTestChangestamp)); resource_metadata->SetStartPageToken(kTestStartPageToken));
} }
} // namespace } // namespace
...@@ -181,6 +181,16 @@ TEST_F(ResourceMetadataTest, LargestChangestamp) { ...@@ -181,6 +181,16 @@ TEST_F(ResourceMetadataTest, LargestChangestamp) {
EXPECT_EQ(kChangestamp, changestamp); EXPECT_EQ(kChangestamp, changestamp);
} }
TEST_F(ResourceMetadataTest, StartPageToken) {
constexpr char kStartPageToken[] = "a different token";
EXPECT_EQ(FILE_ERROR_OK,
resource_metadata_->SetStartPageToken(kStartPageToken));
std::string start_page_token;
EXPECT_EQ(FILE_ERROR_OK,
resource_metadata_->GetStartPageToken(&start_page_token));
EXPECT_EQ(kStartPageToken, start_page_token);
}
TEST_F(ResourceMetadataTest, GetResourceEntryByPath) { TEST_F(ResourceMetadataTest, GetResourceEntryByPath) {
// Confirm that an existing file is found. // Confirm that an existing file is found.
ResourceEntry entry; ResourceEntry entry;
...@@ -200,7 +210,7 @@ TEST_F(ResourceMetadataTest, GetResourceEntryByPath) { ...@@ -200,7 +210,7 @@ TEST_F(ResourceMetadataTest, GetResourceEntryByPath) {
EXPECT_EQ(FILE_ERROR_NOT_FOUND, resource_metadata_->GetResourceEntryByPath( EXPECT_EQ(FILE_ERROR_NOT_FOUND, resource_metadata_->GetResourceEntryByPath(
base::FilePath::FromUTF8Unsafe("non_existing"), &entry)); base::FilePath::FromUTF8Unsafe("non_existing"), &entry));
// Confirm that an entry is not found with a wrong root. // Confirm that an entry is not found with a wrong root.
EXPECT_EQ(FILE_ERROR_NOT_FOUND, resource_metadata_->GetResourceEntryByPath( EXPECT_EQ(FILE_ERROR_NOT_FOUND, resource_metadata_->GetResourceEntryByPath(
base::FilePath::FromUTF8Unsafe("non_existing/root"), &entry)); base::FilePath::FromUTF8Unsafe("non_existing/root"), &entry));
} }
...@@ -675,10 +685,10 @@ TEST_F(ResourceMetadataTest, Reset) { ...@@ -675,10 +685,10 @@ TEST_F(ResourceMetadataTest, Reset) {
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->Reset()); EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->Reset());
// change stamp should be reset. // change stamp should be reset.
int64_t changestamp = 0; std::string start_page_token;
EXPECT_EQ(FILE_ERROR_OK, EXPECT_EQ(FILE_ERROR_OK,
resource_metadata_->GetLargestChangestamp(&changestamp)); resource_metadata_->GetStartPageToken(&start_page_token));
EXPECT_EQ(0, changestamp); EXPECT_TRUE(start_page_token.empty());
// root should continue to exist. // root should continue to exist.
ResourceEntry entry; ResourceEntry entry;
......
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