Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5961)

Unified Diff: chrome/browser/chromeos/drive/sync_client.cc

Issue 68543002: drive: Support offline delete (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Stop modifying local state after server side update Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/drive/sync_client.h ('k') | chrome/browser/chromeos/drive/sync_client_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 f2bd3c869d6fd495a21eeac017f0d8794d00c1bb..aa3e7aa4cd7a1510af5ecf24933c1698c74250f2 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,34 @@ 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 in the trash.
+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);
+ const ResourceEntry& entry = it->GetValue();
+ if (entry.parent_local_id() == util::kDriveTrashDirLocalId) {
+ to_remove->push_back(local_id);
+ continue;
+ }
- if (cache_entry.is_dirty())
- to_upload->push_back(local_id);
+ 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 +140,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 +158,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() {
@@ -188,6 +204,16 @@ void SyncClient::AddUploadTask(const ClientContext& context,
AddTaskToQueue(UPLOAD, context, 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 ClientContext& context,
const std::string& local_id,
@@ -268,7 +294,8 @@ void SyncClient::StartTask(SyncType type,
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
@@ -284,6 +311,12 @@ void SyncClient::OnGetLocalIdsOfBacklog(
DVLOG(1) << "Queuing to fetch: " << local_id;
AddTaskToQueue(FETCH, ClientContext(BACKGROUND), 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) {
@@ -353,5 +386,33 @@ 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.
+ base::MessageLoopProxy::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&SyncClient::AddRemoveTask,
+ weak_ptr_factory_.GetWeakPtr(),
+ local_id),
+ long_delay_);
+ break;
+ default:
+ LOG(WARNING) << "Failed to remove " << local_id << ": "
+ << FileErrorToString(error);
+ }
+ }
+}
+
} // namespace internal
} // namespace drive
« no previous file with comments | « chrome/browser/chromeos/drive/sync_client.h ('k') | chrome/browser/chromeos/drive/sync_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698