summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-27 08:24:49 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-27 08:24:49 +0000
commite5247de9fc0763db6ce215ae841c410c7e783f97 (patch)
tree903b15f2cf5ec80167d5dc4c99126aa6464b2566
parentaee93295090d20ce79f04538209bc512ddccffbb (diff)
downloadchromium_src-e5247de9fc0763db6ce215ae841c410c7e783f97.zip
chromium_src-e5247de9fc0763db6ce215ae841c410c7e783f97.tar.gz
chromium_src-e5247de9fc0763db6ce215ae841c410c7e783f97.tar.bz2
drive: Rewrite TouchOperation to prepare for the local ID switch
Add stub implementation of ResourceMetadata::GetIdByResourceId Rewrite TouchOperation to make it work with local ID. Discard the FilePath passed to TouchOperation::TouchFile, it may be obsolete when TouchOperation::TouchFileAfterRefreshMetadata gets called. BUG=260514 TEST=unit_tests R=kinaba@chromium.org Review URL: https://codereview.chromium.org/23422002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219742 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/drive/file_system/touch_operation.cc81
-rw-r--r--chrome/browser/chromeos/drive/file_system/touch_operation.h8
-rw-r--r--chrome/browser/chromeos/drive/resource_metadata.cc10
-rw-r--r--chrome/browser/chromeos/drive/resource_metadata.h4
4 files changed, 77 insertions, 26 deletions
diff --git a/chrome/browser/chromeos/drive/file_system/touch_operation.cc b/chrome/browser/chromeos/drive/file_system/touch_operation.cc
index 3fc77ad..1ead717 100644
--- a/chrome/browser/chromeos/drive/file_system/touch_operation.cc
+++ b/chrome/browser/chromeos/drive/file_system/touch_operation.cc
@@ -21,6 +21,50 @@ using content::BrowserThread;
namespace drive {
namespace file_system {
+namespace {
+
+// Returns ResourceEntry and the local ID of the entry at the given path.
+FileError GetResourceEntryAndIdByPath(internal::ResourceMetadata* metadata,
+ const base::FilePath& file_path,
+ std::string* local_id,
+ ResourceEntry* entry) {
+ FileError error = metadata->GetIdByPath(file_path, local_id);
+ if (error != FILE_ERROR_OK)
+ return error;
+ return metadata->GetResourceEntryById(*local_id, entry);
+}
+
+// Refreshes the entry specified by |local_id| with the contents of
+// |resource_entry|.
+FileError RefreshEntry(internal::ResourceMetadata* metadata,
+ const std::string& local_id,
+ scoped_ptr<google_apis::ResourceEntry> resource_entry,
+ base::FilePath* file_path) {
+ DCHECK(resource_entry);
+
+ ResourceEntry entry;
+ std::string parent_resource_id;
+ if (!ConvertToResourceEntry(*resource_entry, &entry, &parent_resource_id))
+ return FILE_ERROR_NOT_A_FILE;
+
+ std::string parent_local_id;
+ FileError error = metadata->GetIdByResourceId(parent_resource_id,
+ &parent_local_id);
+ if (error != FILE_ERROR_OK)
+ return error;
+
+ entry.set_parent_local_id(parent_local_id);
+
+ error = metadata->RefreshEntry(local_id, entry);
+ if (error != FILE_ERROR_OK)
+ return error;
+
+ *file_path = metadata->GetFilePath(local_id);
+ return file_path->empty() ? FILE_ERROR_FAILED : FILE_ERROR_OK;
+}
+
+} // namespace
+
TouchOperation::TouchOperation(base::SequencedTaskRunner* blocking_task_runner,
OperationObserver* observer,
JobScheduler* scheduler,
@@ -43,27 +87,29 @@ void TouchOperation::TouchFile(const base::FilePath& file_path,
DCHECK(!callback.is_null());
ResourceEntry* entry = new ResourceEntry;
+ std::string* local_id = new std::string;
base::PostTaskAndReplyWithResult(
blocking_task_runner_.get(),
FROM_HERE,
- base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath,
+ base::Bind(&GetResourceEntryAndIdByPath,
base::Unretained(metadata_),
file_path,
+ local_id,
entry),
base::Bind(&TouchOperation::TouchFileAfterGetResourceEntry,
weak_ptr_factory_.GetWeakPtr(),
- file_path,
last_access_time,
last_modified_time,
callback,
+ base::Owned(local_id),
base::Owned(entry)));
}
void TouchOperation::TouchFileAfterGetResourceEntry(
- const base::FilePath& file_path,
const base::Time& last_access_time,
const base::Time& last_modified_time,
const FileOperationCallback& callback,
+ std::string* local_id,
ResourceEntry* entry,
FileError error) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -81,11 +127,11 @@ void TouchOperation::TouchFileAfterGetResourceEntry(
entry->resource_id(), last_modified_time, last_access_time,
base::Bind(&TouchOperation::TouchFileAfterServerTimeStampUpdated,
weak_ptr_factory_.GetWeakPtr(),
- file_path, callback));
+ *local_id, callback));
}
void TouchOperation::TouchFileAfterServerTimeStampUpdated(
- const base::FilePath& file_path,
+ const std::string& local_id,
const FileOperationCallback& callback,
google_apis::GDataErrorCode gdata_error,
scoped_ptr<google_apis::ResourceEntry> resource_entry) {
@@ -98,39 +144,30 @@ void TouchOperation::TouchFileAfterServerTimeStampUpdated(
return;
}
- DCHECK(resource_entry);
- ResourceEntry entry;
- std::string parent_resource_id;
- if (!ConvertToResourceEntry(*resource_entry, &entry, &parent_resource_id)) {
- callback.Run(FILE_ERROR_NOT_A_FILE);
- return;
- }
-
- // TODO(hashimoto): Resolve local ID before use. crbug.com/260514
- entry.set_parent_local_id(parent_resource_id);
-
+ base::FilePath* file_path = new base::FilePath;
base::PostTaskAndReplyWithResult(
blocking_task_runner_.get(),
FROM_HERE,
- base::Bind(&internal::ResourceMetadata::RefreshEntry,
+ base::Bind(&RefreshEntry,
base::Unretained(metadata_),
- entry.resource_id(),
- entry),
+ local_id,
+ base::Passed(&resource_entry),
+ file_path),
base::Bind(&TouchOperation::TouchFileAfterRefreshMetadata,
weak_ptr_factory_.GetWeakPtr(),
- file_path,
+ base::Owned(file_path),
callback));
}
void TouchOperation::TouchFileAfterRefreshMetadata(
- const base::FilePath& file_path,
+ const base::FilePath* file_path,
const FileOperationCallback& callback,
FileError error) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (error == FILE_ERROR_OK)
- observer_->OnDirectoryChangedByOperation(file_path.DirName());
+ observer_->OnDirectoryChangedByOperation(file_path->DirName());
callback.Run(error);
}
diff --git a/chrome/browser/chromeos/drive/file_system/touch_operation.h b/chrome/browser/chromeos/drive/file_system/touch_operation.h
index 48a3590..be00163 100644
--- a/chrome/browser/chromeos/drive/file_system/touch_operation.h
+++ b/chrome/browser/chromeos/drive/file_system/touch_operation.h
@@ -52,23 +52,23 @@ class TouchOperation {
private:
// Part of TouchFile(). Runs after GetResourceEntry is completed.
- void TouchFileAfterGetResourceEntry(const base::FilePath& file_path,
- const base::Time& last_access_time,
+ void TouchFileAfterGetResourceEntry(const base::Time& last_access_time,
const base::Time& last_modified_time,
const FileOperationCallback& callback,
+ std::string* local_id,
ResourceEntry* entry,
FileError error);
// Part of TouchFile(). Runs after the server side update for last access time
// and last modified time is completed.
void TouchFileAfterServerTimeStampUpdated(
- const base::FilePath& file_path,
+ const std::string& local_id,
const FileOperationCallback& callback,
google_apis::GDataErrorCode gdata_error,
scoped_ptr<google_apis::ResourceEntry> resource_entry);
// Part of TouchFile(). Runs after refreshing the local metadata is completed.
- void TouchFileAfterRefreshMetadata(const base::FilePath& file_path,
+ void TouchFileAfterRefreshMetadata(const base::FilePath* file_path,
const FileOperationCallback& callback,
FileError error);
diff --git a/chrome/browser/chromeos/drive/resource_metadata.cc b/chrome/browser/chromeos/drive/resource_metadata.cc
index b942b0e..5cb3ec8 100644
--- a/chrome/browser/chromeos/drive/resource_metadata.cc
+++ b/chrome/browser/chromeos/drive/resource_metadata.cc
@@ -503,6 +503,16 @@ FileError ResourceMetadata::GetIdByPath(const base::FilePath& file_path,
return FILE_ERROR_OK;
}
+FileError ResourceMetadata::GetIdByResourceId(const std::string& resource_id,
+ std::string* out_local_id) {
+ DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
+
+ // TODO(hashimoto): Look up the DB actually and generate new one when not
+ // found. crbug.com/260514
+ *out_local_id = resource_id;
+ return FILE_ERROR_OK;
+}
+
void ResourceMetadata::GetResourceEntryPairByPathsOnUIThread(
const base::FilePath& first_path,
const base::FilePath& second_path,
diff --git a/chrome/browser/chromeos/drive/resource_metadata.h b/chrome/browser/chromeos/drive/resource_metadata.h
index 06c9bea..421fede 100644
--- a/chrome/browser/chromeos/drive/resource_metadata.h
+++ b/chrome/browser/chromeos/drive/resource_metadata.h
@@ -187,6 +187,10 @@ class ResourceMetadata {
// Returns ID of the entry at the given path.
FileError GetIdByPath(const base::FilePath& file_path, std::string* out_id);
+ // Returns the local ID associated with the given resource ID.
+ FileError GetIdByResourceId(const std::string& resource_id,
+ std::string* out_local_id);
+
private:
// Note: Use Destroy() to delete this object.
~ResourceMetadata();