| 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 const FilePath& path, | 266 const FilePath& path, |
| 267 DriveFileError error, | 267 DriveFileError error, |
| 268 scoped_ptr<DriveEntryProto> entry_proto) { | 268 scoped_ptr<DriveEntryProto> entry_proto) { |
| 269 if (!callback.is_null()) | 269 if (!callback.is_null()) |
| 270 callback.Run(error, path, entry_proto.Pass()); | 270 callback.Run(error, path, entry_proto.Pass()); |
| 271 } | 271 } |
| 272 | 272 |
| 273 } // namespace | 273 } // namespace |
| 274 | 274 |
| 275 // DriveFileSystem::CreateDirectoryParams struct implementation. | 275 // DriveFileSystem::CreateDirectoryParams struct implementation. |
| 276 struct DriveFileSystem::CreateDirectoryParams { | |
| 277 CreateDirectoryParams(const FilePath& created_directory_path, | |
| 278 const FilePath& target_directory_path, | |
| 279 bool is_exclusive, | |
| 280 bool is_recursive, | |
| 281 const FileOperationCallback& callback); | |
| 282 ~CreateDirectoryParams(); | |
| 283 | |
| 284 const FilePath created_directory_path; | |
| 285 const FilePath target_directory_path; | |
| 286 const bool is_exclusive; | |
| 287 const bool is_recursive; | |
| 288 FileOperationCallback callback; | |
| 289 }; | |
| 290 | |
| 291 DriveFileSystem::CreateDirectoryParams::CreateDirectoryParams( | 276 DriveFileSystem::CreateDirectoryParams::CreateDirectoryParams( |
| 292 const FilePath& created_directory_path, | 277 const FilePath& created_directory_path, |
| 293 const FilePath& target_directory_path, | 278 const FilePath& target_directory_path, |
| 294 bool is_exclusive, | 279 bool is_exclusive, |
| 295 bool is_recursive, | 280 bool is_recursive, |
| 296 const FileOperationCallback& callback) | 281 const FileOperationCallback& callback) |
| 297 : created_directory_path(created_directory_path), | 282 : created_directory_path(created_directory_path), |
| 298 target_directory_path(target_directory_path), | 283 target_directory_path(target_directory_path), |
| 299 is_exclusive(is_exclusive), | 284 is_exclusive(is_exclusive), |
| 300 is_recursive(is_recursive), | 285 is_recursive(is_recursive), |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 callback(in_callback) {} | 363 callback(in_callback) {} |
| 379 | 364 |
| 380 const FilePath local_file_path; | 365 const FilePath local_file_path; |
| 381 const FilePath remote_file_path; | 366 const FilePath remote_file_path; |
| 382 const FileOperationCallback callback; | 367 const FileOperationCallback callback; |
| 383 }; | 368 }; |
| 384 | 369 |
| 385 // DriveFileSystem::AddUploadedFileParams implementation. | 370 // DriveFileSystem::AddUploadedFileParams implementation. |
| 386 struct DriveFileSystem::AddUploadedFileParams { | 371 struct DriveFileSystem::AddUploadedFileParams { |
| 387 AddUploadedFileParams(UploadMode upload_mode, | 372 AddUploadedFileParams(UploadMode upload_mode, |
| 388 DriveDirectory* parent_dir, | 373 const FilePath& directory_path, |
| 389 scoped_ptr<DriveEntry> new_entry, | 374 scoped_ptr<DocumentEntry> doc_entry, |
| 390 const FilePath& file_content_path, | 375 const FilePath& file_content_path, |
| 391 DriveCache::FileOperationType cache_operation, | 376 DriveCache::FileOperationType cache_operation, |
| 392 const base::Closure& callback) | 377 const base::Closure& callback) |
| 393 : upload_mode(upload_mode), | 378 : upload_mode(upload_mode), |
| 394 parent_dir(parent_dir), | 379 directory_path(directory_path), |
| 395 new_entry(new_entry.Pass()), | 380 doc_entry(doc_entry.Pass()), |
| 396 file_content_path(file_content_path), | 381 file_content_path(file_content_path), |
| 397 cache_operation(cache_operation), | 382 cache_operation(cache_operation), |
| 398 callback(callback) { | 383 callback(callback) { |
| 399 } | 384 } |
| 400 | 385 |
| 401 UploadMode upload_mode; | 386 UploadMode upload_mode; |
| 402 DriveDirectory* parent_dir; | 387 FilePath directory_path; |
| 403 scoped_ptr<DriveEntry> new_entry; | 388 scoped_ptr<DocumentEntry> doc_entry; |
| 404 FilePath file_content_path; | 389 FilePath file_content_path; |
| 405 DriveCache::FileOperationType cache_operation; | 390 DriveCache::FileOperationType cache_operation; |
| 406 base::Closure callback; | 391 base::Closure callback; |
| 407 std::string resource_id; | 392 std::string resource_id; |
| 408 std::string md5; | 393 std::string md5; |
| 409 }; | 394 }; |
| 410 | 395 |
| 411 | 396 |
| 412 // DriveFileSystem class implementation. | 397 // DriveFileSystem class implementation. |
| 413 | 398 |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 callback)); | 962 callback)); |
| 978 } | 963 } |
| 979 | 964 |
| 980 void DriveFileSystem::RenameAfterGetEntryInfo( | 965 void DriveFileSystem::RenameAfterGetEntryInfo( |
| 981 const FilePath& file_path, | 966 const FilePath& file_path, |
| 982 const FilePath::StringType& new_name, | 967 const FilePath::StringType& new_name, |
| 983 const FileMoveCallback& callback, | 968 const FileMoveCallback& callback, |
| 984 DriveFileError error, | 969 DriveFileError error, |
| 985 scoped_ptr<DriveEntryProto> entry_proto) { | 970 scoped_ptr<DriveEntryProto> entry_proto) { |
| 986 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 971 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 972 DCHECK(!callback.is_null()); |
| 987 | 973 |
| 988 if (error != DRIVE_FILE_OK) { | 974 if (error != DRIVE_FILE_OK) { |
| 989 if (!callback.is_null()) | 975 callback.Run(error, file_path); |
| 990 callback.Run(error, file_path); | |
| 991 return; | 976 return; |
| 992 } | 977 } |
| 993 DCHECK(entry_proto.get()); | 978 DCHECK(entry_proto.get()); |
| 994 | 979 |
| 995 // Drop the .g<something> extension from |new_name| if the file being | 980 // Drop the .g<something> extension from |new_name| if the file being |
| 996 // renamed is a hosted document and |new_name| has the same .g<something> | 981 // renamed is a hosted document and |new_name| has the same .g<something> |
| 997 // extension as the file. | 982 // extension as the file. |
| 998 FilePath::StringType file_name = new_name; | 983 FilePath::StringType file_name = new_name; |
| 999 if (entry_proto->has_file_specific_info() && | 984 if (entry_proto->has_file_specific_info() && |
| 1000 entry_proto->file_specific_info().is_hosted_document()) { | 985 entry_proto->file_specific_info().is_hosted_document()) { |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1335 if (!callback.is_null()) { | 1320 if (!callback.is_null()) { |
| 1336 MessageLoop::current()->PostTask(FROM_HERE, | 1321 MessageLoop::current()->PostTask(FROM_HERE, |
| 1337 base::Bind(callback, DRIVE_FILE_ERROR_NOT_FOUND)); | 1322 base::Bind(callback, DRIVE_FILE_ERROR_NOT_FOUND)); |
| 1338 } | 1323 } |
| 1339 return; | 1324 return; |
| 1340 } | 1325 } |
| 1341 | 1326 |
| 1342 drive_service_->CreateDirectory( | 1327 drive_service_->CreateDirectory( |
| 1343 last_parent_dir_url, | 1328 last_parent_dir_url, |
| 1344 first_missing_path.BaseName().value(), | 1329 first_missing_path.BaseName().value(), |
| 1345 base::Bind(&DriveFileSystem::OnCreateDirectoryCompleted, | 1330 base::Bind(&DriveFileSystem::AddNewDirectory, |
| 1346 ui_weak_ptr_, | 1331 ui_weak_ptr_, |
| 1347 CreateDirectoryParams( | 1332 CreateDirectoryParams( |
| 1348 first_missing_path, | 1333 first_missing_path, |
| 1349 directory_path, | 1334 directory_path, |
| 1350 is_exclusive, | 1335 is_exclusive, |
| 1351 is_recursive, | 1336 is_recursive, |
| 1352 callback))); | 1337 callback))); |
| 1353 } | 1338 } |
| 1354 | 1339 |
| 1355 void DriveFileSystem::CreateFile(const FilePath& file_path, | 1340 void DriveFileSystem::CreateFile(const FilePath& file_path, |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2174 if (!about.get()) { | 2159 if (!about.get()) { |
| 2175 callback.Run(DRIVE_FILE_ERROR_FAILED, -1, -1); | 2160 callback.Run(DRIVE_FILE_ERROR_FAILED, -1, -1); |
| 2176 return; | 2161 return; |
| 2177 } | 2162 } |
| 2178 | 2163 |
| 2179 callback.Run(DRIVE_FILE_OK, | 2164 callback.Run(DRIVE_FILE_OK, |
| 2180 about->quota_bytes_total(), | 2165 about->quota_bytes_total(), |
| 2181 about->quota_bytes_used()); | 2166 about->quota_bytes_used()); |
| 2182 } | 2167 } |
| 2183 | 2168 |
| 2184 void DriveFileSystem::OnCreateDirectoryCompleted( | 2169 void DriveFileSystem::AddNewDirectory( |
| 2185 const CreateDirectoryParams& params, | 2170 const CreateDirectoryParams& params, |
| 2186 GDataErrorCode status, | 2171 GDataErrorCode status, |
| 2187 scoped_ptr<base::Value> data) { | 2172 scoped_ptr<base::Value> data) { |
| 2188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2189 | 2174 |
| 2190 DriveFileError error = util::GDataToDriveFileError(status); | 2175 DriveFileError error = util::GDataToDriveFileError(status); |
| 2191 if (error != DRIVE_FILE_OK) { | 2176 if (error != DRIVE_FILE_OK) { |
| 2192 if (!params.callback.is_null()) | 2177 if (!params.callback.is_null()) |
| 2193 params.callback.Run(error); | 2178 params.callback.Run(error); |
| 2194 | |
| 2195 return; | 2179 return; |
| 2196 } | 2180 } |
| 2197 | 2181 |
| 2198 base::DictionaryValue* dict_value = NULL; | 2182 resource_metadata_->AddEntryToDirectory( |
| 2199 base::Value* created_entry = NULL; | 2183 params.created_directory_path.DirName(), |
| 2200 if (data.get() && data->GetAsDictionary(&dict_value) && dict_value) | 2184 scoped_ptr<DocumentEntry>(DocumentEntry::ExtractAndParse(*data)), |
| 2201 dict_value->Get("entry", &created_entry); | 2185 base::Bind(&DriveFileSystem::ContinueCreateDirectory, |
| 2202 error = AddNewDirectory(params.created_directory_path.DirName(), | 2186 ui_weak_ptr_, |
| 2203 created_entry); | 2187 params)); |
| 2188 } |
| 2189 |
| 2190 void DriveFileSystem::ContinueCreateDirectory( |
| 2191 const CreateDirectoryParams& params, |
| 2192 DriveFileError error, |
| 2193 const FilePath& moved_file_path) { |
| 2194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2204 | 2195 |
| 2205 if (error != DRIVE_FILE_OK) { | 2196 if (error != DRIVE_FILE_OK) { |
| 2206 if (!params.callback.is_null()) | 2197 if (!params.callback.is_null()) |
| 2207 params.callback.Run(error); | 2198 params.callback.Run(error); |
| 2208 | |
| 2209 return; | 2199 return; |
| 2210 } | 2200 } |
| 2211 | 2201 |
| 2202 OnDirectoryChanged(moved_file_path.DirName()); |
| 2203 |
| 2212 // Not done yet with recursive directory creation? | 2204 // Not done yet with recursive directory creation? |
| 2213 if (params.target_directory_path != params.created_directory_path && | 2205 if (params.target_directory_path != params.created_directory_path && |
| 2214 params.is_recursive) { | 2206 params.is_recursive) { |
| 2215 CreateDirectory(params.target_directory_path, | 2207 CreateDirectory(params.target_directory_path, |
| 2216 params.is_exclusive, | 2208 params.is_exclusive, |
| 2217 params.is_recursive, | 2209 params.is_recursive, |
| 2218 params.callback); | 2210 params.callback); |
| 2219 return; | 2211 } else if (!params.callback.is_null()) { |
| 2220 } | |
| 2221 | |
| 2222 if (!params.callback.is_null()) { | |
| 2223 // Finally done with the create request. | 2212 // Finally done with the create request. |
| 2224 params.callback.Run(DRIVE_FILE_OK); | 2213 params.callback.Run(DRIVE_FILE_OK); |
| 2225 } | 2214 } |
| 2226 } | 2215 } |
| 2227 | 2216 |
| 2228 void DriveFileSystem::OnSearch(const SearchCallback& callback, | 2217 void DriveFileSystem::OnSearch(const SearchCallback& callback, |
| 2229 GetDocumentsParams* params, | 2218 GetDocumentsParams* params, |
| 2230 DriveFileError error) { | 2219 DriveFileError error) { |
| 2231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2232 | 2221 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2372 scoped_ptr<base::Value> data) { | 2361 scoped_ptr<base::Value> data) { |
| 2373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2374 DCHECK(!callback.is_null()); | 2363 DCHECK(!callback.is_null()); |
| 2375 | 2364 |
| 2376 DriveFileError error = util::GDataToDriveFileError(status); | 2365 DriveFileError error = util::GDataToDriveFileError(status); |
| 2377 if (error != DRIVE_FILE_OK) { | 2366 if (error != DRIVE_FILE_OK) { |
| 2378 callback.Run(error); | 2367 callback.Run(error); |
| 2379 return; | 2368 return; |
| 2380 } | 2369 } |
| 2381 | 2370 |
| 2382 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); | |
| 2383 if (!doc_entry.get()) { | |
| 2384 callback.Run(DRIVE_FILE_ERROR_FAILED); | |
| 2385 return; | |
| 2386 } | |
| 2387 | |
| 2388 DriveEntry* entry = resource_metadata_->FromDocumentEntry(*doc_entry); | |
| 2389 if (!entry) { | |
| 2390 callback.Run(DRIVE_FILE_ERROR_FAILED); | |
| 2391 return; | |
| 2392 } | |
| 2393 | |
| 2394 // |entry| was added in the root directory on the server, so we should | 2371 // |entry| was added in the root directory on the server, so we should |
| 2395 // first add it to |root_| to mirror the state and then move it to the | 2372 // first add it to |root_| to mirror the state and then move it to the |
| 2396 // destination directory by MoveEntryFromRootDirectory(). | 2373 // destination directory by MoveEntryFromRootDirectory(). |
| 2397 resource_metadata_->AddEntryToDirectory( | 2374 resource_metadata_->AddEntryToDirectory( |
| 2398 resource_metadata_->root(), | 2375 resource_metadata_->root()->GetFilePath(), |
| 2399 entry, | 2376 scoped_ptr<DocumentEntry>(DocumentEntry::ExtractAndParse(*data)), |
| 2400 base::Bind(&DriveFileSystem::MoveEntryFromRootDirectory, | 2377 base::Bind(&DriveFileSystem::MoveEntryFromRootDirectory, |
| 2401 ui_weak_ptr_, | 2378 ui_weak_ptr_, |
| 2402 dir_path, | 2379 dir_path, |
| 2403 callback)); | 2380 callback)); |
| 2404 } | 2381 } |
| 2405 | 2382 |
| 2406 void DriveFileSystem::OnMoveEntryFromRootDirectoryCompleted( | 2383 void DriveFileSystem::OnMoveEntryFromRootDirectoryCompleted( |
| 2407 const FileOperationCallback& callback, | 2384 const FileOperationCallback& callback, |
| 2408 const FilePath& file_path, | 2385 const FilePath& file_path, |
| 2409 const FilePath& dir_path, | 2386 const FilePath& dir_path, |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2562 // Nothing much to do here for now. | 2539 // Nothing much to do here for now. |
| 2563 } | 2540 } |
| 2564 | 2541 |
| 2565 void DriveFileSystem::RenameEntryLocally( | 2542 void DriveFileSystem::RenameEntryLocally( |
| 2566 const FilePath& file_path, | 2543 const FilePath& file_path, |
| 2567 const FilePath::StringType& new_name, | 2544 const FilePath::StringType& new_name, |
| 2568 const FileMoveCallback& callback, | 2545 const FileMoveCallback& callback, |
| 2569 GDataErrorCode status, | 2546 GDataErrorCode status, |
| 2570 const GURL& document_url) { | 2547 const GURL& document_url) { |
| 2571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2549 DCHECK(!callback.is_null()); |
| 2572 | 2550 |
| 2573 const DriveFileError error = util::GDataToDriveFileError(status); | 2551 const DriveFileError error = util::GDataToDriveFileError(status); |
| 2574 if (error != DRIVE_FILE_OK) { | 2552 if (error != DRIVE_FILE_OK) { |
| 2575 if (!callback.is_null()) | 2553 callback.Run(error, FilePath()); |
| 2576 callback.Run(error, FilePath()); | |
| 2577 return; | 2554 return; |
| 2578 } | 2555 } |
| 2579 | 2556 |
| 2580 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); | 2557 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); |
| 2581 if (!entry) { | 2558 if (!entry) { |
| 2582 if (!callback.is_null()) | 2559 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, FilePath()); |
| 2583 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, FilePath()); | |
| 2584 return; | 2560 return; |
| 2585 } | 2561 } |
| 2586 | 2562 |
| 2587 DCHECK(entry->parent()); | 2563 DCHECK(entry->parent()); |
| 2588 entry->set_title(new_name); | 2564 entry->set_title(new_name); |
| 2589 // After changing the title of the entry, call MoveEntryToDirectory() to | 2565 // After changing the title of the entry, call MoveEntryToDirectory() to |
| 2590 // remove the entry from its parent directory and then add it back in order to | 2566 // remove the entry from its parent directory and then add it back in order to |
| 2591 // go through the file name de-duplication. | 2567 // go through the file name de-duplication. |
| 2592 // TODO(achuith/satorux/zel): This code is fragile. The title has been | 2568 // TODO(achuith/satorux/zel): This code is fragile. The title has been |
| 2593 // changed, but not the file_name. MoveEntryToDirectory calls RemoveChild to | 2569 // changed, but not the file_name. MoveEntryToDirectory calls RemoveChild to |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2628 base::Bind(&DriveFileSystem::NotifyAndRunFileMoveCallback, | 2604 base::Bind(&DriveFileSystem::NotifyAndRunFileMoveCallback, |
| 2629 ui_weak_ptr_, | 2605 ui_weak_ptr_, |
| 2630 callback)); | 2606 callback)); |
| 2631 } | 2607 } |
| 2632 | 2608 |
| 2633 void DriveFileSystem::NotifyAndRunFileMoveCallback( | 2609 void DriveFileSystem::NotifyAndRunFileMoveCallback( |
| 2634 const FileMoveCallback& callback, | 2610 const FileMoveCallback& callback, |
| 2635 DriveFileError error, | 2611 DriveFileError error, |
| 2636 const FilePath& moved_file_path) { | 2612 const FilePath& moved_file_path) { |
| 2637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2613 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2614 DCHECK(!callback.is_null()); |
| 2638 | 2615 |
| 2639 if (error == DRIVE_FILE_OK) | 2616 if (error == DRIVE_FILE_OK) |
| 2640 OnDirectoryChanged(moved_file_path.DirName()); | 2617 OnDirectoryChanged(moved_file_path.DirName()); |
| 2641 | 2618 |
| 2642 if (!callback.is_null()) | 2619 callback.Run(error, moved_file_path); |
| 2643 callback.Run(error, moved_file_path); | |
| 2644 } | 2620 } |
| 2645 | 2621 |
| 2646 void DriveFileSystem::NotifyAndRunFileOperationCallback( | 2622 void DriveFileSystem::NotifyAndRunFileOperationCallback( |
| 2647 const FileOperationCallback& callback, | 2623 const FileOperationCallback& callback, |
| 2648 DriveFileError error, | 2624 DriveFileError error, |
| 2649 const FilePath& moved_file_path) { | 2625 const FilePath& moved_file_path) { |
| 2650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2626 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2651 DCHECK(!callback.is_null()); | 2627 DCHECK(!callback.is_null()); |
| 2652 | 2628 |
| 2653 if (error == DRIVE_FILE_OK) | 2629 if (error == DRIVE_FILE_OK) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2691 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2667 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2692 DCHECK(!callback.is_null()); | 2668 DCHECK(!callback.is_null()); |
| 2693 | 2669 |
| 2694 // Notify the observers that root directory has been initialized. | 2670 // Notify the observers that root directory has been initialized. |
| 2695 FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, | 2671 FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, |
| 2696 OnInitialLoadFinished()); | 2672 OnInitialLoadFinished()); |
| 2697 | 2673 |
| 2698 callback.Run(error); | 2674 callback.Run(error); |
| 2699 } | 2675 } |
| 2700 | 2676 |
| 2701 DriveFileError DriveFileSystem::AddNewDirectory( | |
| 2702 const FilePath& directory_path, base::Value* entry_value) { | |
| 2703 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 2704 | |
| 2705 if (!entry_value) | |
| 2706 return DRIVE_FILE_ERROR_FAILED; | |
| 2707 | |
| 2708 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value)); | |
| 2709 | |
| 2710 if (!doc_entry.get()) | |
| 2711 return DRIVE_FILE_ERROR_FAILED; | |
| 2712 | |
| 2713 // Find parent directory element within the cached file system snapshot. | |
| 2714 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(directory_path); | |
| 2715 if (!entry) | |
| 2716 return DRIVE_FILE_ERROR_FAILED; | |
| 2717 | |
| 2718 // Check if parent is a directory since in theory since this is a callback | |
| 2719 // something could in the meantime have nuked the parent dir and created a | |
| 2720 // file with the exact same name. | |
| 2721 DriveDirectory* parent_dir = entry->AsDriveDirectory(); | |
| 2722 if (!parent_dir) | |
| 2723 return DRIVE_FILE_ERROR_FAILED; | |
| 2724 | |
| 2725 DriveEntry* new_entry = | |
| 2726 resource_metadata_->FromDocumentEntry(*doc_entry); | |
| 2727 if (!new_entry) | |
| 2728 return DRIVE_FILE_ERROR_FAILED; | |
| 2729 | |
| 2730 resource_metadata_->AddEntryToDirectory( | |
| 2731 parent_dir, | |
| 2732 new_entry, | |
| 2733 base::Bind(&DriveFileSystem::NotifyAndRunFileMoveCallback, | |
| 2734 ui_weak_ptr_, | |
| 2735 FileMoveCallback())); | |
| 2736 return DRIVE_FILE_OK; | |
| 2737 } | |
| 2738 | |
| 2739 DriveFileSystem::FindMissingDirectoryResult | 2677 DriveFileSystem::FindMissingDirectoryResult |
| 2740 DriveFileSystem::FindFirstMissingParentDirectory( | 2678 DriveFileSystem::FindFirstMissingParentDirectory( |
| 2741 const FilePath& directory_path, | 2679 const FilePath& directory_path, |
| 2742 GURL* last_dir_content_url, | 2680 GURL* last_dir_content_url, |
| 2743 FilePath* first_missing_parent_path) { | 2681 FilePath* first_missing_parent_path) { |
| 2744 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2682 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2745 | 2683 |
| 2746 // Let's find which how deep is the existing directory structure and | 2684 // Let's find which how deep is the existing directory structure and |
| 2747 // get the first element that's missing. | 2685 // get the first element that's missing. |
| 2748 std::vector<FilePath::StringType> path_parts; | 2686 std::vector<FilePath::StringType> path_parts; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2764 } else { | 2702 } else { |
| 2765 *first_missing_parent_path = current_path; | 2703 *first_missing_parent_path = current_path; |
| 2766 return FOUND_MISSING; | 2704 return FOUND_MISSING; |
| 2767 } | 2705 } |
| 2768 } | 2706 } |
| 2769 return DIRECTORY_ALREADY_PRESENT; | 2707 return DIRECTORY_ALREADY_PRESENT; |
| 2770 } | 2708 } |
| 2771 | 2709 |
| 2772 void DriveFileSystem::AddUploadedFile( | 2710 void DriveFileSystem::AddUploadedFile( |
| 2773 UploadMode upload_mode, | 2711 UploadMode upload_mode, |
| 2774 const FilePath& virtual_dir_path, | 2712 const FilePath& directory_path, |
| 2775 scoped_ptr<DocumentEntry> entry, | 2713 scoped_ptr<DocumentEntry> entry, |
| 2776 const FilePath& file_content_path, | 2714 const FilePath& file_content_path, |
| 2777 DriveCache::FileOperationType cache_operation, | 2715 DriveCache::FileOperationType cache_operation, |
| 2778 const base::Closure& callback) { | 2716 const base::Closure& callback) { |
| 2779 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2717 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2780 | 2718 |
| 2781 // Post a task to the same thread, rather than calling it here, as | 2719 // Post a task to the same thread, rather than calling it here, as |
| 2782 // AddUploadedFile() is asynchronous. | 2720 // AddUploadedFile() is asynchronous. |
| 2783 base::MessageLoopProxy::current()->PostTask( | 2721 base::MessageLoopProxy::current()->PostTask( |
| 2784 FROM_HERE, | 2722 FROM_HERE, |
| 2785 base::Bind(&DriveFileSystem::AddUploadedFileOnUIThread, | 2723 base::Bind(&DriveFileSystem::AddUploadedFileOnUIThread, |
| 2786 ui_weak_ptr_, | 2724 ui_weak_ptr_, |
| 2787 upload_mode, | 2725 upload_mode, |
| 2788 virtual_dir_path, | 2726 directory_path, |
| 2789 base::Passed(&entry), | 2727 base::Passed(&entry), |
| 2790 file_content_path, | 2728 file_content_path, |
| 2791 cache_operation, | 2729 cache_operation, |
| 2792 callback)); | 2730 callback)); |
| 2793 } | 2731 } |
| 2794 | 2732 |
| 2795 void DriveFileSystem::AddUploadedFileOnUIThread( | 2733 void DriveFileSystem::AddUploadedFileOnUIThread( |
| 2796 UploadMode upload_mode, | 2734 UploadMode upload_mode, |
| 2797 const FilePath& virtual_dir_path, | 2735 const FilePath& directory_path, |
| 2798 scoped_ptr<DocumentEntry> entry, | 2736 scoped_ptr<DocumentEntry> doc_entry, |
| 2799 const FilePath& file_content_path, | 2737 const FilePath& file_content_path, |
| 2800 DriveCache::FileOperationType cache_operation, | 2738 DriveCache::FileOperationType cache_operation, |
| 2801 const base::Closure& callback) { | 2739 const base::Closure& callback) { |
| 2802 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2740 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2741 DCHECK(doc_entry.get()); |
| 2803 | 2742 |
| 2804 // ScopedClosureRunner ensures that the specified callback is always invoked | 2743 const std::string& resource_id = doc_entry->resource_id(); |
| 2805 // upon return or passed on. | |
| 2806 base::ScopedClosureRunner callback_runner(callback); | |
| 2807 | |
| 2808 if (!entry.get()) { | |
| 2809 NOTREACHED(); | |
| 2810 return; | |
| 2811 } | |
| 2812 | |
| 2813 DriveEntry* dir_entry = resource_metadata_->FindEntryByPathSync( | |
| 2814 virtual_dir_path); | |
| 2815 if (!dir_entry) | |
| 2816 return; | |
| 2817 | |
| 2818 DriveDirectory* parent_dir = dir_entry->AsDriveDirectory(); | |
| 2819 if (!parent_dir) | |
| 2820 return; | |
| 2821 | |
| 2822 scoped_ptr<DriveEntry> new_entry( | |
| 2823 resource_metadata_->FromDocumentEntry(*entry)); | |
| 2824 if (!new_entry.get()) | |
| 2825 return; | |
| 2826 | |
| 2827 const std::string& resource_id = new_entry->resource_id(); | |
| 2828 AddUploadedFileParams* params = | 2744 AddUploadedFileParams* params = |
| 2829 new AddUploadedFileParams(upload_mode, | 2745 new AddUploadedFileParams(upload_mode, |
| 2830 parent_dir, | 2746 directory_path, |
| 2831 new_entry.Pass(), | 2747 doc_entry.Pass(), |
| 2832 file_content_path, | 2748 file_content_path, |
| 2833 cache_operation, | 2749 cache_operation, |
| 2834 callback_runner.Release()); | 2750 callback); |
| 2835 | 2751 |
| 2836 const FileMoveCallback file_move_callback = | 2752 const FileMoveCallback file_move_callback = |
| 2837 base::Bind(&DriveFileSystem::ContinueAddUploadedFile, | 2753 base::Bind(&DriveFileSystem::ContinueAddUploadedFile, |
| 2838 ui_weak_ptr_, params); | 2754 ui_weak_ptr_, params); |
| 2839 | 2755 |
| 2840 if (upload_mode == UPLOAD_EXISTING_FILE) { | 2756 if (upload_mode == UPLOAD_EXISTING_FILE) { |
| 2841 // Remove the existing entry. | 2757 // Remove the existing entry. |
| 2842 resource_metadata_->RemoveEntryFromParent(resource_id, file_move_callback); | 2758 resource_metadata_->RemoveEntryFromParent(resource_id, file_move_callback); |
| 2843 } else { | 2759 } else { |
| 2844 file_move_callback.Run(DRIVE_FILE_OK, FilePath()); | 2760 file_move_callback.Run(DRIVE_FILE_OK, FilePath()); |
| 2845 } | 2761 } |
| 2846 } | 2762 } |
| 2847 | 2763 |
| 2848 void DriveFileSystem::ContinueAddUploadedFile( | 2764 void DriveFileSystem::ContinueAddUploadedFile( |
| 2849 AddUploadedFileParams* params, | 2765 AddUploadedFileParams* params, |
| 2850 DriveFileError error, | 2766 DriveFileError error, |
| 2851 const FilePath& file_path) { | 2767 const FilePath& /* file_path */) { |
| 2852 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2768 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2853 DCHECK_EQ(DRIVE_FILE_OK, error); | 2769 DCHECK_EQ(DRIVE_FILE_OK, error); |
| 2854 DCHECK(params->new_entry.get()); | 2770 DCHECK(params->doc_entry.get()); |
| 2855 DriveFile* file = params->new_entry->AsDriveFile(); | |
| 2856 DCHECK(file); | |
| 2857 | 2771 |
| 2858 params->resource_id = file->resource_id(); | 2772 params->resource_id = params->doc_entry->resource_id(); |
| 2859 params->md5 = file->file_md5(); | 2773 params->md5 = params->doc_entry->file_md5(); |
| 2774 DCHECK(!params->resource_id.empty()); |
| 2775 DCHECK(!params->md5.empty()); |
| 2776 |
| 2860 resource_metadata_->AddEntryToDirectory( | 2777 resource_metadata_->AddEntryToDirectory( |
| 2861 params->parent_dir, | 2778 params->directory_path, |
| 2862 params->new_entry.release(), | 2779 params->doc_entry.Pass(), |
| 2863 base::Bind(&DriveFileSystem::NotifyAndRunFileMoveCallback, | 2780 base::Bind(&DriveFileSystem::AddUploadedFileToCache, |
| 2864 ui_weak_ptr_, | 2781 ui_weak_ptr_, |
| 2865 base::Bind(&DriveFileSystem::AddUploadedFileToCache, | 2782 base::Owned(params))); |
| 2866 ui_weak_ptr_, | |
| 2867 base::Owned(params)))); | |
| 2868 } | 2783 } |
| 2869 | 2784 |
| 2870 void DriveFileSystem::AddUploadedFileToCache( | 2785 void DriveFileSystem::AddUploadedFileToCache( |
| 2871 AddUploadedFileParams* params, | 2786 AddUploadedFileParams* params, |
| 2872 DriveFileError error, | 2787 DriveFileError error, |
| 2873 const FilePath& file_path) { | 2788 const FilePath& file_path) { |
| 2874 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2790 DCHECK(!params->resource_id.empty()); |
| 2791 DCHECK(!params->md5.empty()); |
| 2792 DCHECK(!params->resource_id.empty()); |
| 2793 DCHECK(!params->callback.is_null()); |
| 2794 |
| 2795 if (error != DRIVE_FILE_OK) { |
| 2796 params->callback.Run(); |
| 2797 return; |
| 2798 } |
| 2799 |
| 2800 OnDirectoryChanged(file_path.DirName()); |
| 2875 | 2801 |
| 2876 if (params->upload_mode == UPLOAD_NEW_FILE) { | 2802 if (params->upload_mode == UPLOAD_NEW_FILE) { |
| 2877 // Add the file to the cache if we have uploaded a new file. | 2803 // Add the file to the cache if we have uploaded a new file. |
| 2878 cache_->StoreOnUIThread(params->resource_id, | 2804 cache_->StoreOnUIThread(params->resource_id, |
| 2879 params->md5, | 2805 params->md5, |
| 2880 params->file_content_path, | 2806 params->file_content_path, |
| 2881 params->cache_operation, | 2807 params->cache_operation, |
| 2882 base::Bind(&OnCacheUpdatedForAddUploadedFile, | 2808 base::Bind(&OnCacheUpdatedForAddUploadedFile, |
| 2883 params->callback)); | 2809 params->callback)); |
| 2884 } else if (params->upload_mode == UPLOAD_EXISTING_FILE) { | 2810 } else if (params->upload_mode == UPLOAD_EXISTING_FILE) { |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3305 return; | 3231 return; |
| 3306 } | 3232 } |
| 3307 | 3233 |
| 3308 PlatformFileInfoProto entry_file_info; | 3234 PlatformFileInfoProto entry_file_info; |
| 3309 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3235 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
| 3310 *entry_proto->mutable_file_info() = entry_file_info; | 3236 *entry_proto->mutable_file_info() = entry_file_info; |
| 3311 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); | 3237 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
| 3312 } | 3238 } |
| 3313 | 3239 |
| 3314 } // namespace gdata | 3240 } // namespace gdata |
| OLD | NEW |