summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/drive/sync_client.cc
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-28 02:17:16 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-28 02:17:16 +0000
commitc724115447db8f50d19b2a7e7c5f14a1d8676539 (patch)
tree6491755f45fbc606cd7089e9a480ae8843aac35b /chrome/browser/chromeos/drive/sync_client.cc
parentc3f6564821de1c4cf041d6df578aa3845b7bd39e (diff)
downloadchromium_src-c724115447db8f50d19b2a7e7c5f14a1d8676539.zip
chromium_src-c724115447db8f50d19b2a7e7c5f14a1d8676539.tar.gz
chromium_src-c724115447db8f50d19b2a7e7c5f14a1d8676539.tar.bz2
drive: Stop mentioning resource ID in SyncClient
BUG=275270 R=hidehiko@chromium.org Review URL: https://codereview.chromium.org/23565002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219884 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/drive/sync_client.cc')
-rw-r--r--chrome/browser/chromeos/drive/sync_client.cc138
1 files changed, 67 insertions, 71 deletions
diff --git a/chrome/browser/chromeos/drive/sync_client.cc b/chrome/browser/chromeos/drive/sync_client.cc
index 31771d6..5eb8bc6 100644
--- a/chrome/browser/chromeos/drive/sync_client.cc
+++ b/chrome/browser/chromeos/drive/sync_client.cc
@@ -41,21 +41,21 @@ 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
+// Appends |local_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.
void CollectBacklog(std::vector<std::string>* to_fetch,
std::vector<std::string>* to_upload,
- const std::string& resource_id,
+ const std::string& local_id,
const FileCacheEntry& cache_entry) {
DCHECK(to_fetch);
DCHECK(to_upload);
if (cache_entry.is_pinned() && !cache_entry.is_present())
- to_fetch->push_back(resource_id);
+ to_fetch->push_back(local_id);
if (cache_entry.is_dirty())
- to_upload->push_back(resource_id);
+ to_upload->push_back(local_id);
}
} // namespace
@@ -96,7 +96,7 @@ 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>;
cache_->IterateOnUIThread(base::Bind(&CollectBacklog, to_fetch, to_upload),
- base::Bind(&SyncClient::OnGetResourceIdsOfBacklog,
+ base::Bind(&SyncClient::OnGetLocalIdsOfBacklog,
weak_ptr_factory_.GetWeakPtr(),
base::Owned(to_fetch),
base::Owned(to_upload)));
@@ -106,49 +106,49 @@ void SyncClient::StartCheckingExistingPinnedFiles() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
cache_->IterateOnUIThread(
- base::Bind(&SyncClient::OnGetResourceIdOfExistingPinnedFile,
+ base::Bind(&SyncClient::OnGetLocalIdOfExistingPinnedFile,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&base::DoNothing));
}
-void SyncClient::AddFetchTask(const std::string& resource_id) {
+void SyncClient::AddFetchTask(const std::string& local_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- AddTaskToQueue(FETCH, resource_id, delay_);
+ AddTaskToQueue(FETCH, local_id, delay_);
}
-void SyncClient::RemoveFetchTask(const std::string& resource_id) {
+void SyncClient::RemoveFetchTask(const std::string& local_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// TODO(kinaba): Cancel tasks in JobScheduler as well. crbug.com/248856
- pending_fetch_list_.erase(resource_id);
+ pending_fetch_list_.erase(local_id);
}
-void SyncClient::AddUploadTask(const std::string& resource_id) {
+void SyncClient::AddUploadTask(const std::string& local_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- AddTaskToQueue(UPLOAD, resource_id, delay_);
+ AddTaskToQueue(UPLOAD, local_id, delay_);
}
void SyncClient::AddTaskToQueue(SyncType type,
- const std::string& resource_id,
+ const std::string& local_id,
const base::TimeDelta& delay) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// If the same task is already queued, ignore this task.
switch (type) {
case FETCH:
- if (fetch_list_.find(resource_id) == fetch_list_.end()) {
- fetch_list_.insert(resource_id);
- pending_fetch_list_.insert(resource_id);
+ if (fetch_list_.find(local_id) == fetch_list_.end()) {
+ fetch_list_.insert(local_id);
+ pending_fetch_list_.insert(local_id);
} else {
return;
}
break;
case UPLOAD:
case UPLOAD_NO_CONTENT_CHECK:
- if (upload_list_.find(resource_id) == upload_list_.end()) {
- upload_list_.insert(resource_id);
+ if (upload_list_.find(local_id) == upload_list_.end()) {
+ upload_list_.insert(local_id);
} else {
return;
}
@@ -160,47 +160,47 @@ void SyncClient::AddTaskToQueue(SyncType type,
base::Bind(&SyncClient::StartTask,
weak_ptr_factory_.GetWeakPtr(),
type,
- resource_id),
+ local_id),
delay);
}
-void SyncClient::StartTask(SyncType type, const std::string& resource_id) {
+void SyncClient::StartTask(SyncType type, const std::string& local_id) {
switch (type) {
case FETCH:
// Check if the resource has been removed from the start list.
- if (pending_fetch_list_.find(resource_id) != pending_fetch_list_.end()) {
- DVLOG(1) << "Fetching " << resource_id;
- pending_fetch_list_.erase(resource_id);
+ if (pending_fetch_list_.find(local_id) != pending_fetch_list_.end()) {
+ DVLOG(1) << "Fetching " << local_id;
+ pending_fetch_list_.erase(local_id);
download_operation_->EnsureFileDownloadedByResourceId(
- resource_id,
+ local_id,
ClientContext(BACKGROUND),
GetFileContentInitializedCallback(),
google_apis::GetContentCallback(),
base::Bind(&SyncClient::OnFetchFileComplete,
weak_ptr_factory_.GetWeakPtr(),
- resource_id));
+ local_id));
} else {
// Cancel the task.
- fetch_list_.erase(resource_id);
+ fetch_list_.erase(local_id);
}
break;
case UPLOAD:
case UPLOAD_NO_CONTENT_CHECK:
- DVLOG(1) << "Uploading " << resource_id;
+ DVLOG(1) << "Uploading " << local_id;
update_operation_->UpdateFileByResourceId(
- resource_id,
+ local_id,
ClientContext(BACKGROUND),
type == UPLOAD ? file_system::UpdateOperation::RUN_CONTENT_CHECK
: file_system::UpdateOperation::NO_CONTENT_CHECK,
base::Bind(&SyncClient::OnUploadFileComplete,
weak_ptr_factory_.GetWeakPtr(),
- resource_id));
+ local_id));
break;
}
}
-void SyncClient::OnGetResourceIdsOfBacklog(
+void SyncClient::OnGetLocalIdsOfBacklog(
const std::vector<std::string>* to_fetch,
const std::vector<std::string>* to_upload) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -208,45 +208,44 @@ void SyncClient::OnGetResourceIdsOfBacklog(
// Give priority to upload tasks over fetch tasks, so that dirty files are
// uploaded as soon as possible.
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, delay_);
+ const std::string& local_id = (*to_upload)[i];
+ DVLOG(1) << "Queuing to upload: " << local_id;
+ AddTaskToQueue(UPLOAD_NO_CONTENT_CHECK, local_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, delay_);
+ const std::string& local_id = (*to_fetch)[i];
+ DVLOG(1) << "Queuing to fetch: " << local_id;
+ AddTaskToQueue(FETCH, local_id, delay_);
}
}
-void SyncClient::OnGetResourceIdOfExistingPinnedFile(
- const std::string& resource_id,
+void SyncClient::OnGetLocalIdOfExistingPinnedFile(
+ const std::string& local_id,
const FileCacheEntry& cache_entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (cache_entry.is_pinned() && cache_entry.is_present()) {
metadata_->GetResourceEntryByIdOnUIThread(
- resource_id,
+ local_id,
base::Bind(&SyncClient::OnGetResourceEntryById,
weak_ptr_factory_.GetWeakPtr(),
- resource_id,
+ local_id,
cache_entry));
}
}
-void SyncClient::OnGetResourceEntryById(
- const std::string& resource_id,
- const FileCacheEntry& cache_entry,
- FileError error,
- scoped_ptr<ResourceEntry> entry) {
+void SyncClient::OnGetResourceEntryById(const std::string& local_id,
+ const FileCacheEntry& cache_entry,
+ FileError error,
+ scoped_ptr<ResourceEntry> entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (entry.get() && !entry->has_file_specific_info())
error = FILE_ERROR_NOT_FOUND;
if (error != FILE_ERROR_OK) {
- LOG(WARNING) << "Entry not found: " << resource_id;
+ LOG(WARNING) << "Entry not found: " << local_id;
return;
}
@@ -255,97 +254,94 @@ void SyncClient::OnGetResourceEntryById(
// file when we have a locally modified version.
if (entry->file_specific_info().md5() != cache_entry.md5() &&
!cache_entry.is_dirty()) {
- cache_->RemoveOnUIThread(resource_id,
+ cache_->RemoveOnUIThread(local_id,
base::Bind(&SyncClient::OnRemove,
weak_ptr_factory_.GetWeakPtr(),
- resource_id));
+ local_id));
}
}
-void SyncClient::OnRemove(const std::string& resource_id,
- FileError error) {
+void SyncClient::OnRemove(const std::string& local_id, FileError error) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (error != FILE_ERROR_OK) {
- LOG(WARNING) << "Failed to remove cache entry: " << resource_id;
+ LOG(WARNING) << "Failed to remove cache entry: " << local_id;
return;
}
// Before fetching, we should pin this file again, so that the fetched file
// is downloaded properly to the persistent directory and marked pinned.
- cache_->PinOnUIThread(resource_id,
+ cache_->PinOnUIThread(local_id,
base::Bind(&SyncClient::OnPinned,
weak_ptr_factory_.GetWeakPtr(),
- resource_id));
+ local_id));
}
-void SyncClient::OnPinned(const std::string& resource_id,
- FileError error) {
+void SyncClient::OnPinned(const std::string& local_id, FileError error) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (error != FILE_ERROR_OK) {
- LOG(WARNING) << "Failed to pin cache entry: " << resource_id;
+ LOG(WARNING) << "Failed to pin cache entry: " << local_id;
return;
}
// Finally, adding to the queue.
- AddTaskToQueue(FETCH, resource_id, delay_);
+ AddTaskToQueue(FETCH, local_id, delay_);
}
-void SyncClient::OnFetchFileComplete(const std::string& resource_id,
+void SyncClient::OnFetchFileComplete(const std::string& local_id,
FileError error,
const base::FilePath& local_path,
scoped_ptr<ResourceEntry> entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- fetch_list_.erase(resource_id);
+ fetch_list_.erase(local_id);
if (error == FILE_ERROR_OK) {
- DVLOG(1) << "Fetched " << resource_id << ": "
- << local_path.value();
+ DVLOG(1) << "Fetched " << local_id << ": " << local_path.value();
} else {
switch (error) {
case FILE_ERROR_ABORT:
// If user cancels download, unpin the file so that we do not sync the
// file again.
- cache_->UnpinOnUIThread(resource_id,
+ cache_->UnpinOnUIThread(local_id,
base::Bind(&util::EmptyFileOperationCallback));
break;
case FILE_ERROR_NO_CONNECTION:
// Re-queue the task so that we'll retry once the connection is back.
- AddTaskToQueue(FETCH, resource_id, delay_);
+ AddTaskToQueue(FETCH, local_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_);
+ AddTaskToQueue(FETCH, local_id, long_delay_);
break;
default:
- LOG(WARNING) << "Failed to fetch " << resource_id
+ LOG(WARNING) << "Failed to fetch " << local_id
<< ": " << FileErrorToString(error);
}
}
}
-void SyncClient::OnUploadFileComplete(const std::string& resource_id,
+void SyncClient::OnUploadFileComplete(const std::string& local_id,
FileError error) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- upload_list_.erase(resource_id);
+ upload_list_.erase(local_id);
if (error == FILE_ERROR_OK) {
- DVLOG(1) << "Uploaded " << resource_id;
+ DVLOG(1) << "Uploaded " << local_id;
} else {
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, delay_);
+ AddTaskToQueue(UPLOAD_NO_CONTENT_CHECK, local_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_);
+ AddTaskToQueue(UPLOAD_NO_CONTENT_CHECK, local_id, long_delay_);
break;
default:
- LOG(WARNING) << "Failed to upload " << resource_id << ": "
+ LOG(WARNING) << "Failed to upload " << local_id << ": "
<< FileErrorToString(error);
}
}