Commit e544c099 authored by satorux@chromium.org's avatar satorux@chromium.org

drive: Fix a crash caused by an empty edit URL

For some reason, edit URL can be null in some entries, which
causes a crash.

Along the way, make |callback| parameter of DriveFilesystemInterface::Remove()
mandatory. The only caller in gdata_file_system_proxy.cc passes a non-null
callback.

BUG=144993
TEST=remove operation works as before


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153603 0039d316-1c4b-4281-b951-d872f2087c98
parent 41068282
...@@ -1212,6 +1212,8 @@ void DriveFileSystem::Remove(const FilePath& file_path, ...@@ -1212,6 +1212,8 @@ void DriveFileSystem::Remove(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(&DriveFileSystem::RemoveOnUIThread, RunTaskOnUIThread(base::Bind(&DriveFileSystem::RemoveOnUIThread,
ui_weak_ptr_, ui_weak_ptr_,
file_path, file_path,
...@@ -1222,6 +1224,7 @@ void DriveFileSystem::RemoveOnUIThread( ...@@ -1222,6 +1224,7 @@ void DriveFileSystem::RemoveOnUIThread(
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());
// Get the edit URL of an entry at |file_path|. // Get the edit URL of an entry at |file_path|.
resource_metadata_->GetEntryInfoByPath( resource_metadata_->GetEntryInfoByPath(
...@@ -1237,16 +1240,20 @@ void DriveFileSystem::RemoveOnUIThreadAfterGetEntryInfo( ...@@ -1237,16 +1240,20 @@ void DriveFileSystem::RemoveOnUIThreadAfterGetEntryInfo(
DriveFileError error, DriveFileError error,
scoped_ptr<DriveEntryProto> entry_proto) { scoped_ptr<DriveEntryProto> entry_proto) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (error != DRIVE_FILE_OK) { if (error != DRIVE_FILE_OK) {
if (!callback.is_null()) { callback.Run(error);
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, base::Bind(callback, error));
}
return; return;
} }
DCHECK(entry_proto.get()); DCHECK(entry_proto.get());
// The edit URL can be empty for some reason.
if (entry_proto->edit_url().empty()) {
callback.Run(DRIVE_FILE_ERROR_NOT_FOUND);
return;
}
drive_service_->DeleteDocument( drive_service_->DeleteDocument(
GURL(entry_proto->edit_url()), GURL(entry_proto->edit_url()),
base::Bind(&DriveFileSystem::RemoveResourceLocally, base::Bind(&DriveFileSystem::RemoveResourceLocally,
...@@ -2416,11 +2423,11 @@ void DriveFileSystem::RemoveResourceLocally( ...@@ -2416,11 +2423,11 @@ void DriveFileSystem::RemoveResourceLocally(
GDataErrorCode status, GDataErrorCode status,
const GURL& /* document_url */) { const GURL& /* document_url */) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
DriveFileError error = util::GDataToDriveFileError(status); DriveFileError error = util::GDataToDriveFileError(status);
if (error != DRIVE_FILE_OK) { if (error != DRIVE_FILE_OK) {
if (!callback.is_null()) callback.Run(error);
callback.Run(error);
return; return;
} }
......
...@@ -511,7 +511,7 @@ class DriveFileSystem : public DriveFileSystemInterface, ...@@ -511,7 +511,7 @@ class DriveFileSystem : public DriveFileSystemInterface,
// Callback for DriveServiceInterface::DeleteDocument. Removes the entry with // Callback for DriveServiceInterface::DeleteDocument. Removes the entry with
// |resource_id| from the local snapshot of the filesystem and the cache. // |resource_id| from the local snapshot of the filesystem and the cache.
// |document_url| is unused. |callback| may be null. // |document_url| is unused. |callback| must not be null.
void RemoveResourceLocally(const FileOperationCallback& callback, void RemoveResourceLocally(const FileOperationCallback& callback,
const std::string& resource_id, const std::string& resource_id,
GDataErrorCode status, GDataErrorCode status,
...@@ -797,6 +797,7 @@ class DriveFileSystem : public DriveFileSystemInterface, ...@@ -797,6 +797,7 @@ class DriveFileSystem : public DriveFileSystemInterface,
// Part of RemoveOnUIThread(). Called after GetEntryInfoByPath() is // Part of RemoveOnUIThread(). Called after GetEntryInfoByPath() is
// complete. // complete.
// |callback| must not be null.
void RemoveOnUIThreadAfterGetEntryInfo( void RemoveOnUIThreadAfterGetEntryInfo(
const FileOperationCallback& callback, const FileOperationCallback& callback,
DriveFileError error, DriveFileError error,
......
...@@ -227,6 +227,7 @@ class DriveFileSystemInterface { ...@@ -227,6 +227,7 @@ class DriveFileSystemInterface {
// TODO(satorux): is_recursive is not supported yet. crbug.com/138282 // TODO(satorux): is_recursive is not supported yet. crbug.com/138282
// //
// 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 Remove(const FilePath& file_path, virtual void Remove(const FilePath& file_path,
bool is_recursive, bool is_recursive,
const FileOperationCallback& callback) = 0; const FileOperationCallback& callback) = 0;
......
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