Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: chrome/browser/chromeos/drive/file_cache.h

Issue 15681009: Extract GetResolveFile into DownloadOperation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/file_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_ 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // runs |completion_callback| upon completion. 141 // runs |completion_callback| upon completion.
142 // Must be called on UI thread. 142 // Must be called on UI thread.
143 void IterateOnUIThread(const CacheIterateCallback& iteration_callback, 143 void IterateOnUIThread(const CacheIterateCallback& iteration_callback,
144 const base::Closure& completion_callback); 144 const base::Closure& completion_callback);
145 145
146 // Iterates all files in the cache and calls |iteration_callback| for each 146 // Iterates all files in the cache and calls |iteration_callback| for each
147 // file. |completion_callback| is run upon completion. 147 // file. |completion_callback| is run upon completion.
148 // TODO(hashimoto): Stop using callbacks for this method. crbug.com/242818 148 // TODO(hashimoto): Stop using callbacks for this method. crbug.com/242818
149 void Iterate(const CacheIterateCallback& iteration_callback); 149 void Iterate(const CacheIterateCallback& iteration_callback);
150 150
151 // Frees up disk space to store the given number of bytes, while keeping 151
152 // kMinFreeSpace bytes on the disk, if needed. 152 // Runs FreeDiskSpaceIfNeededFor() on |blocking_task_runner_|, and calls
153 // Runs |callback| with true when we successfully manage to have enough space. 153 // |callback| with the result asynchronously.
154 // |callback| must not be null.
154 // Must be called on the UI thread. 155 // Must be called on the UI thread.
155 void FreeDiskSpaceIfNeededForOnUIThread( 156 void FreeDiskSpaceIfNeededForOnUIThread(
156 int64 num_bytes, 157 int64 num_bytes,
157 const InitializeCacheCallback& callback); 158 const InitializeCacheCallback& callback);
158 159
159 // Checks if file corresponding to |resource_id| and |md5| exists in cache. 160 // Frees up disk space to store a file with |num_bytes| size content, while
161 // keeping kMinFreeSpace bytes on the disk, if needed.
162 // Returns true if we successfully manage to have enough space, otherwise
163 // false.
164 bool FreeDiskSpaceIfNeededFor(int64 num_bytes);
165
166 // Runs GetFile() on |blocking_task_runner_|, and calls |callback| with
167 // the result asynchronously.
160 // |callback| must not be null. 168 // |callback| must not be null.
161 // Must be called on the UI thread. 169 // Must be called on the UI thread.
162 void GetFileOnUIThread(const std::string& resource_id, 170 void GetFileOnUIThread(const std::string& resource_id,
163 const std::string& md5, 171 const std::string& md5,
164 const GetFileFromCacheCallback& callback); 172 const GetFileFromCacheCallback& callback);
165 173
174 // Checks if file corresponding to |resource_id| and |md5| exists in cache,
175 // and returns FILE_ERROR_OK with |cache_file_path| storing the path to
176 // the file.
177 // |cache_file_path| must not be null.
178 FileError GetFile(const std::string& resource_id,
179 const std::string& md5,
180 base::FilePath* cache_file_path);
181
166 // Runs Store() on |blocking_task_runner_|, and calls |callback| with 182 // Runs Store() on |blocking_task_runner_|, and calls |callback| with
167 // the result asynchronously. 183 // the result asynchronously.
168 // |callback| must not be null. 184 // |callback| must not be null.
169 // Must be called on the UI thread. 185 // Must be called on the UI thread.
170 void StoreOnUIThread(const std::string& resource_id, 186 void StoreOnUIThread(const std::string& resource_id,
171 const std::string& md5, 187 const std::string& md5,
172 const base::FilePath& source_path, 188 const base::FilePath& source_path,
173 FileOperationType file_operation_type, 189 FileOperationType file_operation_type,
174 const FileOperationCallback& callback); 190 const FileOperationCallback& callback);
175 191
(...skipping 18 matching lines...) Expand all
194 // - moves |source_path| to |dest_path| in persistent dir if 210 // - moves |source_path| to |dest_path| in persistent dir if
195 // file is not dirty 211 // file is not dirty
196 // - creates symlink in pinned dir that references downloaded or locally 212 // - creates symlink in pinned dir that references downloaded or locally
197 // modified file 213 // modified file
198 // |callback| must not be null. 214 // |callback| must not be null.
199 // Must be called on the UI thread. 215 // Must be called on the UI thread.
200 void PinOnUIThread(const std::string& resource_id, 216 void PinOnUIThread(const std::string& resource_id,
201 const std::string& md5, 217 const std::string& md5,
202 const FileOperationCallback& callback); 218 const FileOperationCallback& callback);
203 219
204 // Modifies cache state, which involves the following: 220 // Runs Unpin() on |blocking_task_runner_|, and calls |callback| with the
205 // - moves |source_path| to |dest_path| in tmp dir if file is not dirty 221 // result asynchronously.
206 // - deletes symlink from pinned dir
207 // |callback| must not be null. 222 // |callback| must not be null.
208 // Must be called on the UI thread. 223 // Must be called on the UI thread.
209 void UnpinOnUIThread(const std::string& resource_id, 224 void UnpinOnUIThread(const std::string& resource_id,
210 const std::string& md5, 225 const std::string& md5,
211 const FileOperationCallback& callback); 226 const FileOperationCallback& callback);
212 227
228 // Modifies cache state, which involves the following:
229 // - moves the local file from pinned directory to unpinned directory.
230 // - update cache metadata.
231 FileError Unpin(const std::string& resource_id, const std::string& md5);
232
213 // Sets the state of the cache entry corresponding to |resource_id| and |md5| 233 // Sets the state of the cache entry corresponding to |resource_id| and |md5|
214 // as mounted. 234 // as mounted.
215 // |callback| must not be null. 235 // |callback| must not be null.
216 // Must be called on the UI thread. 236 // Must be called on the UI thread.
217 void MarkAsMountedOnUIThread(const std::string& resource_id, 237 void MarkAsMountedOnUIThread(const std::string& resource_id,
218 const std::string& md5, 238 const std::string& md5,
219 const GetFileFromCacheCallback& callback); 239 const GetFileFromCacheCallback& callback);
220 240
221 // Set the state of the cache entry corresponding to file_path as unmounted. 241 // Set the state of the cache entry corresponding to file_path as unmounted.
222 // |callback| must not be null. 242 // |callback| must not be null.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 // Initializes the cache. Returns true on success. 349 // Initializes the cache. Returns true on success.
330 bool InitializeOnBlockingPool(); 350 bool InitializeOnBlockingPool();
331 351
332 // Initializes the cache with in-memory cache for testing. 352 // Initializes the cache with in-memory cache for testing.
333 // The in-memory cache is used since it's faster than the db. 353 // The in-memory cache is used since it's faster than the db.
334 void InitializeOnBlockingPoolForTesting(); 354 void InitializeOnBlockingPoolForTesting();
335 355
336 // Destroys the cache on the blocking pool. 356 // Destroys the cache on the blocking pool.
337 void DestroyOnBlockingPool(); 357 void DestroyOnBlockingPool();
338 358
339 // Used to implement FreeDiskSpaceIfNeededForOnUIThread().
340 bool FreeDiskSpaceIfNeededFor(int64 num_bytes);
341
342 // Used to implement GetFileOnUIThread.
343 FileError GetFile(const std::string& resource_id,
344 const std::string& md5,
345 base::FilePath* cache_file_path);
346
347 // Used to implement Store and StoreLocallyModifiedOnUIThread. 359 // Used to implement Store and StoreLocallyModifiedOnUIThread.
348 // TODO(hidehiko): Merge this method with Store(), after 360 // TODO(hidehiko): Merge this method with Store(), after
349 // StoreLocallyModifiedOnUIThread is removed. 361 // StoreLocallyModifiedOnUIThread is removed.
350 FileError StoreInternal(const std::string& resource_id, 362 FileError StoreInternal(const std::string& resource_id,
351 const std::string& md5, 363 const std::string& md5,
352 const base::FilePath& source_path, 364 const base::FilePath& source_path,
353 FileOperationType file_operation_type, 365 FileOperationType file_operation_type,
354 CachedFileOrigin origin); 366 CachedFileOrigin origin);
355 367
356 // Used to implement PinOnUIThread. 368 // Used to implement PinOnUIThread.
357 FileError Pin(const std::string& resource_id, 369 FileError Pin(const std::string& resource_id,
358 const std::string& md5); 370 const std::string& md5);
359 371
360 // Used to implement UnpinOnUIThread.
361 FileError Unpin(const std::string& resource_id,
362 const std::string& md5);
363
364 // Used to implement MarkAsMountedOnUIThread. 372 // Used to implement MarkAsMountedOnUIThread.
365 FileError MarkAsMounted(const std::string& resource_id, 373 FileError MarkAsMounted(const std::string& resource_id,
366 const std::string& md5, 374 const std::string& md5,
367 base::FilePath* cache_file_path); 375 base::FilePath* cache_file_path);
368 376
369 // Used to implement MarkAsUnmountedOnUIThread. 377 // Used to implement MarkAsUnmountedOnUIThread.
370 FileError MarkAsUnmounted(const base::FilePath& file_path); 378 FileError MarkAsUnmounted(const base::FilePath& file_path);
371 379
372 // Used to implement MarkDirtyOnUIThread. 380 // Used to implement MarkDirtyOnUIThread.
373 FileError MarkDirty(const std::string& resource_id, 381 FileError MarkDirty(const std::string& resource_id,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 // this value. 435 // this value.
428 // 436 //
429 // Copied from cryptohome/homedirs.h. 437 // Copied from cryptohome/homedirs.h.
430 // TODO(satorux): Share the constant. 438 // TODO(satorux): Share the constant.
431 const int64 kMinFreeSpace = 512 * 1LL << 20; 439 const int64 kMinFreeSpace = 512 * 1LL << 20;
432 440
433 } // namespace internal 441 } // namespace internal
434 } // namespace drive 442 } // namespace drive
435 443
436 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_ 444 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/file_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698