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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 const FileOperationCallback& in_callback) | 495 const FileOperationCallback& in_callback) |
496 : local_file_path(in_local_file_path), | 496 : local_file_path(in_local_file_path), |
497 remote_file_path(in_remote_file_path), | 497 remote_file_path(in_remote_file_path), |
498 callback(in_callback) {} | 498 callback(in_callback) {} |
499 | 499 |
500 const FilePath local_file_path; | 500 const FilePath local_file_path; |
501 const FilePath remote_file_path; | 501 const FilePath remote_file_path; |
502 const FileOperationCallback callback; | 502 const FileOperationCallback callback; |
503 }; | 503 }; |
504 | 504 |
| 505 // GDataFileSystem::AddUploadedFileParams implementation. |
| 506 struct GDataFileSystem::AddUploadedFileParams { |
| 507 AddUploadedFileParams(UploadMode upload_mode, |
| 508 GDataDirectory* parent_dir, |
| 509 scoped_ptr<GDataEntry> new_entry, |
| 510 const FilePath& file_content_path, |
| 511 GDataCache::FileOperationType cache_operation, |
| 512 const base::Closure& callback) |
| 513 : upload_mode(upload_mode), |
| 514 parent_dir(parent_dir), |
| 515 new_entry(new_entry.Pass()), |
| 516 file_content_path(file_content_path), |
| 517 cache_operation(cache_operation), |
| 518 callback(callback) { |
| 519 } |
| 520 |
| 521 UploadMode upload_mode; |
| 522 GDataDirectory* parent_dir; |
| 523 scoped_ptr<GDataEntry> new_entry; |
| 524 FilePath file_content_path; |
| 525 GDataCache::FileOperationType cache_operation; |
| 526 base::Closure callback; |
| 527 std::string resource_id; |
| 528 std::string md5; |
| 529 }; |
| 530 |
| 531 |
505 // GDataFileSystem class implementation. | 532 // GDataFileSystem class implementation. |
506 | 533 |
507 GDataFileSystem::GDataFileSystem( | 534 GDataFileSystem::GDataFileSystem( |
508 Profile* profile, | 535 Profile* profile, |
509 GDataCache* cache, | 536 GDataCache* cache, |
510 DocumentsServiceInterface* documents_service, | 537 DocumentsServiceInterface* documents_service, |
511 GDataUploaderInterface* uploader, | 538 GDataUploaderInterface* uploader, |
512 DriveWebAppsRegistryInterface* webapps_registry, | 539 DriveWebAppsRegistryInterface* webapps_registry, |
513 base::SequencedTaskRunner* blocking_task_runner) | 540 base::SequencedTaskRunner* blocking_task_runner) |
514 : profile_(profile), | 541 : profile_(profile), |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 | 1237 |
1211 // Otherwise, the move operation involves three steps: | 1238 // Otherwise, the move operation involves three steps: |
1212 // 1. Renames the file at |src_file_path| to basename(|dest_file_path|) | 1239 // 1. Renames the file at |src_file_path| to basename(|dest_file_path|) |
1213 // within the same directory. The rename operation is a no-op if | 1240 // within the same directory. The rename operation is a no-op if |
1214 // basename(|src_file_path|) equals to basename(|dest_file_path|). | 1241 // basename(|src_file_path|) equals to basename(|dest_file_path|). |
1215 // 2. Removes the file from its parent directory (the file is not deleted), | 1242 // 2. Removes the file from its parent directory (the file is not deleted), |
1216 // which effectively moves the file to the root directory. | 1243 // which effectively moves the file to the root directory. |
1217 // 3. Adds the file to the parent directory of |dest_file_path|, which | 1244 // 3. Adds the file to the parent directory of |dest_file_path|, which |
1218 // effectively moves the file from the root directory to the parent | 1245 // effectively moves the file from the root directory to the parent |
1219 // directory of |dest_file_path|. | 1246 // directory of |dest_file_path|. |
1220 FileMoveCallback add_file_to_directory_callback = | 1247 const FileMoveCallback add_file_to_directory_callback = |
1221 base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory, | 1248 base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory, |
1222 ui_weak_ptr_, | 1249 ui_weak_ptr_, |
1223 dest_file_path.DirName(), | 1250 dest_file_path.DirName(), |
1224 callback); | 1251 callback); |
1225 | 1252 |
1226 FileMoveCallback remove_file_from_directory_callback = | 1253 const FileMoveCallback remove_file_from_directory_callback = |
1227 base::Bind(&GDataFileSystem::RemoveEntryFromNonRootDirectory, | 1254 base::Bind(&GDataFileSystem::RemoveEntryFromNonRootDirectory, |
1228 ui_weak_ptr_, | 1255 ui_weak_ptr_, |
1229 add_file_to_directory_callback); | 1256 add_file_to_directory_callback); |
1230 | 1257 |
1231 Rename(src_file_path, dest_file_path.BaseName().value(), | 1258 Rename(src_file_path, dest_file_path.BaseName().value(), |
1232 remove_file_from_directory_callback); | 1259 remove_file_from_directory_callback); |
1233 } | 1260 } |
1234 | 1261 |
1235 void GDataFileSystem::MoveEntryFromRootDirectory( | 1262 void GDataFileSystem::MoveEntryFromRootDirectory( |
1236 const FilePath& dir_path, | 1263 const FilePath& dir_path, |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2036 *params->feed_list, | 2063 *params->feed_list, |
2037 &file_map, | 2064 &file_map, |
2038 &unused_delta_feed_changestamp, | 2065 &unused_delta_feed_changestamp, |
2039 &unused_uma_stats); | 2066 &unused_uma_stats); |
2040 if (error != GDATA_FILE_OK) { | 2067 if (error != GDATA_FILE_OK) { |
2041 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() | 2068 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() |
2042 << ": " << error; | 2069 << ": " << error; |
2043 return; | 2070 return; |
2044 } | 2071 } |
2045 | 2072 |
2046 directory_service_->GetEntryByResourceIdAsync(params->directory_resource_id, | 2073 directory_service_->RefreshDirectory( |
2047 base::Bind(&GDataFileSystem::RequestDirectoryRefreshByEntry, | 2074 params->directory_resource_id, |
2048 ui_weak_ptr_, | 2075 file_map, |
2049 directory_path, | 2076 base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback, |
2050 params->directory_resource_id, | 2077 ui_weak_ptr_)); |
2051 file_map)); | |
2052 } | |
2053 | |
2054 void GDataFileSystem::RequestDirectoryRefreshByEntry( | |
2055 const FilePath& directory_path, | |
2056 const std::string& directory_resource_id, | |
2057 const FileResourceIdMap& file_map, | |
2058 GDataEntry* directory_entry) { | |
2059 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
2060 | |
2061 if (!directory_entry || !directory_entry->AsGDataDirectory()) { | |
2062 LOG(ERROR) << "Directory entry is gone: " << directory_path.value() | |
2063 << ": " << directory_resource_id; | |
2064 return; | |
2065 } | |
2066 GDataDirectory* directory = directory_entry->AsGDataDirectory(); | |
2067 | |
2068 // Remove the existing files. | |
2069 directory->RemoveChildFiles(); | |
2070 // Go through all entries generated by the feed and add files. | |
2071 for (FileResourceIdMap::const_iterator it = file_map.begin(); | |
2072 it != file_map.end(); ++it) { | |
2073 scoped_ptr<GDataEntry> entry(it->second); | |
2074 // Skip if it's not a file (i.e. directory). | |
2075 if (!entry->AsGDataFile()) | |
2076 continue; | |
2077 directory->AddEntry(entry.release()); | |
2078 } | |
2079 | |
2080 // Note that there may be no change in the directory, but it's expensive to | |
2081 // check if the new metadata matches the existing one, so we just always | |
2082 // notify that the directory is changed. | |
2083 OnDirectoryChanged(directory_path); | |
2084 DVLOG(1) << "Directory refreshed: " << directory_path.value(); | |
2085 } | 2078 } |
2086 | 2079 |
2087 void GDataFileSystem::UpdateFileByResourceId( | 2080 void GDataFileSystem::UpdateFileByResourceId( |
2088 const std::string& resource_id, | 2081 const std::string& resource_id, |
2089 const FileOperationCallback& callback) { | 2082 const FileOperationCallback& callback) { |
2090 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2083 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
2091 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2084 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2092 RunTaskOnUIThread( | 2085 RunTaskOnUIThread( |
2093 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, | 2086 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, |
2094 ui_weak_ptr_, | 2087 ui_weak_ptr_, |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2535 | 2528 |
2536 GDataEntry* entry = directory_service_->FromDocumentEntry(doc_entry.get()); | 2529 GDataEntry* entry = directory_service_->FromDocumentEntry(doc_entry.get()); |
2537 if (!entry) { | 2530 if (!entry) { |
2538 callback.Run(GDATA_FILE_ERROR_FAILED); | 2531 callback.Run(GDATA_FILE_ERROR_FAILED); |
2539 return; | 2532 return; |
2540 } | 2533 } |
2541 | 2534 |
2542 // |entry| was added in the root directory on the server, so we should | 2535 // |entry| was added in the root directory on the server, so we should |
2543 // first add it to |root_| to mirror the state and then move it to the | 2536 // first add it to |root_| to mirror the state and then move it to the |
2544 // destination directory by MoveEntryFromRootDirectory(). | 2537 // destination directory by MoveEntryFromRootDirectory(). |
2545 directory_service_->root()->AddEntry(entry); | 2538 directory_service_->AddEntryToDirectory( |
2546 MoveEntryFromRootDirectory(dir_path, | 2539 directory_service_->root(), |
2547 callback, | 2540 entry, |
2548 GDATA_FILE_OK, | 2541 base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory, |
2549 entry->GetFilePath()); | 2542 ui_weak_ptr_, |
| 2543 dir_path, |
| 2544 callback)); |
2550 } | 2545 } |
2551 | 2546 |
2552 void GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted( | 2547 void GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted( |
2553 const FileOperationCallback& callback, | 2548 const FileOperationCallback& callback, |
2554 const FilePath& file_path, | 2549 const FilePath& file_path, |
2555 const FilePath& dir_path, | 2550 const FilePath& dir_path, |
2556 GDataErrorCode status, | 2551 GDataErrorCode status, |
2557 const GURL& document_url) { | 2552 const GURL& document_url) { |
2558 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2553 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2559 DCHECK(!callback.is_null()); | 2554 DCHECK(!callback.is_null()); |
2560 | 2555 |
2561 GDataFileError error = util::GDataToGDataFileError(status); | 2556 GDataFileError error = util::GDataToGDataFileError(status); |
2562 if (error == GDATA_FILE_OK) { | 2557 if (error == GDATA_FILE_OK) { |
2563 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); | 2558 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
2564 if (entry) { | 2559 if (entry) { |
2565 DCHECK_EQ(directory_service_->root(), entry->parent()); | 2560 DCHECK_EQ(directory_service_->root(), entry->parent()); |
2566 directory_service_->MoveEntryToDirectory(dir_path, entry, | 2561 directory_service_->MoveEntryToDirectory( |
| 2562 dir_path, |
| 2563 entry, |
2567 base::Bind( | 2564 base::Bind( |
2568 &GDataFileSystem::NotifyAndRunFileOperationCallback, | 2565 &GDataFileSystem::NotifyAndRunFileOperationCallback, |
2569 ui_weak_ptr_, | 2566 ui_weak_ptr_, |
2570 callback)); | 2567 callback)); |
2571 return; | 2568 return; |
2572 } else { | 2569 } else { |
2573 error = GDATA_FILE_ERROR_NOT_FOUND; | 2570 error = GDATA_FILE_ERROR_NOT_FOUND; |
2574 } | 2571 } |
2575 } | 2572 } |
2576 | 2573 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2766 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, | 2763 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, |
2767 ui_weak_ptr_, | 2764 ui_weak_ptr_, |
2768 callback)); | 2765 callback)); |
2769 } | 2766 } |
2770 | 2767 |
2771 void GDataFileSystem::NotifyAndRunFileMoveCallback( | 2768 void GDataFileSystem::NotifyAndRunFileMoveCallback( |
2772 const FileMoveCallback& callback, | 2769 const FileMoveCallback& callback, |
2773 GDataFileError error, | 2770 GDataFileError error, |
2774 const FilePath& moved_file_path) { | 2771 const FilePath& moved_file_path) { |
2775 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2772 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2776 DCHECK(!callback.is_null()); | |
2777 | 2773 |
2778 if (error == GDATA_FILE_OK) | 2774 if (error == GDATA_FILE_OK) |
2779 OnDirectoryChanged(moved_file_path.DirName()); | 2775 OnDirectoryChanged(moved_file_path.DirName()); |
2780 | 2776 |
| 2777 if (!callback.is_null()) |
2781 callback.Run(error, moved_file_path); | 2778 callback.Run(error, moved_file_path); |
2782 } | 2779 } |
2783 | 2780 |
2784 void GDataFileSystem::NotifyAndRunFileOperationCallback( | 2781 void GDataFileSystem::NotifyAndRunFileOperationCallback( |
2785 const FileOperationCallback& callback, | 2782 const FileOperationCallback& callback, |
2786 GDataFileError error, | 2783 GDataFileError error, |
2787 const FilePath& moved_file_path) { | 2784 const FilePath& moved_file_path) { |
2788 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2785 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2789 DCHECK(!callback.is_null()); | 2786 DCHECK(!callback.is_null()); |
2790 | 2787 |
2791 if (error == GDATA_FILE_OK) | 2788 if (error == GDATA_FILE_OK) |
2792 OnDirectoryChanged(moved_file_path.DirName()); | 2789 OnDirectoryChanged(moved_file_path.DirName()); |
2793 | 2790 |
2794 callback.Run(error); | 2791 callback.Run(error); |
2795 } | 2792 } |
2796 | 2793 |
| 2794 void GDataFileSystem::OnDirectoryChangeFileMoveCallback( |
| 2795 GDataFileError error, |
| 2796 const FilePath& directory_path) { |
| 2797 if (error == GDATA_FILE_OK) |
| 2798 OnDirectoryChanged(directory_path); |
| 2799 } |
| 2800 |
2797 GDataFileError GDataFileSystem::RemoveEntryAndCacheLocally( | 2801 GDataFileError GDataFileSystem::RemoveEntryAndCacheLocally( |
2798 const FilePath& file_path) { | 2802 const FilePath& file_path) { |
2799 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2803 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2800 | 2804 |
2801 std::string resource_id; | 2805 std::string resource_id; |
2802 GDataFileError error = RemoveEntryLocally(file_path, &resource_id); | 2806 GDataFileError error = RemoveEntryLocally(file_path, &resource_id); |
2803 if (error != GDATA_FILE_OK) | 2807 if (error != GDATA_FILE_OK) |
2804 return error; | 2808 return error; |
2805 | 2809 |
2806 // If resource_id is not empty, remove its corresponding file from cache. | 2810 // If resource_id is not empty, remove its corresponding file from cache. |
2807 if (!resource_id.empty()) | 2811 if (!resource_id.empty()) |
2808 cache_->RemoveOnUIThread(resource_id, CacheOperationCallback()); | 2812 cache_->RemoveOnUIThread(resource_id, CacheOperationCallback()); |
2809 | 2813 |
2810 return GDATA_FILE_OK; | 2814 return GDATA_FILE_OK; |
2811 } | 2815 } |
2812 | 2816 |
2813 // static | 2817 void GDataFileSystem::RemoveStaleEntryOnUpload( |
2814 void GDataFileSystem::RemoveStaleEntryOnUpload(const std::string& resource_id, | 2818 const std::string& resource_id, |
2815 GDataDirectory* parent_dir, | 2819 GDataDirectory* parent_dir, |
2816 GDataEntry* existing_entry) { | 2820 const FileMoveCallback& callback, |
| 2821 GDataEntry* existing_entry) { |
2817 if (existing_entry && | 2822 if (existing_entry && |
2818 // This should always match, but just in case. | 2823 // This should always match, but just in case. |
2819 existing_entry->parent() == parent_dir) { | 2824 existing_entry->parent() == parent_dir) { |
2820 parent_dir->RemoveEntry(existing_entry); | 2825 directory_service_->RemoveEntryFromParent(existing_entry, callback); |
2821 } else { | 2826 } else { |
| 2827 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath()); |
2822 LOG(ERROR) << "Entry for the existing file not found: " << resource_id; | 2828 LOG(ERROR) << "Entry for the existing file not found: " << resource_id; |
2823 } | 2829 } |
2824 } | 2830 } |
2825 | 2831 |
2826 void GDataFileSystem::NotifyFileSystemMounted() { | 2832 void GDataFileSystem::NotifyFileSystemMounted() { |
2827 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2828 | 2834 |
2829 DVLOG(1) << "File System is mounted"; | 2835 DVLOG(1) << "File System is mounted"; |
2830 // Notify the observers that the file system is mounted. | 2836 // Notify the observers that the file system is mounted. |
2831 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2837 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2879 // file with the exact same name. | 2885 // file with the exact same name. |
2880 GDataDirectory* parent_dir = entry->AsGDataDirectory(); | 2886 GDataDirectory* parent_dir = entry->AsGDataDirectory(); |
2881 if (!parent_dir) | 2887 if (!parent_dir) |
2882 return GDATA_FILE_ERROR_FAILED; | 2888 return GDATA_FILE_ERROR_FAILED; |
2883 | 2889 |
2884 GDataEntry* new_entry = | 2890 GDataEntry* new_entry = |
2885 directory_service_->FromDocumentEntry(doc_entry.get()); | 2891 directory_service_->FromDocumentEntry(doc_entry.get()); |
2886 if (!new_entry) | 2892 if (!new_entry) |
2887 return GDATA_FILE_ERROR_FAILED; | 2893 return GDATA_FILE_ERROR_FAILED; |
2888 | 2894 |
2889 parent_dir->AddEntry(new_entry); | 2895 directory_service_->AddEntryToDirectory( |
2890 | 2896 parent_dir, |
2891 OnDirectoryChanged(directory_path); | 2897 new_entry, |
| 2898 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, |
| 2899 ui_weak_ptr_, |
| 2900 FileMoveCallback())); |
2892 return GDATA_FILE_OK; | 2901 return GDATA_FILE_OK; |
2893 } | 2902 } |
2894 | 2903 |
2895 GDataFileSystem::FindMissingDirectoryResult | 2904 GDataFileSystem::FindMissingDirectoryResult |
2896 GDataFileSystem::FindFirstMissingParentDirectory( | 2905 GDataFileSystem::FindFirstMissingParentDirectory( |
2897 const FilePath& directory_path, | 2906 const FilePath& directory_path, |
2898 GURL* last_dir_content_url, | 2907 GURL* last_dir_content_url, |
2899 FilePath* first_missing_parent_path) { | 2908 FilePath* first_missing_parent_path) { |
2900 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2909 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2901 | 2910 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2939 | 2948 |
2940 // You can't remove root element. | 2949 // You can't remove root element. |
2941 if (!entry->parent()) | 2950 if (!entry->parent()) |
2942 return GDATA_FILE_ERROR_ACCESS_DENIED; | 2951 return GDATA_FILE_ERROR_ACCESS_DENIED; |
2943 | 2952 |
2944 // If it's a file (only files have resource id), get its resource id so that | 2953 // If it's a file (only files have resource id), get its resource id so that |
2945 // we can remove it after releasing the auto lock. | 2954 // we can remove it after releasing the auto lock. |
2946 if (entry->AsGDataFile()) | 2955 if (entry->AsGDataFile()) |
2947 *resource_id = entry->AsGDataFile()->resource_id(); | 2956 *resource_id = entry->AsGDataFile()->resource_id(); |
2948 | 2957 |
2949 GDataDirectory* parent_dir = entry->parent(); | 2958 directory_service_->RemoveEntryFromParent( |
2950 parent_dir->RemoveEntry(entry); | 2959 entry, |
2951 | 2960 base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback, |
2952 OnDirectoryChanged(parent_dir->GetFilePath()); | 2961 ui_weak_ptr_)); |
2953 return GDATA_FILE_OK; | 2962 return GDATA_FILE_OK; |
2954 } | 2963 } |
2955 | 2964 |
2956 void GDataFileSystem::AddUploadedFile( | 2965 void GDataFileSystem::AddUploadedFile( |
2957 UploadMode upload_mode, | 2966 UploadMode upload_mode, |
2958 const FilePath& virtual_dir_path, | 2967 const FilePath& virtual_dir_path, |
2959 scoped_ptr<DocumentEntry> entry, | 2968 scoped_ptr<DocumentEntry> entry, |
2960 const FilePath& file_content_path, | 2969 const FilePath& file_content_path, |
2961 GDataCache::FileOperationType cache_operation, | 2970 GDataCache::FileOperationType cache_operation, |
2962 const base::Closure& callback) { | 2971 const base::Closure& callback) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3001 | 3010 |
3002 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); | 3011 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); |
3003 if (!parent_dir) | 3012 if (!parent_dir) |
3004 return; | 3013 return; |
3005 | 3014 |
3006 scoped_ptr<GDataEntry> new_entry( | 3015 scoped_ptr<GDataEntry> new_entry( |
3007 directory_service_->FromDocumentEntry(entry.get())); | 3016 directory_service_->FromDocumentEntry(entry.get())); |
3008 if (!new_entry.get()) | 3017 if (!new_entry.get()) |
3009 return; | 3018 return; |
3010 | 3019 |
| 3020 const std::string& resource_id = new_entry->resource_id(); |
| 3021 AddUploadedFileParams* params = |
| 3022 new AddUploadedFileParams(upload_mode, |
| 3023 parent_dir, |
| 3024 new_entry.Pass(), |
| 3025 file_content_path, |
| 3026 cache_operation, |
| 3027 callback_runner.Release()); |
| 3028 |
| 3029 const FileMoveCallback file_move_callback = |
| 3030 base::Bind(&GDataFileSystem::ContinueAddUploadedFile, |
| 3031 ui_weak_ptr_, params); |
| 3032 |
3011 if (upload_mode == UPLOAD_EXISTING_FILE) { | 3033 if (upload_mode == UPLOAD_EXISTING_FILE) { |
3012 // Remove an existing entry, which should be present. | 3034 // Remove an existing entry, which should be present. |
3013 const std::string& resource_id = new_entry->resource_id(); | 3035 directory_service_->GetEntryByResourceIdAsync( |
3014 directory_service_->GetEntryByResourceIdAsync(resource_id, | 3036 resource_id, |
3015 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir)); | 3037 base::Bind(&GDataFileSystem::RemoveStaleEntryOnUpload, |
3016 } | 3038 ui_weak_ptr_, |
3017 | 3039 resource_id, |
3018 GDataFile* file = new_entry->AsGDataFile(); | 3040 parent_dir, |
3019 DCHECK(file); | 3041 file_move_callback)); |
3020 const std::string& resource_id = file->resource_id(); | |
3021 const std::string& md5 = file->file_md5(); | |
3022 parent_dir->AddEntry(new_entry.release()); | |
3023 | |
3024 OnDirectoryChanged(virtual_dir_path); | |
3025 | |
3026 if (upload_mode == UPLOAD_NEW_FILE) { | |
3027 // Add the file to the cache if we have uploaded a new file. | |
3028 cache_->StoreOnUIThread(resource_id, | |
3029 md5, | |
3030 file_content_path, | |
3031 cache_operation, | |
3032 base::Bind(&OnCacheUpdatedForAddUploadedFile, | |
3033 callback_runner.Release())); | |
3034 } else if (upload_mode == UPLOAD_EXISTING_FILE) { | |
3035 // Clear the dirty bit if we have updated an existing file. | |
3036 cache_->ClearDirtyOnUIThread(resource_id, | |
3037 md5, | |
3038 base::Bind(&OnCacheUpdatedForAddUploadedFile, | |
3039 callback_runner.Release())); | |
3040 } else { | 3042 } else { |
3041 NOTREACHED() << "Unexpected upload mode: " << upload_mode; | 3043 file_move_callback.Run(GDATA_FILE_OK, FilePath()); |
3042 } | 3044 } |
3043 } | 3045 } |
3044 | 3046 |
| 3047 void GDataFileSystem::ContinueAddUploadedFile( |
| 3048 AddUploadedFileParams* params, |
| 3049 GDataFileError error, |
| 3050 const FilePath& file_path) { |
| 3051 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 3052 DCHECK_EQ(GDATA_FILE_OK, error); |
| 3053 DCHECK(params->new_entry.get()); |
| 3054 GDataFile* file = params->new_entry->AsGDataFile(); |
| 3055 DCHECK(file); |
| 3056 |
| 3057 params->resource_id = file->resource_id(); |
| 3058 params->md5 = file->file_md5(); |
| 3059 directory_service_->AddEntryToDirectory( |
| 3060 params->parent_dir, |
| 3061 params->new_entry.release(), |
| 3062 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, |
| 3063 ui_weak_ptr_, |
| 3064 base::Bind(&GDataFileSystem::AddUploadedFileToCache, |
| 3065 ui_weak_ptr_, |
| 3066 base::Owned(params)))); |
| 3067 } |
| 3068 |
| 3069 void GDataFileSystem::AddUploadedFileToCache( |
| 3070 AddUploadedFileParams* params, |
| 3071 GDataFileError error, |
| 3072 const FilePath& file_path) { |
| 3073 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 3074 |
| 3075 if (params->upload_mode == UPLOAD_NEW_FILE) { |
| 3076 // Add the file to the cache if we have uploaded a new file. |
| 3077 cache_->StoreOnUIThread(params->resource_id, |
| 3078 params->md5, |
| 3079 params->file_content_path, |
| 3080 params->cache_operation, |
| 3081 base::Bind(&OnCacheUpdatedForAddUploadedFile, |
| 3082 params->callback)); |
| 3083 } else if (params->upload_mode == UPLOAD_EXISTING_FILE) { |
| 3084 // Clear the dirty bit if we have updated an existing file. |
| 3085 cache_->ClearDirtyOnUIThread(params->resource_id, |
| 3086 params->md5, |
| 3087 base::Bind(&OnCacheUpdatedForAddUploadedFile, |
| 3088 params->callback)); |
| 3089 } else { |
| 3090 NOTREACHED() << "Unexpected upload mode: " << params->upload_mode; |
| 3091 } |
| 3092 params->callback.Run(); |
| 3093 } |
| 3094 |
3045 void GDataFileSystem::Observe(int type, | 3095 void GDataFileSystem::Observe(int type, |
3046 const content::NotificationSource& source, | 3096 const content::NotificationSource& source, |
3047 const content::NotificationDetails& details) { | 3097 const content::NotificationDetails& details) { |
3048 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3098 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3049 | 3099 |
3050 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 3100 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
3051 PrefService* pref_service = profile_->GetPrefs(); | 3101 PrefService* pref_service = profile_->GetPrefs(); |
3052 std::string* pref_name = content::Details<std::string>(details).ptr(); | 3102 std::string* pref_name = content::Details<std::string>(details).ptr(); |
3053 if (*pref_name == prefs::kDisableGDataHostedFiles) { | 3103 if (*pref_name == prefs::kDisableGDataHostedFiles) { |
3054 SetHideHostedDocuments( | 3104 SetHideHostedDocuments( |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3406 return; | 3456 return; |
3407 } | 3457 } |
3408 | 3458 |
3409 PlatformFileInfoProto entry_file_info; | 3459 PlatformFileInfoProto entry_file_info; |
3410 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3460 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
3411 *entry_proto->mutable_file_info() = entry_file_info; | 3461 *entry_proto->mutable_file_info() = entry_file_info; |
3412 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3462 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
3413 } | 3463 } |
3414 | 3464 |
3415 } // namespace gdata | 3465 } // namespace gdata |
OLD | NEW |