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_cache.h" | 5 #include "chrome/browser/chromeos/drive/file_cache.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 | 375 |
376 FileError FileCache::Store(const std::string& resource_id, | 376 FileError FileCache::Store(const std::string& resource_id, |
377 const std::string& md5, | 377 const std::string& md5, |
378 const base::FilePath& source_path, | 378 const base::FilePath& source_path, |
379 FileOperationType file_operation_type) { | 379 FileOperationType file_operation_type) { |
380 AssertOnSequencedWorkerPool(); | 380 AssertOnSequencedWorkerPool(); |
381 return StoreInternal(resource_id, md5, source_path, file_operation_type, | 381 return StoreInternal(resource_id, md5, source_path, file_operation_type, |
382 CACHED_FILE_FROM_SERVER); | 382 CACHED_FILE_FROM_SERVER); |
383 } | 383 } |
384 | 384 |
385 void FileCache::StoreLocallyModifiedOnUIThread( | |
386 const std::string& resource_id, | |
387 const std::string& md5, | |
388 const base::FilePath& source_path, | |
389 FileOperationType file_operation_type, | |
390 const FileOperationCallback& callback) { | |
391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
392 DCHECK(!callback.is_null()); | |
393 | |
394 base::PostTaskAndReplyWithResult( | |
395 blocking_task_runner_, | |
396 FROM_HERE, | |
397 base::Bind(&FileCache::StoreInternal, | |
398 base::Unretained(this), | |
399 resource_id, md5, source_path, file_operation_type, | |
400 CACHED_FILE_LOCALLY_MODIFIED), | |
kinaba
2013/06/11 07:08:37
Except this call StoreInternal is called always wi
hashimoto
2013/06/11 07:37:57
Done.
I'll merge StoreInternal to Store in another
| |
401 base::Bind(&FileCache::OnCommitDirty, | |
402 weak_ptr_factory_.GetWeakPtr(), resource_id, callback)); | |
403 } | |
404 | |
405 void FileCache::PinOnUIThread(const std::string& resource_id, | 385 void FileCache::PinOnUIThread(const std::string& resource_id, |
406 const std::string& md5, | 386 const std::string& md5, |
407 const FileOperationCallback& callback) { | 387 const FileOperationCallback& callback) { |
408 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
409 DCHECK(!callback.is_null()); | 389 DCHECK(!callback.is_null()); |
410 | 390 |
411 base::PostTaskAndReplyWithResult( | 391 base::PostTaskAndReplyWithResult( |
412 blocking_task_runner_, | 392 blocking_task_runner_, |
413 FROM_HERE, | 393 FROM_HERE, |
414 base::Bind(&FileCache::Pin, | 394 base::Bind(&FileCache::Pin, |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 return FILE_ERROR_FAILED; | 600 return FILE_ERROR_FAILED; |
621 | 601 |
622 // Now that file operations have completed, update metadata. | 602 // Now that file operations have completed, update metadata. |
623 cache_entry.set_md5(md5); | 603 cache_entry.set_md5(md5); |
624 cache_entry.set_is_dirty(true); | 604 cache_entry.set_is_dirty(true); |
625 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); | 605 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); |
626 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); | 606 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); |
627 return FILE_ERROR_OK; | 607 return FILE_ERROR_OK; |
628 } | 608 } |
629 | 609 |
630 void FileCache::CommitDirtyOnUIThread(const std::string& resource_id, | |
631 const std::string& md5, | |
632 const FileOperationCallback& callback) { | |
633 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
634 DCHECK(!callback.is_null()); | |
635 | |
636 // TODO(hashimoto): Move logic around OnCommitDirty to FileSystem and remove | |
637 // this method. | |
638 base::MessageLoopProxy::current()->PostTask( | |
639 FROM_HERE, | |
640 base::Bind(&FileCache::OnCommitDirty, | |
641 weak_ptr_factory_.GetWeakPtr(), resource_id, callback, | |
642 FILE_ERROR_OK)); | |
643 } | |
644 | |
645 FileError FileCache::ClearDirty(const std::string& resource_id, | 610 FileError FileCache::ClearDirty(const std::string& resource_id, |
646 const std::string& md5) { | 611 const std::string& md5) { |
647 AssertOnSequencedWorkerPool(); | 612 AssertOnSequencedWorkerPool(); |
648 | 613 |
649 // |md5| is the new .<md5> extension to rename the file to. | 614 // |md5| is the new .<md5> extension to rename the file to. |
650 // So, search for entry in cache without comparing md5. | 615 // So, search for entry in cache without comparing md5. |
651 FileCacheEntry cache_entry; | 616 FileCacheEntry cache_entry; |
652 | 617 |
653 // Clearing a dirty file means its entry and actual file blob must exist in | 618 // Clearing a dirty file means its entry and actual file blob must exist in |
654 // cache. | 619 // cache. |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1037 | 1002 |
1038 // Now the file is moved from "persistent" to "tmp" directory. | 1003 // Now the file is moved from "persistent" to "tmp" directory. |
1039 // It's a chance to free up space if needed. | 1004 // It's a chance to free up space if needed. |
1040 blocking_task_runner_->PostTask( | 1005 blocking_task_runner_->PostTask( |
1041 FROM_HERE, | 1006 FROM_HERE, |
1042 base::Bind( | 1007 base::Bind( |
1043 base::IgnoreResult(&FileCache::FreeDiskSpaceIfNeededFor), | 1008 base::IgnoreResult(&FileCache::FreeDiskSpaceIfNeededFor), |
1044 base::Unretained(this), 0)); | 1009 base::Unretained(this), 0)); |
1045 } | 1010 } |
1046 | 1011 |
1047 void FileCache::OnCommitDirty(const std::string& resource_id, | |
1048 const FileOperationCallback& callback, | |
1049 FileError error) { | |
1050 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1051 DCHECK(!callback.is_null()); | |
1052 | |
1053 callback.Run(error); | |
1054 | |
1055 if (error == FILE_ERROR_OK) | |
1056 FOR_EACH_OBSERVER(FileCacheObserver, | |
1057 observers_, | |
1058 OnCacheCommitted(resource_id)); | |
1059 } | |
1060 | |
1061 bool FileCache::HasEnoughSpaceFor(int64 num_bytes, | 1012 bool FileCache::HasEnoughSpaceFor(int64 num_bytes, |
1062 const base::FilePath& path) { | 1013 const base::FilePath& path) { |
1063 int64 free_space = 0; | 1014 int64 free_space = 0; |
1064 if (free_disk_space_getter_) | 1015 if (free_disk_space_getter_) |
1065 free_space = free_disk_space_getter_->AmountOfFreeDiskSpace(); | 1016 free_space = free_disk_space_getter_->AmountOfFreeDiskSpace(); |
1066 else | 1017 else |
1067 free_space = base::SysInfo::AmountOfFreeDiskSpace(path); | 1018 free_space = base::SysInfo::AmountOfFreeDiskSpace(path); |
1068 | 1019 |
1069 // Subtract this as if this portion does not exist. | 1020 // Subtract this as if this portion does not exist. |
1070 free_space -= kMinFreeSpace; | 1021 free_space -= kMinFreeSpace; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1105 } | 1056 } |
1106 | 1057 |
1107 // static | 1058 // static |
1108 FileCache::CacheSubDirectoryType FileCache::GetSubDirectoryType( | 1059 FileCache::CacheSubDirectoryType FileCache::GetSubDirectoryType( |
1109 const FileCacheEntry& cache_entry) { | 1060 const FileCacheEntry& cache_entry) { |
1110 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1061 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
1111 } | 1062 } |
1112 | 1063 |
1113 } // namespace internal | 1064 } // namespace internal |
1114 } // namespace drive | 1065 } // namespace drive |
OLD | NEW |