Commit 50db9b0e authored by satorux@chromium.org's avatar satorux@chromium.org

gdata: Make callback parameters mandatory for CloseFile functions

There was a place where CloseFile() is called with a null callback, but
with the caller fixed, it's safe to make the callback parameter mandatory.

Along the way, removed unused |file_path| parameter from
DataFileSystem::OnGetEntryCompleteForCloseFile()

BUG=126634
TEST=out/Release/unit_tests --gtest_filter=GData*

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151366 0039d316-1c4b-4281-b951-d872f2087c98
parent 301ad565
...@@ -3182,6 +3182,8 @@ void GDataFileSystem::CloseFile(const FilePath& file_path, ...@@ -3182,6 +3182,8 @@ void GDataFileSystem::CloseFile(const FilePath& file_path,
const FileOperationCallback& callback) { const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
BrowserThread::CurrentlyOn(BrowserThread::IO)); BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(!callback.is_null());
RunTaskOnUIThread(base::Bind(&GDataFileSystem::CloseFileOnUIThread, RunTaskOnUIThread(base::Bind(&GDataFileSystem::CloseFileOnUIThread,
ui_weak_ptr_, ui_weak_ptr_,
file_path, file_path,
...@@ -3192,6 +3194,7 @@ void GDataFileSystem::CloseFileOnUIThread( ...@@ -3192,6 +3194,7 @@ void GDataFileSystem::CloseFileOnUIThread(
const FilePath& file_path, const FilePath& file_path,
const FileOperationCallback& callback) { const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (open_files_.find(file_path) == open_files_.end()) { if (open_files_.find(file_path) == open_files_.end()) {
// The file is not being opened. // The file is not being opened.
...@@ -3218,12 +3221,14 @@ void GDataFileSystem::OnGetEntryInfoCompleteForCloseFile( ...@@ -3218,12 +3221,14 @@ void GDataFileSystem::OnGetEntryInfoCompleteForCloseFile(
const FileOperationCallback& callback, const FileOperationCallback& callback,
GDataFileError error, GDataFileError error,
scoped_ptr<GDataEntryProto> entry_proto) { scoped_ptr<GDataEntryProto> entry_proto) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (entry_proto.get() && !entry_proto->has_file_specific_info()) if (entry_proto.get() && !entry_proto->has_file_specific_info())
error = GDATA_FILE_ERROR_NOT_FOUND; error = GDATA_FILE_ERROR_NOT_FOUND;
if (error != GDATA_FILE_OK) { if (error != GDATA_FILE_OK) {
if (!callback.is_null()) callback.Run(error);
callback.Run(error);
return; return;
} }
...@@ -3246,10 +3251,10 @@ void GDataFileSystem::OnGetCacheFilePathCompleteForCloseFile( ...@@ -3246,10 +3251,10 @@ void GDataFileSystem::OnGetCacheFilePathCompleteForCloseFile(
const std::string& md5, const std::string& md5,
const FilePath& local_cache_path) { const FilePath& local_cache_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (error != GDATA_FILE_OK) { if (error != GDATA_FILE_OK) {
if (!callback.is_null()) callback.Run(error);
callback.Run(error);
return; return;
} }
...@@ -3278,10 +3283,10 @@ void GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile( ...@@ -3278,10 +3283,10 @@ void GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile(
bool* get_file_info_result, bool* get_file_info_result,
const FileOperationCallback& callback) { const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (!*get_file_info_result) { if (!*get_file_info_result) {
if (!callback.is_null()) callback.Run(GDATA_FILE_ERROR_NOT_FOUND);
callback.Run(GDATA_FILE_ERROR_NOT_FOUND);
return; return;
} }
...@@ -3291,22 +3296,20 @@ void GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile( ...@@ -3291,22 +3296,20 @@ void GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile(
file_path, file_path,
base::Bind(&GDataFileSystem::OnGetEntryCompleteForCloseFile, base::Bind(&GDataFileSystem::OnGetEntryCompleteForCloseFile,
ui_weak_ptr_, ui_weak_ptr_,
file_path,
*file_info, *file_info,
callback)); callback));
} }
void GDataFileSystem::OnGetEntryCompleteForCloseFile( void GDataFileSystem::OnGetEntryCompleteForCloseFile(
const FilePath& file_path,
const base::PlatformFileInfo& file_info, const base::PlatformFileInfo& file_info,
const FileOperationCallback& callback, const FileOperationCallback& callback,
GDataFileError error, GDataFileError error,
GDataEntry* entry) { GDataEntry* entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (error != GDATA_FILE_OK) { if (error != GDATA_FILE_OK) {
if (!callback.is_null()) callback.Run(error);
callback.Run(error);
return; return;
} }
...@@ -3314,8 +3317,7 @@ void GDataFileSystem::OnGetEntryCompleteForCloseFile( ...@@ -3314,8 +3317,7 @@ void GDataFileSystem::OnGetEntryCompleteForCloseFile(
GDataFile* file = entry->AsGDataFile(); GDataFile* file = entry->AsGDataFile();
if (!file || file->file_md5().empty() || file->is_hosted_document()) { if (!file || file->file_md5().empty() || file->is_hosted_document()) {
// No support for opening a directory or hosted document. // No support for opening a directory or hosted document.
if (!callback.is_null()) callback.Run(GDATA_FILE_ERROR_INVALID_OPERATION);
callback.Run(GDATA_FILE_ERROR_INVALID_OPERATION);
return; return;
} }
DCHECK(!file->resource_id().empty()); DCHECK(!file->resource_id().empty());
...@@ -3344,12 +3346,12 @@ void GDataFileSystem::OnGetEntryCompleteForCloseFile( ...@@ -3344,12 +3346,12 @@ void GDataFileSystem::OnGetEntryCompleteForCloseFile(
void GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile( void GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile(
const FileOperationCallback& callback, const FileOperationCallback& callback,
GDataFileError error, GDataFileError error,
const std::string& resource_id, const std::string& /* resource_id */,
const std::string& md5) { const std::string& /* md5 */) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (!callback.is_null()) callback.Run(error);
callback.Run(error);
} }
void GDataFileSystem::OnCloseFileFinished( void GDataFileSystem::OnCloseFileFinished(
...@@ -3357,6 +3359,7 @@ void GDataFileSystem::OnCloseFileFinished( ...@@ -3357,6 +3359,7 @@ void GDataFileSystem::OnCloseFileFinished(
const FileOperationCallback& callback, const FileOperationCallback& callback,
GDataFileError result) { GDataFileError result) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
// Step 7 of CloseFile. // Step 7 of CloseFile.
// All the invocation of |callback| from operations initiated from CloseFile // All the invocation of |callback| from operations initiated from CloseFile
...@@ -3365,8 +3368,7 @@ void GDataFileSystem::OnCloseFileFinished( ...@@ -3365,8 +3368,7 @@ void GDataFileSystem::OnCloseFileFinished(
open_files_.erase(file_path); open_files_.erase(file_path);
// Then invokes the user-supplied callback function. // Then invokes the user-supplied callback function.
if (!callback.is_null()) callback.Run(result);
callback.Run(result);
} }
void GDataFileSystem::CheckLocalModificationAndRun( void GDataFileSystem::CheckLocalModificationAndRun(
......
...@@ -273,6 +273,7 @@ class GDataFileSystem : public GDataFileSystemInterface, ...@@ -273,6 +273,7 @@ class GDataFileSystem : public GDataFileSystemInterface,
// 5) Modifies GDataEntry using the new PlatformFileInfo. // 5) Modifies GDataEntry using the new PlatformFileInfo.
// 6) Commits the modification to the cache system. // 6) Commits the modification to the cache system.
// 7) Invokes the user-supplied |callback|. // 7) Invokes the user-supplied |callback|.
// |callback| must not be null.
void OnGetEntryInfoCompleteForCloseFile( void OnGetEntryInfoCompleteForCloseFile(
const FilePath& file_path, const FilePath& file_path,
const FileOperationCallback& callback, const FileOperationCallback& callback,
...@@ -291,7 +292,6 @@ class GDataFileSystem : public GDataFileSystemInterface, ...@@ -291,7 +292,6 @@ class GDataFileSystem : public GDataFileSystemInterface,
bool* get_file_info_result, bool* get_file_info_result,
const FileOperationCallback& callback); const FileOperationCallback& callback);
void OnGetEntryCompleteForCloseFile( void OnGetEntryCompleteForCloseFile(
const FilePath& file_path,
const base::PlatformFileInfo& file_info, const base::PlatformFileInfo& file_info,
const FileOperationCallback& callback, const FileOperationCallback& callback,
GDataFileError error, GDataFileError error,
......
...@@ -180,6 +180,7 @@ class GDataFileSystemInterface { ...@@ -180,6 +180,7 @@ class GDataFileSystemInterface {
// which is opened via OpenFile(). It commits the dirty flag on the cache. // which is opened via OpenFile(). It commits the dirty flag on the cache.
// //
// Can be called from UI/IO thread. |callback| is run on the calling thread. // Can be called from UI/IO thread. |callback| is run on the calling thread.
// |callback| must not be null.
virtual void CloseFile(const FilePath& file_path, virtual void CloseFile(const FilePath& file_path,
const FileOperationCallback& callback) = 0; const FileOperationCallback& callback) = 0;
......
...@@ -126,7 +126,9 @@ void CallSnapshotFileCallback( ...@@ -126,7 +126,9 @@ void CallSnapshotFileCallback(
callback.Run(error, final_file_info, local_path, file_ref); callback.Run(error, final_file_info, local_path, file_ref);
} }
void OnClose(const FilePath& local_path, GDataFileError error_code) { // Emits debug log when GDataFileSystem::CloseFile() is complete.
void EmitDebugLogForCloseFile(const FilePath& local_path,
GDataFileError error_code) {
DVLOG(1) << "Closed: " << local_path.AsUTF8Unsafe() << ": " << error_code; DVLOG(1) << "Closed: " << local_path.AsUTF8Unsafe() << ": " << error_code;
} }
...@@ -548,7 +550,8 @@ void GDataFileSystemProxy::NotifyCloseFile(const FileSystemURL& url) { ...@@ -548,7 +550,8 @@ void GDataFileSystemProxy::NotifyCloseFile(const FileSystemURL& url) {
if (!ValidateUrl(url, &file_path)) if (!ValidateUrl(url, &file_path))
return; return;
file_system_->CloseFile(file_path, FileOperationCallback()); file_system_->CloseFile(file_path,
base::Bind(&EmitDebugLogForCloseFile, file_path));
} }
void GDataFileSystemProxy::CreateSnapshotFile( void GDataFileSystemProxy::CreateSnapshotFile(
...@@ -732,7 +735,8 @@ void GDataFileSystemProxy::CloseWritableSnapshotFile( ...@@ -732,7 +735,8 @@ void GDataFileSystemProxy::CloseWritableSnapshotFile(
const FilePath& local_path) { const FilePath& local_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
file_system_->CloseFile(virtual_path, base::Bind(&OnClose, virtual_path)); file_system_->CloseFile(virtual_path,
base::Bind(&EmitDebugLogForCloseFile, virtual_path));
} }
} // namespace gdata } // namespace gdata
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