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