Wait for parent directory sync before performing server-side copy
Add SyncClient::WaitForUpdateTaskToComplete().
Use the new method from CoypOperation.
BUG=384213
TEST=unit_tests
Review URL: https://codereview.chromium.org/372713004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284877 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/chromeos/drive/sync_client.cc b/chrome/browser/chromeos/drive/sync_client.cc
index 52049d52..51b2b42 100644
--- a/chrome/browser/chromeos/drive/sync_client.cc
+++ b/chrome/browser/chromeos/drive/sync_client.cc
@@ -232,6 +232,20 @@
AddUpdateTaskInternal(context, local_id, delay_);
}
+bool SyncClient:: WaitForUpdateTaskToComplete(
+ const std::string& local_id,
+ const FileOperationCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ SyncTasks::iterator it = tasks_.find(SyncTasks::key_type(UPDATE, local_id));
+ if (it == tasks_.end())
+ return false;
+
+ SyncTask* task = &it->second;
+ task->waiting_callbacks.push_back(callback);
+ return true;
+}
+
base::Closure SyncClient::PerformFetchTask(const std::string& local_id,
const ClientContext& context) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -439,6 +453,12 @@
<< ": " << FileErrorToString(error);
}
+ for (size_t i = 0; i < it->second.waiting_callbacks.size(); ++i) {
+ base::MessageLoopProxy::current()->PostTask(
+ FROM_HERE, base::Bind(it->second.waiting_callbacks[i], error));
+ }
+ it->second.waiting_callbacks.clear();
+
if (it->second.should_run_again) {
DVLOG(1) << "Running again: type = " << type << ", id = " << local_id;
it->second.state = PENDING;