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

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

Issue 10832233: gdata: Fix bad function names in GDataFileSystem (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 FilePath new_file(file_name); 1122 FilePath new_file(file_name);
1123 if (new_file.Extension() == 1123 if (new_file.Extension() ==
1124 entry_proto->file_specific_info().document_extension()) { 1124 entry_proto->file_specific_info().document_extension()) {
1125 file_name = new_file.RemoveExtension().value(); 1125 file_name = new_file.RemoveExtension().value();
1126 } 1126 }
1127 } 1127 }
1128 1128
1129 documents_service_->RenameResource( 1129 documents_service_->RenameResource(
1130 GURL(entry_proto->edit_url()), 1130 GURL(entry_proto->edit_url()),
1131 file_name, 1131 file_name,
1132 base::Bind(&GDataFileSystem::RenameFileOnFileSystem, 1132 base::Bind(&GDataFileSystem::RenameFileOnClientSide,
1133 ui_weak_ptr_, 1133 ui_weak_ptr_,
1134 file_path, 1134 file_path,
1135 file_name, 1135 file_name,
1136 callback)); 1136 callback));
1137 } 1137 }
1138 1138
1139 void GDataFileSystem::Move(const FilePath& src_file_path, 1139 void GDataFileSystem::Move(const FilePath& src_file_path,
1140 const FilePath& dest_file_path, 1140 const FilePath& dest_file_path,
1141 const FileOperationCallback& callback) { 1141 const FileOperationCallback& callback) {
1142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 // 3. Adds the file to the parent directory of |dest_file_path|, which 1210 // 3. Adds the file to the parent directory of |dest_file_path|, which
1211 // effectively moves the file from the root directory to the parent 1211 // effectively moves the file from the root directory to the parent
1212 // directory of |dest_file_path|. 1212 // directory of |dest_file_path|.
1213 FileMoveCallback add_file_to_directory_callback = 1213 FileMoveCallback add_file_to_directory_callback =
1214 base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory, 1214 base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory,
1215 ui_weak_ptr_, 1215 ui_weak_ptr_,
1216 dest_file_path.DirName(), 1216 dest_file_path.DirName(),
1217 callback); 1217 callback);
1218 1218
1219 FileMoveCallback remove_file_from_directory_callback = 1219 FileMoveCallback remove_file_from_directory_callback =
1220 base::Bind(&GDataFileSystem::RemoveEntryFromDirectory, 1220 base::Bind(&GDataFileSystem::RemoveEntryFromNonRootDirectory,
1221 ui_weak_ptr_, 1221 ui_weak_ptr_,
1222 src_file_path.DirName(),
1223 add_file_to_directory_callback); 1222 add_file_to_directory_callback);
1224 1223
1225 Rename(src_file_path, dest_file_path.BaseName().value(), 1224 Rename(src_file_path, dest_file_path.BaseName().value(),
1226 remove_file_from_directory_callback); 1225 remove_file_from_directory_callback);
1227 } 1226 }
1228 1227
1229 void GDataFileSystem::MoveEntryFromRootDirectory( 1228 void GDataFileSystem::MoveEntryFromRootDirectory(
1230 const FilePath& dir_path, 1229 const FilePath& dir_path,
1231 const FileOperationCallback& callback, 1230 const FileOperationCallback& callback,
1232 GDataFileError error, 1231 GDataFileError error,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 documents_service_->AddResourceToDirectory( 1277 documents_service_->AddResourceToDirectory(
1279 GURL(dir_proto->content_url()), 1278 GURL(dir_proto->content_url()),
1280 GURL(src_proto->edit_url()), 1279 GURL(src_proto->edit_url()),
1281 base::Bind(&GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted, 1280 base::Bind(&GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted,
1282 ui_weak_ptr_, 1281 ui_weak_ptr_,
1283 callback, 1282 callback,
1284 file_path, 1283 file_path,
1285 dir_path)); 1284 dir_path));
1286 } 1285 }
1287 1286
1288 void GDataFileSystem::RemoveEntryFromDirectory( 1287 void GDataFileSystem::RemoveEntryFromNonRootDirectory(
1289 const FilePath& dir_path,
1290 const FileMoveCallback& callback, 1288 const FileMoveCallback& callback,
1291 GDataFileError error, 1289 GDataFileError error,
1292 const FilePath& file_path) { 1290 const FilePath& file_path) {
1293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1292 DCHECK(!callback.is_null());
1294 1293
1294 const FilePath& dir_path = file_path.DirName();
achuithb 2012/08/10 08:59:13 Can't use a const reference to a temporary.
satorux1 2012/08/10 15:56:03 Good catch! Done.
1295 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); 1295 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
1296 GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path); 1296 GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path);
1297 if (error == GDATA_FILE_OK) { 1297 if (error == GDATA_FILE_OK) {
1298 if (!entry || !dir) { 1298 if (!entry || !dir) {
1299 error = GDATA_FILE_ERROR_NOT_FOUND; 1299 error = GDATA_FILE_ERROR_NOT_FOUND;
1300 } else { 1300 } else {
1301 if (!dir->AsGDataDirectory()) 1301 if (!dir->AsGDataDirectory())
1302 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; 1302 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY;
1303 } 1303 }
1304 } 1304 }
1305 1305
1306 // Returns if there is an error or |dir_path| is the root directory. 1306 // Returns if there is an error or |dir_path| is the root directory.
1307 if (error != GDATA_FILE_OK || 1307 if (error != GDATA_FILE_OK ||
1308 dir->resource_id() == kGDataRootDirectoryResourceId) { 1308 dir->resource_id() == kGDataRootDirectoryResourceId) {
1309 if (!callback.is_null()) { 1309 callback.Run(error, file_path);
1310 MessageLoop::current()->PostTask(FROM_HERE,
1311 base::Bind(callback, error, file_path));
1312 }
1313 return; 1310 return;
1314 } 1311 }
1315 1312
1316 documents_service_->RemoveResourceFromDirectory( 1313 documents_service_->RemoveResourceFromDirectory(
1317 dir->content_url(), 1314 dir->content_url(),
1318 entry->edit_url(), 1315 entry->edit_url(),
1319 entry->resource_id(), 1316 entry->resource_id(),
1320 base::Bind(&GDataFileSystem::RemoveEntryFromDirectoryOnFileSystem, 1317 base::Bind(&GDataFileSystem::MoveEntryToRootDirectoryOnClientSide,
1321 ui_weak_ptr_, 1318 ui_weak_ptr_,
1322 callback, 1319 callback,
1323 file_path, 1320 file_path,
1324 dir_path)); 1321 dir_path));
1325 } 1322 }
1326 1323
1327 void GDataFileSystem::Remove(const FilePath& file_path, 1324 void GDataFileSystem::Remove(const FilePath& file_path,
1328 bool is_recursive, 1325 bool is_recursive,
1329 const FileOperationCallback& callback) { 1326 const FileOperationCallback& callback) {
1330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after
2528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2529 DCHECK(!callback.is_null()); 2526 DCHECK(!callback.is_null());
2530 2527
2531 GDataFileError error = util::GDataToGDataFileError(status); 2528 GDataFileError error = util::GDataToGDataFileError(status);
2532 if (error == GDATA_FILE_OK) { 2529 if (error == GDATA_FILE_OK) {
2533 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); 2530 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
2534 if (entry) { 2531 if (entry) {
2535 DCHECK_EQ(directory_service_->root(), entry->parent()); 2532 DCHECK_EQ(directory_service_->root(), entry->parent());
2536 directory_service_->MoveEntryToDirectory(dir_path, entry, 2533 directory_service_->MoveEntryToDirectory(dir_path, entry,
2537 base::Bind( 2534 base::Bind(
2538 &GDataFileSystem::OnMoveEntryToDirectoryWithFileOperationCallback, 2535 &GDataFileSystem::NotifyAndRunFileOperationCallback,
2539 ui_weak_ptr_, 2536 ui_weak_ptr_,
2540 callback)); 2537 callback));
2541 return; 2538 return;
2542 } else { 2539 } else {
2543 error = GDATA_FILE_ERROR_NOT_FOUND; 2540 error = GDATA_FILE_ERROR_NOT_FOUND;
2544 } 2541 }
2545 } 2542 }
2546 2543
2547 callback.Run(error); 2544 callback.Run(error);
2548 } 2545 }
2549 2546
2550 void GDataFileSystem::OnRemovedDocument( 2547 void GDataFileSystem::OnRemovedDocument(
2551 const FileOperationCallback& callback, 2548 const FileOperationCallback& callback,
2552 const FilePath& file_path, 2549 const FilePath& file_path,
2553 GDataErrorCode status, 2550 GDataErrorCode status,
2554 const GURL& document_url) { 2551 const GURL& document_url) {
2555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2556 2553
2557 GDataFileError error = util::GDataToGDataFileError(status); 2554 GDataFileError error = util::GDataToGDataFileError(status);
2558 2555
2559 if (error == GDATA_FILE_OK) 2556 if (error == GDATA_FILE_OK)
2560 error = RemoveEntryFromFileSystem(file_path); 2557 error = RemoveEntryOnClientSide(file_path);
2561 2558
2562 if (!callback.is_null()) { 2559 if (!callback.is_null()) {
2563 callback.Run(error); 2560 callback.Run(error);
2564 } 2561 }
2565 } 2562 }
2566 2563
2567 void GDataFileSystem::OnFileDownloaded( 2564 void GDataFileSystem::OnFileDownloaded(
2568 const GetFileFromCacheParams& params, 2565 const GetFileFromCacheParams& params,
2569 GDataErrorCode status, 2566 GDataErrorCode status,
2570 const GURL& content_url, 2567 const GURL& content_url,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2663 } 2660 }
2664 } 2661 }
2665 2662
2666 void GDataFileSystem::OnDownloadStoredToCache(GDataFileError error, 2663 void GDataFileSystem::OnDownloadStoredToCache(GDataFileError error,
2667 const std::string& resource_id, 2664 const std::string& resource_id,
2668 const std::string& md5) { 2665 const std::string& md5) {
2669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2666 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2670 // Nothing much to do here for now. 2667 // Nothing much to do here for now.
2671 } 2668 }
2672 2669
2673 void GDataFileSystem::RenameFileOnFileSystem( 2670 void GDataFileSystem::RenameFileOnClientSide(
2674 const FilePath& file_path, 2671 const FilePath& file_path,
2675 const FilePath::StringType& new_name, 2672 const FilePath::StringType& new_name,
2676 const FileMoveCallback& callback, 2673 const FileMoveCallback& callback,
2677 GDataErrorCode status, 2674 GDataErrorCode status,
2678 const GURL& document_url) { 2675 const GURL& document_url) {
2679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2676 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2680 2677
2681 const GDataFileError error = util::GDataToGDataFileError(status); 2678 const GDataFileError error = util::GDataToGDataFileError(status);
2682 if (error != GDATA_FILE_OK) { 2679 if (error != GDATA_FILE_OK) {
2683 if (!callback.is_null()) 2680 if (!callback.is_null())
(...skipping 13 matching lines...) Expand all
2697 // After changing the title of the entry, call MoveEntryToDirectory() to 2694 // After changing the title of the entry, call MoveEntryToDirectory() to
2698 // remove the entry from its parent directory and then add it back in order to 2695 // remove the entry from its parent directory and then add it back in order to
2699 // go through the file name de-duplication. 2696 // go through the file name de-duplication.
2700 // TODO(achuith/satorux/zel): This code is fragile. The title has been 2697 // TODO(achuith/satorux/zel): This code is fragile. The title has been
2701 // changed, but not the file_name. MoveEntryToDirectory calls RemoveChild to 2698 // changed, but not the file_name. MoveEntryToDirectory calls RemoveChild to
2702 // remove the child based on the old file_name, and then re-adds the child by 2699 // remove the child based on the old file_name, and then re-adds the child by
2703 // first assigning the new title to file_name. http://crbug.com/30157 2700 // first assigning the new title to file_name. http://crbug.com/30157
2704 directory_service_->MoveEntryToDirectory( 2701 directory_service_->MoveEntryToDirectory(
2705 entry->parent()->GetFilePath(), 2702 entry->parent()->GetFilePath(),
2706 entry, 2703 entry,
2707 base::Bind(&GDataFileSystem::OnMoveEntryToDirectoryWithFileMoveCallback, 2704 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback,
2708 ui_weak_ptr_, 2705 ui_weak_ptr_,
2709 callback)); 2706 callback));
2710 } 2707 }
2711 2708
2712 void GDataFileSystem::RemoveEntryFromDirectoryOnFileSystem( 2709 void GDataFileSystem::MoveEntryToRootDirectoryOnClientSide(
2713 const FileMoveCallback& callback, 2710 const FileMoveCallback& callback,
2714 const FilePath& file_path, 2711 const FilePath& file_path,
2715 const FilePath& dir_path, 2712 const FilePath& dir_path,
2716 GDataErrorCode status, 2713 GDataErrorCode status,
2717 const GURL& document_url) { 2714 const GURL& document_url) {
2718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2715 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2716 DCHECK(!callback.is_null());
2719 2717
2720 const GDataFileError error = util::GDataToGDataFileError(status); 2718 const GDataFileError error = util::GDataToGDataFileError(status);
2721 if (error != GDATA_FILE_OK) { 2719 if (error != GDATA_FILE_OK) {
2722 if (!callback.is_null()) 2720 callback.Run(error, FilePath());
2723 callback.Run(error, FilePath());
2724 return; 2721 return;
2725 } 2722 }
2726 2723
2727 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); 2724 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
2728 if (!entry) { 2725 if (!entry) {
2729 if (!callback.is_null()) 2726 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath());
2730 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath());
2731 return; 2727 return;
2732 } 2728 }
2733 2729
2734 directory_service_->MoveEntryToDirectory( 2730 directory_service_->MoveEntryToDirectory(
2735 directory_service_->root()->GetFilePath(), 2731 directory_service_->root()->GetFilePath(),
2736 entry, 2732 entry,
2737 base::Bind(&GDataFileSystem::OnMoveEntryToDirectoryWithFileMoveCallback, 2733 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback,
2738 ui_weak_ptr_, 2734 ui_weak_ptr_,
2739 callback)); 2735 callback));
2740 } 2736 }
2741 2737
2742 void GDataFileSystem::OnMoveEntryToDirectoryWithFileMoveCallback( 2738 void GDataFileSystem::NotifyAndRunFileMoveCallback(
2743 const FileMoveCallback& callback, 2739 const FileMoveCallback& callback,
2744 GDataFileError error, 2740 GDataFileError error,
2745 const FilePath& moved_file_path) { 2741 const FilePath& moved_file_path) {
2742 DCHECK(!callback.is_null());
achuithb 2012/08/10 08:59:13 I believe this happens on the UI thread? Can we ad
satorux1 2012/08/10 15:56:03 Done.
2743
2746 if (error == GDATA_FILE_OK) 2744 if (error == GDATA_FILE_OK)
2747 OnDirectoryChanged(moved_file_path.DirName()); 2745 OnDirectoryChanged(moved_file_path.DirName());
2748 2746
2749 if (!callback.is_null()) 2747 callback.Run(error, moved_file_path);
2750 callback.Run(error, moved_file_path);
2751 } 2748 }
2752 2749
2753 void GDataFileSystem::OnMoveEntryToDirectoryWithFileOperationCallback( 2750 void GDataFileSystem::NotifyAndRunFileOperationCallback(
2754 const FileOperationCallback& callback, 2751 const FileOperationCallback& callback,
2755 GDataFileError error, 2752 GDataFileError error,
2756 const FilePath& moved_file_path) { 2753 const FilePath& moved_file_path) {
2757 DCHECK(!callback.is_null()); 2754 DCHECK(!callback.is_null());
achuithb 2012/08/10 08:59:13 Can we add a UI thread DCHECK here?
satorux1 2012/08/10 15:56:03 Done.
2758 2755
2759 if (error == GDATA_FILE_OK) 2756 if (error == GDATA_FILE_OK)
2760 OnDirectoryChanged(moved_file_path.DirName()); 2757 OnDirectoryChanged(moved_file_path.DirName());
2761 2758
2762 callback.Run(error); 2759 callback.Run(error);
2763 } 2760 }
2764 2761
2765 GDataFileError GDataFileSystem::RemoveEntryFromFileSystem( 2762 GDataFileError GDataFileSystem::RemoveEntryOnClientSide(
2766 const FilePath& file_path) { 2763 const FilePath& file_path) {
2767 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2764 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2768 2765
2769 std::string resource_id; 2766 std::string resource_id;
2770 GDataFileError error = RemoveEntryFromGData(file_path, &resource_id); 2767 GDataFileError error = RemoveEntryOnClientSide(file_path, &resource_id);
2771 if (error != GDATA_FILE_OK) 2768 if (error != GDATA_FILE_OK)
2772 return error; 2769 return error;
2773 2770
2774 // If resource_id is not empty, remove its corresponding file from cache. 2771 // If resource_id is not empty, remove its corresponding file from cache.
2775 if (!resource_id.empty()) 2772 if (!resource_id.empty())
2776 cache_->RemoveOnUIThread(resource_id, CacheOperationCallback()); 2773 cache_->RemoveOnUIThread(resource_id, CacheOperationCallback());
2777 2774
2778 return GDATA_FILE_OK; 2775 return GDATA_FILE_OK;
2779 } 2776 }
2780 2777
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
2886 return FOUND_INVALID; 2883 return FOUND_INVALID;
2887 } 2884 }
2888 } else { 2885 } else {
2889 *first_missing_parent_path = current_path; 2886 *first_missing_parent_path = current_path;
2890 return FOUND_MISSING; 2887 return FOUND_MISSING;
2891 } 2888 }
2892 } 2889 }
2893 return DIRECTORY_ALREADY_PRESENT; 2890 return DIRECTORY_ALREADY_PRESENT;
2894 } 2891 }
2895 2892
2896 GDataFileError GDataFileSystem::RemoveEntryFromGData( 2893 GDataFileError GDataFileSystem::RemoveEntryOnClientSide(
2897 const FilePath& file_path, std::string* resource_id) { 2894 const FilePath& file_path, std::string* resource_id) {
2898 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2895 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2899 2896
2900 resource_id->clear(); 2897 resource_id->clear();
2901 2898
2902 // Find directory element within the cached file system snapshot. 2899 // Find directory element within the cached file system snapshot.
2903 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); 2900 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
2904 2901
2905 if (!entry) 2902 if (!entry)
2906 return GDATA_FILE_ERROR_NOT_FOUND; 2903 return GDATA_FILE_ERROR_NOT_FOUND;
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
3471 } 3468 }
3472 3469
3473 PlatformFileInfoProto entry_file_info; 3470 PlatformFileInfoProto entry_file_info;
3474 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 3471 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
3475 *entry_proto->mutable_file_info() = entry_file_info; 3472 *entry_proto->mutable_file_info() = entry_file_info;
3476 if (!callback.is_null()) 3473 if (!callback.is_null())
3477 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 3474 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3478 } 3475 }
3479 3476
3480 } // namespace gdata 3477 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698