blob: 5aa8a06cb2faf4902a24425d1e43273a3d7d307c [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]7986b8d2012-06-14 15:05:1433// Callback for SetMountedStateOnUIThread.
[email protected]7f90e77c2012-07-17 09:35:3134typedef base::Callback<void(GDataFileError error,
[email protected]7986b8d2012-06-14 15:05:1435 const FilePath& file_path)> SetMountedStateCallback;
36
[email protected]73f9c742012-06-15 07:37:1337// Callback for completion of cache operation.
[email protected]7f90e77c2012-07-17 09:35:3138typedef base::Callback<void(GDataFileError error,
[email protected]73f9c742012-06-15 07:37:1339 const std::string& resource_id,
40 const std::string& md5)> CacheOperationCallback;
41
[email protected]c960d222012-06-15 10:03:5042// Callback for GetFileFromCache.
[email protected]7f90e77c2012-07-17 09:35:3143typedef base::Callback<void(GDataFileError error,
[email protected]c960d222012-06-15 10:03:5044 const std::string& resource_id,
45 const std::string& md5,
46 const FilePath& cache_file_path)>
47 GetFileFromCacheCallback;
48
[email protected]b83e5202012-06-27 07:50:2449// Callback for GetResourceIdsOfBacklogOnUIThread.
50// |to_fetch| is for resource IDs of pinned-but-not-fetched files.
51// |to_upload| is for resource IDs of dirty-but-not-uploaded files.
52typedef base::Callback<void(const std::vector<std::string>& to_fetch,
53 const std::vector<std::string>& to_upload)>
[email protected]85b62192012-06-29 19:56:3854 GetResourceIdsOfBacklogCallback;
55
56// Callback for GetResourceIdsOfExistingPinnedFilesOnUIThread.
57typedef base::Callback<void(const std::vector<std::string>& resource_ids)>
[email protected]8764a392012-06-20 06:43:0858 GetResourceIdsCallback;
59
[email protected]fae353a2012-07-11 23:30:2760// Callback for GetCacheEntryOnUIThread.
61// |success| indicates if the operation was successful.
62// |cache_entry| is the obtained cache entry. On failure, |cache_state| is
[email protected]02821102012-07-12 20:19:1763// set to TEST_CACHE_STATE_NONE.
[email protected]fae353a2012-07-11 23:30:2764typedef base::Callback<void(bool success, const GDataCacheEntry& cache_entry)>
65 GetCacheEntryCallback;
66
[email protected]6b70c7b2012-06-14 03:10:4367// GDataCache is used to maintain cache states of GDataFileSystem.
68//
69// All non-static public member functions, unless mentioned otherwise (see
70// GetCacheFilePath() for example), should be called from the sequenced
[email protected]73f9c742012-06-15 07:37:1371// worker pool with the sequence token set by CreateGDataCacheOnUIThread(). This
[email protected]6b70c7b2012-06-14 03:10:4372// threading model is enforced by AssertOnSequencedWorkerPool().
[email protected]73f9c742012-06-15 07:37:1373//
74// TODO(hashimoto): Change threading model of this class to make public methods
75// being called on UI thread unless mentioned otherwise. crbug.com/132926
[email protected]3653146a2012-05-29 13:41:4776class GDataCache {
77 public:
78 // Enum defining GCache subdirectory location.
[email protected]6b70c7b2012-06-14 03:10:4379 // This indexes into |GDataCache::cache_paths_| vector.
[email protected]3653146a2012-05-29 13:41:4780 enum CacheSubDirectoryType {
81 CACHE_TYPE_META = 0, // Downloaded feeds.
82 CACHE_TYPE_PINNED, // Symlinks to files in persistent dir that are
83 // pinned, or to /dev/null for non-existent
84 // files.
85 CACHE_TYPE_OUTGOING, // Symlinks to files in persistent or tmp dir to
86 // be uploaded.
87 CACHE_TYPE_PERSISTENT, // Files that are pinned or modified locally,
88 // not evictable, hopefully.
89 CACHE_TYPE_TMP, // Files that don't meet criteria to be in
90 // persistent dir, and hence evictable.
91 CACHE_TYPE_TMP_DOWNLOADS, // Downloaded files.
92 CACHE_TYPE_TMP_DOCUMENTS, // Temporary JSON files for hosted documents.
93 NUM_CACHE_TYPES, // This must be at the end.
94 };
95
[email protected]32a7fc852012-06-08 17:25:5096 // Enum defining origin of a cached file.
97 enum CachedFileOrigin {
98 CACHED_FILE_FROM_SERVER = 0,
99 CACHED_FILE_LOCALLY_MODIFIED,
100 CACHED_FILE_MOUNTED,
101 };
102
[email protected]a321b9632012-06-14 03:29:17103 // Enum defining type of file operation e.g. copy or move, etc.
104 enum FileOperationType {
105 FILE_OPERATION_MOVE = 0,
106 FILE_OPERATION_COPY,
107 };
[email protected]32a7fc852012-06-08 17:25:50108
[email protected]73f9c742012-06-15 07:37:13109 // Used to notify events. All events are notified on UI thread.
110 class Observer {
111 public:
[email protected]73f9c742012-06-15 07:37:13112 // Triggered when a file has been pinned successfully.
113 virtual void OnCachePinned(const std::string& resource_id,
114 const std::string& md5) {}
115
116 // Triggered when a file has been unpinned successfully.
117 virtual void OnCacheUnpinned(const std::string& resource_id,
118 const std::string& md5) {}
119
[email protected]d7664c22012-06-18 19:35:49120 // Triggered when a dirty file has been committed (saved) successfully.
121 virtual void OnCacheCommitted(const std::string& resource_id) {}
122
[email protected]73f9c742012-06-15 07:37:13123 protected:
124 virtual ~Observer() {}
125 };
126
[email protected]32a7fc852012-06-08 17:25:50127 // Returns the sub-directory under gdata cache directory for the given sub
128 // directory type. Example: <user_profile_dir>/GCache/v1/tmp
[email protected]6b70c7b2012-06-14 03:10:43129 //
130 // Can be called on any thread.
[email protected]32a7fc852012-06-08 17:25:50131 FilePath GetCacheDirectoryPath(CacheSubDirectoryType sub_dir_type) const;
132
133 // Returns absolute path of the file if it were cached or to be cached.
[email protected]6b70c7b2012-06-14 03:10:43134 //
135 // Can be called on any thread.
[email protected]32a7fc852012-06-08 17:25:50136 FilePath GetCacheFilePath(const std::string& resource_id,
137 const std::string& md5,
138 CacheSubDirectoryType sub_dir_type,
139 CachedFileOrigin file_orign) const;
140
[email protected]01ba15f72012-06-09 00:41:05141 // Returns true if the given path is under gdata cache directory, i.e.
142 // <user_profile_dir>/GCache/v1
[email protected]6b70c7b2012-06-14 03:10:43143 //
144 // Can be called on any thread.
[email protected]01ba15f72012-06-09 00:41:05145 bool IsUnderGDataCacheDirectory(const FilePath& path) const;
146
[email protected]73f9c742012-06-15 07:37:13147 // Adds observer.
148 // Must be called on UI thread.
149 void AddObserver(Observer* observer);
150
151 // Removes observer.
152 // Must be called on UI thread.
153 void RemoveObserver(Observer* observer);
154
[email protected]4324fdc2012-06-29 05:32:48155 // Gets the cache entry by the given resource ID and MD5.
156 // See also GetCacheEntry().
157 //
158 // Must be called on UI thread. |callback| is run on UI thread.
159 void GetCacheEntryOnUIThread(
160 const std::string& resource_id,
161 const std::string& md5,
162 const GetCacheEntryCallback& callback);
163
[email protected]b83e5202012-06-27 07:50:24164 // Gets the resource IDs of pinned-but-not-fetched files and
165 // dirty-but-not-uploaded files.
166 //
[email protected]8764a392012-06-20 06:43:08167 // Must be called on UI thread. |callback| is run on UI thread.
[email protected]b83e5202012-06-27 07:50:24168 void GetResourceIdsOfBacklogOnUIThread(
[email protected]85b62192012-06-29 19:56:38169 const GetResourceIdsOfBacklogCallback& callback);
170
[email protected]cd236432012-07-27 18:03:30171 // Gets the resource IDs of all exsiting (i.e. cached locally) pinned
172 // files, including pinned dirty files.
[email protected]85b62192012-06-29 19:56:38173 //
174 // Must be called on UI thread. |callback| is run on UI thread.
175 void GetResourceIdsOfExistingPinnedFilesOnUIThread(
[email protected]8764a392012-06-20 06:43:08176 const GetResourceIdsCallback& callback);
177
[email protected]cd236432012-07-27 18:03:30178 // Gets the resource IDs of all files in the cache.
179 //
180 // Must be called on UI thread. |callback| is run on UI thread.
181 void GetResourceIdsOfAllFilesOnUIThread(
182 const GetResourceIdsCallback& callback);
183
[email protected]a321b9632012-06-14 03:29:17184 // Frees up disk space to store the given number of bytes, while keeping
185 // kMinFreSpace bytes on the disk, if needed. |has_enough_space| is
186 // updated to indicate if we have enough space.
187 void FreeDiskSpaceIfNeededFor(int64 num_bytes,
188 bool* has_enough_space);
189
190 // Checks if file corresponding to |resource_id| and |md5| exists in cache.
[email protected]c960d222012-06-15 10:03:50191 void GetFileOnUIThread(const std::string& resource_id,
192 const std::string& md5,
193 const GetFileFromCacheCallback& callback);
[email protected]a321b9632012-06-14 03:29:17194
195 // Modifies cache state, which involves the following:
196 // - moves or copies (per |file_operation_type|) |source_path|
197 // to |dest_path| in the cache dir
198 // - if necessary, creates symlink
199 // - deletes stale cached versions of |resource_id| in
200 // |dest_path|'s directory.
[email protected]73f9c742012-06-15 07:37:13201 void StoreOnUIThread(const std::string& resource_id,
202 const std::string& md5,
203 const FilePath& source_path,
204 FileOperationType file_operation_type,
205 const CacheOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17206
207 // Modifies cache state, which involves the following:
208 // - moves |source_path| to |dest_path| in persistent dir if
209 // file is not dirty
210 // - creates symlink in pinned dir that references downloaded or locally
211 // modified file
[email protected]73f9c742012-06-15 07:37:13212 void PinOnUIThread(const std::string& resource_id,
213 const std::string& md5,
214 const CacheOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17215
216 // Modifies cache state, which involves the following:
217 // - moves |source_path| to |dest_path| in tmp dir if file is not dirty
218 // - deletes symlink from pinned dir
[email protected]73f9c742012-06-15 07:37:13219 void UnpinOnUIThread(const std::string& resource_id,
220 const std::string& md5,
221 const CacheOperationCallback& callback);
[email protected]7986b8d2012-06-14 15:05:14222
[email protected]a321b9632012-06-14 03:29:17223 // Modifies cache state, which involves the following:
224 // - moves |source_path| to |dest_path|, where
225 // if we're mounting: |source_path| is the unmounted path and has .<md5>
226 // extension, and |dest_path| is the mounted path in persistent dir
227 // and has .<md5>.mounted extension;
228 // if we're unmounting: the opposite is true for the two paths, i.e.
229 // |dest_path| is the mounted path and |source_path| the unmounted path.
[email protected]73f9c742012-06-15 07:37:13230 void SetMountedStateOnUIThread(const FilePath& file_path,
231 bool to_mount,
232 const SetMountedStateCallback& callback);
[email protected]a321b9632012-06-14 03:29:17233
234 // Modifies cache state, which involves the following:
235 // - moves |source_path| to |dest_path| in persistent dir, where
236 // |source_path| has .<md5> extension and |dest_path| has .local extension
237 // - if file is pinned, updates symlink in pinned dir to reference dirty file
[email protected]c960d222012-06-15 10:03:50238 void MarkDirtyOnUIThread(const std::string& resource_id,
239 const std::string& md5,
240 const GetFileFromCacheCallback& callback);
[email protected]a321b9632012-06-14 03:29:17241
242 // Modifies cache state, i.e. creates symlink in outgoing
243 // dir to reference dirty file in persistent dir.
[email protected]73f9c742012-06-15 07:37:13244 void CommitDirtyOnUIThread(const std::string& resource_id,
245 const std::string& md5,
246 const CacheOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17247
248 // Modifies cache state, which involves the following:
249 // - moves |source_path| to |dest_path| in persistent dir if
250 // file is pinned or tmp dir otherwise, where |source_path| has .local
251 // extension and |dest_path| has .<md5> extension
252 // - deletes symlink in outgoing dir
253 // - if file is pinned, updates symlink in pinned dir to reference
254 // |dest_path|
[email protected]73f9c742012-06-15 07:37:13255 void ClearDirtyOnUIThread(const std::string& resource_id,
256 const std::string& md5,
257 const CacheOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17258
259 // Does the following:
260 // - remove all delete stale cache versions corresponding to |resource_id| in
261 // persistent, tmp and pinned directories
262 // - remove entry corresponding to |resource_id| from cache map.
[email protected]73f9c742012-06-15 07:37:13263 void RemoveOnUIThread(const std::string& resource_id,
264 const CacheOperationCallback& callback);
[email protected]a321b9632012-06-14 03:29:17265
[email protected]73f9c742012-06-15 07:37:13266 // Utility method to call Initialize on UI thread.
267 void RequestInitializeOnUIThread();
268
[email protected]79c3752d2012-07-17 12:10:08269 // Force a rescan of cache files, for testing.
270 void ForceRescanOnUIThreadForTesting();
271
[email protected]b22f87f2012-07-12 10:53:17272 // Gets the cache entry for file corresponding to |resource_id| and |md5|
273 // and returns true if entry exists in cache map. Otherwise, returns false.
[email protected]3653146a2012-05-29 13:41:47274 // |md5| can be empty if only matching |resource_id| is desired, which may
275 // happen when looking for pinned entries where symlinks' filenames have no
276 // extension and hence no md5.
[email protected]b22f87f2012-07-12 10:53:17277 bool GetCacheEntry(const std::string& resource_id,
278 const std::string& md5,
279 GDataCacheEntry* entry);
[email protected]3653146a2012-05-29 13:41:47280
281 // Factory methods for GDataCache.
[email protected]fcc92a52012-06-08 22:54:16282 // |pool| and |sequence_token| are used to assert that the functions are
283 // called on the right sequenced worker pool with the right sequence token.
284 //
285 // For testing, the thread assertion can be disabled by passing NULL and
286 // the default value of SequenceToken.
[email protected]73f9c742012-06-15 07:37:13287 static GDataCache* CreateGDataCacheOnUIThread(
[email protected]fcc92a52012-06-08 22:54:16288 const FilePath& cache_root_path,
[email protected]ddbf2052012-07-13 15:07:02289 base::SequencedTaskRunner* blocking_task_runner);
[email protected]3653146a2012-05-29 13:41:47290
[email protected]73f9c742012-06-15 07:37:13291 // Deletes the cache.
292 void DestroyOnUIThread();
293
[email protected]01ba15f72012-06-09 00:41:05294 // Gets the cache root path (i.e. <user_profile_dir>/GCache/v1) from the
295 // profile.
296 // TODO(satorux): Write a unit test for this.
297 static FilePath GetCacheRootPath(Profile* profile);
298
[email protected]30d9dda2012-06-30 05:56:28299 // Returns file paths for all the cache sub directories under
300 // |cache_root_path|.
301 static std::vector<FilePath> GetCachePaths(const FilePath& cache_root_path);
302
303 // Creates cache directory and its sub-directories if they don't exist.
304 // TODO(glotov): take care of this when the setup and cleanup part is
305 // landed, noting that these directories need to be created for development
306 // in linux box and unittest. (http://crosbug.com/27577)
307 static bool CreateCacheDirectories(
308 const std::vector<FilePath>& paths_to_create);
309
[email protected]fae353a2012-07-11 23:30:27310 // Returns the type of the sub directory where the cache file is stored.
311 static CacheSubDirectoryType GetSubDirectoryType(
312 const GDataCacheEntry& cache_entry);
313
[email protected]ca5f6da2012-06-18 12:54:59314 private:
[email protected]ddbf2052012-07-13 15:07:02315 GDataCache(const FilePath& cache_root_path,
316 base::SequencedTaskRunner* blocking_task_runner);
[email protected]73f9c742012-06-15 07:37:13317 virtual ~GDataCache();
[email protected]fcc92a52012-06-08 22:54:16318
319 // Checks whether the current thread is on the right sequenced worker pool
320 // with the right sequence ID. If not, DCHECK will fail.
321 void AssertOnSequencedWorkerPool();
[email protected]3653146a2012-05-29 13:41:47322
[email protected]ca5f6da2012-06-18 12:54:59323 // Initializes the cache.
324 void Initialize();
[email protected]73f9c742012-06-15 07:37:13325
326 // Deletes the cache.
327 void Destroy();
328
[email protected]79c3752d2012-07-17 12:10:08329 // Force a rescan of cache directories.
330 void ForceRescanForTesting();
331
[email protected]b83e5202012-06-27 07:50:24332 // Used to implement GetResourceIdsOfBacklogOnUIThread.
333 void GetResourceIdsOfBacklog(
334 std::vector<std::string>* to_fetch,
335 std::vector<std::string>* to_upload);
[email protected]8764a392012-06-20 06:43:08336
[email protected]85b62192012-06-29 19:56:38337 // Used to implement GetResourceIdsOfExistingPinnedFilesOnUIThread.
338 void GetResourceIdsOfExistingPinnedFiles(
339 std::vector<std::string>* resource_ids);
340
[email protected]cd236432012-07-27 18:03:30341 // Used to implement GetResourceIdsOfAllFilesOnUIThread.
342 void GetResourceIdsOfAllFiles(
343 std::vector<std::string>* resource_ids);
344
[email protected]c960d222012-06-15 10:03:50345 // Used to implement GetFileOnUIThread.
346 void GetFile(const std::string& resource_id,
347 const std::string& md5,
[email protected]7f90e77c2012-07-17 09:35:31348 GDataFileError* error,
[email protected]c960d222012-06-15 10:03:50349 FilePath* cache_file_path);
350
[email protected]73f9c742012-06-15 07:37:13351 // Used to implement StoreOnUIThread.
352 void Store(const std::string& resource_id,
353 const std::string& md5,
354 const FilePath& source_path,
355 FileOperationType file_operation_type,
[email protected]7f90e77c2012-07-17 09:35:31356 GDataFileError* error);
[email protected]73f9c742012-06-15 07:37:13357
358 // Used to implement PinOnUIThread.
359 void Pin(const std::string& resource_id,
360 const std::string& md5,
361 FileOperationType file_operation_type,
[email protected]7f90e77c2012-07-17 09:35:31362 GDataFileError* error);
[email protected]73f9c742012-06-15 07:37:13363
364 // Used to implement UnpinOnUIThread.
365 void Unpin(const std::string& resource_id,
366 const std::string& md5,
367 FileOperationType file_operation_type,
[email protected]7f90e77c2012-07-17 09:35:31368 GDataFileError* error);
[email protected]73f9c742012-06-15 07:37:13369
370 // Used to implement SetMountedStateOnUIThread.
371 void SetMountedState(const FilePath& file_path,
372 bool to_mount,
[email protected]7f90e77c2012-07-17 09:35:31373 GDataFileError* error,
[email protected]73f9c742012-06-15 07:37:13374 FilePath* cache_file_path);
375
[email protected]c960d222012-06-15 10:03:50376 // Used to implement MarkDirtyOnUIThread.
377 void MarkDirty(const std::string& resource_id,
378 const std::string& md5,
379 FileOperationType file_operation_type,
[email protected]7f90e77c2012-07-17 09:35:31380 GDataFileError* error,
[email protected]c960d222012-06-15 10:03:50381 FilePath* cache_file_path);
382
[email protected]73f9c742012-06-15 07:37:13383 // Used to implement CommitDirtyOnUIThread.
384 void CommitDirty(const std::string& resource_id,
385 const std::string& md5,
386 FileOperationType file_operation_type,
[email protected]7f90e77c2012-07-17 09:35:31387 GDataFileError* error);
[email protected]73f9c742012-06-15 07:37:13388
389 // Used to implement ClearDirtyOnUIThread.
390 void ClearDirty(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]73f9c742012-06-15 07:37:13394
395 // Used to implement RemoveOnUIThread.
396 void Remove(const std::string& resource_id,
[email protected]7f90e77c2012-07-17 09:35:31397 GDataFileError* error);
[email protected]73f9c742012-06-15 07:37:13398
[email protected]73f9c742012-06-15 07:37:13399 // Runs callback and notifies the observers when file is pinned.
[email protected]7f90e77c2012-07-17 09:35:31400 void OnPinned(GDataFileError* error,
[email protected]73f9c742012-06-15 07:37:13401 const std::string& resource_id,
402 const std::string& md5,
403 const CacheOperationCallback& callback);
404
405 // Runs callback and notifies the observers when file is unpinned.
[email protected]7f90e77c2012-07-17 09:35:31406 void OnUnpinned(GDataFileError* error,
[email protected]73f9c742012-06-15 07:37:13407 const std::string& resource_id,
408 const std::string& md5,
409 const CacheOperationCallback& callback);
410
[email protected]d7664c22012-06-18 19:35:49411 // Runs callback and notifies the observers when file is committed.
[email protected]7f90e77c2012-07-17 09:35:31412 void OnCommitDirty(GDataFileError* error,
[email protected]d7664c22012-06-18 19:35:49413 const std::string& resource_id,
414 const std::string& md5,
415 const CacheOperationCallback& callback);
416
[email protected]4324fdc2012-06-29 05:32:48417 // Helper function to implement GetCacheEntryOnUIThread().
418 void GetCacheEntryHelper(const std::string& resource_id,
419 const std::string& md5,
420 bool* success,
[email protected]fae353a2012-07-11 23:30:27421 GDataCacheEntry* cache_entry);
[email protected]4324fdc2012-06-29 05:32:48422
[email protected]01ba15f72012-06-09 00:41:05423 // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1).
424 const FilePath cache_root_path_;
[email protected]32a7fc852012-06-08 17:25:50425 // Paths for all subdirectories of GCache, one for each
426 // GDataCache::CacheSubDirectoryType enum.
[email protected]6b70c7b2012-06-14 03:10:43427 const std::vector<FilePath> cache_paths_;
[email protected]ddbf2052012-07-13 15:07:02428 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
[email protected]32a7fc852012-06-08 17:25:50429
[email protected]ca5f6da2012-06-18 12:54:59430 // The cache state data. This member must be access only on the blocking pool.
431 scoped_ptr<GDataCacheMetadata> metadata_;
432
[email protected]73f9c742012-06-15 07:37:13433 // WeakPtrFactory and WeakPtr bound to the UI thread.
434 base::WeakPtrFactory<GDataCache> ui_weak_ptr_factory_;
435 base::WeakPtr<GDataCache> ui_weak_ptr_;
436
437 // List of observers, this member must be accessed on UI thread.
438 ObserverList<Observer> observers_;
439
[email protected]3653146a2012-05-29 13:41:47440 DISALLOW_COPY_AND_ASSIGN(GDataCache);
441};
442
[email protected]a321b9632012-06-14 03:29:17443
444// The minimum free space to keep. GDataFileSystem::GetFileByPath() returns
[email protected]7f90e77c2012-07-17 09:35:31445// GDATA_FILE_ERROR_NO_SPACE if the available space is smaller than
[email protected]a321b9632012-06-14 03:29:17446// this value.
447//
448// Copied from cryptohome/homedirs.h.
449// TODO(satorux): Share the constant.
450const int64 kMinFreeSpace = 512 * 1LL << 20;
451
452// Interface class used for getting the free disk space. Only for testing.
453class FreeDiskSpaceGetterInterface {
454 public:
455 virtual ~FreeDiskSpaceGetterInterface() {}
456 virtual int64 AmountOfFreeDiskSpace() const = 0;
457};
458
459// Sets the free disk space getter for testing.
460// The existing getter is deleted.
461void SetFreeDiskSpaceGetterForTesting(
462 FreeDiskSpaceGetterInterface* getter);
463
[email protected]3653146a2012-05-29 13:41:47464} // namespace gdata
465
466#endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_