| 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 #ifndef COMPONENTS_DRIVE_CHROMEOS_FILE_CACHE_H_ | 5 #ifndef COMPONENTS_DRIVE_CHROMEOS_FILE_CACHE_H_ |
| 6 #define COMPONENTS_DRIVE_CHROMEOS_FILE_CACHE_H_ | 6 #define COMPONENTS_DRIVE_CHROMEOS_FILE_CACHE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 virtual ~FreeDiskSpaceGetterInterface() {} | 46 virtual ~FreeDiskSpaceGetterInterface() {} |
| 47 virtual int64_t AmountOfFreeDiskSpace() = 0; | 47 virtual int64_t AmountOfFreeDiskSpace() = 0; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 // FileCache is used to maintain cache states of FileSystem. | 50 // FileCache is used to maintain cache states of FileSystem. |
| 51 // | 51 // |
| 52 // All non-static public member functions, unless mentioned otherwise (see | 52 // All non-static public member functions, unless mentioned otherwise (see |
| 53 // GetCacheFilePath() for example), should be run with |blocking_task_runner|. | 53 // GetCacheFilePath() for example), should be run with |blocking_task_runner|. |
| 54 class FileCache { | 54 class FileCache { |
| 55 public: | 55 public: |
| 56 // The file extended attribute assigned to Drive cache directory. |
| 57 static const char kGCacheFilesAttribute[]; |
| 58 |
| 56 // Enum defining type of file operation e.g. copy or move, etc. | 59 // Enum defining type of file operation e.g. copy or move, etc. |
| 57 enum FileOperationType { | 60 enum FileOperationType { |
| 58 FILE_OPERATION_MOVE = 0, | 61 FILE_OPERATION_MOVE = 0, |
| 59 FILE_OPERATION_COPY, | 62 FILE_OPERATION_COPY, |
| 60 }; | 63 }; |
| 61 | 64 |
| 62 // |cache_file_directory| stores cached files. | 65 // |cache_file_directory| stores cached files. |
| 63 // | 66 // |
| 64 // |blocking_task_runner| indicates the blocking worker pool for cache | 67 // |blocking_task_runner| indicates the blocking worker pool for cache |
| 65 // operations. All operations on this FileCache must be run on this runner. | 68 // operations. All operations on this FileCache must be run on this runner. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 154 |
| 152 // Moves files in the cache directory which are not managed by FileCache to | 155 // Moves files in the cache directory which are not managed by FileCache to |
| 153 // |dest_directory|. | 156 // |dest_directory|. |
| 154 // |recovered_cache_info| should contain cache info recovered from the trashed | 157 // |recovered_cache_info| should contain cache info recovered from the trashed |
| 155 // metadata DB. It is used to ignore non-dirty files. | 158 // metadata DB. It is used to ignore non-dirty files. |
| 156 bool RecoverFilesFromCacheDirectory( | 159 bool RecoverFilesFromCacheDirectory( |
| 157 const base::FilePath& dest_directory, | 160 const base::FilePath& dest_directory, |
| 158 const ResourceMetadataStorage::RecoveredCacheInfoMap& | 161 const ResourceMetadataStorage::RecoveredCacheInfoMap& |
| 159 recovered_cache_info); | 162 recovered_cache_info); |
| 160 | 163 |
| 161 // Migrates cache files from |from| directory to |to_files| directory with | |
| 162 // creating links in |to_links| directory if necessary. Returns true for | |
| 163 // success. | |
| 164 static bool MigrateCacheFiles(const base::FilePath& from, | |
| 165 const base::FilePath& to_files, | |
| 166 const base::FilePath& to_links, | |
| 167 ResourceMetadataStorage* metadata_storage); | |
| 168 | |
| 169 private: | 164 private: |
| 170 friend class FileCacheTest; | 165 friend class FileCacheTest; |
| 171 | 166 |
| 172 ~FileCache(); | 167 ~FileCache(); |
| 173 | 168 |
| 174 // Returns absolute path of the file if it were cached or to be cached. | 169 // Returns absolute path of the file if it were cached or to be cached. |
| 175 // | 170 // |
| 176 // Can be called on any thread. | 171 // Can be called on any thread. |
| 177 base::FilePath GetCacheFilePath(const std::string& id) const; | 172 base::FilePath GetCacheFilePath(const std::string& id) const; |
| 178 | 173 |
| 179 // Checks whether the current thread is on the right sequenced worker pool | 174 // Checks whether the current thread is on the right sequenced worker pool |
| 180 // with the right sequence ID. If not, DCHECK will fail. | 175 // with the right sequence ID. If not, DCHECK will fail. |
| 181 void AssertOnSequencedWorkerPool(); | 176 void AssertOnSequencedWorkerPool(); |
| 182 | 177 |
| 183 // Destroys the cache on the blocking pool. | 178 // Destroys the cache on the blocking pool. |
| 184 void DestroyOnBlockingPool(); | 179 void DestroyOnBlockingPool(); |
| 185 | 180 |
| 186 // Returns available space, while keeping | 181 // Returns available space, while keeping |
| 187 // drive::internal::kMinFreeSpaceInBytes bytes on the disk. | 182 // drive::internal::kMinFreeSpaceInBytes bytes on the disk. |
| 188 int64_t GetAvailableSpace(); | 183 int64_t GetAvailableSpace(); |
| 189 | 184 |
| 190 // Renames cache files from old "prefix:id.md5" format to the new format. | 185 // Renames cache files from old "prefix:id.md5" format to the new format. |
| 191 // TODO(hashimoto): Remove this method at some point. | 186 // TODO(hashimoto): Remove this method at some point. |
| 192 bool RenameCacheFilesToNewFormat(); | 187 bool RenameCacheFilesToNewFormat(); |
| 193 | 188 |
| 189 // Adds appropriate file attributes to the Drive cache directory and files in |
| 190 // it for crbug.com/533750. Returns true on success. |
| 191 // This also resolves inconsistency between cache files and metadata which can |
| 192 // be produced when cryptohome removed cache files or on abrupt shutdown. |
| 193 bool FixMetadataAndFileAttributes(); |
| 194 |
| 194 // This method must be called after writing to a cache file. | 195 // This method must be called after writing to a cache file. |
| 195 // Used to implement OpenForWrite(). | 196 // Used to implement OpenForWrite(). |
| 196 void CloseForWrite(const std::string& id); | 197 void CloseForWrite(const std::string& id); |
| 197 | 198 |
| 198 // Returns true if the cache entry can be evicted. | 199 // Returns true if the cache entry can be evicted. |
| 199 bool IsEvictable(const std::string& id, const ResourceEntry& entry); | 200 bool IsEvictable(const std::string& id, const ResourceEntry& entry); |
| 200 | 201 |
| 201 const base::FilePath cache_file_directory_; | 202 const base::FilePath cache_file_directory_; |
| 202 | 203 |
| 203 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 204 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 225 // invalidate its weak pointers before any other members are destroyed. | 226 // invalidate its weak pointers before any other members are destroyed. |
| 226 // This object should be accessed only on |blocking_task_runner_|. | 227 // This object should be accessed only on |blocking_task_runner_|. |
| 227 base::WeakPtrFactory<FileCache> weak_ptr_factory_; | 228 base::WeakPtrFactory<FileCache> weak_ptr_factory_; |
| 228 DISALLOW_COPY_AND_ASSIGN(FileCache); | 229 DISALLOW_COPY_AND_ASSIGN(FileCache); |
| 229 }; | 230 }; |
| 230 | 231 |
| 231 } // namespace internal | 232 } // namespace internal |
| 232 } // namespace drive | 233 } // namespace drive |
| 233 | 234 |
| 234 #endif // COMPONENTS_DRIVE_CHROMEOS_FILE_CACHE_H_ | 235 #endif // COMPONENTS_DRIVE_CHROMEOS_FILE_CACHE_H_ |
| OLD | NEW |