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,
const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(!callback.is_null());
RunTaskOnUIThread(base::Bind(&DriveFileSystem::RemoveOnUIThread,
ui_weak_ptr_,
file_path,
......@@ -1222,6 +1224,7 @@ void DriveFileSystem::RemoveOnUIThread(
const FilePath& file_path,
const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
// Get the edit URL of an entry at |file_path|.
resource_metadata_->GetEntryInfoByPath(
......@@ -1237,16 +1240,20 @@ void DriveFileSystem::RemoveOnUIThreadAfterGetEntryInfo(
DriveFileError error,
scoped_ptr<DriveEntryProto> entry_proto) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (error != DRIVE_FILE_OK) {
if (!callback.is_null()) {
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, base::Bind(callback, error));
}
callback.Run(error);
return;
}
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(
GURL(entry_proto->edit_url()),
base::Bind(&DriveFileSystem::RemoveResourceLocally,
......@@ -2416,11 +2423,11 @@ void DriveFileSystem::RemoveResourceLocally(
GDataErrorCode status,
const GURL& /* document_url */) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
DriveFileError error = util::GDataToDriveFileError(status);
if (error != DRIVE_FILE_OK) {
if (!callback.is_null())
callback.Run(error);
callback.Run(error);
return;
}
......
......@@ -511,7 +511,7 @@ class DriveFileSystem : public DriveFileSystemInterface,
// Callback for DriveServiceInterface::DeleteDocument. Removes the entry with
// |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,
const std::string& resource_id,
GDataErrorCode status,
......@@ -797,6 +797,7 @@ class DriveFileSystem : public DriveFileSystemInterface,
// Part of RemoveOnUIThread(). Called after GetEntryInfoByPath() is
// complete.
// |callback| must not be null.
void RemoveOnUIThreadAfterGetEntryInfo(
const FileOperationCallback& callback,
DriveFileError error,
......
......@@ -227,6 +227,7 @@ class DriveFileSystemInterface {
// 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.
// |callback| must not be null.
virtual void Remove(const FilePath& file_path,
bool is_recursive,
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