Commit 6781aa67 authored by kinaba@chromium.org's avatar kinaba@chromium.org

GDataFileSystem::CloseFile needs not modify GDataEntry.

The modification is not needed anymore, because for dirty files
we always look up metadata from the local cache file (r148712).

Besides, this patch renames OnXXXForCloseFile to CloseFileAfterXXX,
to match the recent convention.

BUG=142466
TEST=existing tests, in particular:
 browser_tests --gtest_filter='RemoteFileSystemExtensionApiTest.RemoteMountPoint'
 unit_tests --gtest_filter='GDataFileSystemTest.OpenAndCloseFile'

Review URL: https://chromiumcodereview.appspot.com/10830298

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151437 0039d316-1c4b-4281-b951-d872f2087c98
parent ce79fa7a
......@@ -3229,16 +3229,16 @@ void GDataFileSystem::CloseFileOnUIThread(
// Step 1 of CloseFile: Get resource_id and md5 for |file_path|.
directory_service_->GetEntryInfoByPath(
file_path,
base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForCloseFile,
base::Bind(&GDataFileSystem::CloseFileOnUIThreadAfterGetEntryInfo,
ui_weak_ptr_,
file_path,
base::Bind(&GDataFileSystem::OnCloseFileFinished,
base::Bind(&GDataFileSystem::CloseFileOnUIThreadFinalize,
ui_weak_ptr_,
file_path,
callback)));
}
void GDataFileSystem::OnGetEntryInfoCompleteForCloseFile(
void GDataFileSystem::CloseFileOnUIThreadAfterGetEntryInfo(
const FilePath& file_path,
const FileOperationCallback& callback,
GDataFileError error,
......@@ -3254,118 +3254,21 @@ void GDataFileSystem::OnGetEntryInfoCompleteForCloseFile(
return;
}
// Step 2 of CloseFile: Get the local path of the cache. Since CloseFile must
// always be called on paths opened by OpenFile, the file must be cached,
cache_->GetFileOnUIThread(
entry_proto->resource_id(),
entry_proto->file_specific_info().file_md5(),
base::Bind(&GDataFileSystem::OnGetCacheFilePathCompleteForCloseFile,
ui_weak_ptr_,
file_path,
callback));
}
void GDataFileSystem::OnGetCacheFilePathCompleteForCloseFile(
const FilePath& file_path,
const FileOperationCallback& callback,
GDataFileError error,
const std::string& resource_id,
const std::string& md5,
const FilePath& local_cache_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (error != GDATA_FILE_OK) {
callback.Run(error);
return;
}
// Step 3 of CloseFile: Retrieves the (possibly modified) PlatformFileInfo of
// the cache file.
base::PlatformFileInfo* file_info = new base::PlatformFileInfo;
bool* get_file_info_result = new bool(false);
util::PostBlockingPoolSequencedTaskAndReply(
FROM_HERE,
blocking_task_runner_,
base::Bind(&GetFileInfoOnBlockingPool,
local_cache_path,
base::Unretained(file_info),
base::Unretained(get_file_info_result)),
base::Bind(&GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile,
ui_weak_ptr_,
file_path,
base::Owned(file_info),
base::Owned(get_file_info_result),
callback));
}
void GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile(
const FilePath& file_path,
base::PlatformFileInfo* file_info,
bool* get_file_info_result,
const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (!*get_file_info_result) {
callback.Run(GDATA_FILE_ERROR_NOT_FOUND);
return;
}
// Step 4 of CloseFile: Find GDataEntry corresponding to |file_path|, for
// modifying the entry's metadata.
FindEntryByPathAsyncOnUIThread(
file_path,
base::Bind(&GDataFileSystem::OnGetEntryCompleteForCloseFile,
ui_weak_ptr_,
*file_info,
callback));
}
void GDataFileSystem::OnGetEntryCompleteForCloseFile(
const base::PlatformFileInfo& file_info,
const FileOperationCallback& callback,
GDataFileError error,
GDataEntry* entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (error != GDATA_FILE_OK) {
callback.Run(error);
return;
}
DCHECK(entry);
GDataFile* file = entry->AsGDataFile();
if (!file || file->file_md5().empty() || file->is_hosted_document()) {
// No support for opening a directory or hosted document.
callback.Run(GDATA_FILE_ERROR_INVALID_OPERATION);
return;
}
DCHECK(!file->resource_id().empty());
// Step 5 of CloseFile:
// Update the in-memory meta data. Until the committed cache is uploaded in
// background to the server and the change is propagated back, this in-memory
// meta data is referred by subsequent file operations. So it needs to reflect
// the modification made before committing.
file->set_file_info(file_info);
// Step 6 of CloseFile: Commit the modification in cache. This will trigger
// Step 2 of CloseFile: Commit the modification in cache. This will trigger
// background upload.
// TODO(benchan,kinaba): Call ClearDirtyInCache instead of CommitDirtyInCache
// if the file has not been modified. Come up with a way to detect the
// intactness effectively, or provide a method for user to declare it when
// calling CloseFile().
cache_->CommitDirtyOnUIThread(
file->resource_id(),
file->file_md5(),
base::Bind(&GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile,
entry_proto->resource_id(),
entry_proto->file_specific_info().file_md5(),
base::Bind(&GDataFileSystem::CloseFileOnUIThreadAfterCommitDirtyInCache,
ui_weak_ptr_,
callback));
}
void GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile(
void GDataFileSystem::CloseFileOnUIThreadAfterCommitDirtyInCache(
const FileOperationCallback& callback,
GDataFileError error,
const std::string& /* resource_id */,
......@@ -3376,14 +3279,14 @@ void GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile(
callback.Run(error);
}
void GDataFileSystem::OnCloseFileFinished(
void GDataFileSystem::CloseFileOnUIThreadFinalize(
const FilePath& file_path,
const FileOperationCallback& callback,
GDataFileError result) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
// Step 7 of CloseFile.
// Step 3 of CloseFile.
// All the invocation of |callback| from operations initiated from CloseFile
// must go through here. Removes the |file_path| from the remembered set so
// that subsequent operations can open the file again.
......
......@@ -264,43 +264,23 @@ class GDataFileSystem : public GDataFileSystemInterface,
// Invoked during the process of CloseFile. What is done here is as follows:
// 1) Gets resource_id and md5 of the entry at |file_path|.
// 2) Gets the local path of the cache file from resource_id and md5.
// 3) Gets PlatformFileInfo of the modified local cache file.
// 4) Gets GDataEntry for |file_path|.
// 5) Modifies GDataEntry using the new PlatformFileInfo.
// 6) Commits the modification to the cache system.
// 7) Invokes the user-supplied |callback|.
// 2) Commits the modification to the cache system.
// 3) Removes the |file_path| from the remembered set of opened files.
// 4) Invokes the user-supplied |callback|.
// |callback| must not be null.
void OnGetEntryInfoCompleteForCloseFile(
void CloseFileOnUIThreadAfterGetEntryInfo(
const FilePath& file_path,
const FileOperationCallback& callback,
GDataFileError error,
scoped_ptr<GDataEntryProto> entry_proto);
void OnGetCacheFilePathCompleteForCloseFile(
const FilePath& file_path,
const FileOperationCallback& callback,
GDataFileError error,
const std::string& resource_id,
const std::string& md5,
const FilePath& local_cache_path);
void OnGetModifiedFileInfoCompleteForCloseFile(
const FilePath& file_path,
base::PlatformFileInfo* file_info,
bool* get_file_info_result,
const FileOperationCallback& callback);
void OnGetEntryCompleteForCloseFile(
const base::PlatformFileInfo& file_info,
const FileOperationCallback& callback,
GDataFileError error,
GDataEntry* entry);
void OnCommitDirtyInCacheCompleteForCloseFile(
void CloseFileOnUIThreadAfterCommitDirtyInCache(
const FileOperationCallback& callback,
GDataFileError error,
const std::string& resource_id,
const std::string& md5);
void OnCloseFileFinished(const FilePath& file_path,
const FileOperationCallback& callback,
GDataFileError result);
void CloseFileOnUIThreadFinalize(const FilePath& file_path,
const FileOperationCallback& callback,
GDataFileError result);
// Invoked upon completion of GetFileByPath initiated by Copy. If
// GetFileByPath reports no error, calls TransferRegularFile to transfer
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment