Commit 9b0a21d6 authored by tzik@chromium.org's avatar tzik@chromium.org

Sync FileSystem: Mark empty batch sync origin as incremental sync origin.

Without this, we have no chance to start polling for new app until we make a local change.

BUG=167739
TEST=DriveFileSyncServiceTest.RegisterNewOrigin

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175479 0039d316-1c4b-4281-b951-d872f2087c98
parent 67393f5a
...@@ -327,12 +327,12 @@ void DriveFileSyncService::UnregisterOriginForTrackingChanges( ...@@ -327,12 +327,12 @@ void DriveFileSyncService::UnregisterOriginForTrackingChanges(
return; return;
} }
URLToChange::iterator found = url_to_change_.find(origin); OriginToChangesMap::iterator found = origin_to_changes_map_.find(origin);
if (found != url_to_change_.end()) { if (found != origin_to_changes_map_.end()) {
for (PathToChange::iterator itr = found->second.begin(); for (PathToChangeMap::iterator itr = found->second.begin();
itr != found->second.end(); ++itr) itr != found->second.end(); ++itr)
pending_changes_.erase(itr->second.position_in_queue); pending_changes_.erase(itr->second.position_in_queue);
url_to_change_.erase(found); origin_to_changes_map_.erase(found);
} }
metadata_store_->RemoveOrigin(origin, base::Bind( metadata_store_->RemoveOrigin(origin, base::Bind(
...@@ -371,8 +371,8 @@ void DriveFileSyncService::ProcessRemoteChange( ...@@ -371,8 +371,8 @@ void DriveFileSyncService::ProcessRemoteChange(
const fileapi::FileSystemURL& url = pending_changes_.begin()->url; const fileapi::FileSystemURL& url = pending_changes_.begin()->url;
const GURL& origin = url.origin(); const GURL& origin = url.origin();
const FilePath& path = url.path(); const FilePath& path = url.path();
DCHECK(ContainsKey(url_to_change_, origin)); DCHECK(ContainsKey(origin_to_changes_map_, origin));
PathToChange* path_to_change = &url_to_change_[origin]; PathToChangeMap* path_to_change = &origin_to_changes_map_[origin];
DCHECK(ContainsKey(*path_to_change, path)); DCHECK(ContainsKey(*path_to_change, path));
const RemoteChange& remote_change = (*path_to_change)[path]; const RemoteChange& remote_change = (*path_to_change)[path];
...@@ -887,6 +887,12 @@ void DriveFileSyncService::DidGetDirectoryContentForBatchSync( ...@@ -887,6 +887,12 @@ void DriveFileSyncService::DidGetDirectoryContentForBatchSync(
return; return;
} }
// Move |origin| to the incremental sync origin set if the origin has no file.
if (metadata_store_->IsBatchSyncOrigin(origin) &&
!ContainsKey(origin_to_changes_map_, origin)) {
metadata_store_->MoveBatchSyncOriginToIncremental(origin);
}
NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass());
} }
...@@ -1488,8 +1494,8 @@ bool DriveFileSyncService::AppendRemoteChangeInternal( ...@@ -1488,8 +1494,8 @@ bool DriveFileSyncService::AppendRemoteChangeInternal(
const std::string& resource_id, const std::string& resource_id,
int64 changestamp, int64 changestamp,
RemoteSyncType sync_type) { RemoteSyncType sync_type) {
PathToChange* path_to_change = &url_to_change_[origin]; PathToChangeMap* path_to_change = &origin_to_changes_map_[origin];
PathToChange::iterator found = path_to_change->find(path); PathToChangeMap::iterator found = path_to_change->find(path);
if (found != path_to_change->end()) { if (found != path_to_change->end()) {
if (found->second.changestamp >= changestamp) if (found->second.changestamp >= changestamp)
return false; return false;
...@@ -1527,22 +1533,23 @@ bool DriveFileSyncService::AppendRemoteChangeInternal( ...@@ -1527,22 +1533,23 @@ bool DriveFileSyncService::AppendRemoteChangeInternal(
void DriveFileSyncService::RemoveRemoteChange( void DriveFileSyncService::RemoveRemoteChange(
const fileapi::FileSystemURL& url) { const fileapi::FileSystemURL& url) {
URLToChange::iterator found_origin = url_to_change_.find(url.origin()); OriginToChangesMap::iterator found_origin =
if (found_origin == url_to_change_.end()) origin_to_changes_map_.find(url.origin());
if (found_origin == origin_to_changes_map_.end())
return; return;
PathToChange* path_to_change = &found_origin->second; PathToChangeMap* path_to_change = &found_origin->second;
PathToChange::iterator found_change = path_to_change->find(url.path()); PathToChangeMap::iterator found_change = path_to_change->find(url.path());
if (found_change == path_to_change->end()) if (found_change == path_to_change->end())
return; return;
pending_changes_.erase(found_change->second.position_in_queue); pending_changes_.erase(found_change->second.position_in_queue);
path_to_change->erase(found_change); path_to_change->erase(found_change);
if (path_to_change->empty()) if (path_to_change->empty())
url_to_change_.erase(found_origin); origin_to_changes_map_.erase(found_origin);
if (metadata_store_->IsBatchSyncOrigin(url.origin()) && if (metadata_store_->IsBatchSyncOrigin(url.origin()) &&
!ContainsKey(url_to_change_, url.origin())) { !ContainsKey(origin_to_changes_map_, url.origin())) {
metadata_store_->MoveBatchSyncOriginToIncremental(url.origin()); metadata_store_->MoveBatchSyncOriginToIncremental(url.origin());
} }
} }
...@@ -1551,11 +1558,12 @@ bool DriveFileSyncService::GetPendingChangeForFileSystemURL( ...@@ -1551,11 +1558,12 @@ bool DriveFileSyncService::GetPendingChangeForFileSystemURL(
const fileapi::FileSystemURL& url, const fileapi::FileSystemURL& url,
RemoteChange* change) const { RemoteChange* change) const {
DCHECK(change); DCHECK(change);
URLToChange::const_iterator found_url = url_to_change_.find(url.origin()); OriginToChangesMap::const_iterator found_url =
if (found_url == url_to_change_.end()) origin_to_changes_map_.find(url.origin());
if (found_url == origin_to_changes_map_.end())
return false; return false;
const PathToChange& path_to_change = found_url->second; const PathToChangeMap& path_to_change = found_url->second;
PathToChange::const_iterator found_path = path_to_change.find(url.path()); PathToChangeMap::const_iterator found_path = path_to_change.find(url.path());
if (found_path == path_to_change.end()) if (found_path == path_to_change.end())
return false; return false;
*change = found_path->second; *change = found_path->second;
......
...@@ -142,8 +142,8 @@ class DriveFileSyncService ...@@ -142,8 +142,8 @@ class DriveFileSyncService
// TODO(tzik): Consider using std::pair<FilePath, FileType> as the key below // TODO(tzik): Consider using std::pair<FilePath, FileType> as the key below
// to support directories and custom conflict handling. // to support directories and custom conflict handling.
typedef std::map<FilePath, RemoteChange> PathToChange; typedef std::map<FilePath, RemoteChange> PathToChangeMap;
typedef std::map<GURL, PathToChange> URLToChange; typedef std::map<GURL, PathToChangeMap> OriginToChangesMap;
// Task types; used for task token handling. // Task types; used for task token handling.
enum TaskType { enum TaskType {
...@@ -346,7 +346,7 @@ class DriveFileSyncService ...@@ -346,7 +346,7 @@ class DriveFileSyncService
int64 largest_fetched_changestamp_; int64 largest_fetched_changestamp_;
PendingChangeQueue pending_changes_; PendingChangeQueue pending_changes_;
URLToChange url_to_change_; OriginToChangesMap origin_to_changes_map_;
std::set<GURL> pending_batch_sync_origins_; std::set<GURL> pending_batch_sync_origins_;
......
...@@ -187,8 +187,8 @@ class DriveFileSyncServiceTest : public testing::Test { ...@@ -187,8 +187,8 @@ class DriveFileSyncServiceTest : public testing::Test {
ChangeQueueItem(changestamp, sync_type, url)); ChangeQueueItem(changestamp, sync_type, url));
DCHECK(inserted_to_queue.second); DCHECK(inserted_to_queue.second);
DriveFileSyncService::PathToChange* path_to_change = DriveFileSyncService::PathToChangeMap* path_to_change =
&sync_service_->url_to_change_[url.origin()]; &sync_service_->origin_to_changes_map_[url.origin()];
(*path_to_change)[url.path()] = DriveFileSyncService::RemoteChange( (*path_to_change)[url.path()] = DriveFileSyncService::RemoteChange(
changestamp, resource_id, sync_type, url, file_change, changestamp, resource_id, sync_type, url, file_change,
inserted_to_queue.first); inserted_to_queue.first);
...@@ -548,8 +548,8 @@ TEST_F(DriveFileSyncServiceTest, RegisterNewOrigin) { ...@@ -548,8 +548,8 @@ TEST_F(DriveFileSyncServiceTest, RegisterNewOrigin) {
message_loop()->RunUntilIdle(); message_loop()->RunUntilIdle();
EXPECT_TRUE(done); EXPECT_TRUE(done);
EXPECT_EQ(1u, metadata_store()->batch_sync_origins().size()); EXPECT_TRUE(metadata_store()->batch_sync_origins().empty());
EXPECT_TRUE(metadata_store()->incremental_sync_origins().empty()); EXPECT_EQ(1u, metadata_store()->incremental_sync_origins().size());
EXPECT_TRUE(pending_changes().empty()); EXPECT_TRUE(pending_changes().empty());
} }
......
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