Commit 12507e6f authored by tzik@chromium.org's avatar tzik@chromium.org

[SyncFS] Add per-URL promote of demoted changes in LocalFileChangeTracker

BUG=344769
TEST=unit_tests --gtest_filter=LocalFileChangeTrackerTest.DemoteAndPromote

Review URL: https://codereview.chromium.org/386373002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282933 0039d316-1c4b-4281-b951-d872f2087c98
parent fdd6398b
...@@ -131,8 +131,8 @@ void LocalFileChangeTracker::OnRemoveDirectory(const FileSystemURL& url) { ...@@ -131,8 +131,8 @@ void LocalFileChangeTracker::OnRemoveDirectory(const FileSystemURL& url) {
void LocalFileChangeTracker::GetNextChangedURLs( void LocalFileChangeTracker::GetNextChangedURLs(
std::deque<FileSystemURL>* urls, int max_urls) { std::deque<FileSystemURL>* urls, int max_urls) {
DCHECK(urls);
DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
DCHECK(urls);
urls->clear(); urls->clear();
// Mildly prioritizes the URLs that older changes and have not been updated // Mildly prioritizes the URLs that older changes and have not been updated
// for a while. // for a while.
...@@ -173,12 +173,14 @@ void LocalFileChangeTracker::ClearChangesForURL(const FileSystemURL& url) { ...@@ -173,12 +173,14 @@ void LocalFileChangeTracker::ClearChangesForURL(const FileSystemURL& url) {
void LocalFileChangeTracker::CreateFreshMirrorForURL( void LocalFileChangeTracker::CreateFreshMirrorForURL(
const fileapi::FileSystemURL& url) { const fileapi::FileSystemURL& url) {
DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
DCHECK(!ContainsKey(mirror_changes_, url)); DCHECK(!ContainsKey(mirror_changes_, url));
mirror_changes_[url] = ChangeInfo(); mirror_changes_[url] = ChangeInfo();
} }
void LocalFileChangeTracker::RemoveMirrorAndCommitChangesForURL( void LocalFileChangeTracker::RemoveMirrorAndCommitChangesForURL(
const fileapi::FileSystemURL& url) { const fileapi::FileSystemURL& url) {
DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
FileChangeMap::iterator found = mirror_changes_.find(url); FileChangeMap::iterator found = mirror_changes_.find(url);
if (found == mirror_changes_.end()) if (found == mirror_changes_.end())
return; return;
...@@ -193,6 +195,7 @@ void LocalFileChangeTracker::RemoveMirrorAndCommitChangesForURL( ...@@ -193,6 +195,7 @@ void LocalFileChangeTracker::RemoveMirrorAndCommitChangesForURL(
void LocalFileChangeTracker::ResetToMirrorAndCommitChangesForURL( void LocalFileChangeTracker::ResetToMirrorAndCommitChangesForURL(
const fileapi::FileSystemURL& url) { const fileapi::FileSystemURL& url) {
DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
FileChangeMap::iterator found = mirror_changes_.find(url); FileChangeMap::iterator found = mirror_changes_.find(url);
if (found == mirror_changes_.end() || found->second.change_list.empty()) { if (found == mirror_changes_.end() || found->second.change_list.empty()) {
ClearChangesForURL(url); ClearChangesForURL(url);
...@@ -206,6 +209,7 @@ void LocalFileChangeTracker::ResetToMirrorAndCommitChangesForURL( ...@@ -206,6 +209,7 @@ void LocalFileChangeTracker::ResetToMirrorAndCommitChangesForURL(
void LocalFileChangeTracker::DemoteChangesForURL( void LocalFileChangeTracker::DemoteChangesForURL(
const fileapi::FileSystemURL& url) { const fileapi::FileSystemURL& url) {
DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
FileChangeMap::iterator found = changes_.find(url); FileChangeMap::iterator found = changes_.find(url);
if (found == changes_.end()) if (found == changes_.end())
return; return;
...@@ -223,26 +227,35 @@ void LocalFileChangeTracker::DemoteChangesForURL( ...@@ -223,26 +227,35 @@ void LocalFileChangeTracker::DemoteChangesForURL(
} }
} }
void LocalFileChangeTracker::PromoteDemotedChangesForURL(
const fileapi::FileSystemURL& url) {
DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
FileChangeMap::iterator iter = demoted_changes_.find(url);
if (iter == demoted_changes_.end())
return;
FileChangeList::List change_list = iter->second.change_list.list();
// Make sure that this URL is in no queues.
DCHECK(!ContainsKey(changes_, url));
DCHECK(!ContainsKey(mirror_changes_, url));
demoted_changes_.erase(iter);
while (!change_list.empty()) {
RecordChange(url, change_list.front());
change_list.pop_front();
}
}
bool LocalFileChangeTracker::PromoteDemotedChanges() { bool LocalFileChangeTracker::PromoteDemotedChanges() {
DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
if (demoted_changes_.empty()) if (demoted_changes_.empty())
return false; return false;
for (FileChangeMap::iterator iter = demoted_changes_.begin(); while (!demoted_changes_.empty()) {
iter != demoted_changes_.end();) { fileapi::FileSystemURL url = demoted_changes_.begin()->first;
fileapi::FileSystemURL url = iter->first; PromoteDemotedChangesForURL(url);
FileChangeList::List change_list = iter->second.change_list.list();
demoted_changes_.erase(iter++);
// Make sure that this URL is in no queues.
DCHECK(!ContainsKey(changes_, url));
DCHECK(!ContainsKey(demoted_changes_, url));
DCHECK(!ContainsKey(mirror_changes_, url));
while (!change_list.empty()) {
RecordChange(url, change_list.front());
change_list.pop_front();
}
} }
demoted_changes_.clear();
return true; return true;
} }
...@@ -296,6 +309,7 @@ void LocalFileChangeTracker::UpdateNumChanges() { ...@@ -296,6 +309,7 @@ void LocalFileChangeTracker::UpdateNumChanges() {
} }
void LocalFileChangeTracker::GetAllChangedURLs(FileSystemURLSet* urls) { void LocalFileChangeTracker::GetAllChangedURLs(FileSystemURLSet* urls) {
DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
std::deque<FileSystemURL> url_deque; std::deque<FileSystemURL> url_deque;
GetNextChangedURLs(&url_deque, 0); GetNextChangedURLs(&url_deque, 0);
urls->clear(); urls->clear();
...@@ -303,6 +317,7 @@ void LocalFileChangeTracker::GetAllChangedURLs(FileSystemURLSet* urls) { ...@@ -303,6 +317,7 @@ void LocalFileChangeTracker::GetAllChangedURLs(FileSystemURLSet* urls) {
} }
void LocalFileChangeTracker::DropAllChanges() { void LocalFileChangeTracker::DropAllChanges() {
DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
changes_.clear(); changes_.clear();
change_seqs_.clear(); change_seqs_.clear();
mirror_changes_.clear(); mirror_changes_.clear();
...@@ -319,6 +334,7 @@ SyncStatusCode LocalFileChangeTracker::MarkDirtyOnDatabase( ...@@ -319,6 +334,7 @@ SyncStatusCode LocalFileChangeTracker::MarkDirtyOnDatabase(
SyncStatusCode LocalFileChangeTracker::ClearDirtyOnDatabase( SyncStatusCode LocalFileChangeTracker::ClearDirtyOnDatabase(
const FileSystemURL& url) { const FileSystemURL& url) {
DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
std::string serialized_url; std::string serialized_url;
if (!SerializeSyncableFileSystemURL(url, &serialized_url)) if (!SerializeSyncableFileSystemURL(url, &serialized_url))
return SYNC_FILE_ERROR_INVALID_URL; return SYNC_FILE_ERROR_INVALID_URL;
...@@ -407,6 +423,7 @@ void LocalFileChangeTracker::RecordChange( ...@@ -407,6 +423,7 @@ void LocalFileChangeTracker::RecordChange(
UpdateNumChanges(); UpdateNumChanges();
} }
// static
void LocalFileChangeTracker::RecordChangeToChangeMaps( void LocalFileChangeTracker::RecordChangeToChangeMaps(
const FileSystemURL& url, const FileSystemURL& url,
const FileChange& change, const FileChange& change,
......
...@@ -97,6 +97,9 @@ class LocalFileChangeTracker ...@@ -97,6 +97,9 @@ class LocalFileChangeTracker
// called. // called.
void DemoteChangesForURL(const fileapi::FileSystemURL& url); void DemoteChangesForURL(const fileapi::FileSystemURL& url);
// Promotes demoted changes for |url| to the normal queue.
void PromoteDemotedChangesForURL(const fileapi::FileSystemURL& url);
// Promotes all demoted changes to the normal queue. Returns true if it has // Promotes all demoted changes to the normal queue. Returns true if it has
// promoted any changes. // promoted any changes.
bool PromoteDemotedChanges(); bool PromoteDemotedChanges();
......
...@@ -119,6 +119,35 @@ class LocalFileChangeTrackerTest : public testing::Test { ...@@ -119,6 +119,35 @@ class LocalFileChangeTrackerTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(LocalFileChangeTrackerTest); DISALLOW_COPY_AND_ASSIGN(LocalFileChangeTrackerTest);
}; };
TEST_F(LocalFileChangeTrackerTest, DemoteAndPromote) {
EXPECT_EQ(base::File::FILE_OK, file_system_.OpenFileSystem());
const char kPath[] = "foo/bar";
change_tracker()->OnCreateDirectory(URL(kPath));
FileSystemURLSet urls;
file_system_.GetChangedURLsInTracker(&urls);
ASSERT_EQ(1u, urls.size());
EXPECT_EQ(URL(kPath), *urls.begin());
change_tracker()->DemoteChangesForURL(URL(kPath));
file_system_.GetChangedURLsInTracker(&urls);
ASSERT_TRUE(urls.empty());
change_tracker()->PromoteDemotedChangesForURL(URL(kPath));
file_system_.GetChangedURLsInTracker(&urls);
ASSERT_EQ(1u, urls.size());
EXPECT_EQ(URL(kPath), *urls.begin());
change_tracker()->DemoteChangesForURL(URL(kPath));
change_tracker()->OnRemoveDirectory(URL(kPath));
file_system_.GetChangedURLsInTracker(&urls);
ASSERT_TRUE(urls.empty());
}
TEST_F(LocalFileChangeTrackerTest, GetChanges) { TEST_F(LocalFileChangeTrackerTest, GetChanges) {
EXPECT_EQ(base::File::FILE_OK, file_system_.OpenFileSystem()); EXPECT_EQ(base::File::FILE_OK, file_system_.OpenFileSystem());
......
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