OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/gdata/drive_file_system.h" | 5 #include "chrome/browser/chromeos/gdata/drive_file_system.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 callback, | 1220 callback, |
1221 file_path, | 1221 file_path, |
1222 dir_path)); | 1222 dir_path)); |
1223 } | 1223 } |
1224 | 1224 |
1225 void DriveFileSystem::Remove(const FilePath& file_path, | 1225 void DriveFileSystem::Remove(const FilePath& file_path, |
1226 bool is_recursive, | 1226 bool is_recursive, |
1227 const FileOperationCallback& callback) { | 1227 const FileOperationCallback& callback) { |
1228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1229 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1229 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1230 DCHECK(!callback.is_null()); |
| 1231 |
1230 RunTaskOnUIThread(base::Bind(&DriveFileSystem::RemoveOnUIThread, | 1232 RunTaskOnUIThread(base::Bind(&DriveFileSystem::RemoveOnUIThread, |
1231 ui_weak_ptr_, | 1233 ui_weak_ptr_, |
1232 file_path, | 1234 file_path, |
1233 CreateRelayCallback(callback))); | 1235 CreateRelayCallback(callback))); |
1234 } | 1236 } |
1235 | 1237 |
1236 void DriveFileSystem::RemoveOnUIThread( | 1238 void DriveFileSystem::RemoveOnUIThread( |
1237 const FilePath& file_path, | 1239 const FilePath& file_path, |
1238 const FileOperationCallback& callback) { | 1240 const FileOperationCallback& callback) { |
1239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1242 DCHECK(!callback.is_null()); |
1240 | 1243 |
1241 // Get the edit URL of an entry at |file_path|. | 1244 // Get the edit URL of an entry at |file_path|. |
1242 resource_metadata_->GetEntryInfoByPath( | 1245 resource_metadata_->GetEntryInfoByPath( |
1243 file_path, | 1246 file_path, |
1244 base::Bind( | 1247 base::Bind( |
1245 &DriveFileSystem::RemoveOnUIThreadAfterGetEntryInfo, | 1248 &DriveFileSystem::RemoveOnUIThreadAfterGetEntryInfo, |
1246 ui_weak_ptr_, | 1249 ui_weak_ptr_, |
1247 callback)); | 1250 callback)); |
1248 } | 1251 } |
1249 | 1252 |
1250 void DriveFileSystem::RemoveOnUIThreadAfterGetEntryInfo( | 1253 void DriveFileSystem::RemoveOnUIThreadAfterGetEntryInfo( |
1251 const FileOperationCallback& callback, | 1254 const FileOperationCallback& callback, |
1252 DriveFileError error, | 1255 DriveFileError error, |
1253 scoped_ptr<DriveEntryProto> entry_proto) { | 1256 scoped_ptr<DriveEntryProto> entry_proto) { |
1254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1258 DCHECK(!callback.is_null()); |
1255 | 1259 |
1256 if (error != DRIVE_FILE_OK) { | 1260 if (error != DRIVE_FILE_OK) { |
1257 if (!callback.is_null()) { | 1261 callback.Run(error); |
1258 base::MessageLoopProxy::current()->PostTask( | 1262 return; |
1259 FROM_HERE, base::Bind(callback, error)); | 1263 } |
1260 } | 1264 DCHECK(entry_proto.get()); |
| 1265 |
| 1266 // The edit URL can be empty for some reason. |
| 1267 if (entry_proto->edit_url().empty()) { |
| 1268 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND); |
1261 return; | 1269 return; |
1262 } | 1270 } |
1263 | 1271 |
1264 DCHECK(entry_proto.get()); | |
1265 drive_service_->DeleteDocument( | 1272 drive_service_->DeleteDocument( |
1266 GURL(entry_proto->edit_url()), | 1273 GURL(entry_proto->edit_url()), |
1267 base::Bind(&DriveFileSystem::RemoveResourceLocally, | 1274 base::Bind(&DriveFileSystem::RemoveResourceLocally, |
1268 ui_weak_ptr_, | 1275 ui_weak_ptr_, |
1269 callback, | 1276 callback, |
1270 entry_proto->resource_id())); | 1277 entry_proto->resource_id())); |
1271 } | 1278 } |
1272 | 1279 |
1273 void DriveFileSystem::CreateDirectory( | 1280 void DriveFileSystem::CreateDirectory( |
1274 const FilePath& directory_path, | 1281 const FilePath& directory_path, |
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2432 | 2439 |
2433 callback.Run(error); | 2440 callback.Run(error); |
2434 } | 2441 } |
2435 | 2442 |
2436 void DriveFileSystem::RemoveResourceLocally( | 2443 void DriveFileSystem::RemoveResourceLocally( |
2437 const FileOperationCallback& callback, | 2444 const FileOperationCallback& callback, |
2438 const std::string& resource_id, | 2445 const std::string& resource_id, |
2439 GDataErrorCode status, | 2446 GDataErrorCode status, |
2440 const GURL& /* document_url */) { | 2447 const GURL& /* document_url */) { |
2441 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2449 DCHECK(!callback.is_null()); |
2442 | 2450 |
2443 DriveFileError error = util::GDataToDriveFileError(status); | 2451 DriveFileError error = util::GDataToDriveFileError(status); |
2444 if (error != DRIVE_FILE_OK) { | 2452 if (error != DRIVE_FILE_OK) { |
2445 if (!callback.is_null()) | 2453 callback.Run(error); |
2446 callback.Run(error); | |
2447 return; | 2454 return; |
2448 } | 2455 } |
2449 | 2456 |
2450 resource_metadata_->RemoveEntryFromParent( | 2457 resource_metadata_->RemoveEntryFromParent( |
2451 resource_id, | 2458 resource_id, |
2452 base::Bind(&DriveFileSystem::OnDirectoryChangeFileMoveCallback, | 2459 base::Bind(&DriveFileSystem::OnDirectoryChangeFileMoveCallback, |
2453 ui_weak_ptr_, | 2460 ui_weak_ptr_, |
2454 callback)); | 2461 callback)); |
2455 | 2462 |
2456 cache_->RemoveOnUIThread(resource_id, CacheOperationCallback()); | 2463 cache_->RemoveOnUIThread(resource_id, CacheOperationCallback()); |
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3305 return; | 3312 return; |
3306 } | 3313 } |
3307 | 3314 |
3308 PlatformFileInfoProto entry_file_info; | 3315 PlatformFileInfoProto entry_file_info; |
3309 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3316 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
3310 *entry_proto->mutable_file_info() = entry_file_info; | 3317 *entry_proto->mutable_file_info() = entry_file_info; |
3311 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); | 3318 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
3312 } | 3319 } |
3313 | 3320 |
3314 } // namespace gdata | 3321 } // namespace gdata |
OLD | NEW |