Chromium Code Reviews| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 | 137 |
| 138 // Removes the specified cache entry and delete cache files if available. | 138 // Removes the specified cache entry and delete cache files if available. |
| 139 FileError Remove(const std::string& id); | 139 FileError Remove(const std::string& id); |
| 140 | 140 |
| 141 // Removes all the files in the cache directory. | 141 // Removes all the files in the cache directory. |
| 142 bool ClearAll(); | 142 bool ClearAll(); |
| 143 | 143 |
| 144 // Initializes the cache. Returns true on success. | 144 // Initializes the cache. Returns true on success. |
| 145 bool Initialize(); | 145 bool Initialize(); |
| 146 | 146 |
| 147 // Returns if Drive cache migration for crbug/533750 should be invoked. | |
|
hashimoto
2016/05/02 08:29:20
nit: crbug/533750 ".com" missing.
The same goes fo
oka
2016/05/09 14:27:40
Done.
| |
| 148 // Public for testing. | |
| 149 bool ShouldStartDriveCacheMigration(); | |
| 150 | |
| 147 // Destroys this cache. This function posts a task to the blocking task | 151 // Destroys this cache. This function posts a task to the blocking task |
| 148 // runner to safely delete the object. | 152 // runner to safely delete the object. |
| 149 // Must be called on the UI thread. | 153 // Must be called on the UI thread. |
| 150 void Destroy(); | 154 void Destroy(); |
| 151 | 155 |
| 152 // Moves files in the cache directory which are not managed by FileCache to | 156 // Moves files in the cache directory which are not managed by FileCache to |
| 153 // |dest_directory|. | 157 // |dest_directory|. |
| 154 // |recovered_cache_info| should contain cache info recovered from the trashed | 158 // |recovered_cache_info| should contain cache info recovered from the trashed |
| 155 // metadata DB. It is used to ignore non-dirty files. | 159 // metadata DB. It is used to ignore non-dirty files. |
| 156 bool RecoverFilesFromCacheDirectory( | 160 bool RecoverFilesFromCacheDirectory( |
| 157 const base::FilePath& dest_directory, | 161 const base::FilePath& dest_directory, |
| 158 const ResourceMetadataStorage::RecoveredCacheInfoMap& | 162 const ResourceMetadataStorage::RecoveredCacheInfoMap& |
| 159 recovered_cache_info); | 163 recovered_cache_info); |
| 160 | 164 |
| 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: | 165 private: |
| 170 friend class FileCacheTest; | 166 friend class FileCacheTest; |
| 171 | 167 |
| 172 ~FileCache(); | 168 ~FileCache(); |
| 173 | 169 |
| 174 // Returns absolute path of the file if it were cached or to be cached. | 170 // Returns absolute path of the file if it were cached or to be cached. |
| 175 // | 171 // |
| 176 // Can be called on any thread. | 172 // Can be called on any thread. |
| 177 base::FilePath GetCacheFilePath(const std::string& id) const; | 173 base::FilePath GetCacheFilePath(const std::string& id) const; |
| 178 | 174 |
| 179 // Checks whether the current thread is on the right sequenced worker pool | 175 // Checks whether the current thread is on the right sequenced worker pool |
| 180 // with the right sequence ID. If not, DCHECK will fail. | 176 // with the right sequence ID. If not, DCHECK will fail. |
| 181 void AssertOnSequencedWorkerPool(); | 177 void AssertOnSequencedWorkerPool(); |
| 182 | 178 |
| 183 // Destroys the cache on the blocking pool. | 179 // Destroys the cache on the blocking pool. |
| 184 void DestroyOnBlockingPool(); | 180 void DestroyOnBlockingPool(); |
| 185 | 181 |
| 186 // Returns available space, while keeping | 182 // Returns available space, while keeping |
| 187 // drive::internal::kMinFreeSpaceInBytes bytes on the disk. | 183 // drive::internal::kMinFreeSpaceInBytes bytes on the disk. |
| 188 int64_t GetAvailableSpace(); | 184 int64_t GetAvailableSpace(); |
| 189 | 185 |
| 190 // Renames cache files from old "prefix:id.md5" format to the new format. | 186 // Renames cache files from old "prefix:id.md5" format to the new format. |
| 191 // TODO(hashimoto): Remove this method at some point. | 187 // TODO(hashimoto): Remove this method at some point. |
| 192 bool RenameCacheFilesToNewFormat(); | 188 bool RenameCacheFilesToNewFormat(); |
| 193 | 189 |
| 190 // Add appropriate file attributes to the Drive cache directory and files in | |
|
hashimoto
2016/05/02 08:29:20
nit: "Add" -> "Adds".
https://google.github.io/sty
oka
2016/05/09 14:27:40
Done.
Merged MigrateCacheFiles and ResolveMetadat
| |
| 191 // it for crbug/533750. Returns true on success. | |
| 192 // Inconsistency between cache and metadata should be resolved before this | |
|
hashimoto
2016/05/02 08:29:20
nit: How about "cache" -> "cache files" to avoid c
oka
2016/05/09 14:27:40
Done.
| |
| 193 // method is called. | |
| 194 bool MigrateCacheFiles(); | |
| 195 | |
| 196 // Resolve metadata inconsistency in case cryptohome removed cache files. | |
| 197 bool ResolveMetadataInconsistency(); | |
| 198 | |
| 194 // This method must be called after writing to a cache file. | 199 // This method must be called after writing to a cache file. |
| 195 // Used to implement OpenForWrite(). | 200 // Used to implement OpenForWrite(). |
| 196 void CloseForWrite(const std::string& id); | 201 void CloseForWrite(const std::string& id); |
| 197 | 202 |
| 198 // Returns true if the cache entry can be evicted. | 203 // Returns true if the cache entry can be evicted. |
| 199 bool IsEvictable(const std::string& id, const ResourceEntry& entry); | 204 bool IsEvictable(const std::string& id, const ResourceEntry& entry); |
| 200 | 205 |
| 201 const base::FilePath cache_file_directory_; | 206 const base::FilePath cache_file_directory_; |
| 202 | 207 |
| 203 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 208 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. | 230 // invalidate its weak pointers before any other members are destroyed. |
| 226 // This object should be accessed only on |blocking_task_runner_|. | 231 // This object should be accessed only on |blocking_task_runner_|. |
| 227 base::WeakPtrFactory<FileCache> weak_ptr_factory_; | 232 base::WeakPtrFactory<FileCache> weak_ptr_factory_; |
| 228 DISALLOW_COPY_AND_ASSIGN(FileCache); | 233 DISALLOW_COPY_AND_ASSIGN(FileCache); |
| 229 }; | 234 }; |
| 230 | 235 |
| 231 } // namespace internal | 236 } // namespace internal |
| 232 } // namespace drive | 237 } // namespace drive |
| 233 | 238 |
| 234 #endif // COMPONENTS_DRIVE_CHROMEOS_FILE_CACHE_H_ | 239 #endif // COMPONENTS_DRIVE_CHROMEOS_FILE_CACHE_H_ |
| OLD | NEW |