Chromium Code Reviews| 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 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1203 | 1230 |
| 1204 // Otherwise, the move operation involves three steps: | 1231 // Otherwise, the move operation involves three steps: |
| 1205 // 1. Renames the file at |src_file_path| to basename(|dest_file_path|) | 1232 // 1. Renames the file at |src_file_path| to basename(|dest_file_path|) |
| 1206 // within the same directory. The rename operation is a no-op if | 1233 // within the same directory. The rename operation is a no-op if |
| 1207 // basename(|src_file_path|) equals to basename(|dest_file_path|). | 1234 // basename(|src_file_path|) equals to basename(|dest_file_path|). |
| 1208 // 2. Removes the file from its parent directory (the file is not deleted), | 1235 // 2. Removes the file from its parent directory (the file is not deleted), |
| 1209 // which effectively moves the file to the root directory. | 1236 // which effectively moves the file to the root directory. |
| 1210 // 3. Adds the file to the parent directory of |dest_file_path|, which | 1237 // 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 | 1238 // effectively moves the file from the root directory to the parent |
| 1212 // directory of |dest_file_path|. | 1239 // directory of |dest_file_path|. |
| 1213 FileMoveCallback add_file_to_directory_callback = | 1240 const FileMoveCallback add_file_to_directory_callback = |
| 1214 base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory, | 1241 base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory, |
| 1215 ui_weak_ptr_, | 1242 ui_weak_ptr_, |
| 1216 dest_file_path.DirName(), | 1243 dest_file_path.DirName(), |
| 1217 callback); | 1244 callback); |
| 1218 | 1245 |
| 1219 FileMoveCallback remove_file_from_directory_callback = | 1246 const FileMoveCallback remove_file_from_directory_callback = |
| 1220 base::Bind(&GDataFileSystem::RemoveEntryFromDirectory, | 1247 base::Bind(&GDataFileSystem::RemoveEntryFromDirectory, |
| 1221 ui_weak_ptr_, | 1248 ui_weak_ptr_, |
| 1222 src_file_path.DirName(), | 1249 src_file_path.DirName(), |
| 1223 add_file_to_directory_callback); | 1250 add_file_to_directory_callback); |
| 1224 | 1251 |
| 1225 Rename(src_file_path, dest_file_path.BaseName().value(), | 1252 Rename(src_file_path, dest_file_path.BaseName().value(), |
| 1226 remove_file_from_directory_callback); | 1253 remove_file_from_directory_callback); |
| 1227 } | 1254 } |
| 1228 | 1255 |
| 1229 void GDataFileSystem::MoveEntryFromRootDirectory( | 1256 void GDataFileSystem::MoveEntryFromRootDirectory( |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1980 *params->feed_list, | 2007 *params->feed_list, |
| 1981 &file_map, | 2008 &file_map, |
| 1982 &unused_delta_feed_changestamp, | 2009 &unused_delta_feed_changestamp, |
| 1983 &unused_uma_stats); | 2010 &unused_uma_stats); |
| 1984 if (error != GDATA_FILE_OK) { | 2011 if (error != GDATA_FILE_OK) { |
| 1985 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() | 2012 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() |
| 1986 << ": " << error; | 2013 << ": " << error; |
| 1987 return; | 2014 return; |
| 1988 } | 2015 } |
| 1989 | 2016 |
| 1990 directory_service_->GetEntryByResourceIdAsync(params->directory_resource_id, | 2017 directory_service_->RefreshDirectory( |
| 1991 base::Bind(&GDataFileSystem::RequestDirectoryRefreshByEntry, | 2018 params->directory_resource_id, |
| 1992 ui_weak_ptr_, | 2019 file_map, |
| 1993 directory_path, | 2020 base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback, |
| 1994 params->directory_resource_id, | 2021 ui_weak_ptr_)); |
| 1995 file_map)); | |
| 1996 } | |
| 1997 | |
| 1998 void GDataFileSystem::RequestDirectoryRefreshByEntry( | |
| 1999 const FilePath& directory_path, | |
| 2000 const std::string& directory_resource_id, | |
| 2001 const FileResourceIdMap& file_map, | |
| 2002 GDataEntry* directory_entry) { | |
| 2003 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 2004 | |
| 2005 if (!directory_entry || !directory_entry->AsGDataDirectory()) { | |
| 2006 LOG(ERROR) << "Directory entry is gone: " << directory_path.value() | |
| 2007 << ": " << directory_resource_id; | |
| 2008 return; | |
| 2009 } | |
| 2010 GDataDirectory* directory = directory_entry->AsGDataDirectory(); | |
| 2011 | |
| 2012 // Remove the existing files. | |
| 2013 directory->RemoveChildFiles(); | |
| 2014 // Go through all entries generated by the feed and add files. | |
| 2015 for (FileResourceIdMap::const_iterator it = file_map.begin(); | |
| 2016 it != file_map.end(); ++it) { | |
| 2017 scoped_ptr<GDataEntry> entry(it->second); | |
| 2018 // Skip if it's not a file (i.e. directory). | |
| 2019 if (!entry->AsGDataFile()) | |
| 2020 continue; | |
| 2021 directory->AddEntry(entry.release()); | |
| 2022 } | |
| 2023 | |
| 2024 // Note that there may be no change in the directory, but it's expensive to | |
| 2025 // check if the new metadata matches the existing one, so we just always | |
| 2026 // notify that the directory is changed. | |
| 2027 OnDirectoryChanged(directory_path); | |
| 2028 DVLOG(1) << "Directory refreshed: " << directory_path.value(); | |
| 2029 } | 2022 } |
| 2030 | 2023 |
| 2031 void GDataFileSystem::UpdateFileByResourceId( | 2024 void GDataFileSystem::UpdateFileByResourceId( |
| 2032 const std::string& resource_id, | 2025 const std::string& resource_id, |
| 2033 const FileOperationCallback& callback) { | 2026 const FileOperationCallback& callback) { |
| 2034 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2027 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 2035 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2028 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2036 RunTaskOnUIThread( | 2029 RunTaskOnUIThread( |
| 2037 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, | 2030 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, |
| 2038 ui_weak_ptr_, | 2031 ui_weak_ptr_, |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2479 | 2472 |
| 2480 GDataEntry* entry = directory_service_->FromDocumentEntry(doc_entry.get()); | 2473 GDataEntry* entry = directory_service_->FromDocumentEntry(doc_entry.get()); |
| 2481 if (!entry) { | 2474 if (!entry) { |
| 2482 callback.Run(GDATA_FILE_ERROR_FAILED); | 2475 callback.Run(GDATA_FILE_ERROR_FAILED); |
| 2483 return; | 2476 return; |
| 2484 } | 2477 } |
| 2485 | 2478 |
| 2486 // |entry| was added in the root directory on the server, so we should | 2479 // |entry| was added in the root directory on the server, so we should |
| 2487 // first add it to |root_| to mirror the state and then move it to the | 2480 // first add it to |root_| to mirror the state and then move it to the |
| 2488 // destination directory by MoveEntryFromRootDirectory(). | 2481 // destination directory by MoveEntryFromRootDirectory(). |
| 2489 directory_service_->root()->AddEntry(entry); | 2482 directory_service_->AddEntryToDirectory( |
| 2490 MoveEntryFromRootDirectory(dir_path, | 2483 directory_service_->root(), |
| 2491 callback, | 2484 entry, |
| 2492 GDATA_FILE_OK, | 2485 base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory, |
| 2493 entry->GetFilePath()); | 2486 ui_weak_ptr_, |
| 2487 dir_path, | |
| 2488 callback)); | |
| 2494 } | 2489 } |
| 2495 | 2490 |
| 2496 void GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted( | 2491 void GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted( |
| 2497 const FileOperationCallback& callback, | 2492 const FileOperationCallback& callback, |
| 2498 const FilePath& file_path, | 2493 const FilePath& file_path, |
| 2499 const FilePath& dir_path, | 2494 const FilePath& dir_path, |
| 2500 GDataErrorCode status, | 2495 GDataErrorCode status, |
| 2501 const GURL& document_url) { | 2496 const GURL& document_url) { |
| 2502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2503 DCHECK(!callback.is_null()); | 2498 DCHECK(!callback.is_null()); |
| 2504 | 2499 |
| 2505 GDataFileError error = util::GDataToGDataFileError(status); | 2500 GDataFileError error = util::GDataToGDataFileError(status); |
| 2506 if (error == GDATA_FILE_OK) { | 2501 if (error == GDATA_FILE_OK) { |
| 2507 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); | 2502 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
| 2508 if (entry) { | 2503 if (entry) { |
| 2509 DCHECK_EQ(directory_service_->root(), entry->parent()); | 2504 DCHECK_EQ(directory_service_->root(), entry->parent()); |
| 2510 directory_service_->MoveEntryToDirectory(dir_path, entry, | 2505 directory_service_->MoveEntryToDirectory( |
| 2506 dir_path, | |
| 2507 entry, | |
| 2511 base::Bind( | 2508 base::Bind( |
| 2512 &GDataFileSystem::OnMoveEntryToDirectoryWithFileOperationCallback, | 2509 &GDataFileSystem::OnMoveEntryToDirectoryWithFileOperationCallback, |
| 2513 ui_weak_ptr_, | 2510 ui_weak_ptr_, |
| 2514 callback)); | 2511 callback)); |
| 2515 return; | 2512 return; |
| 2516 } else { | 2513 } else { |
| 2517 error = GDATA_FILE_ERROR_NOT_FOUND; | 2514 error = GDATA_FILE_ERROR_NOT_FOUND; |
| 2518 } | 2515 } |
| 2519 } | 2516 } |
| 2520 | 2517 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2729 GDataFileError error, | 2726 GDataFileError error, |
| 2730 const FilePath& moved_file_path) { | 2727 const FilePath& moved_file_path) { |
| 2731 DCHECK(!callback.is_null()); | 2728 DCHECK(!callback.is_null()); |
| 2732 | 2729 |
| 2733 if (error == GDATA_FILE_OK) | 2730 if (error == GDATA_FILE_OK) |
| 2734 OnDirectoryChanged(moved_file_path.DirName()); | 2731 OnDirectoryChanged(moved_file_path.DirName()); |
| 2735 | 2732 |
| 2736 callback.Run(error); | 2733 callback.Run(error); |
| 2737 } | 2734 } |
| 2738 | 2735 |
| 2736 void GDataFileSystem::OnDirectoryChangeFileMoveCallback( | |
| 2737 GDataFileError error, | |
| 2738 const FilePath& directory_path) { | |
| 2739 if (error == GDATA_FILE_OK) | |
| 2740 OnDirectoryChanged(directory_path); | |
| 2741 } | |
| 2742 | |
| 2739 GDataFileError GDataFileSystem::RemoveEntryFromFileSystem( | 2743 GDataFileError GDataFileSystem::RemoveEntryFromFileSystem( |
| 2740 const FilePath& file_path) { | 2744 const FilePath& file_path) { |
| 2741 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2745 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2742 | 2746 |
| 2743 std::string resource_id; | 2747 std::string resource_id; |
| 2744 GDataFileError error = RemoveEntryFromGData(file_path, &resource_id); | 2748 GDataFileError error = RemoveEntryFromGData(file_path, &resource_id); |
| 2745 if (error != GDATA_FILE_OK) | 2749 if (error != GDATA_FILE_OK) |
| 2746 return error; | 2750 return error; |
| 2747 | 2751 |
| 2748 // If resource_id is not empty, remove its corresponding file from cache. | 2752 // If resource_id is not empty, remove its corresponding file from cache. |
| 2749 if (!resource_id.empty()) | 2753 if (!resource_id.empty()) |
| 2750 cache_->RemoveOnUIThread(resource_id, CacheOperationCallback()); | 2754 cache_->RemoveOnUIThread(resource_id, CacheOperationCallback()); |
| 2751 | 2755 |
| 2752 return GDATA_FILE_OK; | 2756 return GDATA_FILE_OK; |
| 2753 } | 2757 } |
| 2754 | 2758 |
| 2755 // static | 2759 void GDataFileSystem::RemoveStaleEntryOnUpload( |
| 2756 void GDataFileSystem::RemoveStaleEntryOnUpload(const std::string& resource_id, | 2760 const std::string& resource_id, |
| 2757 GDataDirectory* parent_dir, | 2761 GDataDirectory* parent_dir, |
| 2758 GDataEntry* existing_entry) { | 2762 const FileMoveCallback& callback, |
| 2763 GDataEntry* existing_entry) { | |
| 2759 if (existing_entry && | 2764 if (existing_entry && |
| 2760 // This should always match, but just in case. | 2765 // This should always match, but just in case. |
| 2761 existing_entry->parent() == parent_dir) { | 2766 existing_entry->parent() == parent_dir) { |
| 2762 parent_dir->RemoveEntry(existing_entry); | 2767 directory_service_->RemoveEntryFromParent(existing_entry, callback); |
| 2763 } else { | 2768 } else { |
| 2769 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath()); | |
| 2764 LOG(ERROR) << "Entry for the existing file not found: " << resource_id; | 2770 LOG(ERROR) << "Entry for the existing file not found: " << resource_id; |
| 2765 } | 2771 } |
| 2766 } | 2772 } |
| 2767 | 2773 |
| 2768 void GDataFileSystem::NotifyFileSystemMounted() { | 2774 void GDataFileSystem::NotifyFileSystemMounted() { |
| 2769 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2775 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2770 | 2776 |
| 2771 DVLOG(1) << "File System is mounted"; | 2777 DVLOG(1) << "File System is mounted"; |
| 2772 // Notify the observers that the file system is mounted. | 2778 // Notify the observers that the file system is mounted. |
| 2773 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2779 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2821 // file with the exact same name. | 2827 // file with the exact same name. |
| 2822 GDataDirectory* parent_dir = entry->AsGDataDirectory(); | 2828 GDataDirectory* parent_dir = entry->AsGDataDirectory(); |
| 2823 if (!parent_dir) | 2829 if (!parent_dir) |
| 2824 return GDATA_FILE_ERROR_FAILED; | 2830 return GDATA_FILE_ERROR_FAILED; |
| 2825 | 2831 |
| 2826 GDataEntry* new_entry = | 2832 GDataEntry* new_entry = |
| 2827 directory_service_->FromDocumentEntry(doc_entry.get()); | 2833 directory_service_->FromDocumentEntry(doc_entry.get()); |
| 2828 if (!new_entry) | 2834 if (!new_entry) |
| 2829 return GDATA_FILE_ERROR_FAILED; | 2835 return GDATA_FILE_ERROR_FAILED; |
| 2830 | 2836 |
| 2831 parent_dir->AddEntry(new_entry); | 2837 directory_service_->AddEntryToDirectory( |
| 2832 | 2838 parent_dir, |
| 2833 OnDirectoryChanged(directory_path); | 2839 new_entry, |
| 2840 base::Bind(&GDataFileSystem::OnMoveEntryToDirectoryWithFileMoveCallback, | |
| 2841 ui_weak_ptr_, | |
| 2842 FileMoveCallback())); | |
| 2834 return GDATA_FILE_OK; | 2843 return GDATA_FILE_OK; |
| 2835 } | 2844 } |
| 2836 | 2845 |
| 2837 GDataFileSystem::FindMissingDirectoryResult | 2846 GDataFileSystem::FindMissingDirectoryResult |
| 2838 GDataFileSystem::FindFirstMissingParentDirectory( | 2847 GDataFileSystem::FindFirstMissingParentDirectory( |
| 2839 const FilePath& directory_path, | 2848 const FilePath& directory_path, |
| 2840 GURL* last_dir_content_url, | 2849 GURL* last_dir_content_url, |
| 2841 FilePath* first_missing_parent_path) { | 2850 FilePath* first_missing_parent_path) { |
| 2842 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2851 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2843 | 2852 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2881 | 2890 |
| 2882 // You can't remove root element. | 2891 // You can't remove root element. |
| 2883 if (!entry->parent()) | 2892 if (!entry->parent()) |
| 2884 return GDATA_FILE_ERROR_ACCESS_DENIED; | 2893 return GDATA_FILE_ERROR_ACCESS_DENIED; |
| 2885 | 2894 |
| 2886 // If it's a file (only files have resource id), get its resource id so that | 2895 // If it's a file (only files have resource id), get its resource id so that |
| 2887 // we can remove it after releasing the auto lock. | 2896 // we can remove it after releasing the auto lock. |
| 2888 if (entry->AsGDataFile()) | 2897 if (entry->AsGDataFile()) |
| 2889 *resource_id = entry->AsGDataFile()->resource_id(); | 2898 *resource_id = entry->AsGDataFile()->resource_id(); |
| 2890 | 2899 |
| 2891 GDataDirectory* parent_dir = entry->parent(); | 2900 directory_service_->RemoveEntryFromParent( |
| 2892 parent_dir->RemoveEntry(entry); | 2901 entry, |
| 2893 | 2902 base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback, |
| 2894 OnDirectoryChanged(parent_dir->GetFilePath()); | 2903 ui_weak_ptr_)); |
| 2895 return GDATA_FILE_OK; | 2904 return GDATA_FILE_OK; |
| 2896 } | 2905 } |
| 2897 | 2906 |
| 2898 void GDataFileSystem::AddUploadedFile( | 2907 void GDataFileSystem::AddUploadedFile( |
| 2899 UploadMode upload_mode, | 2908 UploadMode upload_mode, |
| 2900 const FilePath& virtual_dir_path, | 2909 const FilePath& virtual_dir_path, |
| 2901 scoped_ptr<DocumentEntry> entry, | 2910 scoped_ptr<DocumentEntry> entry, |
| 2902 const FilePath& file_content_path, | 2911 const FilePath& file_content_path, |
| 2903 GDataCache::FileOperationType cache_operation, | 2912 GDataCache::FileOperationType cache_operation, |
| 2904 const base::Closure& callback) { | 2913 const base::Closure& callback) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2943 | 2952 |
| 2944 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); | 2953 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); |
| 2945 if (!parent_dir) | 2954 if (!parent_dir) |
| 2946 return; | 2955 return; |
| 2947 | 2956 |
| 2948 scoped_ptr<GDataEntry> new_entry( | 2957 scoped_ptr<GDataEntry> new_entry( |
| 2949 directory_service_->FromDocumentEntry(entry.get())); | 2958 directory_service_->FromDocumentEntry(entry.get())); |
| 2950 if (!new_entry.get()) | 2959 if (!new_entry.get()) |
| 2951 return; | 2960 return; |
| 2952 | 2961 |
| 2962 const std::string& resource_id = new_entry->resource_id(); | |
| 2963 AddUploadedFileParams* params = new AddUploadedFileParams( | |
| 2964 upload_mode, parent_dir, new_entry.Pass(), file_content_path, | |
| 2965 cache_operation, callback_runner.Release()); | |
|
satorux1
2012/08/14 06:11:32
nit: could you list parameters vertically?
achuithb
2012/08/14 23:33:59
Done.
| |
| 2966 | |
| 2967 const FileMoveCallback file_move_callback = | |
| 2968 base::Bind(&GDataFileSystem::ContinueAddUploadedFile, | |
| 2969 ui_weak_ptr_, params); | |
| 2970 | |
| 2953 if (upload_mode == UPLOAD_EXISTING_FILE) { | 2971 if (upload_mode == UPLOAD_EXISTING_FILE) { |
| 2954 // Remove an existing entry, which should be present. | 2972 // Remove an existing entry, which should be present. |
| 2955 const std::string& resource_id = new_entry->resource_id(); | 2973 directory_service_->GetEntryByResourceIdAsync( |
| 2956 directory_service_->GetEntryByResourceIdAsync(resource_id, | 2974 resource_id, |
| 2957 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir)); | 2975 base::Bind(&GDataFileSystem::RemoveStaleEntryOnUpload, |
| 2958 } | 2976 ui_weak_ptr_, |
| 2959 | 2977 resource_id, |
| 2960 GDataFile* file = new_entry->AsGDataFile(); | 2978 parent_dir, |
| 2961 DCHECK(file); | 2979 file_move_callback)); |
| 2962 const std::string& resource_id = file->resource_id(); | |
| 2963 const std::string& md5 = file->file_md5(); | |
| 2964 parent_dir->AddEntry(new_entry.release()); | |
| 2965 | |
| 2966 OnDirectoryChanged(virtual_dir_path); | |
| 2967 | |
| 2968 if (upload_mode == UPLOAD_NEW_FILE) { | |
| 2969 // Add the file to the cache if we have uploaded a new file. | |
| 2970 cache_->StoreOnUIThread(resource_id, | |
| 2971 md5, | |
| 2972 file_content_path, | |
| 2973 cache_operation, | |
| 2974 base::Bind(&OnCacheUpdatedForAddUploadedFile, | |
| 2975 callback_runner.Release())); | |
| 2976 } else if (upload_mode == UPLOAD_EXISTING_FILE) { | |
| 2977 // Clear the dirty bit if we have updated an existing file. | |
| 2978 cache_->ClearDirtyOnUIThread(resource_id, | |
| 2979 md5, | |
| 2980 base::Bind(&OnCacheUpdatedForAddUploadedFile, | |
| 2981 callback_runner.Release())); | |
| 2982 } else { | 2980 } else { |
| 2983 NOTREACHED() << "Unexpected upload mode: " << upload_mode; | 2981 file_move_callback.Run(GDATA_FILE_OK, FilePath()); |
| 2984 } | 2982 } |
| 2985 } | 2983 } |
| 2986 | 2984 |
| 2985 void GDataFileSystem::ContinueAddUploadedFile( | |
| 2986 AddUploadedFileParams* params, | |
| 2987 GDataFileError error, | |
| 2988 const FilePath& file_path) { | |
| 2989 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 2990 DCHECK_EQ(GDATA_FILE_OK, error); | |
| 2991 DCHECK(params->new_entry.get()); | |
| 2992 GDataFile* file = params->new_entry->AsGDataFile(); | |
| 2993 DCHECK(file); | |
| 2994 | |
| 2995 params->resource_id = file->resource_id(); | |
| 2996 params->md5 = file->file_md5(); | |
| 2997 directory_service_->AddEntryToDirectory( | |
| 2998 params->parent_dir, | |
| 2999 params->new_entry.release(), | |
| 3000 base::Bind(&GDataFileSystem::OnMoveEntryToDirectoryWithFileMoveCallback, | |
| 3001 ui_weak_ptr_, | |
| 3002 base::Bind(&GDataFileSystem::AddUploadedFileToCache, | |
| 3003 ui_weak_ptr_, | |
| 3004 base::Owned(params)))); | |
| 3005 } | |
| 3006 | |
| 3007 void GDataFileSystem::AddUploadedFileToCache( | |
| 3008 AddUploadedFileParams* params, | |
| 3009 GDataFileError error, | |
| 3010 const FilePath& file_path) { | |
| 3011 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 3012 | |
| 3013 if (params->upload_mode == UPLOAD_NEW_FILE) { | |
| 3014 // Add the file to the cache if we have uploaded a new file. | |
| 3015 cache_->StoreOnUIThread(params->resource_id, | |
| 3016 params->md5, | |
| 3017 params->file_content_path, | |
| 3018 params->cache_operation, | |
| 3019 base::Bind(&OnCacheUpdatedForAddUploadedFile, | |
| 3020 params->callback)); | |
| 3021 } else if (params->upload_mode == UPLOAD_EXISTING_FILE) { | |
| 3022 // Clear the dirty bit if we have updated an existing file. | |
| 3023 cache_->ClearDirtyOnUIThread(params->resource_id, | |
| 3024 params->md5, | |
| 3025 base::Bind(&OnCacheUpdatedForAddUploadedFile, | |
| 3026 params->callback)); | |
| 3027 } else { | |
| 3028 NOTREACHED() << "Unexpected upload mode: " << params->upload_mode; | |
| 3029 } | |
| 3030 params->callback.Run(); | |
| 3031 } | |
| 3032 | |
| 2987 void GDataFileSystem::Observe(int type, | 3033 void GDataFileSystem::Observe(int type, |
| 2988 const content::NotificationSource& source, | 3034 const content::NotificationSource& source, |
| 2989 const content::NotificationDetails& details) { | 3035 const content::NotificationDetails& details) { |
| 2990 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3036 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2991 | 3037 |
| 2992 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 3038 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| 2993 PrefService* pref_service = profile_->GetPrefs(); | 3039 PrefService* pref_service = profile_->GetPrefs(); |
| 2994 std::string* pref_name = content::Details<std::string>(details).ptr(); | 3040 std::string* pref_name = content::Details<std::string>(details).ptr(); |
| 2995 if (*pref_name == prefs::kDisableGDataHostedFiles) { | 3041 if (*pref_name == prefs::kDisableGDataHostedFiles) { |
| 2996 SetHideHostedDocuments( | 3042 SetHideHostedDocuments( |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3444 } | 3490 } |
| 3445 | 3491 |
| 3446 PlatformFileInfoProto entry_file_info; | 3492 PlatformFileInfoProto entry_file_info; |
| 3447 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3493 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
| 3448 *entry_proto->mutable_file_info() = entry_file_info; | 3494 *entry_proto->mutable_file_info() = entry_file_info; |
| 3449 if (!callback.is_null()) | 3495 if (!callback.is_null()) |
| 3450 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3496 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
| 3451 } | 3497 } |
| 3452 | 3498 |
| 3453 } // namespace gdata | 3499 } // namespace gdata |
| OLD | NEW |