blob: 9178a72947252cda7282de26904f494a31e95609 [file] [log] [blame]
[email protected]3653146a2012-05-29 13:41:471// 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
3// found in the LICENSE file.
4
[email protected]15de8142012-10-11 06:00:545#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_CACHE_H_
6#define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_CACHE_H_
[email protected]3653146a2012-05-29 13:41:477
[email protected]3653146a2012-05-29 13:41:478#include <string>
[email protected]79c3752d2012-07-17 12:10:089#include <vector>
[email protected]3653146a2012-05-29 13:41:4710
[email protected]dd91da82012-09-07 23:49:4911#include "base/callback_forward.h"
[email protected]57999812013-02-24 05:40:5212#include "base/files/file_path.h"
[email protected]3653146a2012-05-29 13:41:4713#include "base/memory/scoped_ptr.h"
[email protected]73f9c742012-06-15 07:37:1314#include "base/memory/weak_ptr.h"
15#include "base/observer_list.h"
[email protected]d68ede02012-11-07 14:30:5316#include "chrome/browser/chromeos/drive/drive_cache_metadata.h"
[email protected]78a158b2013-04-23 06:57:4917#include "chrome/browser/chromeos/drive/file_errors.h"
[email protected]3653146a2012-05-29 13:41:4718
[email protected]01ba15f72012-06-09 00:41:0519class Profile;
20
[email protected]ddbf2052012-07-13 15:07:0221namespace base {
22
23class SequencedTaskRunner;
24
25} // namespace base
26
[email protected]d9d04df2012-10-12 07:06:3527namespace drive {
[email protected]3653146a2012-05-29 13:41:4728
[email protected]28a64092012-08-21 10:01:1229class DriveCacheEntry;
[email protected]fb371812012-08-22 16:05:2330class DriveCacheMetadata;
[email protected]a09275502012-10-10 04:48:0131class DriveCacheObserver;
[email protected]ca5f6da2012-06-18 12:54:5932
[email protected]c960d222012-06-15 10:03:5033// Callback for GetFileFromCache.
[email protected]78a158b2013-04-23 06:57:4934typedef base::Callback<void(FileError error,
[email protected]650b2d52013-02-10 03:41:4535 const base::FilePath& cache_file_path)>
[email protected]c960d222012-06-15 10:03:5036 GetFileFromCacheCallback;
37
[email protected]77fb1a62012-11-01 13:42:3238// Callback for GetCacheEntry.
[email protected]fae353a2012-07-11 23:30:2739// |success| indicates if the operation was successful.
40// |cache_entry| is the obtained cache entry. On failure, |cache_state| is
[email protected]02821102012-07-12 20:19:1741// set to TEST_CACHE_STATE_NONE.
[email protected]28a64092012-08-21 10:01:1242typedef base::Callback<void(bool success, const DriveCacheEntry& cache_entry)>
[email protected]fae353a2012-07-11 23:30:2743 GetCacheEntryCallback;
44
[email protected]77fb1a62012-11-01 13:42:3245// Callback for RequestInitialize.
[email protected]322e0032012-10-07 01:55:5346// |success| indicates if the operation was successful.
[email protected]78a158b2013-04-23 06:57:4947// TODO(satorux): Change this to FileError when it becomes necessary.
[email protected]322e0032012-10-07 01:55:5348typedef base::Callback<void(bool success)>
49 InitializeCacheCallback;
50
[email protected]f6fd98a2012-12-14 00:04:0251// Interface class used for getting the free disk space. Tests can inject an
52// implementation that reports fake free disk space.
53class FreeDiskSpaceGetterInterface {
54 public:
55 virtual ~FreeDiskSpaceGetterInterface() {}
[email protected]cf64404b2012-12-14 07:12:5056 virtual int64 AmountOfFreeDiskSpace() = 0;
[email protected]f6fd98a2012-12-14 00:04:0257};
58
[email protected]7f53dc72012-08-23 19:06:5559// DriveCache is used to maintain cache states of DriveFileSystem.
[email protected]6b70c7b2012-06-14 03:10:4360//
61// All non-static public member functions, unless mentioned otherwise (see
[email protected]77fb1a62012-11-01 13:42:3262// GetCacheFilePath() for example), should be called from the UI thread.
[email protected]fb371812012-08-22 16:05:2363class DriveCache {
[email protected]3653146a2012-05-29 13:41:4764 public:
65 // Enum defining GCache subdirectory location.
[email protected]fb371812012-08-22 16:05:2366 // This indexes into |DriveCache::cache_paths_| vector.
[email protected]3653146a2012-05-29 13:41:4767 enum CacheSubDirectoryType {
68 CACHE_TYPE_META = 0, // Downloaded feeds.
[email protected]3653146a2012-05-29 13:41:4769 CACHE_TYPE_OUTGOING, // Symlinks to files in persistent or tmp dir to
70 // be uploaded.
71 CACHE_TYPE_PERSISTENT, // Files that are pinned or modified locally,
72 // not evictable, hopefully.
73 CACHE_TYPE_TMP, // Files that don't meet criteria to be in
74 // persistent dir, and hence evictable.
75 CACHE_TYPE_TMP_DOWNLOADS, // Downloaded files.
76 CACHE_TYPE_TMP_DOCUMENTS, // Temporary JSON files for hosted documents.
77 NUM_CACHE_TYPES, // This must be at the end.
78 };
79
[email protected]a321b9632012-06-14 03:29:1780 // Enum defining type of file operation e.g. copy or move, etc.
81 enum FileOperationType {
82 FILE_OPERATION_MOVE = 0,
83 FILE_OPERATION_COPY,
84 };
[email protected]32a7fc852012-06-08 17:25:5085
[email protected]17196ee2012-12-13 06:23:5186 // |cache_root_path| specifies the root directory for the cache. Sub
87 // directories will be created under the root directory.
88 //
89 // |blocking_task_runner| is used to post a task to the blocking worker
90 // pool for file operations. Must not be null.
[email protected]f6fd98a2012-12-14 00:04:0291 //
92 // |free_disk_space_getter| is used to inject a custom free disk space
93 // getter for testing. NULL must be passed for production code.
[email protected]650b2d52013-02-10 03:41:4594 DriveCache(const base::FilePath& cache_root_path,
[email protected]f6fd98a2012-12-14 00:04:0295 base::SequencedTaskRunner* blocking_task_runner,
96 FreeDiskSpaceGetterInterface* free_disk_space_getter);
[email protected]17196ee2012-12-13 06:23:5197
[email protected]7bb73e3d2012-09-08 17:41:2998 // Returns the sub-directory under drive cache directory for the given sub
[email protected]32a7fc852012-06-08 17:25:5099 // directory type. Example: <user_profile_dir>/GCache/v1/tmp
[email protected]6b70c7b2012-06-14 03:10:43100 //
101 // Can be called on any thread.
[email protected]650b2d52013-02-10 03:41:45102 base::FilePath GetCacheDirectoryPath(
103 CacheSubDirectoryType sub_dir_type) const;
[email protected]32a7fc852012-06-08 17:25:50104
[email protected]7bb73e3d2012-09-08 17:41:29105 // Returns true if the given path is under drive cache directory, i.e.
[email protected]01ba15f72012-06-09 00:41:05106 // <user_profile_dir>/GCache/v1
[email protected]6b70c7b2012-06-14 03:10:43107 //
108 // Can be called on any thread.
[email protected]650b2d52013-02-10 03:41:45109 bool IsUnderDriveCacheDirectory(const base::FilePath& path) const;
[email protected]01ba15f72012-06-09 00:41:05110
[email protected]73f9c742012-06-15 07:37:13111 // Adds observer.
[email protected]a09275502012-10-10 04:48:01112 void AddObserver(DriveCacheObserver* observer);
[email protected]73f9c742012-06-15 07:37:13113
114 // Removes observer.
[email protected]a09275502012-10-10 04:48:01115 void RemoveObserver(DriveCacheObserver* observer);
[email protected]73f9c742012-06-15 07:37:13116
[email protected]77fb1a62012-11-01 13:42:32117 // Gets the cache entry for file corresponding to |resource_id| and |md5|
[email protected]fba59542012-12-18 06:05:38118 // and runs |callback| with true and the entry found if entry exists in cache
[email protected]77fb1a62012-11-01 13:42:32119 // map. Otherwise, runs |callback| with false.
120 // |md5| can be empty if only matching |resource_id| is desired, which may
121 // happen when looking for pinned entries where symlinks' filenames have no
122 // extension and hence no md5.
[email protected]bdd947c2012-11-06 04:35:34123 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32124 void GetCacheEntry(const std::string& resource_id,
125 const std::string& md5,
126 const GetCacheEntryCallback& callback);
[email protected]4324fdc2012-06-29 05:32:48127
[email protected]d68ede02012-11-07 14:30:53128 // Iterates all files in the cache and calls |iteration_callback| for each
129 // file. |completion_callback| is run upon completion.
130 void Iterate(const CacheIterateCallback& iteration_callback,
131 const base::Closure& completion_callback);
[email protected]cd236432012-07-27 18:03:30132
[email protected]a321b9632012-06-14 03:29:17133 // Frees up disk space to store the given number of bytes, while keeping
[email protected]71314de2012-10-30 13:07:51134 // kMinFreeSpace bytes on the disk, if needed.
[email protected]f423c0b2012-11-22 09:51:10135 // Runs |callback| with true when we successfully manage to have enough space.
136 void FreeDiskSpaceIfNeededFor(int64 num_bytes,
137 const InitializeCacheCallback& callback);
[email protected]a321b9632012-06-14 03:29:17138
139 // Checks if file corresponding to |resource_id| and |md5| exists in cache.
[email protected]bdd947c2012-11-06 04:35:34140 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32141 void GetFile(const std::string& resource_id,
142 const std::string& md5,
143 const GetFileFromCacheCallback& callback);
[email protected]a321b9632012-06-14 03:29:17144
145 // Modifies cache state, which involves the following:
146 // - moves or copies (per |file_operation_type|) |source_path|
147 // to |dest_path| in the cache dir
148 // - if necessary, creates symlink
149 // - deletes stale cached versions of |resource_id| in
150 // |dest_path|'s directory.
[email protected]2a2c4152012-11-26 11:34:50151 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32152 void Store(const std::string& resource_id,
153 const std::string& md5,
[email protected]650b2d52013-02-10 03:41:45154 const base::FilePath& source_path,
[email protected]77fb1a62012-11-01 13:42:32155 FileOperationType file_operation_type,
[email protected]2a2c4152012-11-26 11:34:50156 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17157
158 // Modifies cache state, which involves the following:
159 // - moves |source_path| to |dest_path| in persistent dir if
160 // file is not dirty
161 // - creates symlink in pinned dir that references downloaded or locally
162 // modified file
[email protected]2a2c4152012-11-26 11:34:50163 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32164 void Pin(const std::string& resource_id,
165 const std::string& md5,
[email protected]2a2c4152012-11-26 11:34:50166 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17167
168 // Modifies cache state, which involves the following:
169 // - moves |source_path| to |dest_path| in tmp dir if file is not dirty
170 // - deletes symlink from pinned dir
[email protected]2a2c4152012-11-26 11:34:50171 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32172 void Unpin(const std::string& resource_id,
173 const std::string& md5,
[email protected]2a2c4152012-11-26 11:34:50174 const FileOperationCallback& callback);
[email protected]7986b8d2012-06-14 15:05:14175
[email protected]35c1f9b2013-02-07 07:39:42176 // Sets the state of the cache entry corresponding to |resource_id| and |md5|
177 // as mounted.
[email protected]9564c1502012-11-28 12:12:16178 // |callback| must not be null.
[email protected]35c1f9b2013-02-07 07:39:42179 void MarkAsMounted(const std::string& resource_id,
180 const std::string& md5,
[email protected]9564c1502012-11-28 12:12:16181 const GetFileFromCacheCallback& callback);
182
183 // Set the state of the cache entry corresponding to file_path as unmounted.
184 // |callback| must not be null.
[email protected]650b2d52013-02-10 03:41:45185 void MarkAsUnmounted(const base::FilePath& file_path,
[email protected]9564c1502012-11-28 12:12:16186 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17187
188 // Modifies cache state, which involves the following:
189 // - moves |source_path| to |dest_path| in persistent dir, where
190 // |source_path| has .<md5> extension and |dest_path| has .local extension
191 // - if file is pinned, updates symlink in pinned dir to reference dirty file
[email protected]bdd947c2012-11-06 04:35:34192 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32193 void MarkDirty(const std::string& resource_id,
194 const std::string& md5,
[email protected]bc809e42012-11-28 04:46:29195 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17196
197 // Modifies cache state, i.e. creates symlink in outgoing
198 // dir to reference dirty file in persistent dir.
[email protected]2a2c4152012-11-26 11:34:50199 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32200 void CommitDirty(const std::string& resource_id,
201 const std::string& md5,
[email protected]2a2c4152012-11-26 11:34:50202 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17203
204 // Modifies cache state, which involves the following:
205 // - moves |source_path| to |dest_path| in persistent dir if
206 // file is pinned or tmp dir otherwise, where |source_path| has .local
207 // extension and |dest_path| has .<md5> extension
208 // - deletes symlink in outgoing dir
209 // - if file is pinned, updates symlink in pinned dir to reference
210 // |dest_path|
[email protected]2a2c4152012-11-26 11:34:50211 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32212 void ClearDirty(const std::string& resource_id,
213 const std::string& md5,
[email protected]2a2c4152012-11-26 11:34:50214 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17215
216 // Does the following:
217 // - remove all delete stale cache versions corresponding to |resource_id| in
218 // persistent, tmp and pinned directories
219 // - remove entry corresponding to |resource_id| from cache map.
[email protected]2a2c4152012-11-26 11:34:50220 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32221 void Remove(const std::string& resource_id,
[email protected]2a2c4152012-11-26 11:34:50222 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17223
[email protected]f861b392012-08-03 20:41:12224 // Does the following:
225 // - remove all the files in the cache directory.
226 // - re-create the |metadata_| instance.
[email protected]bdd947c2012-11-06 04:35:34227 // |callback| must not be null.
228 void ClearAll(const InitializeCacheCallback& callback);
[email protected]f861b392012-08-03 20:41:12229
[email protected]322e0032012-10-07 01:55:53230 // Utility method to call Initialize on UI thread. |callback| is called on
231 // UI thread when the initialization is complete.
232 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32233 void RequestInitialize(const InitializeCacheCallback& callback);
[email protected]73f9c742012-06-15 07:37:13234
[email protected]d310bfc2012-08-10 09:41:28235 // Utility method to call InitializeForTesting on UI thread.
[email protected]77fb1a62012-11-01 13:42:32236 void RequestInitializeForTesting();
[email protected]d310bfc2012-08-10 09:41:28237
[email protected]17196ee2012-12-13 06:23:51238 // Destroys this cache. This function posts a task to the blocking task
239 // runner to safely delete the object.
[email protected]77fb1a62012-11-01 13:42:32240 void Destroy();
[email protected]73f9c742012-06-15 07:37:13241
[email protected]01ba15f72012-06-09 00:41:05242 // Gets the cache root path (i.e. <user_profile_dir>/GCache/v1) from the
243 // profile.
244 // TODO(satorux): Write a unit test for this.
[email protected]650b2d52013-02-10 03:41:45245 static base::FilePath GetCacheRootPath(Profile* profile);
[email protected]01ba15f72012-06-09 00:41:05246
[email protected]30d9dda2012-06-30 05:56:28247 // Returns file paths for all the cache sub directories under
248 // |cache_root_path|.
[email protected]650b2d52013-02-10 03:41:45249 static std::vector<base::FilePath> GetCachePaths(
250 const base::FilePath& cache_root_path);
[email protected]30d9dda2012-06-30 05:56:28251
252 // Creates cache directory and its sub-directories if they don't exist.
253 // TODO(glotov): take care of this when the setup and cleanup part is
254 // landed, noting that these directories need to be created for development
255 // in linux box and unittest. (http://crosbug.com/27577)
256 static bool CreateCacheDirectories(
[email protected]650b2d52013-02-10 03:41:45257 const std::vector<base::FilePath>& paths_to_create);
[email protected]30d9dda2012-06-30 05:56:28258
[email protected]fae353a2012-07-11 23:30:27259 // Returns the type of the sub directory where the cache file is stored.
260 static CacheSubDirectoryType GetSubDirectoryType(
[email protected]28a64092012-08-21 10:01:12261 const DriveCacheEntry& cache_entry);
[email protected]fae353a2012-07-11 23:30:27262
[email protected]ca5f6da2012-06-18 12:54:59263 private:
[email protected]e9663392013-04-12 09:55:15264 friend class DriveCacheTest;
265
[email protected]78a158b2013-04-23 06:57:49266 typedef std::pair<FileError, base::FilePath> GetFileResult;
[email protected]bdd947c2012-11-06 04:35:34267
[email protected]e9663392013-04-12 09:55:15268 // Enum defining origin of a cached file.
269 enum CachedFileOrigin {
270 CACHED_FILE_FROM_SERVER = 0,
271 CACHED_FILE_LOCALLY_MODIFIED,
272 CACHED_FILE_MOUNTED,
273 };
274
[email protected]fb371812012-08-22 16:05:23275 virtual ~DriveCache();
[email protected]fcc92a52012-06-08 22:54:16276
[email protected]e9663392013-04-12 09:55:15277 // Returns absolute path of the file if it were cached or to be cached.
278 //
279 // Can be called on any thread.
280 base::FilePath GetCacheFilePath(const std::string& resource_id,
281 const std::string& md5,
282 CacheSubDirectoryType sub_dir_type,
283 CachedFileOrigin file_origin) const;
284
285
[email protected]fcc92a52012-06-08 22:54:16286 // Checks whether the current thread is on the right sequenced worker pool
287 // with the right sequence ID. If not, DCHECK will fail.
288 void AssertOnSequencedWorkerPool();
[email protected]3653146a2012-05-29 13:41:47289
[email protected]bdd947c2012-11-06 04:35:34290 // Initializes the cache. Returns true on success.
291 bool InitializeOnBlockingPool();
[email protected]73f9c742012-06-15 07:37:13292
[email protected]d310bfc2012-08-10 09:41:28293 // Initializes the cache with in-memory cache for testing.
294 // The in-memory cache is used since it's faster than the db.
[email protected]77fb1a62012-11-01 13:42:32295 void InitializeOnBlockingPoolForTesting();
[email protected]d310bfc2012-08-10 09:41:28296
[email protected]17196ee2012-12-13 06:23:51297 // Destroys the cache on the blocking pool.
[email protected]77fb1a62012-11-01 13:42:32298 void DestroyOnBlockingPool();
[email protected]73f9c742012-06-15 07:37:13299
[email protected]717e43c2012-11-22 07:47:39300 // Gets the cache entry by the given resource ID and MD5.
301 // See also GetCacheEntry().
302 bool GetCacheEntryOnBlockingPool(const std::string& resource_id,
303 const std::string& md5,
304 DriveCacheEntry* entry);
305
[email protected]d68ede02012-11-07 14:30:53306 // Used to implement Iterate().
307 void IterateOnBlockingPool(const CacheIterateCallback& iteration_callback);
[email protected]cd236432012-07-27 18:03:30308
[email protected]f423c0b2012-11-22 09:51:10309 // Used to implement FreeDiskSpaceIfNeededFor().
310 bool FreeDiskSpaceOnBlockingPoolIfNeededFor(int64 num_bytes);
311
[email protected]77fb1a62012-11-01 13:42:32312 // Used to implement GetFile.
[email protected]bdd947c2012-11-06 04:35:34313 scoped_ptr<GetFileResult> GetFileOnBlockingPool(
314 const std::string& resource_id,
315 const std::string& md5);
[email protected]c960d222012-06-15 10:03:50316
[email protected]77fb1a62012-11-01 13:42:32317 // Used to implement Store.
[email protected]78a158b2013-04-23 06:57:49318 FileError StoreOnBlockingPool(const std::string& resource_id,
319 const std::string& md5,
320 const base::FilePath& source_path,
321 FileOperationType file_operation_type);
[email protected]73f9c742012-06-15 07:37:13322
[email protected]77fb1a62012-11-01 13:42:32323 // Used to implement Pin.
[email protected]78a158b2013-04-23 06:57:49324 FileError PinOnBlockingPool(const std::string& resource_id,
325 const std::string& md5);
[email protected]73f9c742012-06-15 07:37:13326
[email protected]77fb1a62012-11-01 13:42:32327 // Used to implement Unpin.
[email protected]78a158b2013-04-23 06:57:49328 FileError UnpinOnBlockingPool(const std::string& resource_id,
329 const std::string& md5);
[email protected]73f9c742012-06-15 07:37:13330
[email protected]9564c1502012-11-28 12:12:16331 // Used to implement MarkAsMounted.
332 scoped_ptr<GetFileResult> MarkAsMountedOnBlockingPool(
[email protected]35c1f9b2013-02-07 07:39:42333 const std::string& resource_id,
334 const std::string& md5);
[email protected]9564c1502012-11-28 12:12:16335
336 // Used to implement MarkAsUnmounted.
[email protected]78a158b2013-04-23 06:57:49337 FileError MarkAsUnmountedOnBlockingPool(const base::FilePath& file_path);
[email protected]73f9c742012-06-15 07:37:13338
[email protected]77fb1a62012-11-01 13:42:32339 // Used to implement MarkDirty.
[email protected]78a158b2013-04-23 06:57:49340 FileError MarkDirtyOnBlockingPool(const std::string& resource_id,
341 const std::string& md5);
[email protected]c960d222012-06-15 10:03:50342
[email protected]77fb1a62012-11-01 13:42:32343 // Used to implement CommitDirty.
[email protected]78a158b2013-04-23 06:57:49344 FileError CommitDirtyOnBlockingPool(const std::string& resource_id,
345 const std::string& md5);
[email protected]73f9c742012-06-15 07:37:13346
[email protected]77fb1a62012-11-01 13:42:32347 // Used to implement ClearDirty.
[email protected]78a158b2013-04-23 06:57:49348 FileError ClearDirtyOnBlockingPool(const std::string& resource_id,
349 const std::string& md5);
[email protected]73f9c742012-06-15 07:37:13350
[email protected]77fb1a62012-11-01 13:42:32351 // Used to implement Remove.
[email protected]78a158b2013-04-23 06:57:49352 FileError RemoveOnBlockingPool(const std::string& resource_id);
[email protected]73f9c742012-06-15 07:37:13353
[email protected]77fb1a62012-11-01 13:42:32354 // Used to implement ClearAll.
[email protected]bdd947c2012-11-06 04:35:34355 bool ClearAllOnBlockingPool();
[email protected]f861b392012-08-03 20:41:12356
[email protected]73f9c742012-06-15 07:37:13357 // Runs callback and notifies the observers when file is pinned.
[email protected]bdd947c2012-11-06 04:35:34358 void OnPinned(const std::string& resource_id,
[email protected]73f9c742012-06-15 07:37:13359 const std::string& md5,
[email protected]2a2c4152012-11-26 11:34:50360 const FileOperationCallback& callback,
[email protected]78a158b2013-04-23 06:57:49361 FileError error);
[email protected]73f9c742012-06-15 07:37:13362
363 // Runs callback and notifies the observers when file is unpinned.
[email protected]bdd947c2012-11-06 04:35:34364 void OnUnpinned(const std::string& resource_id,
[email protected]73f9c742012-06-15 07:37:13365 const std::string& md5,
[email protected]2a2c4152012-11-26 11:34:50366 const FileOperationCallback& callback,
[email protected]78a158b2013-04-23 06:57:49367 FileError error);
[email protected]73f9c742012-06-15 07:37:13368
[email protected]d7664c22012-06-18 19:35:49369 // Runs callback and notifies the observers when file is committed.
[email protected]bdd947c2012-11-06 04:35:34370 void OnCommitDirty(const std::string& resource_id,
[email protected]2a2c4152012-11-26 11:34:50371 const FileOperationCallback& callback,
[email protected]78a158b2013-04-23 06:57:49372 FileError error);
[email protected]4324fdc2012-06-29 05:32:48373
[email protected]f6fd98a2012-12-14 00:04:02374 // Returns true if we have sufficient space to store the given number of
375 // bytes, while keeping kMinFreeSpace bytes on the disk.
[email protected]650b2d52013-02-10 03:41:45376 bool HasEnoughSpaceFor(int64 num_bytes, const base::FilePath& path);
[email protected]f6fd98a2012-12-14 00:04:02377
[email protected]01ba15f72012-06-09 00:41:05378 // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1).
[email protected]650b2d52013-02-10 03:41:45379 const base::FilePath cache_root_path_;
[email protected]32a7fc852012-06-08 17:25:50380 // Paths for all subdirectories of GCache, one for each
[email protected]fb371812012-08-22 16:05:23381 // DriveCache::CacheSubDirectoryType enum.
[email protected]650b2d52013-02-10 03:41:45382 const std::vector<base::FilePath> cache_paths_;
[email protected]ddbf2052012-07-13 15:07:02383 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
[email protected]32a7fc852012-06-08 17:25:50384
[email protected]ca5f6da2012-06-18 12:54:59385 // The cache state data. This member must be access only on the blocking pool.
[email protected]fb371812012-08-22 16:05:23386 scoped_ptr<DriveCacheMetadata> metadata_;
[email protected]ca5f6da2012-06-18 12:54:59387
[email protected]73f9c742012-06-15 07:37:13388 // List of observers, this member must be accessed on UI thread.
[email protected]a09275502012-10-10 04:48:01389 ObserverList<DriveCacheObserver> observers_;
[email protected]73f9c742012-06-15 07:37:13390
[email protected]f6fd98a2012-12-14 00:04:02391 FreeDiskSpaceGetterInterface* free_disk_space_getter_; // Not owned.
392
[email protected]e53ac8f2012-08-02 07:05:00393 // Note: This should remain the last member so it'll be destroyed and
394 // invalidate its weak pointers before any other members are destroyed.
[email protected]fb371812012-08-22 16:05:23395 base::WeakPtrFactory<DriveCache> weak_ptr_factory_;
396 DISALLOW_COPY_AND_ASSIGN(DriveCache);
[email protected]3653146a2012-05-29 13:41:47397};
398
[email protected]7f53dc72012-08-23 19:06:55399// The minimum free space to keep. DriveFileSystem::GetFileByPath() returns
[email protected]7f90e77c2012-07-17 09:35:31400// GDATA_FILE_ERROR_NO_SPACE if the available space is smaller than
[email protected]a321b9632012-06-14 03:29:17401// this value.
402//
403// Copied from cryptohome/homedirs.h.
404// TODO(satorux): Share the constant.
405const int64 kMinFreeSpace = 512 * 1LL << 20;
406
[email protected]d9d04df2012-10-12 07:06:35407} // namespace drive
[email protected]3653146a2012-05-29 13:41:47408
[email protected]15de8142012-10-11 06:00:54409#endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_CACHE_H_