Chromium Code Reviews| Index: chrome/browser/chromeos/drive/sync_client.cc |
| diff --git a/chrome/browser/chromeos/drive/sync_client.cc b/chrome/browser/chromeos/drive/sync_client.cc |
| index 413bdcefa01b5fc67a22a12de88f342088047981..3f4c6c2a520ef2308ad5f12be3ac228ed52e60d0 100644 |
| --- a/chrome/browser/chromeos/drive/sync_client.cc |
| +++ b/chrome/browser/chromeos/drive/sync_client.cc |
| @@ -13,6 +13,7 @@ |
| #include "chrome/browser/chromeos/drive/file_system/download_operation.h" |
| #include "chrome/browser/chromeos/drive/file_system/update_operation.h" |
| #include "chrome/browser/chromeos/drive/file_system_util.h" |
| +#include "chrome/browser/chromeos/drive/sync/remove_performer.h" |
| #include "chrome/browser/google_apis/task_util.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -42,24 +43,33 @@ const int kDelaySeconds = 5; |
| // The delay constant is used to delay retrying a sync task on server errors. |
| const int kLongDelaySeconds = 600; |
| -// Iterates cache entries and appends IDs to |to_fetch| if the file is pinned |
| -// but not fetched (not present locally), or to |to_upload| if the file is dirty |
| -// but not uploaded. |
| -void CollectBacklog(FileCache* cache, |
| +// Iterates entries and appends IDs to |to_fetch| if the file is pinned but not |
| +// fetched (not present locally), to |to_upload| if the file is dirty but not |
| +// uploaded, or to |to_remove| if the entry is locally deleted. |
| +void CollectBacklog(ResourceMetadata* metadata, |
| std::vector<std::string>* to_fetch, |
| - std::vector<std::string>* to_upload) { |
| + std::vector<std::string>* to_upload, |
| + std::vector<std::string>* to_remove) { |
| DCHECK(to_fetch); |
| DCHECK(to_upload); |
| + DCHECK(to_remove); |
| - scoped_ptr<FileCache::Iterator> it = cache->GetIterator(); |
| + scoped_ptr<ResourceMetadata::Iterator> it = metadata->GetIterator(); |
| for (; !it->IsAtEnd(); it->Advance()) { |
| - const FileCacheEntry& cache_entry = it->GetValue(); |
| const std::string& local_id = it->GetID(); |
| - if (cache_entry.is_pinned() && !cache_entry.is_present()) |
| - to_fetch->push_back(local_id); |
| - |
| - if (cache_entry.is_dirty()) |
| - to_upload->push_back(local_id); |
| + const ResourceEntry& entry = it->GetValue(); |
| + if (entry.parent_local_id() == util::kDriveOtherDirLocalId && |
| + entry.deleted()) |
| + to_remove->push_back(local_id); |
|
kinaba
2013/11/12 06:21:29
Probably we don't want to, say, fetch a pinned and
hashimoto
2013/11/25 10:13:58
Done.
|
| + |
| + FileCacheEntry cache_entry; |
| + if (it->GetCacheEntry(&cache_entry)) { |
| + if (cache_entry.is_pinned() && !cache_entry.is_present()) |
| + to_fetch->push_back(local_id); |
| + |
| + if (cache_entry.is_dirty()) |
| + to_upload->push_back(local_id); |
| + } |
| } |
| DCHECK(!it->HasError()); |
| } |
| @@ -129,6 +139,9 @@ SyncClient::SyncClient(base::SequencedTaskRunner* blocking_task_runner, |
| scheduler, |
| metadata, |
| cache)), |
| + remove_performer_(new RemovePerformer(blocking_task_runner, |
| + scheduler, |
| + metadata)), |
| delay_(base::TimeDelta::FromSeconds(kDelaySeconds)), |
| long_delay_(base::TimeDelta::FromSeconds(kLongDelaySeconds)), |
| weak_ptr_factory_(this) { |
| @@ -144,13 +157,15 @@ void SyncClient::StartProcessingBacklog() { |
| std::vector<std::string>* to_fetch = new std::vector<std::string>; |
| std::vector<std::string>* to_upload = new std::vector<std::string>; |
| + std::vector<std::string>* to_remove = new std::vector<std::string>; |
| blocking_task_runner_->PostTaskAndReply( |
| FROM_HERE, |
| - base::Bind(&CollectBacklog, cache_, to_fetch, to_upload), |
| + base::Bind(&CollectBacklog, metadata_, to_fetch, to_upload, to_remove), |
| base::Bind(&SyncClient::OnGetLocalIdsOfBacklog, |
| weak_ptr_factory_.GetWeakPtr(), |
| base::Owned(to_fetch), |
| - base::Owned(to_upload))); |
| + base::Owned(to_upload), |
| + base::Owned(to_remove))); |
| } |
| void SyncClient::StartCheckingExistingPinnedFiles() { |
| @@ -187,6 +202,16 @@ void SyncClient::AddUploadTask(const std::string& local_id) { |
| AddTaskToQueue(UPLOAD, local_id, delay_); |
| } |
| +void SyncClient::AddRemoveTask(const std::string& local_id) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + DVLOG(1) << "Removing " << local_id; |
| + remove_performer_->Remove(local_id, |
| + base::Bind(&SyncClient::OnRemoveComplete, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + local_id)); |
| +} |
| + |
| void SyncClient::AddTaskToQueue(SyncType type, |
| const std::string& local_id, |
| const base::TimeDelta& delay) { |
| @@ -259,7 +284,8 @@ void SyncClient::StartTask(SyncType type, const std::string& local_id) { |
| void SyncClient::OnGetLocalIdsOfBacklog( |
| const std::vector<std::string>* to_fetch, |
| - const std::vector<std::string>* to_upload) { |
| + const std::vector<std::string>* to_upload, |
| + const std::vector<std::string>* to_remove) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| // Give priority to upload tasks over fetch tasks, so that dirty files are |
| @@ -275,6 +301,12 @@ void SyncClient::OnGetLocalIdsOfBacklog( |
| DVLOG(1) << "Queuing to fetch: " << local_id; |
| AddTaskToQueue(FETCH, local_id, delay_); |
| } |
| + |
| + for (size_t i = 0; i < to_remove->size(); ++i) { |
| + const std::string& local_id = (*to_remove)[i]; |
| + DVLOG(1) << "Queuing to remove: " << local_id; |
| + AddRemoveTask(local_id); |
| + } |
| } |
| void SyncClient::AddFetchTasks(const std::vector<std::string>* local_ids) { |
| @@ -342,5 +374,28 @@ void SyncClient::OnUploadFileComplete(const std::string& local_id, |
| } |
| } |
| +void SyncClient::OnRemoveComplete(const std::string& local_id, |
| + FileError error) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + if (error == FILE_ERROR_OK) { |
| + DVLOG(1) << "Removed " << local_id; |
| + } else { |
| + switch (error) { |
| + case FILE_ERROR_NO_CONNECTION: |
| + // Re-queue the task so that we'll retry once the connection is back. |
| + AddRemoveTask(local_id); |
| + break; |
| + case FILE_ERROR_SERVICE_UNAVAILABLE: |
| + // Re-queue the task so that we'll retry once the service is back. |
| + AddRemoveTask(local_id); |
|
kinaba
2013/11/12 06:21:29
AddTaskToQueue posts the task after a long_delay_,
hashimoto
2013/11/25 10:13:58
Done.
|
| + break; |
| + default: |
| + LOG(WARNING) << "Failed to remove " << local_id << ": " |
| + << FileErrorToString(error); |
| + } |
| + } |
| +} |
| + |
| } // namespace internal |
| } // namespace drive |