blob: b6610b27494d82ca67d9b015acbb914579048fa7 [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]eca3fc92013-05-01 03:53:405#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_
6#define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_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]aa7365c2013-05-01 05:50:4716#include "chrome/browser/chromeos/drive/file_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]aa7365c2013-05-01 05:50:4729class FileCacheEntry;
[email protected]c960d222012-06-15 10:03:5030
[email protected]77fb1a62012-11-01 13:42:3231// Callback for GetCacheEntry.
[email protected]fae353a2012-07-11 23:30:2732// |success| indicates if the operation was successful.
33// |cache_entry| is the obtained cache entry. On failure, |cache_state| is
[email protected]02821102012-07-12 20:19:1734// set to TEST_CACHE_STATE_NONE.
[email protected]aa7365c2013-05-01 05:50:4735typedef base::Callback<void(bool success, const FileCacheEntry& cache_entry)>
[email protected]fae353a2012-07-11 23:30:2736 GetCacheEntryCallback;
37
[email protected]59c7cdec2013-05-07 04:17:1338namespace internal {
39
40class FileCacheMetadata;
41class FileCacheObserver;
42
43// Callback for GetFileFromCache.
44typedef base::Callback<void(FileError error,
45 const base::FilePath& cache_file_path)>
46 GetFileFromCacheCallback;
47
[email protected]77fb1a62012-11-01 13:42:3248// Callback for RequestInitialize.
[email protected]322e0032012-10-07 01:55:5349// |success| indicates if the operation was successful.
[email protected]78a158b2013-04-23 06:57:4950// TODO(satorux): Change this to FileError when it becomes necessary.
[email protected]322e0032012-10-07 01:55:5351typedef base::Callback<void(bool success)>
52 InitializeCacheCallback;
53
[email protected]f6fd98a2012-12-14 00:04:0254// Interface class used for getting the free disk space. Tests can inject an
55// implementation that reports fake free disk space.
56class FreeDiskSpaceGetterInterface {
57 public:
58 virtual ~FreeDiskSpaceGetterInterface() {}
[email protected]cf64404b2012-12-14 07:12:5059 virtual int64 AmountOfFreeDiskSpace() = 0;
[email protected]f6fd98a2012-12-14 00:04:0260};
61
[email protected]0d52ed52013-05-01 08:21:2162// FileCache is used to maintain cache states of FileSystem.
[email protected]6b70c7b2012-06-14 03:10:4363//
64// All non-static public member functions, unless mentioned otherwise (see
[email protected]54ba37502013-05-09 08:43:4065// GetCacheFilePath() for example), should be run with |blocking_task_runner|.
[email protected]eca3fc92013-05-01 03:53:4066class FileCache {
[email protected]3653146a2012-05-29 13:41:4767 public:
68 // Enum defining GCache subdirectory location.
[email protected]eca3fc92013-05-01 03:53:4069 // This indexes into |FileCache::cache_paths_| vector.
[email protected]3653146a2012-05-29 13:41:4770 enum CacheSubDirectoryType {
71 CACHE_TYPE_META = 0, // Downloaded feeds.
[email protected]3653146a2012-05-29 13:41:4772 CACHE_TYPE_PERSISTENT, // Files that are pinned or modified locally,
73 // not evictable, hopefully.
74 CACHE_TYPE_TMP, // Files that don't meet criteria to be in
75 // persistent dir, and hence evictable.
76 CACHE_TYPE_TMP_DOWNLOADS, // Downloaded files.
77 CACHE_TYPE_TMP_DOCUMENTS, // Temporary JSON files for hosted documents.
78 NUM_CACHE_TYPES, // This must be at the end.
79 };
80
[email protected]a321b9632012-06-14 03:29:1781 // Enum defining type of file operation e.g. copy or move, etc.
82 enum FileOperationType {
83 FILE_OPERATION_MOVE = 0,
84 FILE_OPERATION_COPY,
85 };
[email protected]32a7fc852012-06-08 17:25:5086
[email protected]17196ee2012-12-13 06:23:5187 // |cache_root_path| specifies the root directory for the cache. Sub
88 // directories will be created under the root directory.
89 //
90 // |blocking_task_runner| is used to post a task to the blocking worker
91 // pool for file operations. Must not be null.
[email protected]f6fd98a2012-12-14 00:04:0292 //
93 // |free_disk_space_getter| is used to inject a custom free disk space
94 // getter for testing. NULL must be passed for production code.
[email protected]54ba37502013-05-09 08:43:4095 //
96 // Must be called on the UI thread.
[email protected]eca3fc92013-05-01 03:53:4097 FileCache(const base::FilePath& cache_root_path,
[email protected]54ba37502013-05-09 08:43:4098 base::SequencedTaskRunner* blocking_task_runner,
99 FreeDiskSpaceGetterInterface* free_disk_space_getter);
[email protected]17196ee2012-12-13 06:23:51100
[email protected]7bb73e3d2012-09-08 17:41:29101 // Returns the sub-directory under drive cache directory for the given sub
[email protected]32a7fc852012-06-08 17:25:50102 // directory type. Example: <user_profile_dir>/GCache/v1/tmp
[email protected]6b70c7b2012-06-14 03:10:43103 //
104 // Can be called on any thread.
[email protected]650b2d52013-02-10 03:41:45105 base::FilePath GetCacheDirectoryPath(
106 CacheSubDirectoryType sub_dir_type) const;
[email protected]32a7fc852012-06-08 17:25:50107
[email protected]7bb73e3d2012-09-08 17:41:29108 // Returns true if the given path is under drive cache directory, i.e.
[email protected]01ba15f72012-06-09 00:41:05109 // <user_profile_dir>/GCache/v1
[email protected]6b70c7b2012-06-14 03:10:43110 //
111 // Can be called on any thread.
[email protected]eca3fc92013-05-01 03:53:40112 bool IsUnderFileCacheDirectory(const base::FilePath& path) const;
[email protected]01ba15f72012-06-09 00:41:05113
[email protected]73f9c742012-06-15 07:37:13114 // Adds observer.
[email protected]54ba37502013-05-09 08:43:40115 // Must be called on the UI thread.
[email protected]aa7365c2013-05-01 05:50:47116 void AddObserver(FileCacheObserver* observer);
[email protected]73f9c742012-06-15 07:37:13117
118 // Removes observer.
[email protected]54ba37502013-05-09 08:43:40119 // Must be called on the UI thread.
[email protected]aa7365c2013-05-01 05:50:47120 void RemoveObserver(FileCacheObserver* observer);
[email protected]73f9c742012-06-15 07:37:13121
[email protected]77fb1a62012-11-01 13:42:32122 // Gets the cache entry for file corresponding to |resource_id| and |md5|
[email protected]fba59542012-12-18 06:05:38123 // and runs |callback| with true and the entry found if entry exists in cache
[email protected]77fb1a62012-11-01 13:42:32124 // map. Otherwise, runs |callback| with false.
[email protected]b53e8da2013-05-29 07:47:18125 // |md5| can be empty if only matching |resource_id| is desired.
[email protected]bdd947c2012-11-06 04:35:34126 // |callback| must not be null.
[email protected]54ba37502013-05-09 08:43:40127 // Must be called on the UI thread.
128 void GetCacheEntryOnUIThread(const std::string& resource_id,
129 const std::string& md5,
130 const GetCacheEntryCallback& callback);
[email protected]4324fdc2012-06-29 05:32:48131
[email protected]8e38c9db2013-05-10 02:52:29132 // Gets the cache entry by the given resource ID and MD5.
133 // See also GetCacheEntryOnUIThread().
134 bool GetCacheEntry(const std::string& resource_id,
135 const std::string& md5,
136 FileCacheEntry* entry);
137
[email protected]3361a542013-05-22 17:38:27138 // Runs Iterate() with |iteration_callback| on |blocking_task_runner_| and
139 // runs |completion_callback| upon completion.
140 // Must be called on UI thread.
[email protected]54ba37502013-05-09 08:43:40141 void IterateOnUIThread(const CacheIterateCallback& iteration_callback,
142 const base::Closure& completion_callback);
[email protected]cd236432012-07-27 18:03:30143
[email protected]3361a542013-05-22 17:38:27144 // Iterates all files in the cache and calls |iteration_callback| for each
145 // file. |completion_callback| is run upon completion.
146 // TODO(hashimoto): Stop using callbacks for this method. crbug.com/242818
147 void Iterate(const CacheIterateCallback& iteration_callback);
148
[email protected]ec514362013-05-27 17:52:22149
150 // Runs FreeDiskSpaceIfNeededFor() on |blocking_task_runner_|, and calls
151 // |callback| with the result asynchronously.
152 // |callback| must not be null.
[email protected]54ba37502013-05-09 08:43:40153 // Must be called on the UI thread.
154 void FreeDiskSpaceIfNeededForOnUIThread(
155 int64 num_bytes,
156 const InitializeCacheCallback& callback);
[email protected]a321b9632012-06-14 03:29:17157
[email protected]ec514362013-05-27 17:52:22158 // Frees up disk space to store a file with |num_bytes| size content, while
159 // keeping kMinFreeSpace bytes on the disk, if needed.
160 // Returns true if we successfully manage to have enough space, otherwise
161 // false.
162 bool FreeDiskSpaceIfNeededFor(int64 num_bytes);
163
164 // Runs GetFile() on |blocking_task_runner_|, and calls |callback| with
165 // the result asynchronously.
[email protected]bdd947c2012-11-06 04:35:34166 // |callback| must not be null.
[email protected]54ba37502013-05-09 08:43:40167 // Must be called on the UI thread.
168 void GetFileOnUIThread(const std::string& resource_id,
169 const std::string& md5,
170 const GetFileFromCacheCallback& callback);
[email protected]a321b9632012-06-14 03:29:17171
[email protected]ec514362013-05-27 17:52:22172 // Checks if file corresponding to |resource_id| and |md5| exists in cache,
173 // and returns FILE_ERROR_OK with |cache_file_path| storing the path to
174 // the file.
175 // |cache_file_path| must not be null.
176 FileError GetFile(const std::string& resource_id,
177 const std::string& md5,
178 base::FilePath* cache_file_path);
179
[email protected]82c4eb92013-05-21 11:25:23180 // Runs Store() on |blocking_task_runner_|, and calls |callback| with
181 // the result asynchronously.
[email protected]2a2c4152012-11-26 11:34:50182 // |callback| must not be null.
[email protected]54ba37502013-05-09 08:43:40183 // Must be called on the UI thread.
184 void StoreOnUIThread(const std::string& resource_id,
185 const std::string& md5,
186 const base::FilePath& source_path,
187 FileOperationType file_operation_type,
188 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17189
[email protected]82c4eb92013-05-21 11:25:23190 // Stores |source_path| as a cache of the remote content of the file
191 // with |resource_id| and |md5|.
192 FileError Store(const std::string& resource_Id,
193 const std::string& md5,
194 const base::FilePath& source_path,
195 FileOperationType file_operation_type);
196
[email protected]d8546c92013-05-02 05:09:59197 // Stores |source_path| to the cache and mark it as dirty, i.e., needs to be
198 // uploaded to the remove server for syncing.
199 // |callback| must not be null.
[email protected]54ba37502013-05-09 08:43:40200 // Must be called on the UI thread.
201 void StoreLocallyModifiedOnUIThread(const std::string& resource_id,
202 const std::string& md5,
203 const base::FilePath& source_path,
204 FileOperationType file_operation_type,
205 const FileOperationCallback& callback);
[email protected]d8546c92013-05-02 05:09:59206
[email protected]b53e8da2013-05-29 07:47:18207 // Pins the specified entry.
[email protected]2a2c4152012-11-26 11:34:50208 // |callback| must not be null.
[email protected]54ba37502013-05-09 08:43:40209 // Must be called on the UI thread.
210 void PinOnUIThread(const std::string& resource_id,
211 const std::string& md5,
212 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17213
[email protected]ec514362013-05-27 17:52:22214 // Runs Unpin() on |blocking_task_runner_|, and calls |callback| with the
215 // result asynchronously.
[email protected]2a2c4152012-11-26 11:34:50216 // |callback| must not be null.
[email protected]54ba37502013-05-09 08:43:40217 // Must be called on the UI thread.
218 void UnpinOnUIThread(const std::string& resource_id,
219 const std::string& md5,
220 const FileOperationCallback& callback);
[email protected]7986b8d2012-06-14 15:05:14221
[email protected]b53e8da2013-05-29 07:47:18222 // Unpins the specified entry.
[email protected]ec514362013-05-27 17:52:22223 FileError Unpin(const std::string& resource_id, const std::string& md5);
224
[email protected]35c1f9b2013-02-07 07:39:42225 // Sets the state of the cache entry corresponding to |resource_id| and |md5|
226 // as mounted.
[email protected]9564c1502012-11-28 12:12:16227 // |callback| must not be null.
[email protected]54ba37502013-05-09 08:43:40228 // Must be called on the UI thread.
229 void MarkAsMountedOnUIThread(const std::string& resource_id,
230 const std::string& md5,
231 const GetFileFromCacheCallback& callback);
[email protected]9564c1502012-11-28 12:12:16232
233 // Set the state of the cache entry corresponding to file_path as unmounted.
234 // |callback| must not be null.
[email protected]54ba37502013-05-09 08:43:40235 // Must be called on the UI thread.
236 void MarkAsUnmountedOnUIThread(const base::FilePath& file_path,
237 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17238
[email protected]b53e8da2013-05-29 07:47:18239 // Marks the specified entry dirty.
[email protected]bdd947c2012-11-06 04:35:34240 // |callback| must not be null.
[email protected]54ba37502013-05-09 08:43:40241 // Must be called on the UI thread.
242 void MarkDirtyOnUIThread(const std::string& resource_id,
243 const std::string& md5,
244 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17245
[email protected]b53e8da2013-05-29 07:47:18246 // Commits changes for the specified dirty entry.
[email protected]2a2c4152012-11-26 11:34:50247 // |callback| must not be null.
[email protected]54ba37502013-05-09 08:43:40248 // Must be called on the UI thread.
249 void CommitDirtyOnUIThread(const std::string& resource_id,
250 const std::string& md5,
251 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17252
[email protected]fcf8eafe02013-05-28 11:15:39253 // Clears dirty state of the specified entry.
254 FileError ClearDirty(const std::string& resource_id,
255 const std::string& md5);
[email protected]a321b9632012-06-14 03:29:17256
[email protected]3361a542013-05-22 17:38:27257 // Runs Remove() on |blocking_task_runner_| and runs |callback| with the
258 // result.
[email protected]54ba37502013-05-09 08:43:40259 // Must be called on the UI thread.
260 void RemoveOnUIThread(const std::string& resource_id,
261 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17262
[email protected]3361a542013-05-22 17:38:27263 // Removes the specified cache entry and delete cache files if available.
264 // Synchronous version of RemoveOnUIThread().
265 FileError Remove(const std::string& resource_id);
266
[email protected]f861b392012-08-03 20:41:12267 // Does the following:
268 // - remove all the files in the cache directory.
269 // - re-create the |metadata_| instance.
[email protected]bdd947c2012-11-06 04:35:34270 // |callback| must not be null.
[email protected]54ba37502013-05-09 08:43:40271 // Must be called on the UI thread.
272 void ClearAllOnUIThread(const InitializeCacheCallback& callback);
[email protected]f861b392012-08-03 20:41:12273
[email protected]322e0032012-10-07 01:55:53274 // Utility method to call Initialize on UI thread. |callback| is called on
275 // UI thread when the initialization is complete.
276 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32277 void RequestInitialize(const InitializeCacheCallback& callback);
[email protected]73f9c742012-06-15 07:37:13278
[email protected]d310bfc2012-08-10 09:41:28279 // Utility method to call InitializeForTesting on UI thread.
[email protected]77fb1a62012-11-01 13:42:32280 void RequestInitializeForTesting();
[email protected]d310bfc2012-08-10 09:41:28281
[email protected]17196ee2012-12-13 06:23:51282 // Destroys this cache. This function posts a task to the blocking task
283 // runner to safely delete the object.
[email protected]54ba37502013-05-09 08:43:40284 // Must be called on the UI thread.
[email protected]77fb1a62012-11-01 13:42:32285 void Destroy();
[email protected]73f9c742012-06-15 07:37:13286
[email protected]30d9dda2012-06-30 05:56:28287 // Returns file paths for all the cache sub directories under
288 // |cache_root_path|.
[email protected]650b2d52013-02-10 03:41:45289 static std::vector<base::FilePath> GetCachePaths(
290 const base::FilePath& cache_root_path);
[email protected]30d9dda2012-06-30 05:56:28291
292 // Creates cache directory and its sub-directories if they don't exist.
293 // TODO(glotov): take care of this when the setup and cleanup part is
294 // landed, noting that these directories need to be created for development
295 // in linux box and unittest. (http://crosbug.com/27577)
296 static bool CreateCacheDirectories(
[email protected]650b2d52013-02-10 03:41:45297 const std::vector<base::FilePath>& paths_to_create);
[email protected]30d9dda2012-06-30 05:56:28298
[email protected]fae353a2012-07-11 23:30:27299 // Returns the type of the sub directory where the cache file is stored.
300 static CacheSubDirectoryType GetSubDirectoryType(
[email protected]aa7365c2013-05-01 05:50:47301 const FileCacheEntry& cache_entry);
[email protected]fae353a2012-07-11 23:30:27302
[email protected]ca5f6da2012-06-18 12:54:59303 private:
[email protected]eca3fc92013-05-01 03:53:40304 friend class FileCacheTest;
[email protected]e9663392013-04-12 09:55:15305
[email protected]e9663392013-04-12 09:55:15306 // Enum defining origin of a cached file.
307 enum CachedFileOrigin {
308 CACHED_FILE_FROM_SERVER = 0,
309 CACHED_FILE_LOCALLY_MODIFIED,
310 CACHED_FILE_MOUNTED,
311 };
312
[email protected]54ba37502013-05-09 08:43:40313 ~FileCache();
[email protected]fcc92a52012-06-08 22:54:16314
[email protected]e9663392013-04-12 09:55:15315 // Returns absolute path of the file if it were cached or to be cached.
316 //
317 // Can be called on any thread.
318 base::FilePath GetCacheFilePath(const std::string& resource_id,
319 const std::string& md5,
320 CacheSubDirectoryType sub_dir_type,
321 CachedFileOrigin file_origin) const;
322
323
[email protected]fcc92a52012-06-08 22:54:16324 // Checks whether the current thread is on the right sequenced worker pool
325 // with the right sequence ID. If not, DCHECK will fail.
326 void AssertOnSequencedWorkerPool();
[email protected]3653146a2012-05-29 13:41:47327
[email protected]bdd947c2012-11-06 04:35:34328 // Initializes the cache. Returns true on success.
329 bool InitializeOnBlockingPool();
[email protected]73f9c742012-06-15 07:37:13330
[email protected]d310bfc2012-08-10 09:41:28331 // Initializes the cache with in-memory cache for testing.
332 // The in-memory cache is used since it's faster than the db.
[email protected]77fb1a62012-11-01 13:42:32333 void InitializeOnBlockingPoolForTesting();
[email protected]d310bfc2012-08-10 09:41:28334
[email protected]17196ee2012-12-13 06:23:51335 // Destroys the cache on the blocking pool.
[email protected]77fb1a62012-11-01 13:42:32336 void DestroyOnBlockingPool();
[email protected]73f9c742012-06-15 07:37:13337
[email protected]82c4eb92013-05-21 11:25:23338 // Used to implement Store and StoreLocallyModifiedOnUIThread.
339 // TODO(hidehiko): Merge this method with Store(), after
340 // StoreLocallyModifiedOnUIThread is removed.
341 FileError StoreInternal(const std::string& resource_id,
342 const std::string& md5,
343 const base::FilePath& source_path,
344 FileOperationType file_operation_type,
345 CachedFileOrigin origin);
[email protected]73f9c742012-06-15 07:37:13346
[email protected]54ba37502013-05-09 08:43:40347 // Used to implement PinOnUIThread.
348 FileError Pin(const std::string& resource_id,
349 const std::string& md5);
[email protected]73f9c742012-06-15 07:37:13350
[email protected]54ba37502013-05-09 08:43:40351 // Used to implement MarkAsMountedOnUIThread.
[email protected]7197485b2013-05-23 15:59:34352 FileError MarkAsMounted(const std::string& resource_id,
353 const std::string& md5,
354 base::FilePath* cache_file_path);
[email protected]54ba37502013-05-09 08:43:40355
356 // Used to implement MarkAsUnmountedOnUIThread.
357 FileError MarkAsUnmounted(const base::FilePath& file_path);
358
359 // Used to implement MarkDirtyOnUIThread.
360 FileError MarkDirty(const std::string& resource_id,
361 const std::string& md5);
362
[email protected]54ba37502013-05-09 08:43:40363 // Used to implement ClearAllOnUIThread.
364 bool ClearAll();
[email protected]f861b392012-08-03 20:41:12365
[email protected]73f9c742012-06-15 07:37:13366 // Runs callback and notifies the observers when file is pinned.
[email protected]bdd947c2012-11-06 04:35:34367 void OnPinned(const std::string& resource_id,
[email protected]73f9c742012-06-15 07:37:13368 const std::string& md5,
[email protected]2a2c4152012-11-26 11:34:50369 const FileOperationCallback& callback,
[email protected]78a158b2013-04-23 06:57:49370 FileError error);
[email protected]73f9c742012-06-15 07:37:13371
372 // Runs callback and notifies the observers when file is unpinned.
[email protected]bdd947c2012-11-06 04:35:34373 void OnUnpinned(const std::string& resource_id,
[email protected]73f9c742012-06-15 07:37:13374 const std::string& md5,
[email protected]2a2c4152012-11-26 11:34:50375 const FileOperationCallback& callback,
[email protected]78a158b2013-04-23 06:57:49376 FileError error);
[email protected]73f9c742012-06-15 07:37:13377
[email protected]d7664c22012-06-18 19:35:49378 // Runs callback and notifies the observers when file is committed.
[email protected]bdd947c2012-11-06 04:35:34379 void OnCommitDirty(const std::string& resource_id,
[email protected]2a2c4152012-11-26 11:34:50380 const FileOperationCallback& callback,
[email protected]78a158b2013-04-23 06:57:49381 FileError error);
[email protected]4324fdc2012-06-29 05:32:48382
[email protected]f6fd98a2012-12-14 00:04:02383 // Returns true if we have sufficient space to store the given number of
384 // bytes, while keeping kMinFreeSpace bytes on the disk.
[email protected]650b2d52013-02-10 03:41:45385 bool HasEnoughSpaceFor(int64 num_bytes, const base::FilePath& path);
[email protected]f6fd98a2012-12-14 00:04:02386
[email protected]01ba15f72012-06-09 00:41:05387 // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1).
[email protected]650b2d52013-02-10 03:41:45388 const base::FilePath cache_root_path_;
[email protected]32a7fc852012-06-08 17:25:50389 // Paths for all subdirectories of GCache, one for each
[email protected]eca3fc92013-05-01 03:53:40390 // FileCache::CacheSubDirectoryType enum.
[email protected]650b2d52013-02-10 03:41:45391 const std::vector<base::FilePath> cache_paths_;
[email protected]ddbf2052012-07-13 15:07:02392 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
[email protected]32a7fc852012-06-08 17:25:50393
[email protected]ca5f6da2012-06-18 12:54:59394 // The cache state data. This member must be access only on the blocking pool.
[email protected]aa7365c2013-05-01 05:50:47395 scoped_ptr<FileCacheMetadata> metadata_;
[email protected]ca5f6da2012-06-18 12:54:59396
[email protected]73f9c742012-06-15 07:37:13397 // List of observers, this member must be accessed on UI thread.
[email protected]aa7365c2013-05-01 05:50:47398 ObserverList<FileCacheObserver> observers_;
[email protected]73f9c742012-06-15 07:37:13399
[email protected]f6fd98a2012-12-14 00:04:02400 FreeDiskSpaceGetterInterface* free_disk_space_getter_; // Not owned.
401
[email protected]e53ac8f2012-08-02 07:05:00402 // Note: This should remain the last member so it'll be destroyed and
403 // invalidate its weak pointers before any other members are destroyed.
[email protected]eca3fc92013-05-01 03:53:40404 base::WeakPtrFactory<FileCache> weak_ptr_factory_;
405 DISALLOW_COPY_AND_ASSIGN(FileCache);
[email protected]3653146a2012-05-29 13:41:47406};
407
[email protected]0d52ed52013-05-01 08:21:21408// The minimum free space to keep. FileSystem::GetFileByPath() returns
[email protected]7f90e77c2012-07-17 09:35:31409// GDATA_FILE_ERROR_NO_SPACE if the available space is smaller than
[email protected]a321b9632012-06-14 03:29:17410// this value.
411//
412// Copied from cryptohome/homedirs.h.
413// TODO(satorux): Share the constant.
414const int64 kMinFreeSpace = 512 * 1LL << 20;
415
[email protected]59c7cdec2013-05-07 04:17:13416} // namespace internal
[email protected]d9d04df2012-10-12 07:06:35417} // namespace drive
[email protected]3653146a2012-05-29 13:41:47418
[email protected]eca3fc92013-05-01 03:53:40419#endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_