Index: chrome/browser/chromeos/drive/file_system/touch_operation.cc |
diff --git a/chrome/browser/chromeos/drive/file_system/touch_operation.cc b/chrome/browser/chromeos/drive/file_system/touch_operation.cc |
index 068b38f3d8d13265063450075b583d3307a78db3..914312c4a665a1fc3bb5add400a931193794fce8 100644 |
--- a/chrome/browser/chromeos/drive/file_system/touch_operation.cc |
+++ b/chrome/browser/chromeos/drive/file_system/touch_operation.cc |
@@ -10,9 +10,6 @@ |
#include "base/time/time.h" |
#include "chrome/browser/chromeos/drive/file_errors.h" |
#include "chrome/browser/chromeos/drive/file_system/operation_observer.h" |
-#include "chrome/browser/chromeos/drive/file_system_util.h" |
-#include "chrome/browser/chromeos/drive/job_scheduler.h" |
-#include "chrome/browser/chromeos/drive/resource_entry_conversion.h" |
#include "chrome/browser/chromeos/drive/resource_metadata.h" |
#include "content/public/browser/browser_thread.h" |
@@ -23,45 +20,34 @@ namespace file_system { |
namespace { |
-// 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); |
- |
+// Updates the timestamps of the entry specified by |file_path|. |
+FileError UpdateLocalState(internal::ResourceMetadata* metadata, |
+ const base::FilePath& file_path, |
+ const base::Time& last_access_time, |
+ const base::Time& last_modified_time, |
+ std::string* local_id) { |
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_local_id(local_id); |
- entry.set_parent_local_id(parent_local_id); |
- |
- error = metadata->RefreshEntry(entry); |
+ FileError error = metadata->GetResourceEntryByPath(file_path, &entry); |
if (error != FILE_ERROR_OK) |
return error; |
- |
- *file_path = metadata->GetFilePath(local_id); |
- return file_path->empty() ? FILE_ERROR_FAILED : FILE_ERROR_OK; |
+ *local_id = entry.local_id(); |
+ |
+ PlatformFileInfoProto* file_info = entry.mutable_file_info(); |
+ if (!last_access_time.is_null()) |
+ file_info->set_last_accessed(last_access_time.ToInternalValue()); |
+ if (!last_modified_time.is_null()) |
+ file_info->set_last_modified(last_modified_time.ToInternalValue()); |
+ entry.set_metadata_edit_state(ResourceEntry::DIRTY); |
+ return metadata->RefreshEntry(entry); |
} |
} // namespace |
TouchOperation::TouchOperation(base::SequencedTaskRunner* blocking_task_runner, |
OperationObserver* observer, |
- JobScheduler* scheduler, |
internal::ResourceMetadata* metadata) |
: blocking_task_runner_(blocking_task_runner), |
observer_(observer), |
- scheduler_(scheduler), |
metadata_(metadata), |
weak_ptr_factory_(this) { |
} |
@@ -76,85 +62,35 @@ void TouchOperation::TouchFile(const base::FilePath& file_path, |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
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::Unretained(metadata_), |
+ base::Bind(&UpdateLocalState, |
+ metadata_, |
file_path, |
- entry), |
- base::Bind(&TouchOperation::TouchFileAfterGetResourceEntry, |
- weak_ptr_factory_.GetWeakPtr(), |
last_access_time, |
last_modified_time, |
+ local_id), |
+ base::Bind(&TouchOperation::TouchFileAfterUpdateLocalState, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ file_path, |
callback, |
- base::Owned(entry))); |
+ base::Owned(local_id))); |
} |
-void TouchOperation::TouchFileAfterGetResourceEntry( |
- const base::Time& last_access_time, |
- const base::Time& last_modified_time, |
+void TouchOperation::TouchFileAfterUpdateLocalState( |
+ const base::FilePath& file_path, |
const FileOperationCallback& callback, |
- ResourceEntry* entry, |
+ const std::string* local_id, |
FileError error) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
DCHECK(!callback.is_null()); |
- DCHECK(entry); |
- |
- if (error != FILE_ERROR_OK) { |
- callback.Run(error); |
- return; |
- } |
- |
- // Note: |last_modified_time| is mapped to modifiedDate, |last_access_time| |
- // is mapped to lastViewedByMeDate. See also ConvertToResourceEntry(). |
- scheduler_->TouchResource( |
- entry->resource_id(), last_modified_time, last_access_time, |
- base::Bind(&TouchOperation::TouchFileAfterServerTimeStampUpdated, |
- weak_ptr_factory_.GetWeakPtr(), |
- entry->local_id(), callback)); |
-} |
- |
-void TouchOperation::TouchFileAfterServerTimeStampUpdated( |
- const std::string& local_id, |
- const FileOperationCallback& callback, |
- google_apis::GDataErrorCode gdata_error, |
- scoped_ptr<google_apis::ResourceEntry> resource_entry) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- DCHECK(!callback.is_null()); |
- FileError error = GDataToFileError(gdata_error); |
- if (error != FILE_ERROR_OK) { |
- callback.Run(error); |
- return; |
+ if (error == FILE_ERROR_OK) { |
+ observer_->OnDirectoryChangedByOperation(file_path.DirName()); |
+ observer_->OnEntryUpdatedByOperation(*local_id); |
} |
- |
- base::FilePath* file_path = new base::FilePath; |
- base::PostTaskAndReplyWithResult( |
- blocking_task_runner_.get(), |
- FROM_HERE, |
- base::Bind(&RefreshEntry, |
- base::Unretained(metadata_), |
- local_id, |
- base::Passed(&resource_entry), |
- file_path), |
- base::Bind(&TouchOperation::TouchFileAfterRefreshMetadata, |
- weak_ptr_factory_.GetWeakPtr(), |
- base::Owned(file_path), |
- callback)); |
-} |
- |
-void TouchOperation::TouchFileAfterRefreshMetadata( |
- 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()); |
- |
callback.Run(error); |
} |