blob: f89ab5acd411389a8c8708d745bee26e4ea26bc4 [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]32a7fc852012-06-08 17:25:5012#include "base/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]ae7c98f92012-10-11 09:51:2417#include "chrome/browser/chromeos/drive/drive_file_error.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]11f60db2012-08-23 16:28:1534typedef base::Callback<void(DriveFileError error,
[email protected]c960d222012-06-15 10:03:5035 const FilePath& cache_file_path)>
36 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.
47// TODO(satorux): Change this to DriveFileError when it becomes necessary.
48typedef 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.
69 CACHE_TYPE_PINNED, // Symlinks to files in persistent dir that are
70 // pinned, or to /dev/null for non-existent
71 // files.
72 CACHE_TYPE_OUTGOING, // Symlinks to files in persistent or tmp dir to
73 // be uploaded.
74 CACHE_TYPE_PERSISTENT, // Files that are pinned or modified locally,
75 // not evictable, hopefully.
76 CACHE_TYPE_TMP, // Files that don't meet criteria to be in
77 // persistent dir, and hence evictable.
78 CACHE_TYPE_TMP_DOWNLOADS, // Downloaded files.
79 CACHE_TYPE_TMP_DOCUMENTS, // Temporary JSON files for hosted documents.
80 NUM_CACHE_TYPES, // This must be at the end.
81 };
82
[email protected]32a7fc852012-06-08 17:25:5083 // Enum defining origin of a cached file.
84 enum CachedFileOrigin {
85 CACHED_FILE_FROM_SERVER = 0,
86 CACHED_FILE_LOCALLY_MODIFIED,
87 CACHED_FILE_MOUNTED,
88 };
89
[email protected]a321b9632012-06-14 03:29:1790 // Enum defining type of file operation e.g. copy or move, etc.
91 enum FileOperationType {
92 FILE_OPERATION_MOVE = 0,
93 FILE_OPERATION_COPY,
94 };
[email protected]32a7fc852012-06-08 17:25:5095
[email protected]17196ee2012-12-13 06:23:5196 // |cache_root_path| specifies the root directory for the cache. Sub
97 // directories will be created under the root directory.
98 //
99 // |blocking_task_runner| is used to post a task to the blocking worker
100 // pool for file operations. Must not be null.
[email protected]f6fd98a2012-12-14 00:04:02101 //
102 // |free_disk_space_getter| is used to inject a custom free disk space
103 // getter for testing. NULL must be passed for production code.
[email protected]17196ee2012-12-13 06:23:51104 DriveCache(const FilePath& cache_root_path,
[email protected]f6fd98a2012-12-14 00:04:02105 base::SequencedTaskRunner* blocking_task_runner,
106 FreeDiskSpaceGetterInterface* free_disk_space_getter);
[email protected]17196ee2012-12-13 06:23:51107
[email protected]7bb73e3d2012-09-08 17:41:29108 // Returns the sub-directory under drive cache directory for the given sub
[email protected]32a7fc852012-06-08 17:25:50109 // directory type. Example: <user_profile_dir>/GCache/v1/tmp
[email protected]6b70c7b2012-06-14 03:10:43110 //
111 // Can be called on any thread.
[email protected]32a7fc852012-06-08 17:25:50112 FilePath GetCacheDirectoryPath(CacheSubDirectoryType sub_dir_type) const;
113
114 // Returns absolute path of the file if it were cached or to be cached.
[email protected]6b70c7b2012-06-14 03:10:43115 //
116 // Can be called on any thread.
[email protected]32a7fc852012-06-08 17:25:50117 FilePath GetCacheFilePath(const std::string& resource_id,
118 const std::string& md5,
119 CacheSubDirectoryType sub_dir_type,
[email protected]2fdc0aeb2012-10-16 12:13:44120 CachedFileOrigin file_origin) const;
[email protected]32a7fc852012-06-08 17:25:50121
[email protected]7bb73e3d2012-09-08 17:41:29122 // Returns true if the given path is under drive cache directory, i.e.
[email protected]01ba15f72012-06-09 00:41:05123 // <user_profile_dir>/GCache/v1
[email protected]6b70c7b2012-06-14 03:10:43124 //
125 // Can be called on any thread.
[email protected]fb371812012-08-22 16:05:23126 bool IsUnderDriveCacheDirectory(const FilePath& path) const;
[email protected]01ba15f72012-06-09 00:41:05127
[email protected]73f9c742012-06-15 07:37:13128 // Adds observer.
[email protected]a09275502012-10-10 04:48:01129 void AddObserver(DriveCacheObserver* observer);
[email protected]73f9c742012-06-15 07:37:13130
131 // Removes observer.
[email protected]a09275502012-10-10 04:48:01132 void RemoveObserver(DriveCacheObserver* observer);
[email protected]73f9c742012-06-15 07:37:13133
[email protected]77fb1a62012-11-01 13:42:32134 // Gets the cache entry for file corresponding to |resource_id| and |md5|
135 // and runs |callabck| with true and the entry found if entry exists in cache
136 // map. Otherwise, runs |callback| with false.
137 // |md5| can be empty if only matching |resource_id| is desired, which may
138 // happen when looking for pinned entries where symlinks' filenames have no
139 // extension and hence no md5.
[email protected]bdd947c2012-11-06 04:35:34140 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32141 void GetCacheEntry(const std::string& resource_id,
142 const std::string& md5,
143 const GetCacheEntryCallback& callback);
[email protected]4324fdc2012-06-29 05:32:48144
[email protected]d68ede02012-11-07 14:30:53145 // Iterates all files in the cache and calls |iteration_callback| for each
146 // file. |completion_callback| is run upon completion.
147 void Iterate(const CacheIterateCallback& iteration_callback,
148 const base::Closure& completion_callback);
[email protected]cd236432012-07-27 18:03:30149
[email protected]a321b9632012-06-14 03:29:17150 // Frees up disk space to store the given number of bytes, while keeping
[email protected]71314de2012-10-30 13:07:51151 // kMinFreeSpace bytes on the disk, if needed.
[email protected]f423c0b2012-11-22 09:51:10152 // Runs |callback| with true when we successfully manage to have enough space.
153 void FreeDiskSpaceIfNeededFor(int64 num_bytes,
154 const InitializeCacheCallback& callback);
[email protected]a321b9632012-06-14 03:29:17155
156 // Checks if file corresponding to |resource_id| and |md5| exists in cache.
[email protected]bdd947c2012-11-06 04:35:34157 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32158 void GetFile(const std::string& resource_id,
159 const std::string& md5,
160 const GetFileFromCacheCallback& callback);
[email protected]a321b9632012-06-14 03:29:17161
162 // Modifies cache state, which involves the following:
163 // - moves or copies (per |file_operation_type|) |source_path|
164 // to |dest_path| in the cache dir
165 // - if necessary, creates symlink
166 // - deletes stale cached versions of |resource_id| in
167 // |dest_path|'s directory.
[email protected]2a2c4152012-11-26 11:34:50168 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32169 void Store(const std::string& resource_id,
170 const std::string& md5,
171 const FilePath& source_path,
172 FileOperationType file_operation_type,
[email protected]2a2c4152012-11-26 11:34:50173 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17174
175 // Modifies cache state, which involves the following:
176 // - moves |source_path| to |dest_path| in persistent dir if
177 // file is not dirty
178 // - creates symlink in pinned dir that references downloaded or locally
179 // modified file
[email protected]2a2c4152012-11-26 11:34:50180 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32181 void Pin(const std::string& resource_id,
182 const std::string& md5,
[email protected]2a2c4152012-11-26 11:34:50183 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17184
185 // Modifies cache state, which involves the following:
186 // - moves |source_path| to |dest_path| in tmp dir if file is not dirty
187 // - deletes symlink from pinned dir
[email protected]2a2c4152012-11-26 11:34:50188 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32189 void Unpin(const std::string& resource_id,
190 const std::string& md5,
[email protected]2a2c4152012-11-26 11:34:50191 const FileOperationCallback& callback);
[email protected]7986b8d2012-06-14 15:05:14192
[email protected]9564c1502012-11-28 12:12:16193 // Set the state of the cache entry corresponding to file_path as mounted.
194 // |callback| must not be null.
195 void MarkAsMounted(const FilePath& file_path,
196 const GetFileFromCacheCallback& callback);
197
198 // Set the state of the cache entry corresponding to file_path as unmounted.
199 // |callback| must not be null.
200 void MarkAsUnmounted(const FilePath& file_path,
201 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17202
203 // Modifies cache state, which involves the following:
204 // - moves |source_path| to |dest_path| in persistent dir, where
205 // |source_path| has .<md5> extension and |dest_path| has .local extension
206 // - if file is pinned, updates symlink in pinned dir to reference dirty file
[email protected]bdd947c2012-11-06 04:35:34207 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32208 void MarkDirty(const std::string& resource_id,
209 const std::string& md5,
[email protected]bc809e42012-11-28 04:46:29210 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17211
212 // Modifies cache state, i.e. creates symlink in outgoing
213 // dir to reference dirty file in persistent dir.
[email protected]2a2c4152012-11-26 11:34:50214 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32215 void CommitDirty(const std::string& resource_id,
216 const std::string& md5,
[email protected]2a2c4152012-11-26 11:34:50217 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17218
219 // Modifies cache state, which involves the following:
220 // - moves |source_path| to |dest_path| in persistent dir if
221 // file is pinned or tmp dir otherwise, where |source_path| has .local
222 // extension and |dest_path| has .<md5> extension
223 // - deletes symlink in outgoing dir
224 // - if file is pinned, updates symlink in pinned dir to reference
225 // |dest_path|
[email protected]2a2c4152012-11-26 11:34:50226 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32227 void ClearDirty(const std::string& resource_id,
228 const std::string& md5,
[email protected]2a2c4152012-11-26 11:34:50229 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17230
231 // Does the following:
232 // - remove all delete stale cache versions corresponding to |resource_id| in
233 // persistent, tmp and pinned directories
234 // - remove entry corresponding to |resource_id| from cache map.
[email protected]2a2c4152012-11-26 11:34:50235 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32236 void Remove(const std::string& resource_id,
[email protected]2a2c4152012-11-26 11:34:50237 const FileOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17238
[email protected]f861b392012-08-03 20:41:12239 // Does the following:
240 // - remove all the files in the cache directory.
241 // - re-create the |metadata_| instance.
[email protected]bdd947c2012-11-06 04:35:34242 // |callback| must not be null.
243 void ClearAll(const InitializeCacheCallback& callback);
[email protected]f861b392012-08-03 20:41:12244
[email protected]322e0032012-10-07 01:55:53245 // Utility method to call Initialize on UI thread. |callback| is called on
246 // UI thread when the initialization is complete.
247 // |callback| must not be null.
[email protected]77fb1a62012-11-01 13:42:32248 void RequestInitialize(const InitializeCacheCallback& callback);
[email protected]73f9c742012-06-15 07:37:13249
[email protected]d310bfc2012-08-10 09:41:28250 // Utility method to call InitializeForTesting on UI thread.
[email protected]77fb1a62012-11-01 13:42:32251 void RequestInitializeForTesting();
[email protected]d310bfc2012-08-10 09:41:28252
[email protected]17196ee2012-12-13 06:23:51253 // Destroys this cache. This function posts a task to the blocking task
254 // runner to safely delete the object.
[email protected]77fb1a62012-11-01 13:42:32255 void Destroy();
[email protected]73f9c742012-06-15 07:37:13256
[email protected]01ba15f72012-06-09 00:41:05257 // Gets the cache root path (i.e. <user_profile_dir>/GCache/v1) from the
258 // profile.
259 // TODO(satorux): Write a unit test for this.
260 static FilePath GetCacheRootPath(Profile* profile);
261
[email protected]30d9dda2012-06-30 05:56:28262 // Returns file paths for all the cache sub directories under
263 // |cache_root_path|.
264 static std::vector<FilePath> GetCachePaths(const FilePath& cache_root_path);
265
266 // Creates cache directory and its sub-directories if they don't exist.
267 // TODO(glotov): take care of this when the setup and cleanup part is
268 // landed, noting that these directories need to be created for development
269 // in linux box and unittest. (http://crosbug.com/27577)
270 static bool CreateCacheDirectories(
271 const std::vector<FilePath>& paths_to_create);
272
[email protected]fae353a2012-07-11 23:30:27273 // Returns the type of the sub directory where the cache file is stored.
274 static CacheSubDirectoryType GetSubDirectoryType(
[email protected]28a64092012-08-21 10:01:12275 const DriveCacheEntry& cache_entry);
[email protected]fae353a2012-07-11 23:30:27276
[email protected]ca5f6da2012-06-18 12:54:59277 private:
[email protected]bdd947c2012-11-06 04:35:34278 typedef std::pair<DriveFileError, FilePath> GetFileResult;
279
[email protected]fb371812012-08-22 16:05:23280 virtual ~DriveCache();
[email protected]fcc92a52012-06-08 22:54:16281
282 // Checks whether the current thread is on the right sequenced worker pool
283 // with the right sequence ID. If not, DCHECK will fail.
284 void AssertOnSequencedWorkerPool();
[email protected]3653146a2012-05-29 13:41:47285
[email protected]bdd947c2012-11-06 04:35:34286 // Initializes the cache. Returns true on success.
287 bool InitializeOnBlockingPool();
[email protected]73f9c742012-06-15 07:37:13288
[email protected]d310bfc2012-08-10 09:41:28289 // Initializes the cache with in-memory cache for testing.
290 // The in-memory cache is used since it's faster than the db.
[email protected]77fb1a62012-11-01 13:42:32291 void InitializeOnBlockingPoolForTesting();
[email protected]d310bfc2012-08-10 09:41:28292
[email protected]17196ee2012-12-13 06:23:51293 // Destroys the cache on the blocking pool.
[email protected]77fb1a62012-11-01 13:42:32294 void DestroyOnBlockingPool();
[email protected]73f9c742012-06-15 07:37:13295
[email protected]717e43c2012-11-22 07:47:39296 // Gets the cache entry by the given resource ID and MD5.
297 // See also GetCacheEntry().
298 bool GetCacheEntryOnBlockingPool(const std::string& resource_id,
299 const std::string& md5,
300 DriveCacheEntry* entry);
301
[email protected]d68ede02012-11-07 14:30:53302 // Used to implement Iterate().
303 void IterateOnBlockingPool(const CacheIterateCallback& iteration_callback);
[email protected]cd236432012-07-27 18:03:30304
[email protected]f423c0b2012-11-22 09:51:10305 // Used to implement FreeDiskSpaceIfNeededFor().
306 bool FreeDiskSpaceOnBlockingPoolIfNeededFor(int64 num_bytes);
307
[email protected]77fb1a62012-11-01 13:42:32308 // Used to implement GetFile.
[email protected]bdd947c2012-11-06 04:35:34309 scoped_ptr<GetFileResult> GetFileOnBlockingPool(
310 const std::string& resource_id,
311 const std::string& md5);
[email protected]c960d222012-06-15 10:03:50312
[email protected]77fb1a62012-11-01 13:42:32313 // Used to implement Store.
[email protected]bdd947c2012-11-06 04:35:34314 DriveFileError StoreOnBlockingPool(const std::string& resource_id,
315 const std::string& md5,
316 const FilePath& source_path,
317 FileOperationType file_operation_type);
[email protected]73f9c742012-06-15 07:37:13318
[email protected]77fb1a62012-11-01 13:42:32319 // Used to implement Pin.
[email protected]bdd947c2012-11-06 04:35:34320 DriveFileError PinOnBlockingPool(const std::string& resource_id,
[email protected]3f5e2902012-11-06 08:21:15321 const std::string& md5);
[email protected]73f9c742012-06-15 07:37:13322
[email protected]77fb1a62012-11-01 13:42:32323 // Used to implement Unpin.
[email protected]bdd947c2012-11-06 04:35:34324 DriveFileError UnpinOnBlockingPool(const std::string& resource_id,
[email protected]3f5e2902012-11-06 08:21:15325 const std::string& md5);
[email protected]73f9c742012-06-15 07:37:13326
[email protected]9564c1502012-11-28 12:12:16327 // Used to implement MarkAsMounted.
328 scoped_ptr<GetFileResult> MarkAsMountedOnBlockingPool(
329 const FilePath& file_path);
330
331 // Used to implement MarkAsUnmounted.
332 DriveFileError MarkAsUnmountedOnBlockingPool(const FilePath& file_path);
[email protected]73f9c742012-06-15 07:37:13333
[email protected]77fb1a62012-11-01 13:42:32334 // Used to implement MarkDirty.
[email protected]bc809e42012-11-28 04:46:29335 DriveFileError MarkDirtyOnBlockingPool(const std::string& resource_id,
336 const std::string& md5);
[email protected]c960d222012-06-15 10:03:50337
[email protected]77fb1a62012-11-01 13:42:32338 // Used to implement CommitDirty.
[email protected]3f5e2902012-11-06 08:21:15339 DriveFileError CommitDirtyOnBlockingPool(const std::string& resource_id,
340 const std::string& md5);
[email protected]73f9c742012-06-15 07:37:13341
[email protected]77fb1a62012-11-01 13:42:32342 // Used to implement ClearDirty.
[email protected]3f5e2902012-11-06 08:21:15343 DriveFileError ClearDirtyOnBlockingPool(const std::string& resource_id,
344 const std::string& md5);
[email protected]73f9c742012-06-15 07:37:13345
[email protected]77fb1a62012-11-01 13:42:32346 // Used to implement Remove.
[email protected]bdd947c2012-11-06 04:35:34347 DriveFileError RemoveOnBlockingPool(const std::string& resource_id);
[email protected]73f9c742012-06-15 07:37:13348
[email protected]77fb1a62012-11-01 13:42:32349 // Used to implement ClearAll.
[email protected]bdd947c2012-11-06 04:35:34350 bool ClearAllOnBlockingPool();
[email protected]f861b392012-08-03 20:41:12351
[email protected]73f9c742012-06-15 07:37:13352 // Runs callback and notifies the observers when file is pinned.
[email protected]bdd947c2012-11-06 04:35:34353 void OnPinned(const std::string& resource_id,
[email protected]73f9c742012-06-15 07:37:13354 const std::string& md5,
[email protected]2a2c4152012-11-26 11:34:50355 const FileOperationCallback& callback,
[email protected]bdd947c2012-11-06 04:35:34356 DriveFileError error);
[email protected]73f9c742012-06-15 07:37:13357
358 // Runs callback and notifies the observers when file is unpinned.
[email protected]bdd947c2012-11-06 04:35:34359 void OnUnpinned(const std::string& resource_id,
[email protected]73f9c742012-06-15 07:37:13360 const std::string& md5,
[email protected]2a2c4152012-11-26 11:34:50361 const FileOperationCallback& callback,
[email protected]bdd947c2012-11-06 04:35:34362 DriveFileError error);
[email protected]73f9c742012-06-15 07:37:13363
[email protected]d7664c22012-06-18 19:35:49364 // Runs callback and notifies the observers when file is committed.
[email protected]bdd947c2012-11-06 04:35:34365 void OnCommitDirty(const std::string& resource_id,
[email protected]2a2c4152012-11-26 11:34:50366 const FileOperationCallback& callback,
[email protected]bdd947c2012-11-06 04:35:34367 DriveFileError error);
[email protected]4324fdc2012-06-29 05:32:48368
[email protected]f6fd98a2012-12-14 00:04:02369 // Returns true if we have sufficient space to store the given number of
370 // bytes, while keeping kMinFreeSpace bytes on the disk.
371 bool HasEnoughSpaceFor(int64 num_bytes, const FilePath& path);
372
[email protected]01ba15f72012-06-09 00:41:05373 // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1).
374 const FilePath cache_root_path_;
[email protected]32a7fc852012-06-08 17:25:50375 // Paths for all subdirectories of GCache, one for each
[email protected]fb371812012-08-22 16:05:23376 // DriveCache::CacheSubDirectoryType enum.
[email protected]6b70c7b2012-06-14 03:10:43377 const std::vector<FilePath> cache_paths_;
[email protected]ddbf2052012-07-13 15:07:02378 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
[email protected]32a7fc852012-06-08 17:25:50379
[email protected]ca5f6da2012-06-18 12:54:59380 // The cache state data. This member must be access only on the blocking pool.
[email protected]fb371812012-08-22 16:05:23381 scoped_ptr<DriveCacheMetadata> metadata_;
[email protected]ca5f6da2012-06-18 12:54:59382
[email protected]73f9c742012-06-15 07:37:13383 // List of observers, this member must be accessed on UI thread.
[email protected]a09275502012-10-10 04:48:01384 ObserverList<DriveCacheObserver> observers_;
[email protected]73f9c742012-06-15 07:37:13385
[email protected]f6fd98a2012-12-14 00:04:02386 FreeDiskSpaceGetterInterface* free_disk_space_getter_; // Not owned.
387
[email protected]e53ac8f2012-08-02 07:05:00388 // Note: This should remain the last member so it'll be destroyed and
389 // invalidate its weak pointers before any other members are destroyed.
[email protected]fb371812012-08-22 16:05:23390 base::WeakPtrFactory<DriveCache> weak_ptr_factory_;
391 DISALLOW_COPY_AND_ASSIGN(DriveCache);
[email protected]3653146a2012-05-29 13:41:47392};
393
[email protected]7f53dc72012-08-23 19:06:55394// The minimum free space to keep. DriveFileSystem::GetFileByPath() returns
[email protected]7f90e77c2012-07-17 09:35:31395// GDATA_FILE_ERROR_NO_SPACE if the available space is smaller than
[email protected]a321b9632012-06-14 03:29:17396// this value.
397//
398// Copied from cryptohome/homedirs.h.
399// TODO(satorux): Share the constant.
400const int64 kMinFreeSpace = 512 * 1LL << 20;
401
[email protected]d9d04df2012-10-12 07:06:35402} // namespace drive
[email protected]3653146a2012-05-29 13:41:47403
[email protected]15de8142012-10-11 06:00:54404#endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_CACHE_H_