| 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/file_system.h" | 5 #include "chrome/browser/chromeos/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/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 // TODO(hashimoto): Support pinning directories. crbug.com/127831 | 472 // TODO(hashimoto): Support pinning directories. crbug.com/127831 |
| 473 if (entry && entry->file_info().is_directory()) | 473 if (entry && entry->file_info().is_directory()) |
| 474 error = FILE_ERROR_NOT_A_FILE; | 474 error = FILE_ERROR_NOT_A_FILE; |
| 475 | 475 |
| 476 if (error != FILE_ERROR_OK) { | 476 if (error != FILE_ERROR_OK) { |
| 477 callback.Run(error); | 477 callback.Run(error); |
| 478 return; | 478 return; |
| 479 } | 479 } |
| 480 DCHECK(entry); | 480 DCHECK(entry); |
| 481 | 481 |
| 482 cache_->Pin(entry->resource_id(), entry->file_specific_info().file_md5(), | 482 cache_->PinOnUIThread(entry->resource_id(), |
| 483 callback); | 483 entry->file_specific_info().file_md5(), callback); |
| 484 } | 484 } |
| 485 | 485 |
| 486 void FileSystem::Unpin(const base::FilePath& file_path, | 486 void FileSystem::Unpin(const base::FilePath& file_path, |
| 487 const FileOperationCallback& callback) { | 487 const FileOperationCallback& callback) { |
| 488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 489 DCHECK(!callback.is_null()); | 489 DCHECK(!callback.is_null()); |
| 490 | 490 |
| 491 GetEntryInfoByPath(file_path, | 491 GetEntryInfoByPath(file_path, |
| 492 base::Bind(&FileSystem::UnpinAfterGetEntryInfoByPath, | 492 base::Bind(&FileSystem::UnpinAfterGetEntryInfoByPath, |
| 493 weak_ptr_factory_.GetWeakPtr(), | 493 weak_ptr_factory_.GetWeakPtr(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 504 // TODO(hashimoto): Support pinning directories. crbug.com/127831 | 504 // TODO(hashimoto): Support pinning directories. crbug.com/127831 |
| 505 if (entry && entry->file_info().is_directory()) | 505 if (entry && entry->file_info().is_directory()) |
| 506 error = FILE_ERROR_NOT_A_FILE; | 506 error = FILE_ERROR_NOT_A_FILE; |
| 507 | 507 |
| 508 if (error != FILE_ERROR_OK) { | 508 if (error != FILE_ERROR_OK) { |
| 509 callback.Run(error); | 509 callback.Run(error); |
| 510 return; | 510 return; |
| 511 } | 511 } |
| 512 DCHECK(entry); | 512 DCHECK(entry); |
| 513 | 513 |
| 514 cache_->Unpin(entry->resource_id(), entry->file_specific_info().file_md5(), | 514 cache_->UnpinOnUIThread(entry->resource_id(), |
| 515 callback); | 515 entry->file_specific_info().file_md5(), callback); |
| 516 } | 516 } |
| 517 | 517 |
| 518 void FileSystem::GetFileByPath(const base::FilePath& file_path, | 518 void FileSystem::GetFileByPath(const base::FilePath& file_path, |
| 519 const GetFileCallback& callback) { | 519 const GetFileCallback& callback) { |
| 520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 521 DCHECK(!callback.is_null()); | 521 DCHECK(!callback.is_null()); |
| 522 | 522 |
| 523 resource_metadata_->GetEntryInfoByPath( | 523 resource_metadata_->GetEntryInfoByPath( |
| 524 file_path, | 524 file_path, |
| 525 base::Bind(&FileSystem::OnGetEntryInfoCompleteForGetFileByPath, | 525 base::Bind(&FileSystem::OnGetEntryInfoCompleteForGetFileByPath, |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 base::Bind( | 852 base::Bind( |
| 853 &FileSystem::GetResolvedFileByPathAfterCreateDocumentJsonFile, | 853 &FileSystem::GetResolvedFileByPathAfterCreateDocumentJsonFile, |
| 854 weak_ptr_factory_.GetWeakPtr(), | 854 weak_ptr_factory_.GetWeakPtr(), |
| 855 base::Passed(¶ms), | 855 base::Passed(¶ms), |
| 856 base::Owned(temp_file_path))); | 856 base::Owned(temp_file_path))); |
| 857 return; | 857 return; |
| 858 } | 858 } |
| 859 | 859 |
| 860 // Returns absolute path of the file if it were cached or to be cached. | 860 // Returns absolute path of the file if it were cached or to be cached. |
| 861 ResourceEntry* entry_ptr = params->entry.get(); | 861 ResourceEntry* entry_ptr = params->entry.get(); |
| 862 cache_->GetFile( | 862 cache_->GetFileOnUIThread( |
| 863 entry_ptr->resource_id(), | 863 entry_ptr->resource_id(), |
| 864 entry_ptr->file_specific_info().file_md5(), | 864 entry_ptr->file_specific_info().file_md5(), |
| 865 base::Bind( | 865 base::Bind( |
| 866 &FileSystem::GetResolvedFileByPathAfterGetFileFromCache, | 866 &FileSystem::GetResolvedFileByPathAfterGetFileFromCache, |
| 867 weak_ptr_factory_.GetWeakPtr(), | 867 weak_ptr_factory_.GetWeakPtr(), |
| 868 base::Passed(¶ms))); | 868 base::Passed(¶ms))); |
| 869 } | 869 } |
| 870 | 870 |
| 871 void FileSystem::GetResolvedFileByPathAfterCreateDocumentJsonFile( | 871 void FileSystem::GetResolvedFileByPathAfterCreateDocumentJsonFile( |
| 872 scoped_ptr<GetResolvedFileParams> params, | 872 scoped_ptr<GetResolvedFileParams> params, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 962 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 963 DCHECK(params); | 963 DCHECK(params); |
| 964 | 964 |
| 965 if (error != FILE_ERROR_OK) { | 965 if (error != FILE_ERROR_OK) { |
| 966 params->OnError(error); | 966 params->OnError(error); |
| 967 return; | 967 return; |
| 968 } | 968 } |
| 969 | 969 |
| 970 int64 file_size = entry->file_info().size(); | 970 int64 file_size = entry->file_info().size(); |
| 971 params->entry = entry.Pass(); // Update the entry in |params|. | 971 params->entry = entry.Pass(); // Update the entry in |params|. |
| 972 cache_->FreeDiskSpaceIfNeededFor( | 972 cache_->FreeDiskSpaceIfNeededForOnUIThread( |
| 973 file_size, | 973 file_size, |
| 974 base::Bind(&FileSystem::GetResolvedFileByPathAfterFreeDiskSpace, | 974 base::Bind(&FileSystem::GetResolvedFileByPathAfterFreeDiskSpace, |
| 975 weak_ptr_factory_.GetWeakPtr(), | 975 weak_ptr_factory_.GetWeakPtr(), |
| 976 base::Passed(¶ms), | 976 base::Passed(¶ms), |
| 977 download_url)); | 977 download_url)); |
| 978 } | 978 } |
| 979 | 979 |
| 980 void FileSystem::GetResolvedFileByPathAfterFreeDiskSpace( | 980 void FileSystem::GetResolvedFileByPathAfterFreeDiskSpace( |
| 981 scoped_ptr<GetResolvedFileParams> params, | 981 scoped_ptr<GetResolvedFileParams> params, |
| 982 const GURL& download_url, | 982 const GURL& download_url, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 void FileSystem::GetResolvedFileByPathAfterDownloadFile( | 1039 void FileSystem::GetResolvedFileByPathAfterDownloadFile( |
| 1040 scoped_ptr<GetResolvedFileParams> params, | 1040 scoped_ptr<GetResolvedFileParams> params, |
| 1041 google_apis::GDataErrorCode status, | 1041 google_apis::GDataErrorCode status, |
| 1042 const base::FilePath& downloaded_file_path) { | 1042 const base::FilePath& downloaded_file_path) { |
| 1043 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1043 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1044 DCHECK(params); | 1044 DCHECK(params); |
| 1045 | 1045 |
| 1046 // If user cancels download of a pinned-but-not-fetched file, mark file as | 1046 // If user cancels download of a pinned-but-not-fetched file, mark file as |
| 1047 // unpinned so that we do not sync the file again. | 1047 // unpinned so that we do not sync the file again. |
| 1048 if (status == google_apis::GDATA_CANCELLED) { | 1048 if (status == google_apis::GDATA_CANCELLED) { |
| 1049 cache_->GetCacheEntry( | 1049 cache_->GetCacheEntryOnUIThread( |
| 1050 params->entry->resource_id(), | 1050 params->entry->resource_id(), |
| 1051 params->entry->file_specific_info().file_md5(), | 1051 params->entry->file_specific_info().file_md5(), |
| 1052 base::Bind( | 1052 base::Bind( |
| 1053 &FileSystem::GetResolvedFileByPathAfterGetCacheEntryForCancel, | 1053 &FileSystem::GetResolvedFileByPathAfterGetCacheEntryForCancel, |
| 1054 weak_ptr_factory_.GetWeakPtr(), | 1054 weak_ptr_factory_.GetWeakPtr(), |
| 1055 params->entry->resource_id(), | 1055 params->entry->resource_id(), |
| 1056 params->entry->file_specific_info().file_md5())); | 1056 params->entry->file_specific_info().file_md5())); |
| 1057 } | 1057 } |
| 1058 | 1058 |
| 1059 FileError error = util::GDataToFileError(status); | 1059 FileError error = util::GDataToFileError(status); |
| 1060 if (error != FILE_ERROR_OK) { | 1060 if (error != FILE_ERROR_OK) { |
| 1061 params->OnError(error); | 1061 params->OnError(error); |
| 1062 return; | 1062 return; |
| 1063 } | 1063 } |
| 1064 | 1064 |
| 1065 ResourceEntry* entry = params->entry.get(); | 1065 ResourceEntry* entry = params->entry.get(); |
| 1066 cache_->Store(entry->resource_id(), | 1066 cache_->StoreOnUIThread( |
| 1067 entry->file_specific_info().file_md5(), | 1067 entry->resource_id(), |
| 1068 downloaded_file_path, | 1068 entry->file_specific_info().file_md5(), |
| 1069 internal::FileCache::FILE_OPERATION_MOVE, | 1069 downloaded_file_path, |
| 1070 base::Bind(&FileSystem::GetResolvedFileByPathAfterStore, | 1070 internal::FileCache::FILE_OPERATION_MOVE, |
| 1071 weak_ptr_factory_.GetWeakPtr(), | 1071 base::Bind(&FileSystem::GetResolvedFileByPathAfterStore, |
| 1072 base::Passed(¶ms), | 1072 weak_ptr_factory_.GetWeakPtr(), |
| 1073 downloaded_file_path)); | 1073 base::Passed(¶ms), |
| 1074 downloaded_file_path)); |
| 1074 } | 1075 } |
| 1075 | 1076 |
| 1076 void FileSystem::GetResolvedFileByPathAfterGetCacheEntryForCancel( | 1077 void FileSystem::GetResolvedFileByPathAfterGetCacheEntryForCancel( |
| 1077 const std::string& resource_id, | 1078 const std::string& resource_id, |
| 1078 const std::string& md5, | 1079 const std::string& md5, |
| 1079 bool success, | 1080 bool success, |
| 1080 const FileCacheEntry& cache_entry) { | 1081 const FileCacheEntry& cache_entry) { |
| 1081 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1082 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1082 // TODO(hshi): http://crbug.com/127138 notify when file properties change. | 1083 // TODO(hshi): http://crbug.com/127138 notify when file properties change. |
| 1083 // This allows file manager to clear the "Available offline" checkbox. | 1084 // This allows file manager to clear the "Available offline" checkbox. |
| 1084 if (success && cache_entry.is_pinned()) { | 1085 if (success && cache_entry.is_pinned()) { |
| 1085 cache_->Unpin(resource_id, | 1086 cache_->UnpinOnUIThread(resource_id, |
| 1086 md5, | 1087 md5, |
| 1087 base::Bind(&util::EmptyFileOperationCallback)); | 1088 base::Bind(&util::EmptyFileOperationCallback)); |
| 1088 } | 1089 } |
| 1089 } | 1090 } |
| 1090 | 1091 |
| 1091 void FileSystem::GetResolvedFileByPathAfterStore( | 1092 void FileSystem::GetResolvedFileByPathAfterStore( |
| 1092 scoped_ptr<GetResolvedFileParams> params, | 1093 scoped_ptr<GetResolvedFileParams> params, |
| 1093 const base::FilePath& downloaded_file_path, | 1094 const base::FilePath& downloaded_file_path, |
| 1094 FileError error) { | 1095 FileError error) { |
| 1095 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1096 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1096 DCHECK(params); | 1097 DCHECK(params); |
| 1097 | 1098 |
| 1098 if (error != FILE_ERROR_OK) { | 1099 if (error != FILE_ERROR_OK) { |
| 1099 blocking_task_runner_->PostTask( | 1100 blocking_task_runner_->PostTask( |
| 1100 FROM_HERE, | 1101 FROM_HERE, |
| 1101 base::Bind(base::IgnoreResult(&file_util::Delete), | 1102 base::Bind(base::IgnoreResult(&file_util::Delete), |
| 1102 downloaded_file_path, | 1103 downloaded_file_path, |
| 1103 false /* recursive*/)); | 1104 false /* recursive*/)); |
| 1104 params->OnError(error); | 1105 params->OnError(error); |
| 1105 return; | 1106 return; |
| 1106 } | 1107 } |
| 1107 // Storing to cache changes the "offline available" status, hence notify. | 1108 // Storing to cache changes the "offline available" status, hence notify. |
| 1108 OnDirectoryChanged(params->drive_file_path.DirName()); | 1109 OnDirectoryChanged(params->drive_file_path.DirName()); |
| 1109 | 1110 |
| 1110 ResourceEntry* entry = params->entry.get(); | 1111 ResourceEntry* entry = params->entry.get(); |
| 1111 cache_->GetFile( | 1112 cache_->GetFileOnUIThread( |
| 1112 entry->resource_id(), | 1113 entry->resource_id(), |
| 1113 entry->file_specific_info().file_md5(), | 1114 entry->file_specific_info().file_md5(), |
| 1114 base::Bind(&FileSystem::GetResolvedFileByPathAfterGetFile, | 1115 base::Bind(&FileSystem::GetResolvedFileByPathAfterGetFile, |
| 1115 weak_ptr_factory_.GetWeakPtr(), | 1116 weak_ptr_factory_.GetWeakPtr(), |
| 1116 base::Passed(¶ms))); | 1117 base::Passed(¶ms))); |
| 1117 } | 1118 } |
| 1118 | 1119 |
| 1119 void FileSystem::GetResolvedFileByPathAfterGetFile( | 1120 void FileSystem::GetResolvedFileByPathAfterGetFile( |
| 1120 scoped_ptr<GetResolvedFileParams> params, | 1121 scoped_ptr<GetResolvedFileParams> params, |
| 1121 FileError error, | 1122 FileError error, |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 if (error != FILE_ERROR_OK && error != FILE_ERROR_EXISTS) { | 1385 if (error != FILE_ERROR_OK && error != FILE_ERROR_EXISTS) { |
| 1385 params.callback.Run(error); | 1386 params.callback.Run(error); |
| 1386 return; | 1387 return; |
| 1387 } | 1388 } |
| 1388 | 1389 |
| 1389 OnDirectoryChanged(file_path.DirName()); | 1390 OnDirectoryChanged(file_path.DirName()); |
| 1390 | 1391 |
| 1391 // At this point, upload to the server is fully succeeded. Failure to store to | 1392 // At this point, upload to the server is fully succeeded. Failure to store to |
| 1392 // cache is not a fatal error, so we wrap the callback with IgnoreError, and | 1393 // cache is not a fatal error, so we wrap the callback with IgnoreError, and |
| 1393 // always return success to the caller. | 1394 // always return success to the caller. |
| 1394 cache_->Store(params.resource_id, | 1395 cache_->StoreOnUIThread(params.resource_id, |
| 1395 params.md5, | 1396 params.md5, |
| 1396 params.file_content_path, | 1397 params.file_content_path, |
| 1397 internal::FileCache::FILE_OPERATION_COPY, | 1398 internal::FileCache::FILE_OPERATION_COPY, |
| 1398 base::Bind(&IgnoreError, params.callback)); | 1399 base::Bind(&IgnoreError, params.callback)); |
| 1399 } | 1400 } |
| 1400 | 1401 |
| 1401 void FileSystem::GetMetadata( | 1402 void FileSystem::GetMetadata( |
| 1402 const GetFilesystemMetadataCallback& callback) { | 1403 const GetFilesystemMetadataCallback& callback) { |
| 1403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1404 DCHECK(!callback.is_null()); | 1405 DCHECK(!callback.is_null()); |
| 1405 | 1406 |
| 1406 FileSystemMetadata metadata; | 1407 FileSystemMetadata metadata; |
| 1407 metadata.refreshing = change_list_loader_->IsRefreshing(); | 1408 metadata.refreshing = change_list_loader_->IsRefreshing(); |
| 1408 | 1409 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1432 scoped_ptr<ResourceEntry> entry) { | 1433 scoped_ptr<ResourceEntry> entry) { |
| 1433 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1434 DCHECK(!callback.is_null()); | 1435 DCHECK(!callback.is_null()); |
| 1435 | 1436 |
| 1436 if (error != FILE_ERROR_OK) { | 1437 if (error != FILE_ERROR_OK) { |
| 1437 callback.Run(error, base::FilePath()); | 1438 callback.Run(error, base::FilePath()); |
| 1438 return; | 1439 return; |
| 1439 } | 1440 } |
| 1440 | 1441 |
| 1441 DCHECK(entry); | 1442 DCHECK(entry); |
| 1442 cache_->MarkAsMounted(entry->resource_id(), | 1443 cache_->MarkAsMountedOnUIThread(entry->resource_id(), |
| 1443 entry->file_specific_info().file_md5(), | 1444 entry->file_specific_info().file_md5(), |
| 1444 callback); | 1445 callback); |
| 1445 } | 1446 } |
| 1446 | 1447 |
| 1447 void FileSystem::MarkCacheFileAsUnmounted( | 1448 void FileSystem::MarkCacheFileAsUnmounted( |
| 1448 const base::FilePath& cache_file_path, | 1449 const base::FilePath& cache_file_path, |
| 1449 const FileOperationCallback& callback) { | 1450 const FileOperationCallback& callback) { |
| 1450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1451 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1451 DCHECK(!callback.is_null()); | 1452 DCHECK(!callback.is_null()); |
| 1452 | 1453 |
| 1453 if (!cache_->IsUnderFileCacheDirectory(cache_file_path)) { | 1454 if (!cache_->IsUnderFileCacheDirectory(cache_file_path)) { |
| 1454 callback.Run(FILE_ERROR_FAILED); | 1455 callback.Run(FILE_ERROR_FAILED); |
| 1455 return; | 1456 return; |
| 1456 } | 1457 } |
| 1457 cache_->MarkAsUnmounted(cache_file_path, callback); | 1458 cache_->MarkAsUnmountedOnUIThread(cache_file_path, callback); |
| 1458 } | 1459 } |
| 1459 | 1460 |
| 1460 void FileSystem::GetCacheEntryByResourceId( | 1461 void FileSystem::GetCacheEntryByResourceId( |
| 1461 const std::string& resource_id, | 1462 const std::string& resource_id, |
| 1462 const std::string& md5, | 1463 const std::string& md5, |
| 1463 const GetCacheEntryCallback& callback) { | 1464 const GetCacheEntryCallback& callback) { |
| 1464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1465 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1465 DCHECK(!resource_id.empty()); | 1466 DCHECK(!resource_id.empty()); |
| 1466 DCHECK(!callback.is_null()); | 1467 DCHECK(!callback.is_null()); |
| 1467 | 1468 |
| 1468 cache_->GetCacheEntry(resource_id, md5, callback); | 1469 cache_->GetCacheEntryOnUIThread(resource_id, md5, callback); |
| 1469 } | 1470 } |
| 1470 | 1471 |
| 1471 void FileSystem::OnDisableDriveHostedFilesChanged() { | 1472 void FileSystem::OnDisableDriveHostedFilesChanged() { |
| 1472 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1473 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1473 PrefService* pref_service = profile_->GetPrefs(); | 1474 PrefService* pref_service = profile_->GetPrefs(); |
| 1474 SetHideHostedDocuments( | 1475 SetHideHostedDocuments( |
| 1475 pref_service->GetBoolean(prefs::kDisableDriveHostedFiles)); | 1476 pref_service->GetBoolean(prefs::kDisableDriveHostedFiles)); |
| 1476 } | 1477 } |
| 1477 | 1478 |
| 1478 void FileSystem::SetHideHostedDocuments(bool hide) { | 1479 void FileSystem::SetHideHostedDocuments(bool hide) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1582 DCHECK(!params.callback.is_null()); | 1583 DCHECK(!params.callback.is_null()); |
| 1583 | 1584 |
| 1584 if (error != FILE_ERROR_OK) { | 1585 if (error != FILE_ERROR_OK) { |
| 1585 params.callback.Run(error, base::FilePath()); | 1586 params.callback.Run(error, base::FilePath()); |
| 1586 return; | 1587 return; |
| 1587 } | 1588 } |
| 1588 | 1589 |
| 1589 // OpenFile ensures that the file is a regular file. | 1590 // OpenFile ensures that the file is a regular file. |
| 1590 DCHECK(entry && !entry->file_specific_info().is_hosted_document()); | 1591 DCHECK(entry && !entry->file_specific_info().is_hosted_document()); |
| 1591 | 1592 |
| 1592 cache_->MarkDirty( | 1593 cache_->MarkDirtyOnUIThread( |
| 1593 params.resource_id, | 1594 params.resource_id, |
| 1594 params.md5, | 1595 params.md5, |
| 1595 base::Bind(&FileSystem::OnMarkDirtyInCacheCompleteForOpenFile, | 1596 base::Bind(&FileSystem::OnMarkDirtyInCacheCompleteForOpenFile, |
| 1596 weak_ptr_factory_.GetWeakPtr(), | 1597 weak_ptr_factory_.GetWeakPtr(), |
| 1597 params)); | 1598 params)); |
| 1598 } | 1599 } |
| 1599 | 1600 |
| 1600 void FileSystem::OnMarkDirtyInCacheCompleteForOpenFile( | 1601 void FileSystem::OnMarkDirtyInCacheCompleteForOpenFile( |
| 1601 const GetFileCompleteForOpenParams& params, | 1602 const GetFileCompleteForOpenParams& params, |
| 1602 FileError error) { | 1603 FileError error) { |
| 1603 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1604 DCHECK(!params.callback.is_null()); | 1605 DCHECK(!params.callback.is_null()); |
| 1605 | 1606 |
| 1606 if (error != FILE_ERROR_OK) { | 1607 if (error != FILE_ERROR_OK) { |
| 1607 params.callback.Run(error, base::FilePath()); | 1608 params.callback.Run(error, base::FilePath()); |
| 1608 return; | 1609 return; |
| 1609 } | 1610 } |
| 1610 | 1611 |
| 1611 cache_->GetFile(params.resource_id, params.md5, params.callback); | 1612 cache_->GetFileOnUIThread(params.resource_id, params.md5, params.callback); |
| 1612 } | 1613 } |
| 1613 | 1614 |
| 1614 void FileSystem::OnOpenFileFinished( | 1615 void FileSystem::OnOpenFileFinished( |
| 1615 const base::FilePath& file_path, | 1616 const base::FilePath& file_path, |
| 1616 const OpenFileCallback& callback, | 1617 const OpenFileCallback& callback, |
| 1617 FileError result, | 1618 FileError result, |
| 1618 const base::FilePath& cache_file_path) { | 1619 const base::FilePath& cache_file_path) { |
| 1619 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1620 DCHECK(!callback.is_null()); | 1621 DCHECK(!callback.is_null()); |
| 1621 | 1622 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1668 callback.Run(error); | 1669 callback.Run(error); |
| 1669 return; | 1670 return; |
| 1670 } | 1671 } |
| 1671 | 1672 |
| 1672 // Step 2 of CloseFile: Commit the modification in cache. This will trigger | 1673 // Step 2 of CloseFile: Commit the modification in cache. This will trigger |
| 1673 // background upload. | 1674 // background upload. |
| 1674 // TODO(benchan,kinaba): Call ClearDirtyInCache instead of CommitDirtyInCache | 1675 // TODO(benchan,kinaba): Call ClearDirtyInCache instead of CommitDirtyInCache |
| 1675 // if the file has not been modified. Come up with a way to detect the | 1676 // if the file has not been modified. Come up with a way to detect the |
| 1676 // intactness effectively, or provide a method for user to declare it when | 1677 // intactness effectively, or provide a method for user to declare it when |
| 1677 // calling CloseFile(). | 1678 // calling CloseFile(). |
| 1678 cache_->CommitDirty(entry->resource_id(), | 1679 cache_->CommitDirtyOnUIThread(entry->resource_id(), |
| 1679 entry->file_specific_info().file_md5(), | 1680 entry->file_specific_info().file_md5(), |
| 1680 callback); | 1681 callback); |
| 1681 } | 1682 } |
| 1682 | 1683 |
| 1683 void FileSystem::CloseFileFinalize(const base::FilePath& file_path, | 1684 void FileSystem::CloseFileFinalize(const base::FilePath& file_path, |
| 1684 const FileOperationCallback& callback, | 1685 const FileOperationCallback& callback, |
| 1685 FileError result) { | 1686 FileError result) { |
| 1686 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1687 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1687 DCHECK(!callback.is_null()); | 1688 DCHECK(!callback.is_null()); |
| 1688 | 1689 |
| 1689 // Step 3 of CloseFile. | 1690 // Step 3 of CloseFile. |
| 1690 // All the invocation of |callback| from operations initiated from CloseFile | 1691 // All the invocation of |callback| from operations initiated from CloseFile |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1706 // For entries that will never be cached, use the original entry info as is. | 1707 // For entries that will never be cached, use the original entry info as is. |
| 1707 if (!entry->has_file_specific_info() || | 1708 if (!entry->has_file_specific_info() || |
| 1708 entry->file_specific_info().is_hosted_document()) { | 1709 entry->file_specific_info().is_hosted_document()) { |
| 1709 callback.Run(FILE_ERROR_OK, entry.Pass()); | 1710 callback.Run(FILE_ERROR_OK, entry.Pass()); |
| 1710 return; | 1711 return; |
| 1711 } | 1712 } |
| 1712 | 1713 |
| 1713 // Checks if the file is cached and modified locally. | 1714 // Checks if the file is cached and modified locally. |
| 1714 const std::string resource_id = entry->resource_id(); | 1715 const std::string resource_id = entry->resource_id(); |
| 1715 const std::string md5 = entry->file_specific_info().file_md5(); | 1716 const std::string md5 = entry->file_specific_info().file_md5(); |
| 1716 cache_->GetCacheEntry( | 1717 cache_->GetCacheEntryOnUIThread( |
| 1717 resource_id, | 1718 resource_id, |
| 1718 md5, | 1719 md5, |
| 1719 base::Bind( | 1720 base::Bind( |
| 1720 &FileSystem::CheckLocalModificationAndRunAfterGetCacheEntry, | 1721 &FileSystem::CheckLocalModificationAndRunAfterGetCacheEntry, |
| 1721 weak_ptr_factory_.GetWeakPtr(), | 1722 weak_ptr_factory_.GetWeakPtr(), |
| 1722 base::Passed(&entry), | 1723 base::Passed(&entry), |
| 1723 callback)); | 1724 callback)); |
| 1724 } | 1725 } |
| 1725 | 1726 |
| 1726 void FileSystem::CheckLocalModificationAndRunAfterGetCacheEntry( | 1727 void FileSystem::CheckLocalModificationAndRunAfterGetCacheEntry( |
| 1727 scoped_ptr<ResourceEntry> entry, | 1728 scoped_ptr<ResourceEntry> entry, |
| 1728 const GetEntryInfoCallback& callback, | 1729 const GetEntryInfoCallback& callback, |
| 1729 bool success, | 1730 bool success, |
| 1730 const FileCacheEntry& cache_entry) { | 1731 const FileCacheEntry& cache_entry) { |
| 1731 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1732 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1732 DCHECK(!callback.is_null()); | 1733 DCHECK(!callback.is_null()); |
| 1733 | 1734 |
| 1734 // When no dirty cache is found, use the original entry info as is. | 1735 // When no dirty cache is found, use the original entry info as is. |
| 1735 if (!success || !cache_entry.is_dirty()) { | 1736 if (!success || !cache_entry.is_dirty()) { |
| 1736 callback.Run(FILE_ERROR_OK, entry.Pass()); | 1737 callback.Run(FILE_ERROR_OK, entry.Pass()); |
| 1737 return; | 1738 return; |
| 1738 } | 1739 } |
| 1739 | 1740 |
| 1740 // Gets the cache file path. | 1741 // Gets the cache file path. |
| 1741 const std::string& resource_id = entry->resource_id(); | 1742 const std::string& resource_id = entry->resource_id(); |
| 1742 const std::string& md5 = entry->file_specific_info().file_md5(); | 1743 const std::string& md5 = entry->file_specific_info().file_md5(); |
| 1743 cache_->GetFile( | 1744 cache_->GetFileOnUIThread( |
| 1744 resource_id, | 1745 resource_id, |
| 1745 md5, | 1746 md5, |
| 1746 base::Bind( | 1747 base::Bind( |
| 1747 &FileSystem::CheckLocalModificationAndRunAfterGetCacheFile, | 1748 &FileSystem::CheckLocalModificationAndRunAfterGetCacheFile, |
| 1748 weak_ptr_factory_.GetWeakPtr(), | 1749 weak_ptr_factory_.GetWeakPtr(), |
| 1749 base::Passed(&entry), | 1750 base::Passed(&entry), |
| 1750 callback)); | 1751 callback)); |
| 1751 } | 1752 } |
| 1752 | 1753 |
| 1753 void FileSystem::CheckLocalModificationAndRunAfterGetCacheFile( | 1754 void FileSystem::CheckLocalModificationAndRunAfterGetCacheFile( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1796 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info); | 1797 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info); |
| 1797 *entry->mutable_file_info() = entry_file_info; | 1798 *entry->mutable_file_info() = entry_file_info; |
| 1798 callback.Run(FILE_ERROR_OK, entry.Pass()); | 1799 callback.Run(FILE_ERROR_OK, entry.Pass()); |
| 1799 } | 1800 } |
| 1800 | 1801 |
| 1801 void FileSystem::CancelJobInScheduler(JobID id) { | 1802 void FileSystem::CancelJobInScheduler(JobID id) { |
| 1802 scheduler_->CancelJob(id); | 1803 scheduler_->CancelJob(id); |
| 1803 } | 1804 } |
| 1804 | 1805 |
| 1805 } // namespace drive | 1806 } // namespace drive |
| OLD | NEW |