blob: 2c67f0ea21e9ee98e7677bbf3f9ea482d3622541 [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
5#ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_
6#define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_
[email protected]3653146a2012-05-29 13:41:477
8#include <map>
9#include <string>
[email protected]79c3752d2012-07-17 12:10:0810#include <vector>
[email protected]3653146a2012-05-29 13:41:4711
[email protected]ddbf2052012-07-13 15:07:0212#include "base/callback.h"
[email protected]32a7fc852012-06-08 17:25:5013#include "base/file_path.h"
[email protected]3653146a2012-05-29 13:41:4714#include "base/memory/scoped_ptr.h"
[email protected]73f9c742012-06-15 07:37:1315#include "base/memory/weak_ptr.h"
16#include "base/observer_list.h"
[email protected]a321b9632012-06-14 03:29:1717#include "base/platform_file.h"
[email protected]7f90e77c2012-07-17 09:35:3118#include "chrome/browser/chromeos/gdata/gdata_errorcode.h"
[email protected]3653146a2012-05-29 13:41:4719
[email protected]01ba15f72012-06-09 00:41:0520class Profile;
21
[email protected]ddbf2052012-07-13 15:07:0222namespace base {
23
24class SequencedTaskRunner;
25
26} // namespace base
27
[email protected]3653146a2012-05-29 13:41:4728namespace gdata {
29
[email protected]12e4c182012-07-12 21:30:0430class GDataCacheEntry;
[email protected]ca5f6da2012-06-18 12:54:5931class GDataCacheMetadata;
32
[email protected]f861b392012-08-03 20:41:1233// Callback for SetMountedStateOnUIThread and ClearAllOnUIThread.
[email protected]7f90e77c2012-07-17 09:35:3134typedef base::Callback<void(GDataFileError error,
[email protected]f861b392012-08-03 20:41:1235 const FilePath& file_path)>
36 ChangeCacheStateCallback;
[email protected]7986b8d2012-06-14 15:05:1437
[email protected]73f9c742012-06-15 07:37:1338// Callback for completion of cache operation.
[email protected]7f90e77c2012-07-17 09:35:3139typedef base::Callback<void(GDataFileError error,
[email protected]73f9c742012-06-15 07:37:1340 const std::string& resource_id,
41 const std::string& md5)> CacheOperationCallback;
42
[email protected]c960d222012-06-15 10:03:5043// Callback for GetFileFromCache.
[email protected]7f90e77c2012-07-17 09:35:3144typedef base::Callback<void(GDataFileError error,
[email protected]c960d222012-06-15 10:03:5045 const std::string& resource_id,
46 const std::string& md5,
47 const FilePath& cache_file_path)>
48 GetFileFromCacheCallback;
49
[email protected]b83e5202012-06-27 07:50:2450// Callback for GetResourceIdsOfBacklogOnUIThread.
51// |to_fetch| is for resource IDs of pinned-but-not-fetched files.
52// |to_upload| is for resource IDs of dirty-but-not-uploaded files.
53typedef base::Callback<void(const std::vector<std::string>& to_fetch,
54 const std::vector<std::string>& to_upload)>
[email protected]85b62192012-06-29 19:56:3855 GetResourceIdsOfBacklogCallback;
56
57// Callback for GetResourceIdsOfExistingPinnedFilesOnUIThread.
58typedef base::Callback<void(const std::vector<std::string>& resource_ids)>
[email protected]8764a392012-06-20 06:43:0859 GetResourceIdsCallback;
60
[email protected]fae353a2012-07-11 23:30:2761// Callback for GetCacheEntryOnUIThread.
62// |success| indicates if the operation was successful.
63// |cache_entry| is the obtained cache entry. On failure, |cache_state| is
[email protected]02821102012-07-12 20:19:1764// set to TEST_CACHE_STATE_NONE.
[email protected]fae353a2012-07-11 23:30:2765typedef base::Callback<void(bool success, const GDataCacheEntry& cache_entry)>
66 GetCacheEntryCallback;
67
[email protected]6b70c7b2012-06-14 03:10:4368// GDataCache is used to maintain cache states of GDataFileSystem.
69//
70// All non-static public member functions, unless mentioned otherwise (see
71// GetCacheFilePath() for example), should be called from the sequenced
[email protected]73f9c742012-06-15 07:37:1372// worker pool with the sequence token set by CreateGDataCacheOnUIThread(). This
[email protected]6b70c7b2012-06-14 03:10:4373// threading model is enforced by AssertOnSequencedWorkerPool().
[email protected]73f9c742012-06-15 07:37:1374//
75// TODO(hashimoto): Change threading model of this class to make public methods
76// being called on UI thread unless mentioned otherwise. crbug.com/132926
[email protected]3653146a2012-05-29 13:41:4777class GDataCache {
78 public:
79 // Enum defining GCache subdirectory location.
[email protected]6b70c7b2012-06-14 03:10:4380 // This indexes into |GDataCache::cache_paths_| vector.
[email protected]3653146a2012-05-29 13:41:4781 enum CacheSubDirectoryType {
82 CACHE_TYPE_META = 0, // Downloaded feeds.
83 CACHE_TYPE_PINNED, // Symlinks to files in persistent dir that are
84 // pinned, or to /dev/null for non-existent
85 // files.
86 CACHE_TYPE_OUTGOING, // Symlinks to files in persistent or tmp dir to
87 // be uploaded.
88 CACHE_TYPE_PERSISTENT, // Files that are pinned or modified locally,
89 // not evictable, hopefully.
90 CACHE_TYPE_TMP, // Files that don't meet criteria to be in
91 // persistent dir, and hence evictable.
92 CACHE_TYPE_TMP_DOWNLOADS, // Downloaded files.
93 CACHE_TYPE_TMP_DOCUMENTS, // Temporary JSON files for hosted documents.
94 NUM_CACHE_TYPES, // This must be at the end.
95 };
96
[email protected]32a7fc852012-06-08 17:25:5097 // Enum defining origin of a cached file.
98 enum CachedFileOrigin {
99 CACHED_FILE_FROM_SERVER = 0,
100 CACHED_FILE_LOCALLY_MODIFIED,
101 CACHED_FILE_MOUNTED,
102 };
103
[email protected]a321b9632012-06-14 03:29:17104 // Enum defining type of file operation e.g. copy or move, etc.
105 enum FileOperationType {
106 FILE_OPERATION_MOVE = 0,
107 FILE_OPERATION_COPY,
108 };
[email protected]32a7fc852012-06-08 17:25:50109
[email protected]73f9c742012-06-15 07:37:13110 // Used to notify events. All events are notified on UI thread.
111 class Observer {
112 public:
[email protected]73f9c742012-06-15 07:37:13113 // Triggered when a file has been pinned successfully.
114 virtual void OnCachePinned(const std::string& resource_id,
115 const std::string& md5) {}
116
117 // Triggered when a file has been unpinned successfully.
118 virtual void OnCacheUnpinned(const std::string& resource_id,
119 const std::string& md5) {}
120
[email protected]d7664c22012-06-18 19:35:49121 // Triggered when a dirty file has been committed (saved) successfully.
122 virtual void OnCacheCommitted(const std::string& resource_id) {}
123
[email protected]73f9c742012-06-15 07:37:13124 protected:
125 virtual ~Observer() {}
126 };
127
[email protected]32a7fc852012-06-08 17:25:50128 // Returns the sub-directory under gdata cache directory for the given sub
129 // directory type. Example: <user_profile_dir>/GCache/v1/tmp
[email protected]6b70c7b2012-06-14 03:10:43130 //
131 // Can be called on any thread.
[email protected]32a7fc852012-06-08 17:25:50132 FilePath GetCacheDirectoryPath(CacheSubDirectoryType sub_dir_type) const;
133
134 // Returns absolute path of the file if it were cached or to be cached.
[email protected]6b70c7b2012-06-14 03:10:43135 //
136 // Can be called on any thread.
[email protected]32a7fc852012-06-08 17:25:50137 FilePath GetCacheFilePath(const std::string& resource_id,
138 const std::string& md5,
139 CacheSubDirectoryType sub_dir_type,
140 CachedFileOrigin file_orign) const;
141
[email protected]01ba15f72012-06-09 00:41:05142 // Returns true if the given path is under gdata cache directory, i.e.
143 // <user_profile_dir>/GCache/v1
[email protected]6b70c7b2012-06-14 03:10:43144 //
145 // Can be called on any thread.
[email protected]01ba15f72012-06-09 00:41:05146 bool IsUnderGDataCacheDirectory(const FilePath& path) const;
147
[email protected]73f9c742012-06-15 07:37:13148 // Adds observer.
149 // Must be called on UI thread.
150 void AddObserver(Observer* observer);
151
152 // Removes observer.
153 // Must be called on UI thread.
154 void RemoveObserver(Observer* observer);
155
[email protected]4324fdc2012-06-29 05:32:48156 // Gets the cache entry by the given resource ID and MD5.
157 // See also GetCacheEntry().
158 //
159 // Must be called on UI thread. |callback| is run on UI thread.
160 void GetCacheEntryOnUIThread(
161 const std::string& resource_id,
162 const std::string& md5,
163 const GetCacheEntryCallback& callback);
164
[email protected]b83e5202012-06-27 07:50:24165 // Gets the resource IDs of pinned-but-not-fetched files and
166 // dirty-but-not-uploaded files.
167 //
[email protected]8764a392012-06-20 06:43:08168 // Must be called on UI thread. |callback| is run on UI thread.
[email protected]b83e5202012-06-27 07:50:24169 void GetResourceIdsOfBacklogOnUIThread(
[email protected]85b62192012-06-29 19:56:38170 const GetResourceIdsOfBacklogCallback& callback);
171
[email protected]d7754f52012-08-01 08:45:33172 // Gets the resource IDs of all existing (i.e. cached locally) pinned
[email protected]cd236432012-07-27 18:03:30173 // files, including pinned dirty files.
[email protected]85b62192012-06-29 19:56:38174 //
175 // Must be called on UI thread. |callback| is run on UI thread.
176 void GetResourceIdsOfExistingPinnedFilesOnUIThread(
[email protected]8764a392012-06-20 06:43:08177 const GetResourceIdsCallback& callback);
178
[email protected]cd236432012-07-27 18:03:30179 // Gets the resource IDs of all files in the cache.
180 //
181 // Must be called on UI thread. |callback| is run on UI thread.
182 void GetResourceIdsOfAllFilesOnUIThread(
183 const GetResourceIdsCallback& callback);
184
[email protected]a321b9632012-06-14 03:29:17185 // Frees up disk space to store the given number of bytes, while keeping
186 // kMinFreSpace bytes on the disk, if needed. |has_enough_space| is
187 // updated to indicate if we have enough space.
188 void FreeDiskSpaceIfNeededFor(int64 num_bytes,
189 bool* has_enough_space);
190
191 // Checks if file corresponding to |resource_id| and |md5| exists in cache.
[email protected]c960d222012-06-15 10:03:50192 void GetFileOnUIThread(const std::string& resource_id,
193 const std::string& md5,
194 const GetFileFromCacheCallback& callback);
[email protected]a321b9632012-06-14 03:29:17195
196 // Modifies cache state, which involves the following:
197 // - moves or copies (per |file_operation_type|) |source_path|
198 // to |dest_path| in the cache dir
199 // - if necessary, creates symlink
200 // - deletes stale cached versions of |resource_id| in
201 // |dest_path|'s directory.
[email protected]73f9c742012-06-15 07:37:13202 void StoreOnUIThread(const std::string& resource_id,
203 const std::string& md5,
204 const FilePath& source_path,
205 FileOperationType file_operation_type,
206 const CacheOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17207
208 // Modifies cache state, which involves the following:
209 // - moves |source_path| to |dest_path| in persistent dir if
210 // file is not dirty
211 // - creates symlink in pinned dir that references downloaded or locally
212 // modified file
[email protected]73f9c742012-06-15 07:37:13213 void PinOnUIThread(const std::string& resource_id,
214 const std::string& md5,
215 const CacheOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17216
217 // Modifies cache state, which involves the following:
218 // - moves |source_path| to |dest_path| in tmp dir if file is not dirty
219 // - deletes symlink from pinned dir
[email protected]73f9c742012-06-15 07:37:13220 void UnpinOnUIThread(const std::string& resource_id,
221 const std::string& md5,
222 const CacheOperationCallback& callback);
[email protected]7986b8d2012-06-14 15:05:14223
[email protected]a321b9632012-06-14 03:29:17224 // Modifies cache state, which involves the following:
225 // - moves |source_path| to |dest_path|, where
226 // if we're mounting: |source_path| is the unmounted path and has .<md5>
227 // extension, and |dest_path| is the mounted path in persistent dir
228 // and has .<md5>.mounted extension;
229 // if we're unmounting: the opposite is true for the two paths, i.e.
230 // |dest_path| is the mounted path and |source_path| the unmounted path.
[email protected]73f9c742012-06-15 07:37:13231 void SetMountedStateOnUIThread(const FilePath& file_path,
232 bool to_mount,
[email protected]f861b392012-08-03 20:41:12233 const ChangeCacheStateCallback& callback);
[email protected]a321b9632012-06-14 03:29:17234
235 // Modifies cache state, which involves the following:
236 // - moves |source_path| to |dest_path| in persistent dir, where
237 // |source_path| has .<md5> extension and |dest_path| has .local extension
238 // - if file is pinned, updates symlink in pinned dir to reference dirty file
[email protected]c960d222012-06-15 10:03:50239 void MarkDirtyOnUIThread(const std::string& resource_id,
240 const std::string& md5,
241 const GetFileFromCacheCallback& callback);
[email protected]a321b9632012-06-14 03:29:17242
243 // Modifies cache state, i.e. creates symlink in outgoing
244 // dir to reference dirty file in persistent dir.
[email protected]73f9c742012-06-15 07:37:13245 void CommitDirtyOnUIThread(const std::string& resource_id,
246 const std::string& md5,
247 const CacheOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17248
249 // Modifies cache state, which involves the following:
250 // - moves |source_path| to |dest_path| in persistent dir if
251 // file is pinned or tmp dir otherwise, where |source_path| has .local
252 // extension and |dest_path| has .<md5> extension
253 // - deletes symlink in outgoing dir
254 // - if file is pinned, updates symlink in pinned dir to reference
255 // |dest_path|
[email protected]73f9c742012-06-15 07:37:13256 void ClearDirtyOnUIThread(const std::string& resource_id,
257 const std::string& md5,
258 const CacheOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17259
260 // Does the following:
261 // - remove all delete stale cache versions corresponding to |resource_id| in
262 // persistent, tmp and pinned directories
263 // - remove entry corresponding to |resource_id| from cache map.
[email protected]73f9c742012-06-15 07:37:13264 void RemoveOnUIThread(const std::string& resource_id,
265 const CacheOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17266
[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.
270 void ClearAllOnUIThread(const ChangeCacheStateCallback& callback);
271
[email protected]73f9c742012-06-15 07:37:13272 // Utility method to call Initialize on UI thread.
273 void RequestInitializeOnUIThread();
274
[email protected]d310bfc2012-08-10 09:41:28275 // Utility method to call InitializeForTesting on UI thread.
276 void RequestInitializeOnUIThreadForTesting();
277
[email protected]79c3752d2012-07-17 12:10:08278 // Force a rescan of cache files, for testing.
279 void ForceRescanOnUIThreadForTesting();
280
[email protected]b22f87f2012-07-12 10:53:17281 // Gets the cache entry for file corresponding to |resource_id| and |md5|
282 // and returns true if entry exists in cache map. Otherwise, returns false.
[email protected]3653146a2012-05-29 13:41:47283 // |md5| can be empty if only matching |resource_id| is desired, which may
284 // happen when looking for pinned entries where symlinks' filenames have no
285 // extension and hence no md5.
[email protected]b22f87f2012-07-12 10:53:17286 bool GetCacheEntry(const std::string& resource_id,
287 const std::string& md5,
288 GDataCacheEntry* entry);
[email protected]3653146a2012-05-29 13:41:47289
290 // Factory methods for GDataCache.
[email protected]fcc92a52012-06-08 22:54:16291 // |pool| and |sequence_token| are used to assert that the functions are
292 // called on the right sequenced worker pool with the right sequence token.
293 //
294 // For testing, the thread assertion can be disabled by passing NULL and
295 // the default value of SequenceToken.
[email protected]73f9c742012-06-15 07:37:13296 static GDataCache* CreateGDataCacheOnUIThread(
[email protected]fcc92a52012-06-08 22:54:16297 const FilePath& cache_root_path,
[email protected]ddbf2052012-07-13 15:07:02298 base::SequencedTaskRunner* blocking_task_runner);
[email protected]3653146a2012-05-29 13:41:47299
[email protected]73f9c742012-06-15 07:37:13300 // Deletes the cache.
301 void DestroyOnUIThread();
302
[email protected]01ba15f72012-06-09 00:41:05303 // Gets the cache root path (i.e. <user_profile_dir>/GCache/v1) from the
304 // profile.
305 // TODO(satorux): Write a unit test for this.
306 static FilePath GetCacheRootPath(Profile* profile);
307
[email protected]30d9dda2012-06-30 05:56:28308 // Returns file paths for all the cache sub directories under
309 // |cache_root_path|.
310 static std::vector<FilePath> GetCachePaths(const FilePath& cache_root_path);
311
312 // Creates cache directory and its sub-directories if they don't exist.
313 // TODO(glotov): take care of this when the setup and cleanup part is
314 // landed, noting that these directories need to be created for development
315 // in linux box and unittest. (http://crosbug.com/27577)
316 static bool CreateCacheDirectories(
317 const std::vector<FilePath>& paths_to_create);
318
[email protected]fae353a2012-07-11 23:30:27319 // Returns the type of the sub directory where the cache file is stored.
320 static CacheSubDirectoryType GetSubDirectoryType(
321 const GDataCacheEntry& cache_entry);
322
[email protected]ca5f6da2012-06-18 12:54:59323 private:
[email protected]ddbf2052012-07-13 15:07:02324 GDataCache(const FilePath& cache_root_path,
325 base::SequencedTaskRunner* blocking_task_runner);
[email protected]73f9c742012-06-15 07:37:13326 virtual ~GDataCache();
[email protected]fcc92a52012-06-08 22:54:16327
328 // Checks whether the current thread is on the right sequenced worker pool
329 // with the right sequence ID. If not, DCHECK will fail.
330 void AssertOnSequencedWorkerPool();
[email protected]3653146a2012-05-29 13:41:47331
[email protected]ca5f6da2012-06-18 12:54:59332 // Initializes the cache.
333 void Initialize();
[email protected]73f9c742012-06-15 07:37:13334
[email protected]d310bfc2012-08-10 09:41:28335 // Initializes the cache with in-memory cache for testing.
336 // The in-memory cache is used since it's faster than the db.
337 void InitializeForTesting();
338
[email protected]73f9c742012-06-15 07:37:13339 // Deletes the cache.
340 void Destroy();
341
[email protected]79c3752d2012-07-17 12:10:08342 // Force a rescan of cache directories.
343 void ForceRescanForTesting();
344
[email protected]b83e5202012-06-27 07:50:24345 // Used to implement GetResourceIdsOfBacklogOnUIThread.
346 void GetResourceIdsOfBacklog(
347 std::vector<std::string>* to_fetch,
348 std::vector<std::string>* to_upload);
[email protected]8764a392012-06-20 06:43:08349
[email protected]85b62192012-06-29 19:56:38350 // Used to implement GetResourceIdsOfExistingPinnedFilesOnUIThread.
351 void GetResourceIdsOfExistingPinnedFiles(
352 std::vector<std::string>* resource_ids);
353
[email protected]cd236432012-07-27 18:03:30354 // Used to implement GetResourceIdsOfAllFilesOnUIThread.
355 void GetResourceIdsOfAllFiles(
356 std::vector<std::string>* resource_ids);
357
[email protected]c960d222012-06-15 10:03:50358 // Used to implement GetFileOnUIThread.
359 void GetFile(const std::string& resource_id,
360 const std::string& md5,
[email protected]7f90e77c2012-07-17 09:35:31361 GDataFileError* error,
[email protected]c960d222012-06-15 10:03:50362 FilePath* cache_file_path);
363
[email protected]73f9c742012-06-15 07:37:13364 // Used to implement StoreOnUIThread.
365 void Store(const std::string& resource_id,
366 const std::string& md5,
367 const FilePath& source_path,
368 FileOperationType file_operation_type,
[email protected]7f90e77c2012-07-17 09:35:31369 GDataFileError* error);
[email protected]73f9c742012-06-15 07:37:13370
371 // Used to implement PinOnUIThread.
372 void Pin(const std::string& resource_id,
373 const std::string& md5,
374 FileOperationType file_operation_type,
[email protected]7f90e77c2012-07-17 09:35:31375 GDataFileError* error);
[email protected]73f9c742012-06-15 07:37:13376
377 // Used to implement UnpinOnUIThread.
378 void Unpin(const std::string& resource_id,
379 const std::string& md5,
380 FileOperationType file_operation_type,
[email protected]7f90e77c2012-07-17 09:35:31381 GDataFileError* error);
[email protected]73f9c742012-06-15 07:37:13382
383 // Used to implement SetMountedStateOnUIThread.
384 void SetMountedState(const FilePath& file_path,
385 bool to_mount,
[email protected]7f90e77c2012-07-17 09:35:31386 GDataFileError* error,
[email protected]73f9c742012-06-15 07:37:13387 FilePath* cache_file_path);
388
[email protected]c960d222012-06-15 10:03:50389 // Used to implement MarkDirtyOnUIThread.
390 void MarkDirty(const std::string& resource_id,
391 const std::string& md5,
392 FileOperationType file_operation_type,
[email protected]7f90e77c2012-07-17 09:35:31393 GDataFileError* error,
[email protected]c960d222012-06-15 10:03:50394 FilePath* cache_file_path);
395
[email protected]73f9c742012-06-15 07:37:13396 // Used to implement CommitDirtyOnUIThread.
397 void CommitDirty(const std::string& resource_id,
398 const std::string& md5,
399 FileOperationType file_operation_type,
[email protected]7f90e77c2012-07-17 09:35:31400 GDataFileError* error);
[email protected]73f9c742012-06-15 07:37:13401
402 // Used to implement ClearDirtyOnUIThread.
403 void ClearDirty(const std::string& resource_id,
404 const std::string& md5,
405 FileOperationType file_operation_type,
[email protected]7f90e77c2012-07-17 09:35:31406 GDataFileError* error);
[email protected]73f9c742012-06-15 07:37:13407
408 // Used to implement RemoveOnUIThread.
409 void Remove(const std::string& resource_id,
[email protected]7f90e77c2012-07-17 09:35:31410 GDataFileError* error);
[email protected]73f9c742012-06-15 07:37:13411
[email protected]f861b392012-08-03 20:41:12412 // Used to implement ClearAllUIThread.
413 void ClearAll(GDataFileError* error);
414
[email protected]73f9c742012-06-15 07:37:13415 // Runs callback and notifies the observers when file is pinned.
[email protected]7f90e77c2012-07-17 09:35:31416 void OnPinned(GDataFileError* error,
[email protected]73f9c742012-06-15 07:37:13417 const std::string& resource_id,
418 const std::string& md5,
419 const CacheOperationCallback& callback);
420
421 // Runs callback and notifies the observers when file is unpinned.
[email protected]7f90e77c2012-07-17 09:35:31422 void OnUnpinned(GDataFileError* error,
[email protected]73f9c742012-06-15 07:37:13423 const std::string& resource_id,
424 const std::string& md5,
425 const CacheOperationCallback& callback);
426
[email protected]d7664c22012-06-18 19:35:49427 // Runs callback and notifies the observers when file is committed.
[email protected]7f90e77c2012-07-17 09:35:31428 void OnCommitDirty(GDataFileError* error,
[email protected]d7664c22012-06-18 19:35:49429 const std::string& resource_id,
430 const std::string& md5,
431 const CacheOperationCallback& callback);
432
[email protected]4324fdc2012-06-29 05:32:48433 // Helper function to implement GetCacheEntryOnUIThread().
434 void GetCacheEntryHelper(const std::string& resource_id,
435 const std::string& md5,
436 bool* success,
[email protected]fae353a2012-07-11 23:30:27437 GDataCacheEntry* cache_entry);
[email protected]4324fdc2012-06-29 05:32:48438
[email protected]01ba15f72012-06-09 00:41:05439 // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1).
440 const FilePath cache_root_path_;
[email protected]32a7fc852012-06-08 17:25:50441 // Paths for all subdirectories of GCache, one for each
442 // GDataCache::CacheSubDirectoryType enum.
[email protected]6b70c7b2012-06-14 03:10:43443 const std::vector<FilePath> cache_paths_;
[email protected]ddbf2052012-07-13 15:07:02444 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
[email protected]32a7fc852012-06-08 17:25:50445
[email protected]ca5f6da2012-06-18 12:54:59446 // The cache state data. This member must be access only on the blocking pool.
447 scoped_ptr<GDataCacheMetadata> metadata_;
448
[email protected]73f9c742012-06-15 07:37:13449 // List of observers, this member must be accessed on UI thread.
450 ObserverList<Observer> observers_;
451
[email protected]e53ac8f2012-08-02 07:05:00452 // Note: This should remain the last member so it'll be destroyed and
453 // invalidate its weak pointers before any other members are destroyed.
454 base::WeakPtrFactory<GDataCache> weak_ptr_factory_;
[email protected]3653146a2012-05-29 13:41:47455 DISALLOW_COPY_AND_ASSIGN(GDataCache);
456};
457
[email protected]a321b9632012-06-14 03:29:17458
459// The minimum free space to keep. GDataFileSystem::GetFileByPath() returns
[email protected]7f90e77c2012-07-17 09:35:31460// GDATA_FILE_ERROR_NO_SPACE if the available space is smaller than
[email protected]a321b9632012-06-14 03:29:17461// this value.
462//
463// Copied from cryptohome/homedirs.h.
464// TODO(satorux): Share the constant.
465const int64 kMinFreeSpace = 512 * 1LL << 20;
466
467// Interface class used for getting the free disk space. Only for testing.
468class FreeDiskSpaceGetterInterface {
469 public:
470 virtual ~FreeDiskSpaceGetterInterface() {}
471 virtual int64 AmountOfFreeDiskSpace() const = 0;
472};
473
474// Sets the free disk space getter for testing.
475// The existing getter is deleted.
476void SetFreeDiskSpaceGetterForTesting(
477 FreeDiskSpaceGetterInterface* getter);
478
[email protected]3653146a2012-05-29 13:41:47479} // namespace gdata
480
481#endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_