drive: Retry sync task with a long delay on server errors
Add a new FileError value FILE_ERROR_SERVICE_UNAVAILABLE
Queue the task again with a long delay on FILE_ERROR_SERVICE_UNAVAILABLE in SyncClient.
BUG=266643
Review URL: https://chromiumcodereview.appspot.com/22385007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216465 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/chromeos/drive/sync_client.cc b/chrome/browser/chromeos/drive/sync_client.cc
index c1f487b0..31771d65 100644
--- a/chrome/browser/chromeos/drive/sync_client.cc
+++ b/chrome/browser/chromeos/drive/sync_client.cc
@@ -38,6 +38,9 @@
// and shorten the delay. crbug.com/134774
const int kDelaySeconds = 5;
+// The delay constant is used to delay retrying a sync task on server errors.
+const int kLongDelaySeconds = 600;
+
// Appends |resource_id| 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.
@@ -78,6 +81,7 @@
metadata,
cache)),
delay_(base::TimeDelta::FromSeconds(kDelaySeconds)),
+ long_delay_(base::TimeDelta::FromSeconds(kLongDelaySeconds)),
weak_ptr_factory_(this) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
@@ -110,7 +114,7 @@
void SyncClient::AddFetchTask(const std::string& resource_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- AddTaskToQueue(FETCH, resource_id);
+ AddTaskToQueue(FETCH, resource_id, delay_);
}
void SyncClient::RemoveFetchTask(const std::string& resource_id) {
@@ -123,11 +127,12 @@
void SyncClient::AddUploadTask(const std::string& resource_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- AddTaskToQueue(UPLOAD, resource_id);
+ AddTaskToQueue(UPLOAD, resource_id, delay_);
}
void SyncClient::AddTaskToQueue(SyncType type,
- const std::string& resource_id) {
+ const std::string& resource_id,
+ const base::TimeDelta& delay) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// If the same task is already queued, ignore this task.
@@ -156,7 +161,7 @@
weak_ptr_factory_.GetWeakPtr(),
type,
resource_id),
- delay_);
+ delay);
}
void SyncClient::StartTask(SyncType type, const std::string& resource_id) {
@@ -205,13 +210,13 @@
for (size_t i = 0; i < to_upload->size(); ++i) {
const std::string& resource_id = (*to_upload)[i];
DVLOG(1) << "Queuing to upload: " << resource_id;
- AddTaskToQueue(UPLOAD_NO_CONTENT_CHECK, resource_id);
+ AddTaskToQueue(UPLOAD_NO_CONTENT_CHECK, resource_id, delay_);
}
for (size_t i = 0; i < to_fetch->size(); ++i) {
const std::string& resource_id = (*to_fetch)[i];
DVLOG(1) << "Queuing to fetch: " << resource_id;
- AddTaskToQueue(FETCH, resource_id);
+ AddTaskToQueue(FETCH, resource_id, delay_);
}
}
@@ -284,7 +289,7 @@
}
// Finally, adding to the queue.
- AddTaskToQueue(FETCH, resource_id);
+ AddTaskToQueue(FETCH, resource_id, delay_);
}
void SyncClient::OnFetchFileComplete(const std::string& resource_id,
@@ -308,7 +313,11 @@
break;
case FILE_ERROR_NO_CONNECTION:
// Re-queue the task so that we'll retry once the connection is back.
- AddTaskToQueue(FETCH, resource_id);
+ AddTaskToQueue(FETCH, resource_id, delay_);
+ break;
+ case FILE_ERROR_SERVICE_UNAVAILABLE:
+ // Re-queue the task so that we'll retry once the service is back.
+ AddTaskToQueue(FETCH, resource_id, long_delay_);
break;
default:
LOG(WARNING) << "Failed to fetch " << resource_id
@@ -329,7 +338,11 @@
switch (error) {
case FILE_ERROR_NO_CONNECTION:
// Re-queue the task so that we'll retry once the connection is back.
- AddTaskToQueue(UPLOAD_NO_CONTENT_CHECK, resource_id);
+ AddTaskToQueue(UPLOAD_NO_CONTENT_CHECK, resource_id, delay_);
+ break;
+ case FILE_ERROR_SERVICE_UNAVAILABLE:
+ // Re-queue the task so that we'll retry once the service is back.
+ AddTaskToQueue(UPLOAD_NO_CONTENT_CHECK, resource_id, long_delay_);
break;
default:
LOG(WARNING) << "Failed to upload " << resource_id << ": "