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/gdata_file_system.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 }; | 564 }; |
565 | 565 |
566 // Returns callback which runs the given |callback| on the current thread. | 566 // Returns callback which runs the given |callback| on the current thread. |
567 template<typename CallbackType> | 567 template<typename CallbackType> |
568 CallbackType CreateRelayCallback(const CallbackType& callback) { | 568 CallbackType CreateRelayCallback(const CallbackType& callback) { |
569 return base::Bind(&RelayCallback<CallbackType>::Run, | 569 return base::Bind(&RelayCallback<CallbackType>::Run, |
570 base::MessageLoopProxy::current(), | 570 base::MessageLoopProxy::current(), |
571 callback); | 571 callback); |
572 } | 572 } |
573 | 573 |
574 // Callback used to find a directory element for file system updates. | |
575 void ReadOnlyFindEntryCallback(GDataEntry** out, | |
576 GDataFileError error, | |
577 GDataEntry* entry) { | |
578 if (error == GDATA_FILE_OK) | |
579 *out = entry; | |
580 } | |
581 | |
582 // Wrapper around BrowserThread::PostTask to post a task to the blocking | 574 // Wrapper around BrowserThread::PostTask to post a task to the blocking |
583 // pool with the given sequence token. | 575 // pool with the given sequence token. |
584 void PostBlockingPoolSequencedTask( | 576 void PostBlockingPoolSequencedTask( |
585 const tracked_objects::Location& from_here, | 577 const tracked_objects::Location& from_here, |
586 base::SequencedTaskRunner* blocking_task_runner, | 578 base::SequencedTaskRunner* blocking_task_runner, |
587 const base::Closure& task) { | 579 const base::Closure& task) { |
588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
589 | 581 |
590 const bool posted = blocking_task_runner->PostTask(from_here, task); | 582 const bool posted = blocking_task_runner->PostTask(from_here, task); |
591 DCHECK(posted); | 583 DCHECK(posted); |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
967 ui_weak_ptr_, | 959 ui_weak_ptr_, |
968 search_file_path, | 960 search_file_path, |
969 callback)); | 961 callback)); |
970 } | 962 } |
971 | 963 |
972 void GDataFileSystem::FindEntryByPathSyncOnUIThread( | 964 void GDataFileSystem::FindEntryByPathSyncOnUIThread( |
973 const FilePath& search_file_path, | 965 const FilePath& search_file_path, |
974 const FindEntryCallback& callback) { | 966 const FindEntryCallback& callback) { |
975 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 967 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
976 | 968 |
977 directory_service_->FindEntryByPath(search_file_path, callback); | 969 GDataEntry* entry = directory_service_->FindEntryByPathSync( |
970 search_file_path); | |
971 if (entry) | |
achuithb
2012/07/30 21:54:40
Alternatively, you could do:
callback.Run(entry ?
satorux1
2012/07/30 22:10:40
Done.
| |
972 callback.Run(GDATA_FILE_OK, entry); | |
973 else | |
974 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, entry); | |
978 } | 975 } |
979 | 976 |
980 void GDataFileSystem::ReloadFeedFromServerIfNeeded( | 977 void GDataFileSystem::ReloadFeedFromServerIfNeeded( |
981 ContentOrigin initial_origin, | 978 ContentOrigin initial_origin, |
982 int local_changestamp, | 979 int local_changestamp, |
983 const FilePath& search_file_path, | 980 const FilePath& search_file_path, |
984 const FindEntryCallback& callback) { | 981 const FindEntryCallback& callback) { |
985 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 982 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
986 | 983 |
987 // First fetch the latest changestamp to see if there were any new changes | 984 // First fetch the latest changestamp to see if there were any new changes |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1380 const FilePath& dest_file_path, | 1377 const FilePath& dest_file_path, |
1381 const FileOperationCallback& callback) { | 1378 const FileOperationCallback& callback) { |
1382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1383 | 1380 |
1384 GDataFileError error = GDATA_FILE_OK; | 1381 GDataFileError error = GDATA_FILE_OK; |
1385 FilePath dest_parent_path = dest_file_path.DirName(); | 1382 FilePath dest_parent_path = dest_file_path.DirName(); |
1386 | 1383 |
1387 std::string src_file_resource_id; | 1384 std::string src_file_resource_id; |
1388 bool src_file_is_hosted_document = false; | 1385 bool src_file_is_hosted_document = false; |
1389 | 1386 |
1390 GDataEntry* src_entry = GetGDataEntryByPath(src_file_path); | 1387 GDataEntry* src_entry = directory_service_->FindEntryByPathSync( |
1391 GDataEntry* dest_parent = GetGDataEntryByPath(dest_parent_path); | 1388 src_file_path); |
1389 GDataEntry* dest_parent = directory_service_->FindEntryByPathSync( | |
1390 dest_parent_path); | |
1392 if (!src_entry || !dest_parent) { | 1391 if (!src_entry || !dest_parent) { |
1393 error = GDATA_FILE_ERROR_NOT_FOUND; | 1392 error = GDATA_FILE_ERROR_NOT_FOUND; |
1394 } else if (!dest_parent->AsGDataDirectory()) { | 1393 } else if (!dest_parent->AsGDataDirectory()) { |
1395 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 1394 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; |
1396 } else if (!src_entry->AsGDataFile()) { | 1395 } else if (!src_entry->AsGDataFile()) { |
1397 // TODO(benchan): Implement copy for directories. In the interim, | 1396 // TODO(benchan): Implement copy for directories. In the interim, |
1398 // we handle recursive directory copy in the file manager. | 1397 // we handle recursive directory copy in the file manager. |
1399 error = GDATA_FILE_ERROR_INVALID_OPERATION; | 1398 error = GDATA_FILE_ERROR_INVALID_OPERATION; |
1400 } else { | 1399 } else { |
1401 src_file_resource_id = src_entry->resource_id(); | 1400 src_file_resource_id = src_entry->resource_id(); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1586 } | 1585 } |
1587 | 1586 |
1588 void GDataFileSystem::MoveOnUIThread(const FilePath& src_file_path, | 1587 void GDataFileSystem::MoveOnUIThread(const FilePath& src_file_path, |
1589 const FilePath& dest_file_path, | 1588 const FilePath& dest_file_path, |
1590 const FileOperationCallback& callback) { | 1589 const FileOperationCallback& callback) { |
1591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1592 | 1591 |
1593 GDataFileError error = GDATA_FILE_OK; | 1592 GDataFileError error = GDATA_FILE_OK; |
1594 FilePath dest_parent_path = dest_file_path.DirName(); | 1593 FilePath dest_parent_path = dest_file_path.DirName(); |
1595 | 1594 |
1596 GDataEntry* src_entry = GetGDataEntryByPath(src_file_path); | 1595 GDataEntry* src_entry = directory_service_->FindEntryByPathSync( |
1597 GDataEntry* dest_parent = GetGDataEntryByPath(dest_parent_path); | 1596 src_file_path); |
1597 GDataEntry* dest_parent = directory_service_->FindEntryByPathSync( | |
1598 dest_parent_path); | |
1598 if (!src_entry || !dest_parent) { | 1599 if (!src_entry || !dest_parent) { |
1599 error = GDATA_FILE_ERROR_NOT_FOUND; | 1600 error = GDATA_FILE_ERROR_NOT_FOUND; |
1600 } else if (!dest_parent->AsGDataDirectory()) { | 1601 } else if (!dest_parent->AsGDataDirectory()) { |
1601 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 1602 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; |
1602 } | 1603 } |
1603 | 1604 |
1604 if (error != GDATA_FILE_OK) { | 1605 if (error != GDATA_FILE_OK) { |
1605 if (!callback.is_null()) { | 1606 if (!callback.is_null()) { |
1606 MessageLoop::current()->PostTask(FROM_HERE, | 1607 MessageLoop::current()->PostTask(FROM_HERE, |
1607 base::Bind(callback, error)); | 1608 base::Bind(callback, error)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1646 remove_file_from_directory_callback); | 1647 remove_file_from_directory_callback); |
1647 } | 1648 } |
1648 | 1649 |
1649 void GDataFileSystem::AddEntryToDirectory( | 1650 void GDataFileSystem::AddEntryToDirectory( |
1650 const FilePath& dir_path, | 1651 const FilePath& dir_path, |
1651 const FileOperationCallback& callback, | 1652 const FileOperationCallback& callback, |
1652 GDataFileError error, | 1653 GDataFileError error, |
1653 const FilePath& file_path) { | 1654 const FilePath& file_path) { |
1654 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1655 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1655 | 1656 |
1656 GDataEntry* entry = GetGDataEntryByPath(file_path); | 1657 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
1657 GDataEntry* dir_entry = GetGDataEntryByPath(dir_path); | 1658 GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(dir_path); |
1658 if (error == GDATA_FILE_OK) { | 1659 if (error == GDATA_FILE_OK) { |
1659 if (!entry || !dir_entry) { | 1660 if (!entry || !dir_entry) { |
1660 error = GDATA_FILE_ERROR_NOT_FOUND; | 1661 error = GDATA_FILE_ERROR_NOT_FOUND; |
1661 } else { | 1662 } else { |
1662 if (!dir_entry->AsGDataDirectory()) | 1663 if (!dir_entry->AsGDataDirectory()) |
1663 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 1664 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; |
1664 } | 1665 } |
1665 } | 1666 } |
1666 | 1667 |
1667 // Returns if there is an error or |dir_path| is the root directory. | 1668 // Returns if there is an error or |dir_path| is the root directory. |
(...skipping 15 matching lines...) Expand all Loading... | |
1683 dir_path)); | 1684 dir_path)); |
1684 } | 1685 } |
1685 | 1686 |
1686 void GDataFileSystem::RemoveEntryFromDirectory( | 1687 void GDataFileSystem::RemoveEntryFromDirectory( |
1687 const FilePath& dir_path, | 1688 const FilePath& dir_path, |
1688 const FilePathUpdateCallback& callback, | 1689 const FilePathUpdateCallback& callback, |
1689 GDataFileError error, | 1690 GDataFileError error, |
1690 const FilePath& file_path) { | 1691 const FilePath& file_path) { |
1691 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1692 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1692 | 1693 |
1693 GDataEntry* entry = GetGDataEntryByPath(file_path); | 1694 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
1694 GDataEntry* dir = GetGDataEntryByPath(dir_path); | 1695 GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path); |
1695 if (error == GDATA_FILE_OK) { | 1696 if (error == GDATA_FILE_OK) { |
1696 if (!entry || !dir) { | 1697 if (!entry || !dir) { |
1697 error = GDATA_FILE_ERROR_NOT_FOUND; | 1698 error = GDATA_FILE_ERROR_NOT_FOUND; |
1698 } else { | 1699 } else { |
1699 if (!dir->AsGDataDirectory()) | 1700 if (!dir->AsGDataDirectory()) |
1700 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 1701 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; |
1701 } | 1702 } |
1702 } | 1703 } |
1703 | 1704 |
1704 // Returns if there is an error or |dir_path| is the root directory. | 1705 // Returns if there is an error or |dir_path| is the root directory. |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2451 directory->AddEntry(entry.release()); | 2452 directory->AddEntry(entry.release()); |
2452 } | 2453 } |
2453 | 2454 |
2454 // Note that there may be no change in the directory, but it's expensive to | 2455 // Note that there may be no change in the directory, but it's expensive to |
2455 // check if the new metadata matches the existing one, so we just always | 2456 // check if the new metadata matches the existing one, so we just always |
2456 // notify that the directory is changed. | 2457 // notify that the directory is changed. |
2457 NotifyDirectoryChanged(directory_path); | 2458 NotifyDirectoryChanged(directory_path); |
2458 DVLOG(1) << "Directory refreshed: " << directory_path.value(); | 2459 DVLOG(1) << "Directory refreshed: " << directory_path.value(); |
2459 } | 2460 } |
2460 | 2461 |
2461 GDataEntry* GDataFileSystem::GetGDataEntryByPath( | |
2462 const FilePath& file_path) { | |
2463 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
2464 | |
2465 // Find directory element within the cached file system snapshot. | |
2466 GDataEntry* entry = NULL; | |
2467 directory_service_->FindEntryByPath(file_path, | |
2468 base::Bind(&ReadOnlyFindEntryCallback, &entry)); | |
2469 return entry; | |
2470 } | |
2471 | |
2472 void GDataFileSystem::UpdateFileByResourceId( | 2462 void GDataFileSystem::UpdateFileByResourceId( |
2473 const std::string& resource_id, | 2463 const std::string& resource_id, |
2474 const FileOperationCallback& callback) { | 2464 const FileOperationCallback& callback) { |
2475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2465 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
2476 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2466 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2477 RunTaskOnUIThread( | 2467 RunTaskOnUIThread( |
2478 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, | 2468 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, |
2479 ui_weak_ptr_, | 2469 ui_weak_ptr_, |
2480 resource_id, | 2470 resource_id, |
2481 CreateRelayCallback(callback))); | 2471 CreateRelayCallback(callback))); |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3074 void GDataFileSystem::OnAddEntryToDirectoryCompleted( | 3064 void GDataFileSystem::OnAddEntryToDirectoryCompleted( |
3075 const FileOperationCallback& callback, | 3065 const FileOperationCallback& callback, |
3076 const FilePath& file_path, | 3066 const FilePath& file_path, |
3077 const FilePath& dir_path, | 3067 const FilePath& dir_path, |
3078 GDataErrorCode status, | 3068 GDataErrorCode status, |
3079 const GURL& document_url) { | 3069 const GURL& document_url) { |
3080 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3070 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3081 | 3071 |
3082 GDataFileError error = GDataToGDataFileError(status); | 3072 GDataFileError error = GDataToGDataFileError(status); |
3083 if (error == GDATA_FILE_OK) { | 3073 if (error == GDATA_FILE_OK) { |
3084 GDataEntry* entry = GetGDataEntryByPath(file_path); | 3074 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
3085 if (entry) { | 3075 if (entry) { |
3086 DCHECK_EQ(directory_service_->root(), entry->parent()); | 3076 DCHECK_EQ(directory_service_->root(), entry->parent()); |
3087 error = AddEntryToDirectoryOnFilesystem(entry, dir_path); | 3077 error = AddEntryToDirectoryOnFilesystem(entry, dir_path); |
3088 } else { | 3078 } else { |
3089 error = GDATA_FILE_ERROR_NOT_FOUND; | 3079 error = GDATA_FILE_ERROR_NOT_FOUND; |
3090 } | 3080 } |
3091 } | 3081 } |
3092 | 3082 |
3093 if (!callback.is_null()) | 3083 if (!callback.is_null()) |
3094 callback.Run(error); | 3084 callback.Run(error); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3235 // Nothing much to do here for now. | 3225 // Nothing much to do here for now. |
3236 } | 3226 } |
3237 | 3227 |
3238 GDataFileError GDataFileSystem::RenameFileOnFilesystem( | 3228 GDataFileError GDataFileSystem::RenameFileOnFilesystem( |
3239 const FilePath& file_path, | 3229 const FilePath& file_path, |
3240 const FilePath::StringType& new_name, | 3230 const FilePath::StringType& new_name, |
3241 FilePath* updated_file_path) { | 3231 FilePath* updated_file_path) { |
3242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3243 DCHECK(updated_file_path); | 3233 DCHECK(updated_file_path); |
3244 | 3234 |
3245 GDataEntry* entry = GetGDataEntryByPath(file_path); | 3235 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
3246 if (!entry) | 3236 if (!entry) |
3247 return GDATA_FILE_ERROR_NOT_FOUND; | 3237 return GDATA_FILE_ERROR_NOT_FOUND; |
3248 | 3238 |
3249 DCHECK(entry->parent()); | 3239 DCHECK(entry->parent()); |
3250 entry->set_title(new_name); | 3240 entry->set_title(new_name); |
3251 // After changing the title of the entry, call TakeFile() to remove the | 3241 // After changing the title of the entry, call TakeFile() to remove the |
3252 // entry from its parent directory and then add it back in order to go | 3242 // entry from its parent directory and then add it back in order to go |
3253 // through the file name de-duplication. | 3243 // through the file name de-duplication. |
3254 // TODO(achuith/satorux/zel): This code is fragile. The title has been | 3244 // TODO(achuith/satorux/zel): This code is fragile. The title has been |
3255 // changed, but not the file_name. TakeEntry removes the child based on the | 3245 // changed, but not the file_name. TakeEntry removes the child based on the |
3256 // old file_name, and then re-adds the child by first assigning the new title | 3246 // old file_name, and then re-adds the child by first assigning the new title |
3257 // to file_name. http://crbug.com/30157 | 3247 // to file_name. http://crbug.com/30157 |
3258 if (!entry->parent()->TakeEntry(entry)) | 3248 if (!entry->parent()->TakeEntry(entry)) |
3259 return GDATA_FILE_ERROR_FAILED; | 3249 return GDATA_FILE_ERROR_FAILED; |
3260 | 3250 |
3261 *updated_file_path = entry->GetFilePath(); | 3251 *updated_file_path = entry->GetFilePath(); |
3262 | 3252 |
3263 NotifyDirectoryChanged(updated_file_path->DirName()); | 3253 NotifyDirectoryChanged(updated_file_path->DirName()); |
3264 return GDATA_FILE_OK; | 3254 return GDATA_FILE_OK; |
3265 } | 3255 } |
3266 | 3256 |
3267 GDataFileError GDataFileSystem::AddEntryToDirectoryOnFilesystem( | 3257 GDataFileError GDataFileSystem::AddEntryToDirectoryOnFilesystem( |
3268 GDataEntry* entry, const FilePath& dir_path) { | 3258 GDataEntry* entry, const FilePath& dir_path) { |
3269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3270 DCHECK(entry); | 3260 DCHECK(entry); |
3271 | 3261 |
3272 GDataEntry* dir_entry = GetGDataEntryByPath(dir_path); | 3262 GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(dir_path); |
3273 if (!dir_entry) | 3263 if (!dir_entry) |
3274 return GDATA_FILE_ERROR_NOT_FOUND; | 3264 return GDATA_FILE_ERROR_NOT_FOUND; |
3275 | 3265 |
3276 GDataDirectory* dir = dir_entry->AsGDataDirectory(); | 3266 GDataDirectory* dir = dir_entry->AsGDataDirectory(); |
3277 if (!dir) | 3267 if (!dir) |
3278 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 3268 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; |
3279 | 3269 |
3280 if (!dir->TakeEntry(entry)) | 3270 if (!dir->TakeEntry(entry)) |
3281 return GDATA_FILE_ERROR_FAILED; | 3271 return GDATA_FILE_ERROR_FAILED; |
3282 | 3272 |
3283 NotifyDirectoryChanged(dir_path); | 3273 NotifyDirectoryChanged(dir_path); |
3284 return GDATA_FILE_OK; | 3274 return GDATA_FILE_OK; |
3285 } | 3275 } |
3286 | 3276 |
3287 GDataFileError GDataFileSystem::RemoveEntryFromDirectoryOnFilesystem( | 3277 GDataFileError GDataFileSystem::RemoveEntryFromDirectoryOnFilesystem( |
3288 const FilePath& file_path, const FilePath& dir_path, | 3278 const FilePath& file_path, const FilePath& dir_path, |
3289 FilePath* updated_file_path) { | 3279 FilePath* updated_file_path) { |
3290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3291 DCHECK(updated_file_path); | 3281 DCHECK(updated_file_path); |
3292 | 3282 |
3293 GDataEntry* entry = GetGDataEntryByPath(file_path); | 3283 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
3294 if (!entry) | 3284 if (!entry) |
3295 return GDATA_FILE_ERROR_NOT_FOUND; | 3285 return GDATA_FILE_ERROR_NOT_FOUND; |
3296 | 3286 |
3297 GDataEntry* dir = GetGDataEntryByPath(dir_path); | 3287 GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path); |
3298 if (!dir) | 3288 if (!dir) |
3299 return GDATA_FILE_ERROR_NOT_FOUND; | 3289 return GDATA_FILE_ERROR_NOT_FOUND; |
3300 | 3290 |
3301 if (!dir->AsGDataDirectory()) | 3291 if (!dir->AsGDataDirectory()) |
3302 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 3292 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; |
3303 | 3293 |
3304 DCHECK_EQ(dir->AsGDataDirectory(), entry->parent()); | 3294 DCHECK_EQ(dir->AsGDataDirectory(), entry->parent()); |
3305 | 3295 |
3306 if (!directory_service_->root()->TakeEntry(entry)) | 3296 if (!directory_service_->root()->TakeEntry(entry)) |
3307 return GDATA_FILE_ERROR_FAILED; | 3297 return GDATA_FILE_ERROR_FAILED; |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3636 | 3626 |
3637 if (!entry_value) | 3627 if (!entry_value) |
3638 return GDATA_FILE_ERROR_FAILED; | 3628 return GDATA_FILE_ERROR_FAILED; |
3639 | 3629 |
3640 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value)); | 3630 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value)); |
3641 | 3631 |
3642 if (!doc_entry.get()) | 3632 if (!doc_entry.get()) |
3643 return GDATA_FILE_ERROR_FAILED; | 3633 return GDATA_FILE_ERROR_FAILED; |
3644 | 3634 |
3645 // Find parent directory element within the cached file system snapshot. | 3635 // Find parent directory element within the cached file system snapshot. |
3646 GDataEntry* entry = GetGDataEntryByPath(directory_path); | 3636 GDataEntry* entry = directory_service_->FindEntryByPathSync(directory_path); |
3647 if (!entry) | 3637 if (!entry) |
3648 return GDATA_FILE_ERROR_FAILED; | 3638 return GDATA_FILE_ERROR_FAILED; |
3649 | 3639 |
3650 // Check if parent is a directory since in theory since this is a callback | 3640 // Check if parent is a directory since in theory since this is a callback |
3651 // something could in the meantime have nuked the parent dir and created a | 3641 // something could in the meantime have nuked the parent dir and created a |
3652 // file with the exact same name. | 3642 // file with the exact same name. |
3653 GDataDirectory* parent_dir = entry->AsGDataDirectory(); | 3643 GDataDirectory* parent_dir = entry->AsGDataDirectory(); |
3654 if (!parent_dir) | 3644 if (!parent_dir) |
3655 return GDATA_FILE_ERROR_FAILED; | 3645 return GDATA_FILE_ERROR_FAILED; |
3656 | 3646 |
(...skipping 18 matching lines...) Expand all Loading... | |
3675 // Let's find which how deep is the existing directory structure and | 3665 // Let's find which how deep is the existing directory structure and |
3676 // get the first element that's missing. | 3666 // get the first element that's missing. |
3677 std::vector<FilePath::StringType> path_parts; | 3667 std::vector<FilePath::StringType> path_parts; |
3678 directory_path.GetComponents(&path_parts); | 3668 directory_path.GetComponents(&path_parts); |
3679 FilePath current_path; | 3669 FilePath current_path; |
3680 | 3670 |
3681 for (std::vector<FilePath::StringType>::const_iterator iter = | 3671 for (std::vector<FilePath::StringType>::const_iterator iter = |
3682 path_parts.begin(); | 3672 path_parts.begin(); |
3683 iter != path_parts.end(); ++iter) { | 3673 iter != path_parts.end(); ++iter) { |
3684 current_path = current_path.Append(*iter); | 3674 current_path = current_path.Append(*iter); |
3685 GDataEntry* entry = GetGDataEntryByPath(current_path); | 3675 GDataEntry* entry = directory_service_->FindEntryByPathSync(current_path); |
3686 if (entry) { | 3676 if (entry) { |
3687 if (entry->file_info().is_directory) { | 3677 if (entry->file_info().is_directory) { |
3688 *last_dir_content_url = entry->content_url(); | 3678 *last_dir_content_url = entry->content_url(); |
3689 } else { | 3679 } else { |
3690 // Huh, the segment found is a file not a directory? | 3680 // Huh, the segment found is a file not a directory? |
3691 return FOUND_INVALID; | 3681 return FOUND_INVALID; |
3692 } | 3682 } |
3693 } else { | 3683 } else { |
3694 *first_missing_parent_path = current_path; | 3684 *first_missing_parent_path = current_path; |
3695 return FOUND_MISSING; | 3685 return FOUND_MISSING; |
3696 } | 3686 } |
3697 } | 3687 } |
3698 return DIRECTORY_ALREADY_PRESENT; | 3688 return DIRECTORY_ALREADY_PRESENT; |
3699 } | 3689 } |
3700 | 3690 |
3701 GDataFileError GDataFileSystem::RemoveEntryFromGData( | 3691 GDataFileError GDataFileSystem::RemoveEntryFromGData( |
3702 const FilePath& file_path, std::string* resource_id) { | 3692 const FilePath& file_path, std::string* resource_id) { |
3703 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3693 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3704 | 3694 |
3705 resource_id->clear(); | 3695 resource_id->clear(); |
3706 | 3696 |
3707 // Find directory element within the cached file system snapshot. | 3697 // Find directory element within the cached file system snapshot. |
3708 GDataEntry* entry = GetGDataEntryByPath(file_path); | 3698 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
3709 | 3699 |
3710 if (!entry) | 3700 if (!entry) |
3711 return GDATA_FILE_ERROR_NOT_FOUND; | 3701 return GDATA_FILE_ERROR_NOT_FOUND; |
3712 | 3702 |
3713 // You can't remove root element. | 3703 // You can't remove root element. |
3714 if (!entry->parent()) | 3704 if (!entry->parent()) |
3715 return GDATA_FILE_ERROR_ACCESS_DENIED; | 3705 return GDATA_FILE_ERROR_ACCESS_DENIED; |
3716 | 3706 |
3717 // If it's a file (only files have resource id), get its resource id so that | 3707 // If it's a file (only files have resource id), get its resource id so that |
3718 // we can remove it after releasing the auto lock. | 3708 // we can remove it after releasing the auto lock. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3759 const base::Closure& callback) { | 3749 const base::Closure& callback) { |
3760 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3750 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3761 DCHECK(!callback.is_null()); | 3751 DCHECK(!callback.is_null()); |
3762 | 3752 |
3763 if (!entry.get()) { | 3753 if (!entry.get()) { |
3764 NOTREACHED(); | 3754 NOTREACHED(); |
3765 callback.Run(); | 3755 callback.Run(); |
3766 return; | 3756 return; |
3767 } | 3757 } |
3768 | 3758 |
3769 GDataEntry* dir_entry = GetGDataEntryByPath(virtual_dir_path); | 3759 GDataEntry* dir_entry = directory_service_->FindEntryByPathSync( |
3760 virtual_dir_path); | |
3770 if (!dir_entry) { | 3761 if (!dir_entry) { |
3771 callback.Run(); | 3762 callback.Run(); |
3772 return; | 3763 return; |
3773 } | 3764 } |
3774 | 3765 |
3775 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); | 3766 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); |
3776 if (!parent_dir) { | 3767 if (!parent_dir) { |
3777 callback.Run(); | 3768 callback.Run(); |
3778 return; | 3769 return; |
3779 } | 3770 } |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4279 } | 4270 } |
4280 | 4271 |
4281 PlatformFileInfoProto entry_file_info; | 4272 PlatformFileInfoProto entry_file_info; |
4282 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 4273 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
4283 *entry_proto->mutable_file_info() = entry_file_info; | 4274 *entry_proto->mutable_file_info() = entry_file_info; |
4284 if (!callback.is_null()) | 4275 if (!callback.is_null()) |
4285 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 4276 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
4286 } | 4277 } |
4287 | 4278 |
4288 } // namespace gdata | 4279 } // namespace gdata |
OLD | NEW |