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 <errno.h> | 7 #include <errno.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 *error = file_util::CopyFile(src_file_path, dest_file_path) ? | 778 *error = file_util::CopyFile(src_file_path, dest_file_path) ? |
779 base::PLATFORM_FILE_OK : base::PLATFORM_FILE_ERROR_FAILED; | 779 base::PLATFORM_FILE_OK : base::PLATFORM_FILE_ERROR_FAILED; |
780 } | 780 } |
781 | 781 |
782 // Relays the given FindEntryCallback to another thread via |replay_proxy|. | 782 // Relays the given FindEntryCallback to another thread via |replay_proxy|. |
783 void RelayFindEntryCallback(scoped_refptr<base::MessageLoopProxy> relay_proxy, | 783 void RelayFindEntryCallback(scoped_refptr<base::MessageLoopProxy> relay_proxy, |
784 const FindEntryCallback& callback, | 784 const FindEntryCallback& callback, |
785 base::PlatformFileError error, | 785 base::PlatformFileError error, |
786 const FilePath& directory_path, | 786 const FilePath& directory_path, |
787 GDataEntry* entry) { | 787 GDataEntry* entry) { |
788 relay_proxy->PostTask(FROM_HERE, base::Bind(callback, error, entry)); | 788 relay_proxy->PostTask(FROM_HERE, |
| 789 base::Bind(callback, error, directory_path, entry)); |
789 } | 790 } |
790 | 791 |
791 // Ditto for FileOperationCallback. | 792 // Ditto for FileOperationCallback. |
792 void RelayFileOperationCallback( | 793 void RelayFileOperationCallback( |
793 scoped_refptr<base::MessageLoopProxy> relay_proxy, | 794 scoped_refptr<base::MessageLoopProxy> relay_proxy, |
794 const FileOperationCallback& callback, | 795 const FileOperationCallback& callback, |
795 base::PlatformFileError error) { | 796 base::PlatformFileError error) { |
796 relay_proxy->PostTask(FROM_HERE, base::Bind(callback, error)); | 797 relay_proxy->PostTask(FROM_HERE, base::Bind(callback, error)); |
797 } | 798 } |
798 | 799 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 root_->largest_changestamp(), | 1015 root_->largest_changestamp(), |
1015 root_->GetFilePath(), | 1016 root_->GetFilePath(), |
1016 base::Bind(&GDataFileSystem::OnUpdateChecked, | 1017 base::Bind(&GDataFileSystem::OnUpdateChecked, |
1017 ui_weak_ptr_, | 1018 ui_weak_ptr_, |
1018 initial_origin)); | 1019 initial_origin)); |
1019 } | 1020 } |
1020 } | 1021 } |
1021 | 1022 |
1022 void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin, | 1023 void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin, |
1023 base::PlatformFileError error, | 1024 base::PlatformFileError error, |
| 1025 const FilePath& /* directory_path */, |
1024 GDataEntry* /* entry */) { | 1026 GDataEntry* /* entry */) { |
1025 if (error != base::PLATFORM_FILE_OK) { | 1027 if (error != base::PLATFORM_FILE_OK) { |
1026 base::AutoLock lock(lock_); | 1028 base::AutoLock lock(lock_); |
1027 root_->set_origin(initial_origin); | 1029 root_->set_origin(initial_origin); |
1028 } | 1030 } |
1029 } | 1031 } |
1030 | 1032 |
1031 bool GDataFileSystem::SetCacheRootPathForTesting(const FilePath& root_path) { | 1033 bool GDataFileSystem::SetCacheRootPathForTesting(const FilePath& root_path) { |
1032 if (cache_initialization_started_) | 1034 if (cache_initialization_started_) |
1033 return false; | 1035 return false; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 const std::string& resource_id, | 1110 const std::string& resource_id, |
1109 const FindEntryCallback& callback) { | 1111 const FindEntryCallback& callback) { |
1110 base::AutoLock lock(lock_); // To access the cache map. | 1112 base::AutoLock lock(lock_); // To access the cache map. |
1111 | 1113 |
1112 GDataFile* file = NULL; | 1114 GDataFile* file = NULL; |
1113 GDataEntry* entry = root_->GetEntryByResourceId(resource_id); | 1115 GDataEntry* entry = root_->GetEntryByResourceId(resource_id); |
1114 if (entry) | 1116 if (entry) |
1115 file = entry->AsGDataFile(); | 1117 file = entry->AsGDataFile(); |
1116 | 1118 |
1117 if (file) | 1119 if (file) |
1118 callback.Run(base::PLATFORM_FILE_OK, file); | 1120 callback.Run(base::PLATFORM_FILE_OK, file->parent()->GetFilePath(), file); |
1119 else | 1121 else |
1120 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, NULL); | 1122 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); |
1121 } | 1123 } |
1122 | 1124 |
1123 void GDataFileSystem::FindEntryByPathAsyncOnUIThread( | 1125 void GDataFileSystem::FindEntryByPathAsyncOnUIThread( |
1124 const FilePath& search_file_path, | 1126 const FilePath& search_file_path, |
1125 const FindEntryCallback& callback) { | 1127 const FindEntryCallback& callback) { |
1126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1127 | 1129 |
1128 base::AutoLock lock(lock_); | 1130 base::AutoLock lock(lock_); |
1129 if (root_->origin() == INITIALIZING) { | 1131 if (root_->origin() == INITIALIZING) { |
1130 // If root feed is not initialized but the initilization process has | 1132 // If root feed is not initialized but the initilization process has |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 feed_list.release(), | 1294 feed_list.release(), |
1293 should_fetch_multiple_feeds, | 1295 should_fetch_multiple_feeds, |
1294 search_file_path, | 1296 search_file_path, |
1295 search_query, | 1297 search_query, |
1296 entry_found_callback)))); | 1298 entry_found_callback)))); |
1297 } | 1299 } |
1298 | 1300 |
1299 void GDataFileSystem::OnFeedFromServerLoaded(GetDocumentsParams* params, | 1301 void GDataFileSystem::OnFeedFromServerLoaded(GetDocumentsParams* params, |
1300 base::PlatformFileError error) { | 1302 base::PlatformFileError error) { |
1301 if (error != base::PLATFORM_FILE_OK) { | 1303 if (error != base::PLATFORM_FILE_OK) { |
1302 if (!params->callback.is_null()) | 1304 if (!params->callback.is_null()) { |
1303 params->callback.Run(error, NULL); | 1305 params->callback.Run(error, FilePath(), |
| 1306 reinterpret_cast<GDataEntry*>(NULL)); |
| 1307 } |
1304 return; | 1308 return; |
1305 } | 1309 } |
1306 | 1310 |
1307 error = UpdateFromFeed(*params->feed_list, | 1311 error = UpdateFromFeed(*params->feed_list, |
1308 FROM_SERVER, | 1312 FROM_SERVER, |
1309 params->start_changestamp, | 1313 params->start_changestamp, |
1310 params->root_feed_changestamp); | 1314 params->root_feed_changestamp); |
1311 | 1315 |
1312 if (error != base::PLATFORM_FILE_OK) { | 1316 if (error != base::PLATFORM_FILE_OK) { |
1313 if (!params->callback.is_null()) | 1317 if (!params->callback.is_null()) { |
1314 params->callback.Run(error, NULL); | 1318 params->callback.Run(error, FilePath(), |
| 1319 reinterpret_cast<GDataEntry*>(NULL)); |
| 1320 } |
1315 | 1321 |
1316 return; | 1322 return; |
1317 } | 1323 } |
1318 | 1324 |
1319 // Save file system metadata to disk. | 1325 // Save file system metadata to disk. |
1320 SaveFileSystemAsProto(); | 1326 SaveFileSystemAsProto(); |
1321 | 1327 |
1322 // If we had someone to report this too, then this retrieval was done in a | 1328 // If we had someone to report this too, then this retrieval was done in a |
1323 // context of search... so continue search. | 1329 // context of search... so continue search. |
1324 if (!params->callback.is_null()) { | 1330 if (!params->callback.is_null()) { |
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2382 | 2388 |
2383 FindEntryByPathAsyncOnUIThread( | 2389 FindEntryByPathAsyncOnUIThread( |
2384 file_path, | 2390 file_path, |
2385 base::Bind(&GDataFileSystem::OnGetEntryInfo, | 2391 base::Bind(&GDataFileSystem::OnGetEntryInfo, |
2386 ui_weak_ptr_, | 2392 ui_weak_ptr_, |
2387 callback)); | 2393 callback)); |
2388 } | 2394 } |
2389 | 2395 |
2390 void GDataFileSystem::OnGetEntryInfo(const GetEntryInfoCallback& callback, | 2396 void GDataFileSystem::OnGetEntryInfo(const GetEntryInfoCallback& callback, |
2391 base::PlatformFileError error, | 2397 base::PlatformFileError error, |
| 2398 const FilePath& directory_path, |
2392 GDataEntry* entry) { | 2399 GDataEntry* entry) { |
2393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2394 | 2401 |
2395 if (error != base::PLATFORM_FILE_OK) { | 2402 if (error != base::PLATFORM_FILE_OK) { |
2396 if (!callback.is_null()) | 2403 if (!callback.is_null()) |
2397 callback.Run(error, FilePath(), scoped_ptr<GDataEntryProto>()); | 2404 callback.Run(error, FilePath(), scoped_ptr<GDataEntryProto>()); |
2398 return; | 2405 return; |
2399 } | 2406 } |
2400 DCHECK(entry); | 2407 DCHECK(entry); |
2401 | 2408 |
(...skipping 27 matching lines...) Expand all Loading... |
2429 GetFileInfoByPathAsyncOnUIThread(file_path, callback); | 2436 GetFileInfoByPathAsyncOnUIThread(file_path, callback); |
2430 } | 2437 } |
2431 | 2438 |
2432 void GDataFileSystem::GetFileInfoByPathAsyncOnUIThread( | 2439 void GDataFileSystem::GetFileInfoByPathAsyncOnUIThread( |
2433 const FilePath& file_path, | 2440 const FilePath& file_path, |
2434 const GetFileInfoCallback& callback) { | 2441 const GetFileInfoCallback& callback) { |
2435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2436 | 2443 |
2437 FindEntryByPathAsyncOnUIThread( | 2444 FindEntryByPathAsyncOnUIThread( |
2438 file_path, | 2445 file_path, |
2439 base::Bind(&GDataFileSystem::OnGetFileInfo, ui_weak_ptr_, callback)); | 2446 base::Bind(&GDataFileSystem::OnGetFileInfo, |
| 2447 ui_weak_ptr_, |
| 2448 callback)); |
2440 } | 2449 } |
2441 | 2450 |
2442 void GDataFileSystem::OnGetFileInfo(const GetFileInfoCallback& callback, | 2451 void GDataFileSystem::OnGetFileInfo(const GetFileInfoCallback& callback, |
2443 base::PlatformFileError error, | 2452 base::PlatformFileError error, |
| 2453 const FilePath& directory_path, |
2444 GDataEntry* entry) { | 2454 GDataEntry* entry) { |
2445 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2446 | 2456 |
2447 if (error != base::PLATFORM_FILE_OK) { | 2457 if (error != base::PLATFORM_FILE_OK) { |
2448 if (!callback.is_null()) | 2458 if (!callback.is_null()) |
2449 callback.Run(error, scoped_ptr<GDataFileProto>()); | 2459 callback.Run(error, scoped_ptr<GDataFileProto>()); |
2450 return; | 2460 return; |
2451 } | 2461 } |
2452 DCHECK(entry); | 2462 DCHECK(entry); |
2453 | 2463 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2494 | 2504 |
2495 FindEntryByPathAsyncOnUIThread( | 2505 FindEntryByPathAsyncOnUIThread( |
2496 file_path, | 2506 file_path, |
2497 base::Bind(&GDataFileSystem::OnReadDirectory, | 2507 base::Bind(&GDataFileSystem::OnReadDirectory, |
2498 ui_weak_ptr_, | 2508 ui_weak_ptr_, |
2499 callback)); | 2509 callback)); |
2500 } | 2510 } |
2501 | 2511 |
2502 void GDataFileSystem::OnReadDirectory(const ReadDirectoryCallback& callback, | 2512 void GDataFileSystem::OnReadDirectory(const ReadDirectoryCallback& callback, |
2503 base::PlatformFileError error, | 2513 base::PlatformFileError error, |
| 2514 const FilePath& directory_path, |
2504 GDataEntry* entry) { | 2515 GDataEntry* entry) { |
2505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2516 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2506 | 2517 |
2507 if (error != base::PLATFORM_FILE_OK) { | 2518 if (error != base::PLATFORM_FILE_OK) { |
2508 if (!callback.is_null()) | 2519 if (!callback.is_null()) |
2509 callback.Run(error, scoped_ptr<GDataDirectoryProto>()); | 2520 callback.Run(error, scoped_ptr<GDataDirectoryProto>()); |
2510 return; | 2521 return; |
2511 } | 2522 } |
2512 DCHECK(entry); | 2523 DCHECK(entry); |
2513 | 2524 |
(...skipping 2587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5101 pref_registrar_->Init(profile_->GetPrefs()); | 5112 pref_registrar_->Init(profile_->GetPrefs()); |
5102 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 5113 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
5103 } | 5114 } |
5104 | 5115 |
5105 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 5116 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
5106 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 5117 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
5107 global_free_disk_getter_for_testing = getter; | 5118 global_free_disk_getter_for_testing = getter; |
5108 } | 5119 } |
5109 | 5120 |
5110 } // namespace gdata | 5121 } // namespace gdata |
OLD | NEW |