Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10831076: gdata: Get rid of callback from GDataDirectoryService::FindEntryByPath() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 callback.Run(entry ? GDATA_FILE_OK : GDATA_FILE_ERROR_NOT_FOUND, entry);
978 } 972 }
979 973
980 void GDataFileSystem::ReloadFeedFromServerIfNeeded( 974 void GDataFileSystem::ReloadFeedFromServerIfNeeded(
981 ContentOrigin initial_origin, 975 ContentOrigin initial_origin,
982 int local_changestamp, 976 int local_changestamp,
983 const FilePath& search_file_path, 977 const FilePath& search_file_path,
984 const FindEntryCallback& callback) { 978 const FindEntryCallback& callback) {
985 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 979 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
986 980
987 // First fetch the latest changestamp to see if there were any new changes 981 // 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
1380 const FilePath& dest_file_path, 1374 const FilePath& dest_file_path,
1381 const FileOperationCallback& callback) { 1375 const FileOperationCallback& callback) {
1382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1383 1377
1384 GDataFileError error = GDATA_FILE_OK; 1378 GDataFileError error = GDATA_FILE_OK;
1385 FilePath dest_parent_path = dest_file_path.DirName(); 1379 FilePath dest_parent_path = dest_file_path.DirName();
1386 1380
1387 std::string src_file_resource_id; 1381 std::string src_file_resource_id;
1388 bool src_file_is_hosted_document = false; 1382 bool src_file_is_hosted_document = false;
1389 1383
1390 GDataEntry* src_entry = GetGDataEntryByPath(src_file_path); 1384 GDataEntry* src_entry = directory_service_->FindEntryByPathSync(
1391 GDataEntry* dest_parent = GetGDataEntryByPath(dest_parent_path); 1385 src_file_path);
1386 GDataEntry* dest_parent = directory_service_->FindEntryByPathSync(
1387 dest_parent_path);
1392 if (!src_entry || !dest_parent) { 1388 if (!src_entry || !dest_parent) {
1393 error = GDATA_FILE_ERROR_NOT_FOUND; 1389 error = GDATA_FILE_ERROR_NOT_FOUND;
1394 } else if (!dest_parent->AsGDataDirectory()) { 1390 } else if (!dest_parent->AsGDataDirectory()) {
1395 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; 1391 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY;
1396 } else if (!src_entry->AsGDataFile()) { 1392 } else if (!src_entry->AsGDataFile()) {
1397 // TODO(benchan): Implement copy for directories. In the interim, 1393 // TODO(benchan): Implement copy for directories. In the interim,
1398 // we handle recursive directory copy in the file manager. 1394 // we handle recursive directory copy in the file manager.
1399 error = GDATA_FILE_ERROR_INVALID_OPERATION; 1395 error = GDATA_FILE_ERROR_INVALID_OPERATION;
1400 } else { 1396 } else {
1401 src_file_resource_id = src_entry->resource_id(); 1397 src_file_resource_id = src_entry->resource_id();
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 } 1582 }
1587 1583
1588 void GDataFileSystem::MoveOnUIThread(const FilePath& src_file_path, 1584 void GDataFileSystem::MoveOnUIThread(const FilePath& src_file_path,
1589 const FilePath& dest_file_path, 1585 const FilePath& dest_file_path,
1590 const FileOperationCallback& callback) { 1586 const FileOperationCallback& callback) {
1591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1587 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1592 1588
1593 GDataFileError error = GDATA_FILE_OK; 1589 GDataFileError error = GDATA_FILE_OK;
1594 FilePath dest_parent_path = dest_file_path.DirName(); 1590 FilePath dest_parent_path = dest_file_path.DirName();
1595 1591
1596 GDataEntry* src_entry = GetGDataEntryByPath(src_file_path); 1592 GDataEntry* src_entry = directory_service_->FindEntryByPathSync(
1597 GDataEntry* dest_parent = GetGDataEntryByPath(dest_parent_path); 1593 src_file_path);
1594 GDataEntry* dest_parent = directory_service_->FindEntryByPathSync(
1595 dest_parent_path);
1598 if (!src_entry || !dest_parent) { 1596 if (!src_entry || !dest_parent) {
1599 error = GDATA_FILE_ERROR_NOT_FOUND; 1597 error = GDATA_FILE_ERROR_NOT_FOUND;
1600 } else if (!dest_parent->AsGDataDirectory()) { 1598 } else if (!dest_parent->AsGDataDirectory()) {
1601 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; 1599 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY;
1602 } 1600 }
1603 1601
1604 if (error != GDATA_FILE_OK) { 1602 if (error != GDATA_FILE_OK) {
1605 if (!callback.is_null()) { 1603 if (!callback.is_null()) {
1606 MessageLoop::current()->PostTask(FROM_HERE, 1604 MessageLoop::current()->PostTask(FROM_HERE,
1607 base::Bind(callback, error)); 1605 base::Bind(callback, error));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 remove_file_from_directory_callback); 1644 remove_file_from_directory_callback);
1647 } 1645 }
1648 1646
1649 void GDataFileSystem::AddEntryToDirectory( 1647 void GDataFileSystem::AddEntryToDirectory(
1650 const FilePath& dir_path, 1648 const FilePath& dir_path,
1651 const FileOperationCallback& callback, 1649 const FileOperationCallback& callback,
1652 GDataFileError error, 1650 GDataFileError error,
1653 const FilePath& file_path) { 1651 const FilePath& file_path) {
1654 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1652 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1655 1653
1656 GDataEntry* entry = GetGDataEntryByPath(file_path); 1654 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
1657 GDataEntry* dir_entry = GetGDataEntryByPath(dir_path); 1655 GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(dir_path);
1658 if (error == GDATA_FILE_OK) { 1656 if (error == GDATA_FILE_OK) {
1659 if (!entry || !dir_entry) { 1657 if (!entry || !dir_entry) {
1660 error = GDATA_FILE_ERROR_NOT_FOUND; 1658 error = GDATA_FILE_ERROR_NOT_FOUND;
1661 } else { 1659 } else {
1662 if (!dir_entry->AsGDataDirectory()) 1660 if (!dir_entry->AsGDataDirectory())
1663 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; 1661 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY;
1664 } 1662 }
1665 } 1663 }
1666 1664
1667 // Returns if there is an error or |dir_path| is the root directory. 1665 // Returns if there is an error or |dir_path| is the root directory.
(...skipping 15 matching lines...) Expand all
1683 dir_path)); 1681 dir_path));
1684 } 1682 }
1685 1683
1686 void GDataFileSystem::RemoveEntryFromDirectory( 1684 void GDataFileSystem::RemoveEntryFromDirectory(
1687 const FilePath& dir_path, 1685 const FilePath& dir_path,
1688 const FilePathUpdateCallback& callback, 1686 const FilePathUpdateCallback& callback,
1689 GDataFileError error, 1687 GDataFileError error,
1690 const FilePath& file_path) { 1688 const FilePath& file_path) {
1691 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1689 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1692 1690
1693 GDataEntry* entry = GetGDataEntryByPath(file_path); 1691 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
1694 GDataEntry* dir = GetGDataEntryByPath(dir_path); 1692 GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path);
1695 if (error == GDATA_FILE_OK) { 1693 if (error == GDATA_FILE_OK) {
1696 if (!entry || !dir) { 1694 if (!entry || !dir) {
1697 error = GDATA_FILE_ERROR_NOT_FOUND; 1695 error = GDATA_FILE_ERROR_NOT_FOUND;
1698 } else { 1696 } else {
1699 if (!dir->AsGDataDirectory()) 1697 if (!dir->AsGDataDirectory())
1700 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; 1698 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY;
1701 } 1699 }
1702 } 1700 }
1703 1701
1704 // Returns if there is an error or |dir_path| is the root directory. 1702 // 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
2451 directory->AddEntry(entry.release()); 2449 directory->AddEntry(entry.release());
2452 } 2450 }
2453 2451
2454 // Note that there may be no change in the directory, but it's expensive to 2452 // 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 2453 // check if the new metadata matches the existing one, so we just always
2456 // notify that the directory is changed. 2454 // notify that the directory is changed.
2457 NotifyDirectoryChanged(directory_path); 2455 NotifyDirectoryChanged(directory_path);
2458 DVLOG(1) << "Directory refreshed: " << directory_path.value(); 2456 DVLOG(1) << "Directory refreshed: " << directory_path.value();
2459 } 2457 }
2460 2458
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( 2459 void GDataFileSystem::UpdateFileByResourceId(
2473 const std::string& resource_id, 2460 const std::string& resource_id,
2474 const FileOperationCallback& callback) { 2461 const FileOperationCallback& callback) {
2475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2476 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2463 BrowserThread::CurrentlyOn(BrowserThread::IO));
2477 RunTaskOnUIThread( 2464 RunTaskOnUIThread(
2478 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, 2465 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread,
2479 ui_weak_ptr_, 2466 ui_weak_ptr_,
2480 resource_id, 2467 resource_id,
2481 CreateRelayCallback(callback))); 2468 CreateRelayCallback(callback)));
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
3074 void GDataFileSystem::OnAddEntryToDirectoryCompleted( 3061 void GDataFileSystem::OnAddEntryToDirectoryCompleted(
3075 const FileOperationCallback& callback, 3062 const FileOperationCallback& callback,
3076 const FilePath& file_path, 3063 const FilePath& file_path,
3077 const FilePath& dir_path, 3064 const FilePath& dir_path,
3078 GDataErrorCode status, 3065 GDataErrorCode status,
3079 const GURL& document_url) { 3066 const GURL& document_url) {
3080 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3067 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3081 3068
3082 GDataFileError error = GDataToGDataFileError(status); 3069 GDataFileError error = GDataToGDataFileError(status);
3083 if (error == GDATA_FILE_OK) { 3070 if (error == GDATA_FILE_OK) {
3084 GDataEntry* entry = GetGDataEntryByPath(file_path); 3071 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
3085 if (entry) { 3072 if (entry) {
3086 DCHECK_EQ(directory_service_->root(), entry->parent()); 3073 DCHECK_EQ(directory_service_->root(), entry->parent());
3087 error = AddEntryToDirectoryOnFilesystem(entry, dir_path); 3074 error = AddEntryToDirectoryOnFilesystem(entry, dir_path);
3088 } else { 3075 } else {
3089 error = GDATA_FILE_ERROR_NOT_FOUND; 3076 error = GDATA_FILE_ERROR_NOT_FOUND;
3090 } 3077 }
3091 } 3078 }
3092 3079
3093 if (!callback.is_null()) 3080 if (!callback.is_null())
3094 callback.Run(error); 3081 callback.Run(error);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
3235 // Nothing much to do here for now. 3222 // Nothing much to do here for now.
3236 } 3223 }
3237 3224
3238 GDataFileError GDataFileSystem::RenameFileOnFilesystem( 3225 GDataFileError GDataFileSystem::RenameFileOnFilesystem(
3239 const FilePath& file_path, 3226 const FilePath& file_path,
3240 const FilePath::StringType& new_name, 3227 const FilePath::StringType& new_name,
3241 FilePath* updated_file_path) { 3228 FilePath* updated_file_path) {
3242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3243 DCHECK(updated_file_path); 3230 DCHECK(updated_file_path);
3244 3231
3245 GDataEntry* entry = GetGDataEntryByPath(file_path); 3232 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
3246 if (!entry) 3233 if (!entry)
3247 return GDATA_FILE_ERROR_NOT_FOUND; 3234 return GDATA_FILE_ERROR_NOT_FOUND;
3248 3235
3249 DCHECK(entry->parent()); 3236 DCHECK(entry->parent());
3250 entry->set_title(new_name); 3237 entry->set_title(new_name);
3251 // After changing the title of the entry, call TakeFile() to remove the 3238 // 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 3239 // entry from its parent directory and then add it back in order to go
3253 // through the file name de-duplication. 3240 // through the file name de-duplication.
3254 // TODO(achuith/satorux/zel): This code is fragile. The title has been 3241 // 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 3242 // 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 3243 // old file_name, and then re-adds the child by first assigning the new title
3257 // to file_name. http://crbug.com/30157 3244 // to file_name. http://crbug.com/30157
3258 if (!entry->parent()->TakeEntry(entry)) 3245 if (!entry->parent()->TakeEntry(entry))
3259 return GDATA_FILE_ERROR_FAILED; 3246 return GDATA_FILE_ERROR_FAILED;
3260 3247
3261 *updated_file_path = entry->GetFilePath(); 3248 *updated_file_path = entry->GetFilePath();
3262 3249
3263 NotifyDirectoryChanged(updated_file_path->DirName()); 3250 NotifyDirectoryChanged(updated_file_path->DirName());
3264 return GDATA_FILE_OK; 3251 return GDATA_FILE_OK;
3265 } 3252 }
3266 3253
3267 GDataFileError GDataFileSystem::AddEntryToDirectoryOnFilesystem( 3254 GDataFileError GDataFileSystem::AddEntryToDirectoryOnFilesystem(
3268 GDataEntry* entry, const FilePath& dir_path) { 3255 GDataEntry* entry, const FilePath& dir_path) {
3269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3270 DCHECK(entry); 3257 DCHECK(entry);
3271 3258
3272 GDataEntry* dir_entry = GetGDataEntryByPath(dir_path); 3259 GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(dir_path);
3273 if (!dir_entry) 3260 if (!dir_entry)
3274 return GDATA_FILE_ERROR_NOT_FOUND; 3261 return GDATA_FILE_ERROR_NOT_FOUND;
3275 3262
3276 GDataDirectory* dir = dir_entry->AsGDataDirectory(); 3263 GDataDirectory* dir = dir_entry->AsGDataDirectory();
3277 if (!dir) 3264 if (!dir)
3278 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; 3265 return GDATA_FILE_ERROR_NOT_A_DIRECTORY;
3279 3266
3280 if (!dir->TakeEntry(entry)) 3267 if (!dir->TakeEntry(entry))
3281 return GDATA_FILE_ERROR_FAILED; 3268 return GDATA_FILE_ERROR_FAILED;
3282 3269
3283 NotifyDirectoryChanged(dir_path); 3270 NotifyDirectoryChanged(dir_path);
3284 return GDATA_FILE_OK; 3271 return GDATA_FILE_OK;
3285 } 3272 }
3286 3273
3287 GDataFileError GDataFileSystem::RemoveEntryFromDirectoryOnFilesystem( 3274 GDataFileError GDataFileSystem::RemoveEntryFromDirectoryOnFilesystem(
3288 const FilePath& file_path, const FilePath& dir_path, 3275 const FilePath& file_path, const FilePath& dir_path,
3289 FilePath* updated_file_path) { 3276 FilePath* updated_file_path) {
3290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3291 DCHECK(updated_file_path); 3278 DCHECK(updated_file_path);
3292 3279
3293 GDataEntry* entry = GetGDataEntryByPath(file_path); 3280 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
3294 if (!entry) 3281 if (!entry)
3295 return GDATA_FILE_ERROR_NOT_FOUND; 3282 return GDATA_FILE_ERROR_NOT_FOUND;
3296 3283
3297 GDataEntry* dir = GetGDataEntryByPath(dir_path); 3284 GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path);
3298 if (!dir) 3285 if (!dir)
3299 return GDATA_FILE_ERROR_NOT_FOUND; 3286 return GDATA_FILE_ERROR_NOT_FOUND;
3300 3287
3301 if (!dir->AsGDataDirectory()) 3288 if (!dir->AsGDataDirectory())
3302 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; 3289 return GDATA_FILE_ERROR_NOT_A_DIRECTORY;
3303 3290
3304 DCHECK_EQ(dir->AsGDataDirectory(), entry->parent()); 3291 DCHECK_EQ(dir->AsGDataDirectory(), entry->parent());
3305 3292
3306 if (!directory_service_->root()->TakeEntry(entry)) 3293 if (!directory_service_->root()->TakeEntry(entry))
3307 return GDATA_FILE_ERROR_FAILED; 3294 return GDATA_FILE_ERROR_FAILED;
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
3636 3623
3637 if (!entry_value) 3624 if (!entry_value)
3638 return GDATA_FILE_ERROR_FAILED; 3625 return GDATA_FILE_ERROR_FAILED;
3639 3626
3640 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value)); 3627 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value));
3641 3628
3642 if (!doc_entry.get()) 3629 if (!doc_entry.get())
3643 return GDATA_FILE_ERROR_FAILED; 3630 return GDATA_FILE_ERROR_FAILED;
3644 3631
3645 // Find parent directory element within the cached file system snapshot. 3632 // Find parent directory element within the cached file system snapshot.
3646 GDataEntry* entry = GetGDataEntryByPath(directory_path); 3633 GDataEntry* entry = directory_service_->FindEntryByPathSync(directory_path);
3647 if (!entry) 3634 if (!entry)
3648 return GDATA_FILE_ERROR_FAILED; 3635 return GDATA_FILE_ERROR_FAILED;
3649 3636
3650 // Check if parent is a directory since in theory since this is a callback 3637 // 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 3638 // something could in the meantime have nuked the parent dir and created a
3652 // file with the exact same name. 3639 // file with the exact same name.
3653 GDataDirectory* parent_dir = entry->AsGDataDirectory(); 3640 GDataDirectory* parent_dir = entry->AsGDataDirectory();
3654 if (!parent_dir) 3641 if (!parent_dir)
3655 return GDATA_FILE_ERROR_FAILED; 3642 return GDATA_FILE_ERROR_FAILED;
3656 3643
(...skipping 18 matching lines...) Expand all
3675 // Let's find which how deep is the existing directory structure and 3662 // Let's find which how deep is the existing directory structure and
3676 // get the first element that's missing. 3663 // get the first element that's missing.
3677 std::vector<FilePath::StringType> path_parts; 3664 std::vector<FilePath::StringType> path_parts;
3678 directory_path.GetComponents(&path_parts); 3665 directory_path.GetComponents(&path_parts);
3679 FilePath current_path; 3666 FilePath current_path;
3680 3667
3681 for (std::vector<FilePath::StringType>::const_iterator iter = 3668 for (std::vector<FilePath::StringType>::const_iterator iter =
3682 path_parts.begin(); 3669 path_parts.begin();
3683 iter != path_parts.end(); ++iter) { 3670 iter != path_parts.end(); ++iter) {
3684 current_path = current_path.Append(*iter); 3671 current_path = current_path.Append(*iter);
3685 GDataEntry* entry = GetGDataEntryByPath(current_path); 3672 GDataEntry* entry = directory_service_->FindEntryByPathSync(current_path);
3686 if (entry) { 3673 if (entry) {
3687 if (entry->file_info().is_directory) { 3674 if (entry->file_info().is_directory) {
3688 *last_dir_content_url = entry->content_url(); 3675 *last_dir_content_url = entry->content_url();
3689 } else { 3676 } else {
3690 // Huh, the segment found is a file not a directory? 3677 // Huh, the segment found is a file not a directory?
3691 return FOUND_INVALID; 3678 return FOUND_INVALID;
3692 } 3679 }
3693 } else { 3680 } else {
3694 *first_missing_parent_path = current_path; 3681 *first_missing_parent_path = current_path;
3695 return FOUND_MISSING; 3682 return FOUND_MISSING;
3696 } 3683 }
3697 } 3684 }
3698 return DIRECTORY_ALREADY_PRESENT; 3685 return DIRECTORY_ALREADY_PRESENT;
3699 } 3686 }
3700 3687
3701 GDataFileError GDataFileSystem::RemoveEntryFromGData( 3688 GDataFileError GDataFileSystem::RemoveEntryFromGData(
3702 const FilePath& file_path, std::string* resource_id) { 3689 const FilePath& file_path, std::string* resource_id) {
3703 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3690 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3704 3691
3705 resource_id->clear(); 3692 resource_id->clear();
3706 3693
3707 // Find directory element within the cached file system snapshot. 3694 // Find directory element within the cached file system snapshot.
3708 GDataEntry* entry = GetGDataEntryByPath(file_path); 3695 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
3709 3696
3710 if (!entry) 3697 if (!entry)
3711 return GDATA_FILE_ERROR_NOT_FOUND; 3698 return GDATA_FILE_ERROR_NOT_FOUND;
3712 3699
3713 // You can't remove root element. 3700 // You can't remove root element.
3714 if (!entry->parent()) 3701 if (!entry->parent())
3715 return GDATA_FILE_ERROR_ACCESS_DENIED; 3702 return GDATA_FILE_ERROR_ACCESS_DENIED;
3716 3703
3717 // If it's a file (only files have resource id), get its resource id so that 3704 // 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. 3705 // we can remove it after releasing the auto lock.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3759 const base::Closure& callback) { 3746 const base::Closure& callback) {
3760 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3747 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3761 DCHECK(!callback.is_null()); 3748 DCHECK(!callback.is_null());
3762 3749
3763 if (!entry.get()) { 3750 if (!entry.get()) {
3764 NOTREACHED(); 3751 NOTREACHED();
3765 callback.Run(); 3752 callback.Run();
3766 return; 3753 return;
3767 } 3754 }
3768 3755
3769 GDataEntry* dir_entry = GetGDataEntryByPath(virtual_dir_path); 3756 GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(
3757 virtual_dir_path);
3770 if (!dir_entry) { 3758 if (!dir_entry) {
3771 callback.Run(); 3759 callback.Run();
3772 return; 3760 return;
3773 } 3761 }
3774 3762
3775 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); 3763 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory();
3776 if (!parent_dir) { 3764 if (!parent_dir) {
3777 callback.Run(); 3765 callback.Run();
3778 return; 3766 return;
3779 } 3767 }
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
4279 } 4267 }
4280 4268
4281 PlatformFileInfoProto entry_file_info; 4269 PlatformFileInfoProto entry_file_info;
4282 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 4270 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
4283 *entry_proto->mutable_file_info() = entry_file_info; 4271 *entry_proto->mutable_file_info() = entry_file_info;
4284 if (!callback.is_null()) 4272 if (!callback.is_null())
4285 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 4273 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
4286 } 4274 }
4287 4275
4288 } // namespace gdata 4276 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_files.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698