| 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/drive/drive_file_system.h" | 5 #include "chrome/browser/chromeos/drive/drive_file_system.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 } | 841 } |
| 842 | 842 |
| 843 // For a hosted document, we create a special JSON file to represent the | 843 // For a hosted document, we create a special JSON file to represent the |
| 844 // document instead of fetching the document content in one of the exported | 844 // document instead of fetching the document content in one of the exported |
| 845 // formats. The JSON file contains the edit URL and resource ID of the | 845 // formats. The JSON file contains the edit URL and resource ID of the |
| 846 // document. | 846 // document. |
| 847 if (entry_proto->file_specific_info().is_hosted_document()) { | 847 if (entry_proto->file_specific_info().is_hosted_document()) { |
| 848 FilePath* temp_file_path = new FilePath; | 848 FilePath* temp_file_path = new FilePath; |
| 849 const std::string mime_type = kMimeTypeJson; | 849 const std::string mime_type = kMimeTypeJson; |
| 850 const DriveFileType file_type = HOSTED_DOCUMENT; | 850 const DriveFileType file_type = HOSTED_DOCUMENT; |
| 851 google_apis::util::PostBlockingPoolSequencedTaskAndReplyWithResult( | 851 base::PostTaskAndReplyWithResult( |
| 852 blocking_task_runner_, |
| 852 FROM_HERE, | 853 FROM_HERE, |
| 853 blocking_task_runner_, | |
| 854 base::Bind(&CreateDocumentJsonFileOnBlockingPool, | 854 base::Bind(&CreateDocumentJsonFileOnBlockingPool, |
| 855 cache_->GetCacheDirectoryPath( | 855 cache_->GetCacheDirectoryPath( |
| 856 DriveCache::CACHE_TYPE_TMP_DOCUMENTS), | 856 DriveCache::CACHE_TYPE_TMP_DOCUMENTS), |
| 857 GURL(entry_proto->file_specific_info().alternate_url()), | 857 GURL(entry_proto->file_specific_info().alternate_url()), |
| 858 entry_proto->resource_id(), | 858 entry_proto->resource_id(), |
| 859 temp_file_path), | 859 temp_file_path), |
| 860 base::Bind(&RunGetFileCallbackHelper, | 860 base::Bind(&RunGetFileCallbackHelper, |
| 861 get_file_callback, | 861 get_file_callback, |
| 862 base::Owned(temp_file_path), | 862 base::Owned(temp_file_path), |
| 863 mime_type, | 863 mime_type, |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 DCHECK(!params.get_file_callback.is_null()); | 1034 DCHECK(!params.get_file_callback.is_null()); |
| 1035 | 1035 |
| 1036 if (error != DRIVE_FILE_OK) { | 1036 if (error != DRIVE_FILE_OK) { |
| 1037 params.get_file_callback.Run(error, | 1037 params.get_file_callback.Run(error, |
| 1038 params.cache_file_path, | 1038 params.cache_file_path, |
| 1039 params.mime_type, | 1039 params.mime_type, |
| 1040 REGULAR_FILE); | 1040 REGULAR_FILE); |
| 1041 return; | 1041 return; |
| 1042 } | 1042 } |
| 1043 | 1043 |
| 1044 google_apis::util::PostBlockingPoolSequencedTaskAndReplyWithResult( | 1044 base::PostTaskAndReplyWithResult( |
| 1045 blocking_task_runner_, |
| 1045 FROM_HERE, | 1046 FROM_HERE, |
| 1046 blocking_task_runner_, | |
| 1047 base::Bind(&DriveCache::FreeDiskSpaceOnBlockingPoolIfNeededFor, | 1047 base::Bind(&DriveCache::FreeDiskSpaceOnBlockingPoolIfNeededFor, |
| 1048 base::Unretained(cache_), | 1048 base::Unretained(cache_), |
| 1049 file_size), | 1049 file_size), |
| 1050 base::Bind(&DriveFileSystem::StartDownloadFileIfEnoughSpace, | 1050 base::Bind(&DriveFileSystem::StartDownloadFileIfEnoughSpace, |
| 1051 ui_weak_ptr_, | 1051 ui_weak_ptr_, |
| 1052 params, | 1052 params, |
| 1053 content_url, | 1053 content_url, |
| 1054 params.cache_file_path)); | 1054 params.cache_file_path)); |
| 1055 } | 1055 } |
| 1056 | 1056 |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 DCHECK(!callback.is_null()); | 1343 DCHECK(!callback.is_null()); |
| 1344 | 1344 |
| 1345 if (error != DRIVE_FILE_OK) { | 1345 if (error != DRIVE_FILE_OK) { |
| 1346 callback.Run(error); | 1346 callback.Run(error); |
| 1347 return; | 1347 return; |
| 1348 } | 1348 } |
| 1349 | 1349 |
| 1350 // Gets the size of the cache file. Since the file is locally modified, the | 1350 // Gets the size of the cache file. Since the file is locally modified, the |
| 1351 // file size information stored in DriveEntry is not correct. | 1351 // file size information stored in DriveEntry is not correct. |
| 1352 int64* file_size = new int64(0); | 1352 int64* file_size = new int64(0); |
| 1353 google_apis::util::PostBlockingPoolSequencedTaskAndReplyWithResult( | 1353 base::PostTaskAndReplyWithResult( |
| 1354 blocking_task_runner_, |
| 1354 FROM_HERE, | 1355 FROM_HERE, |
| 1355 blocking_task_runner_, | |
| 1356 base::Bind(&file_util::GetFileSize, | 1356 base::Bind(&file_util::GetFileSize, |
| 1357 cache_file_path, | 1357 cache_file_path, |
| 1358 file_size), | 1358 file_size), |
| 1359 base::Bind(&DriveFileSystem::OnGetFileSizeCompleteForUpdateFile, | 1359 base::Bind(&DriveFileSystem::OnGetFileSizeCompleteForUpdateFile, |
| 1360 ui_weak_ptr_, | 1360 ui_weak_ptr_, |
| 1361 callback, | 1361 callback, |
| 1362 drive_file_path, | 1362 drive_file_path, |
| 1363 base::Passed(&entry_proto), | 1363 base::Passed(&entry_proto), |
| 1364 cache_file_path, | 1364 cache_file_path, |
| 1365 base::Owned(file_size))); | 1365 base::Owned(file_size))); |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1729 } | 1729 } |
| 1730 | 1730 |
| 1731 // At this point, the disk can be full or nearly full for several reasons: | 1731 // At this point, the disk can be full or nearly full for several reasons: |
| 1732 // - The expected file size was incorrect and the file was larger | 1732 // - The expected file size was incorrect and the file was larger |
| 1733 // - There was an in-flight download operation and it used up space | 1733 // - There was an in-flight download operation and it used up space |
| 1734 // - The disk became full for some user actions we cannot control | 1734 // - The disk became full for some user actions we cannot control |
| 1735 // (ex. the user might have downloaded a large file from a regular web site) | 1735 // (ex. the user might have downloaded a large file from a regular web site) |
| 1736 // | 1736 // |
| 1737 // If we don't have enough space, we return PLATFORM_FILE_ERROR_NO_SPACE, | 1737 // If we don't have enough space, we return PLATFORM_FILE_ERROR_NO_SPACE, |
| 1738 // and try to free up space, even if the file was downloaded successfully. | 1738 // and try to free up space, even if the file was downloaded successfully. |
| 1739 google_apis::util::PostBlockingPoolSequencedTaskAndReplyWithResult( | 1739 base::PostTaskAndReplyWithResult( |
| 1740 blocking_task_runner_, |
| 1740 FROM_HERE, | 1741 FROM_HERE, |
| 1741 blocking_task_runner_, | |
| 1742 base::Bind(&DriveCache::FreeDiskSpaceOnBlockingPoolIfNeededFor, | 1742 base::Bind(&DriveCache::FreeDiskSpaceOnBlockingPoolIfNeededFor, |
| 1743 base::Unretained(cache_), | 1743 base::Unretained(cache_), |
| 1744 0), | 1744 0), |
| 1745 base::Bind(&DriveFileSystem::OnFileDownloadedAndSpaceChecked, | 1745 base::Bind(&DriveFileSystem::OnFileDownloadedAndSpaceChecked, |
| 1746 ui_weak_ptr_, | 1746 ui_weak_ptr_, |
| 1747 params, | 1747 params, |
| 1748 status, | 1748 status, |
| 1749 content_url, | 1749 content_url, |
| 1750 downloaded_file_path)); | 1750 downloaded_file_path)); |
| 1751 } | 1751 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1780 if (has_enough_space) { | 1780 if (has_enough_space) { |
| 1781 cache_->Store(params.resource_id, | 1781 cache_->Store(params.resource_id, |
| 1782 params.md5, | 1782 params.md5, |
| 1783 downloaded_file_path, | 1783 downloaded_file_path, |
| 1784 DriveCache::FILE_OPERATION_MOVE, | 1784 DriveCache::FILE_OPERATION_MOVE, |
| 1785 base::Bind(&DriveFileSystem::OnDownloadStoredToCache, | 1785 base::Bind(&DriveFileSystem::OnDownloadStoredToCache, |
| 1786 ui_weak_ptr_)); | 1786 ui_weak_ptr_)); |
| 1787 } else { | 1787 } else { |
| 1788 // If we don't have enough space, remove the downloaded file, and | 1788 // If we don't have enough space, remove the downloaded file, and |
| 1789 // report "no space" error. | 1789 // report "no space" error. |
| 1790 google_apis::util::PostBlockingPoolSequencedTask( | 1790 blocking_task_runner_->PostTask( |
| 1791 FROM_HERE, | 1791 FROM_HERE, |
| 1792 blocking_task_runner_, | |
| 1793 base::Bind(base::IgnoreResult(&file_util::Delete), | 1792 base::Bind(base::IgnoreResult(&file_util::Delete), |
| 1794 downloaded_file_path, | 1793 downloaded_file_path, |
| 1795 false /* recursive*/)); | 1794 false /* recursive*/)); |
| 1796 error = DRIVE_FILE_ERROR_NO_SPACE; | 1795 error = DRIVE_FILE_ERROR_NO_SPACE; |
| 1797 } | 1796 } |
| 1798 } | 1797 } |
| 1799 | 1798 |
| 1800 params.get_file_callback.Run(error, | 1799 params.get_file_callback.Run(error, |
| 1801 downloaded_file_path, | 1800 downloaded_file_path, |
| 1802 params.mime_type, | 1801 params.mime_type, |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2373 DCHECK(!callback.is_null()); | 2372 DCHECK(!callback.is_null()); |
| 2374 | 2373 |
| 2375 // When no dirty cache is found, use the original entry info as is. | 2374 // When no dirty cache is found, use the original entry info as is. |
| 2376 if (error != DRIVE_FILE_OK) { | 2375 if (error != DRIVE_FILE_OK) { |
| 2377 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); | 2376 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
| 2378 return; | 2377 return; |
| 2379 } | 2378 } |
| 2380 | 2379 |
| 2381 // If the cache is dirty, obtain the file info from the cache file itself. | 2380 // If the cache is dirty, obtain the file info from the cache file itself. |
| 2382 base::PlatformFileInfo* file_info = new base::PlatformFileInfo; | 2381 base::PlatformFileInfo* file_info = new base::PlatformFileInfo; |
| 2383 google_apis::util::PostBlockingPoolSequencedTaskAndReplyWithResult( | 2382 base::PostTaskAndReplyWithResult( |
| 2383 blocking_task_runner_, |
| 2384 FROM_HERE, | 2384 FROM_HERE, |
| 2385 blocking_task_runner_, | |
| 2386 base::Bind(&file_util::GetFileInfo, | 2385 base::Bind(&file_util::GetFileInfo, |
| 2387 local_cache_path, | 2386 local_cache_path, |
| 2388 base::Unretained(file_info)), | 2387 base::Unretained(file_info)), |
| 2389 base::Bind(&DriveFileSystem::CheckLocalModificationAndRunAfterGetFileInfo, | 2388 base::Bind(&DriveFileSystem::CheckLocalModificationAndRunAfterGetFileInfo, |
| 2390 ui_weak_ptr_, | 2389 ui_weak_ptr_, |
| 2391 base::Passed(&entry_proto), | 2390 base::Passed(&entry_proto), |
| 2392 callback, | 2391 callback, |
| 2393 base::Owned(file_info))); | 2392 base::Owned(file_info))); |
| 2394 } | 2393 } |
| 2395 | 2394 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2406 return; | 2405 return; |
| 2407 } | 2406 } |
| 2408 | 2407 |
| 2409 PlatformFileInfoProto entry_file_info; | 2408 PlatformFileInfoProto entry_file_info; |
| 2410 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 2409 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
| 2411 *entry_proto->mutable_file_info() = entry_file_info; | 2410 *entry_proto->mutable_file_info() = entry_file_info; |
| 2412 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); | 2411 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
| 2413 } | 2412 } |
| 2414 | 2413 |
| 2415 } // namespace drive | 2414 } // namespace drive |
| OLD | NEW |