Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: chrome/browser/chromeos/drive/file_system.cc

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

Powered by Google App Engine
This is Rietveld 408576698