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

Side by Side Diff: chrome/browser/chromeos/gdata/drive_cache.cc

Issue 10877005: Rename GDataCache* to DriveCache* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 years, 4 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
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 #include "chrome/browser/chromeos/gdata/gdata_cache.h" 5 #include "chrome/browser/chromeos/gdata/drive_cache.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/chromeos/chromeos_version.h" 9 #include "base/chromeos/chromeos_version.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/sys_info.h" 15 #include "base/sys_info.h"
16 #include "chrome/browser/chromeos/gdata/drive.pb.h" 16 #include "chrome/browser/chromeos/gdata/drive.pb.h"
17 #include "chrome/browser/chromeos/gdata/gdata_cache_metadata.h" 17 #include "chrome/browser/chromeos/gdata/drive_cache_metadata.h"
18 #include "chrome/browser/chromeos/gdata/gdata_util.h" 18 #include "chrome/browser/chromeos/gdata/gdata_util.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/chrome_constants.h" 20 #include "chrome/common/chrome_constants.h"
21 #include "chrome/common/chrome_paths_internal.h" 21 #include "chrome/common/chrome_paths_internal.h"
22 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
23 23
24 using content::BrowserThread; 24 using content::BrowserThread;
25 25
26 namespace gdata { 26 namespace gdata {
27 namespace { 27 namespace {
28 28
29 const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1"); 29 const FilePath::CharType kDriveCacheVersionDir[] = FILE_PATH_LITERAL("v1");
30 const FilePath::CharType kGDataCacheMetaDir[] = FILE_PATH_LITERAL("meta"); 30 const FilePath::CharType kDriveCacheMetaDir[] = FILE_PATH_LITERAL("meta");
31 const FilePath::CharType kGDataCachePinnedDir[] = FILE_PATH_LITERAL("pinned"); 31 const FilePath::CharType kDriveCachePinnedDir[] = FILE_PATH_LITERAL("pinned");
32 const FilePath::CharType kGDataCacheOutgoingDir[] = 32 const FilePath::CharType kDriveCacheOutgoingDir[] =
33 FILE_PATH_LITERAL("outgoing"); 33 FILE_PATH_LITERAL("outgoing");
34 const FilePath::CharType kGDataCachePersistentDir[] = 34 const FilePath::CharType kDriveCachePersistentDir[] =
35 FILE_PATH_LITERAL("persistent"); 35 FILE_PATH_LITERAL("persistent");
36 const FilePath::CharType kGDataCacheTmpDir[] = FILE_PATH_LITERAL("tmp"); 36 const FilePath::CharType kDriveCacheTmpDir[] = FILE_PATH_LITERAL("tmp");
37 const FilePath::CharType kGDataCacheTmpDownloadsDir[] = 37 const FilePath::CharType kDriveCacheTmpDownloadsDir[] =
38 FILE_PATH_LITERAL("tmp/downloads"); 38 FILE_PATH_LITERAL("tmp/downloads");
39 const FilePath::CharType kGDataCacheTmpDocumentsDir[] = 39 const FilePath::CharType kDriveCacheTmpDocumentsDir[] =
40 FILE_PATH_LITERAL("tmp/documents"); 40 FILE_PATH_LITERAL("tmp/documents");
41 41
42 // Used to tweak GetAmountOfFreeDiskSpace() behavior for testing. 42 // Used to tweak GetAmountOfFreeDiskSpace() behavior for testing.
43 FreeDiskSpaceGetterInterface* global_free_disk_getter_for_testing = NULL; 43 FreeDiskSpaceGetterInterface* global_free_disk_getter_for_testing = NULL;
44 44
45 // Gets the amount of free disk space. Use 45 // Gets the amount of free disk space. Use
46 // |global_free_disk_getter_for_testing| if set. 46 // |global_free_disk_getter_for_testing| if set.
47 int64 GetAmountOfFreeDiskSpace() { 47 int64 GetAmountOfFreeDiskSpace() {
48 if (global_free_disk_getter_for_testing) 48 if (global_free_disk_getter_for_testing)
49 return global_free_disk_getter_for_testing->AmountOfFreeDiskSpace(); 49 return global_free_disk_getter_for_testing->AmountOfFreeDiskSpace();
(...skipping 10 matching lines...) Expand all
60 // bytes, while keeping kMinFreeSpace bytes on the disk. 60 // bytes, while keeping kMinFreeSpace bytes on the disk.
61 bool HasEnoughSpaceFor(int64 num_bytes) { 61 bool HasEnoughSpaceFor(int64 num_bytes) {
62 int64 free_space = GetAmountOfFreeDiskSpace(); 62 int64 free_space = GetAmountOfFreeDiskSpace();
63 // Subtract this as if this portion does not exist. 63 // Subtract this as if this portion does not exist.
64 free_space -= kMinFreeSpace; 64 free_space -= kMinFreeSpace;
65 return (free_space >= num_bytes); 65 return (free_space >= num_bytes);
66 } 66 }
67 67
68 // Create cache directory paths and set permissions. 68 // Create cache directory paths and set permissions.
69 void InitCachePaths(const std::vector<FilePath>& cache_paths) { 69 void InitCachePaths(const std::vector<FilePath>& cache_paths) {
70 if (cache_paths.size() < GDataCache::NUM_CACHE_TYPES) { 70 if (cache_paths.size() < DriveCache::NUM_CACHE_TYPES) {
71 NOTREACHED(); 71 NOTREACHED();
72 LOG(ERROR) << "Size of cache_paths is invalid."; 72 LOG(ERROR) << "Size of cache_paths is invalid.";
73 return; 73 return;
74 } 74 }
75 75
76 if (!GDataCache::CreateCacheDirectories(cache_paths)) 76 if (!DriveCache::CreateCacheDirectories(cache_paths))
77 return; 77 return;
78 78
79 // Change permissions of cache persistent directory to u+rwx,og+x (711) in 79 // Change permissions of cache persistent directory to u+rwx,og+x (711) in
80 // order to allow archive files in that directory to be mounted by cros-disks. 80 // order to allow archive files in that directory to be mounted by cros-disks.
81 file_util::SetPosixFilePermissions( 81 file_util::SetPosixFilePermissions(
82 cache_paths[GDataCache::CACHE_TYPE_PERSISTENT], 82 cache_paths[DriveCache::CACHE_TYPE_PERSISTENT],
83 file_util::FILE_PERMISSION_USER_MASK | 83 file_util::FILE_PERMISSION_USER_MASK |
84 file_util::FILE_PERMISSION_EXECUTE_BY_GROUP | 84 file_util::FILE_PERMISSION_EXECUTE_BY_GROUP |
85 file_util::FILE_PERMISSION_EXECUTE_BY_OTHERS); 85 file_util::FILE_PERMISSION_EXECUTE_BY_OTHERS);
86 } 86 }
87 87
88 // Remove all files under the given directory, non-recursively. 88 // Remove all files under the given directory, non-recursively.
89 // Do not remove recursively as we don't want to touch <gcache>/tmp/downloads, 89 // Do not remove recursively as we don't want to touch <gcache>/tmp/downloads,
90 // which is used for user initiated downloads like "Save As" 90 // which is used for user initiated downloads like "Save As"
91 void RemoveAllFiles(const FilePath& directory) { 91 void RemoveAllFiles(const FilePath& directory) {
92 using file_util::FileEnumerator; 92 using file_util::FileEnumerator;
(...skipping 10 matching lines...) Expand all
103 103
104 // Modifies cache state of file on blocking pool, which involves: 104 // Modifies cache state of file on blocking pool, which involves:
105 // - moving or copying file (per |file_operation_type|) from |source_path| to 105 // - moving or copying file (per |file_operation_type|) from |source_path| to
106 // |dest_path| if they're different 106 // |dest_path| if they're different
107 // - deleting symlink if |symlink_path| is not empty 107 // - deleting symlink if |symlink_path| is not empty
108 // - creating symlink if |symlink_path| is not empty and |create_symlink| is 108 // - creating symlink if |symlink_path| is not empty and |create_symlink| is
109 // true. 109 // true.
110 GDataFileError ModifyCacheState( 110 GDataFileError ModifyCacheState(
111 const FilePath& source_path, 111 const FilePath& source_path,
112 const FilePath& dest_path, 112 const FilePath& dest_path,
113 GDataCache::FileOperationType file_operation_type, 113 DriveCache::FileOperationType file_operation_type,
114 const FilePath& symlink_path, 114 const FilePath& symlink_path,
115 bool create_symlink) { 115 bool create_symlink) {
116 // Move or copy |source_path| to |dest_path| if they are different. 116 // Move or copy |source_path| to |dest_path| if they are different.
117 if (source_path != dest_path) { 117 if (source_path != dest_path) {
118 bool success = false; 118 bool success = false;
119 if (file_operation_type == GDataCache::FILE_OPERATION_MOVE) 119 if (file_operation_type == DriveCache::FILE_OPERATION_MOVE)
120 success = file_util::Move(source_path, dest_path); 120 success = file_util::Move(source_path, dest_path);
121 else if (file_operation_type == GDataCache::FILE_OPERATION_COPY) 121 else if (file_operation_type == DriveCache::FILE_OPERATION_COPY)
122 success = file_util::CopyFile(source_path, dest_path); 122 success = file_util::CopyFile(source_path, dest_path);
123 if (!success) { 123 if (!success) {
124 LOG(ERROR) << "Failed to " 124 LOG(ERROR) << "Failed to "
125 << (file_operation_type == GDataCache::FILE_OPERATION_MOVE ? 125 << (file_operation_type == DriveCache::FILE_OPERATION_MOVE ?
126 "move " : "copy ") 126 "move " : "copy ")
127 << source_path.value() 127 << source_path.value()
128 << " to " << dest_path.value(); 128 << " to " << dest_path.value();
129 return GDATA_FILE_ERROR_FAILED; 129 return GDATA_FILE_ERROR_FAILED;
130 } else { 130 } else {
131 DVLOG(1) << (file_operation_type == GDataCache::FILE_OPERATION_MOVE ? 131 DVLOG(1) << (file_operation_type == DriveCache::FILE_OPERATION_MOVE ?
132 "Moved " : "Copied ") 132 "Moved " : "Copied ")
133 << source_path.value() 133 << source_path.value()
134 << " to " << dest_path.value(); 134 << " to " << dest_path.value();
135 } 135 }
136 } else { 136 } else {
137 DVLOG(1) << "No need to move file: source = destination"; 137 DVLOG(1) << "No need to move file: source = destination";
138 } 138 }
139 139
140 if (symlink_path.empty()) 140 if (symlink_path.empty())
141 return GDATA_FILE_OK; 141 return GDATA_FILE_OK;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 DriveCacheEntry* cache_entry) { 301 DriveCacheEntry* cache_entry) {
302 DCHECK(success); 302 DCHECK(success);
303 DCHECK(cache_entry); 303 DCHECK(cache_entry);
304 304
305 if (!callback.is_null()) 305 if (!callback.is_null())
306 callback.Run(*success, *cache_entry); 306 callback.Run(*success, *cache_entry);
307 } 307 }
308 308
309 } // namespace 309 } // namespace
310 310
311 GDataCache::GDataCache(const FilePath& cache_root_path, 311 DriveCache::DriveCache(const FilePath& cache_root_path,
312 base::SequencedTaskRunner* blocking_task_runner) 312 base::SequencedTaskRunner* blocking_task_runner)
313 : cache_root_path_(cache_root_path), 313 : cache_root_path_(cache_root_path),
314 cache_paths_(GetCachePaths(cache_root_path_)), 314 cache_paths_(GetCachePaths(cache_root_path_)),
315 blocking_task_runner_(blocking_task_runner), 315 blocking_task_runner_(blocking_task_runner),
316 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 316 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
318 } 318 }
319 319
320 GDataCache::~GDataCache() { 320 DriveCache::~DriveCache() {
321 AssertOnSequencedWorkerPool(); 321 AssertOnSequencedWorkerPool();
322 } 322 }
323 323
324 FilePath GDataCache::GetCacheDirectoryPath( 324 FilePath DriveCache::GetCacheDirectoryPath(
325 CacheSubDirectoryType sub_dir_type) const { 325 CacheSubDirectoryType sub_dir_type) const {
326 DCHECK_LE(0, sub_dir_type); 326 DCHECK_LE(0, sub_dir_type);
327 DCHECK_GT(NUM_CACHE_TYPES, sub_dir_type); 327 DCHECK_GT(NUM_CACHE_TYPES, sub_dir_type);
328 return cache_paths_[sub_dir_type]; 328 return cache_paths_[sub_dir_type];
329 } 329 }
330 330
331 FilePath GDataCache::GetCacheFilePath(const std::string& resource_id, 331 FilePath DriveCache::GetCacheFilePath(const std::string& resource_id,
332 const std::string& md5, 332 const std::string& md5,
333 CacheSubDirectoryType sub_dir_type, 333 CacheSubDirectoryType sub_dir_type,
334 CachedFileOrigin file_origin) const { 334 CachedFileOrigin file_origin) const {
335 DCHECK(sub_dir_type != CACHE_TYPE_META); 335 DCHECK(sub_dir_type != CACHE_TYPE_META);
336 336
337 // Runs on any thread. 337 // Runs on any thread.
338 // Filename is formatted as resource_id.md5, i.e. resource_id is the base 338 // Filename is formatted as resource_id.md5, i.e. resource_id is the base
339 // name and md5 is the extension. 339 // name and md5 is the extension.
340 std::string base_name = util::EscapeCacheFileName(resource_id); 340 std::string base_name = util::EscapeCacheFileName(resource_id);
341 if (file_origin == CACHED_FILE_LOCALLY_MODIFIED) { 341 if (file_origin == CACHED_FILE_LOCALLY_MODIFIED) {
342 DCHECK(sub_dir_type == CACHE_TYPE_PERSISTENT); 342 DCHECK(sub_dir_type == CACHE_TYPE_PERSISTENT);
343 base_name += FilePath::kExtensionSeparator; 343 base_name += FilePath::kExtensionSeparator;
344 base_name += util::kLocallyModifiedFileExtension; 344 base_name += util::kLocallyModifiedFileExtension;
345 } else if (!md5.empty()) { 345 } else if (!md5.empty()) {
346 base_name += FilePath::kExtensionSeparator; 346 base_name += FilePath::kExtensionSeparator;
347 base_name += util::EscapeCacheFileName(md5); 347 base_name += util::EscapeCacheFileName(md5);
348 } 348 }
349 // For mounted archives the filename is formatted as resource_id.md5.mounted, 349 // For mounted archives the filename is formatted as resource_id.md5.mounted,
350 // i.e. resource_id.md5 is the base name and ".mounted" is the extension 350 // i.e. resource_id.md5 is the base name and ".mounted" is the extension
351 if (file_origin == CACHED_FILE_MOUNTED) { 351 if (file_origin == CACHED_FILE_MOUNTED) {
352 DCHECK(sub_dir_type == CACHE_TYPE_PERSISTENT); 352 DCHECK(sub_dir_type == CACHE_TYPE_PERSISTENT);
353 base_name += FilePath::kExtensionSeparator; 353 base_name += FilePath::kExtensionSeparator;
354 base_name += util::kMountedArchiveFileExtension; 354 base_name += util::kMountedArchiveFileExtension;
355 } 355 }
356 return GetCacheDirectoryPath(sub_dir_type).Append(base_name); 356 return GetCacheDirectoryPath(sub_dir_type).Append(base_name);
357 } 357 }
358 358
359 void GDataCache::AssertOnSequencedWorkerPool() { 359 void DriveCache::AssertOnSequencedWorkerPool() {
360 DCHECK(!blocking_task_runner_ || 360 DCHECK(!blocking_task_runner_ ||
361 blocking_task_runner_->RunsTasksOnCurrentThread()); 361 blocking_task_runner_->RunsTasksOnCurrentThread());
362 } 362 }
363 363
364 bool GDataCache::IsUnderGDataCacheDirectory(const FilePath& path) const { 364 bool DriveCache::IsUnderDriveCacheDirectory(const FilePath& path) const {
365 return cache_root_path_ == path || cache_root_path_.IsParent(path); 365 return cache_root_path_ == path || cache_root_path_.IsParent(path);
366 } 366 }
367 367
368 void GDataCache::AddObserver(Observer* observer) { 368 void DriveCache::AddObserver(Observer* observer) {
369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
370 observers_.AddObserver(observer); 370 observers_.AddObserver(observer);
371 } 371 }
372 372
373 void GDataCache::RemoveObserver(Observer* observer) { 373 void DriveCache::RemoveObserver(Observer* observer) {
374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
375 observers_.RemoveObserver(observer); 375 observers_.RemoveObserver(observer);
376 } 376 }
377 377
378 void GDataCache::GetCacheEntryOnUIThread( 378 void DriveCache::GetCacheEntryOnUIThread(
379 const std::string& resource_id, 379 const std::string& resource_id,
380 const std::string& md5, 380 const std::string& md5,
381 const GetCacheEntryCallback& callback) { 381 const GetCacheEntryCallback& callback) {
382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
383 383
384 bool* success = new bool(false); 384 bool* success = new bool(false);
385 DriveCacheEntry* cache_entry = new DriveCacheEntry; 385 DriveCacheEntry* cache_entry = new DriveCacheEntry;
386 blocking_task_runner_->PostTaskAndReply( 386 blocking_task_runner_->PostTaskAndReply(
387 FROM_HERE, 387 FROM_HERE,
388 base::Bind(&GDataCache::GetCacheEntryHelper, 388 base::Bind(&DriveCache::GetCacheEntryHelper,
389 base::Unretained(this), 389 base::Unretained(this),
390 resource_id, 390 resource_id,
391 md5, 391 md5,
392 success, 392 success,
393 cache_entry), 393 cache_entry),
394 base::Bind(&RunGetCacheEntryCallback, 394 base::Bind(&RunGetCacheEntryCallback,
395 callback, 395 callback,
396 base::Owned(success), 396 base::Owned(success),
397 base::Owned(cache_entry))); 397 base::Owned(cache_entry)));
398 } 398 }
399 399
400 void GDataCache::GetResourceIdsOfBacklogOnUIThread( 400 void DriveCache::GetResourceIdsOfBacklogOnUIThread(
401 const GetResourceIdsOfBacklogCallback& callback) { 401 const GetResourceIdsOfBacklogCallback& callback) {
402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
403 403
404 std::vector<std::string>* to_fetch = new std::vector<std::string>; 404 std::vector<std::string>* to_fetch = new std::vector<std::string>;
405 std::vector<std::string>* to_upload = new std::vector<std::string>; 405 std::vector<std::string>* to_upload = new std::vector<std::string>;
406 blocking_task_runner_->PostTaskAndReply( 406 blocking_task_runner_->PostTaskAndReply(
407 FROM_HERE, 407 FROM_HERE,
408 base::Bind(&GDataCache::GetResourceIdsOfBacklog, 408 base::Bind(&DriveCache::GetResourceIdsOfBacklog,
409 base::Unretained(this), 409 base::Unretained(this),
410 to_fetch, 410 to_fetch,
411 to_upload), 411 to_upload),
412 base::Bind(&RunGetResourceIdsOfBacklogCallback, 412 base::Bind(&RunGetResourceIdsOfBacklogCallback,
413 callback, 413 callback,
414 base::Owned(to_fetch), 414 base::Owned(to_fetch),
415 base::Owned(to_upload))); 415 base::Owned(to_upload)));
416 } 416 }
417 417
418 void GDataCache::GetResourceIdsOfExistingPinnedFilesOnUIThread( 418 void DriveCache::GetResourceIdsOfExistingPinnedFilesOnUIThread(
419 const GetResourceIdsCallback& callback) { 419 const GetResourceIdsCallback& callback) {
420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
421 421
422 std::vector<std::string>* resource_ids = new std::vector<std::string>; 422 std::vector<std::string>* resource_ids = new std::vector<std::string>;
423 blocking_task_runner_->PostTaskAndReply( 423 blocking_task_runner_->PostTaskAndReply(
424 FROM_HERE, 424 FROM_HERE,
425 base::Bind(&GDataCache::GetResourceIdsOfExistingPinnedFiles, 425 base::Bind(&DriveCache::GetResourceIdsOfExistingPinnedFiles,
426 base::Unretained(this), 426 base::Unretained(this),
427 resource_ids), 427 resource_ids),
428 base::Bind(&RunGetResourceIdsCallback, 428 base::Bind(&RunGetResourceIdsCallback,
429 callback, 429 callback,
430 base::Owned(resource_ids))); 430 base::Owned(resource_ids)));
431 } 431 }
432 432
433 void GDataCache::GetResourceIdsOfAllFilesOnUIThread( 433 void DriveCache::GetResourceIdsOfAllFilesOnUIThread(
434 const GetResourceIdsCallback& callback) { 434 const GetResourceIdsCallback& callback) {
435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
436 436
437 std::vector<std::string>* resource_ids = new std::vector<std::string>; 437 std::vector<std::string>* resource_ids = new std::vector<std::string>;
438 blocking_task_runner_->PostTaskAndReply( 438 blocking_task_runner_->PostTaskAndReply(
439 FROM_HERE, 439 FROM_HERE,
440 base::Bind(&GDataCache::GetResourceIdsOfAllFiles, 440 base::Bind(&DriveCache::GetResourceIdsOfAllFiles,
441 base::Unretained(this), 441 base::Unretained(this),
442 resource_ids), 442 resource_ids),
443 base::Bind(&RunGetResourceIdsCallback, 443 base::Bind(&RunGetResourceIdsCallback,
444 callback, 444 callback,
445 base::Owned(resource_ids))); 445 base::Owned(resource_ids)));
446 } 446 }
447 447
448 void GDataCache::FreeDiskSpaceIfNeededFor(int64 num_bytes, 448 void DriveCache::FreeDiskSpaceIfNeededFor(int64 num_bytes,
449 bool* has_enough_space) { 449 bool* has_enough_space) {
450 AssertOnSequencedWorkerPool(); 450 AssertOnSequencedWorkerPool();
451 451
452 // Do nothing and return if we have enough space. 452 // Do nothing and return if we have enough space.
453 *has_enough_space = HasEnoughSpaceFor(num_bytes); 453 *has_enough_space = HasEnoughSpaceFor(num_bytes);
454 if (*has_enough_space) 454 if (*has_enough_space)
455 return; 455 return;
456 456
457 // Otherwise, try to free up the disk space. 457 // Otherwise, try to free up the disk space.
458 DVLOG(1) << "Freeing up disk space for " << num_bytes; 458 DVLOG(1) << "Freeing up disk space for " << num_bytes;
459 // First remove temporary files from the cache map. 459 // First remove temporary files from the cache map.
460 metadata_->RemoveTemporaryFiles(); 460 metadata_->RemoveTemporaryFiles();
461 // Then remove all files under "tmp" directory. 461 // Then remove all files under "tmp" directory.
462 RemoveAllFiles(GetCacheDirectoryPath(GDataCache::CACHE_TYPE_TMP)); 462 RemoveAllFiles(GetCacheDirectoryPath(DriveCache::CACHE_TYPE_TMP));
463 463
464 // Check the disk space again. 464 // Check the disk space again.
465 *has_enough_space = HasEnoughSpaceFor(num_bytes); 465 *has_enough_space = HasEnoughSpaceFor(num_bytes);
466 } 466 }
467 467
468 void GDataCache::GetFileOnUIThread(const std::string& resource_id, 468 void DriveCache::GetFileOnUIThread(const std::string& resource_id,
469 const std::string& md5, 469 const std::string& md5,
470 const GetFileFromCacheCallback& callback) { 470 const GetFileFromCacheCallback& callback) {
471 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 471 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
472 472
473 GDataFileError* error = 473 GDataFileError* error =
474 new GDataFileError(GDATA_FILE_OK); 474 new GDataFileError(GDATA_FILE_OK);
475 FilePath* cache_file_path = new FilePath; 475 FilePath* cache_file_path = new FilePath;
476 blocking_task_runner_->PostTaskAndReply( 476 blocking_task_runner_->PostTaskAndReply(
477 FROM_HERE, 477 FROM_HERE,
478 base::Bind(&GDataCache::GetFile, 478 base::Bind(&DriveCache::GetFile,
479 base::Unretained(this), 479 base::Unretained(this),
480 resource_id, 480 resource_id,
481 md5, 481 md5,
482 error, 482 error,
483 cache_file_path), 483 cache_file_path),
484 base::Bind(&RunGetFileFromCacheCallback, 484 base::Bind(&RunGetFileFromCacheCallback,
485 callback, 485 callback,
486 base::Owned(error), 486 base::Owned(error),
487 resource_id, 487 resource_id,
488 md5, 488 md5,
489 base::Owned(cache_file_path))); 489 base::Owned(cache_file_path)));
490 } 490 }
491 491
492 void GDataCache::StoreOnUIThread(const std::string& resource_id, 492 void DriveCache::StoreOnUIThread(const std::string& resource_id,
493 const std::string& md5, 493 const std::string& md5,
494 const FilePath& source_path, 494 const FilePath& source_path,
495 FileOperationType file_operation_type, 495 FileOperationType file_operation_type,
496 const CacheOperationCallback& callback) { 496 const CacheOperationCallback& callback) {
497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
498 498
499 GDataFileError* error = 499 GDataFileError* error =
500 new GDataFileError(GDATA_FILE_OK); 500 new GDataFileError(GDATA_FILE_OK);
501 blocking_task_runner_->PostTaskAndReply( 501 blocking_task_runner_->PostTaskAndReply(
502 FROM_HERE, 502 FROM_HERE,
503 base::Bind(&GDataCache::Store, 503 base::Bind(&DriveCache::Store,
504 base::Unretained(this), 504 base::Unretained(this),
505 resource_id, 505 resource_id,
506 md5, 506 md5,
507 source_path, 507 source_path,
508 file_operation_type, 508 file_operation_type,
509 error), 509 error),
510 base::Bind(&RunCacheOperationCallback, 510 base::Bind(&RunCacheOperationCallback,
511 callback, 511 callback,
512 base::Owned(error), 512 base::Owned(error),
513 resource_id, 513 resource_id,
514 md5)); 514 md5));
515 } 515 }
516 516
517 void GDataCache::PinOnUIThread(const std::string& resource_id, 517 void DriveCache::PinOnUIThread(const std::string& resource_id,
518 const std::string& md5, 518 const std::string& md5,
519 const CacheOperationCallback& callback) { 519 const CacheOperationCallback& callback) {
520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
521 521
522 GDataFileError* error = 522 GDataFileError* error =
523 new GDataFileError(GDATA_FILE_OK); 523 new GDataFileError(GDATA_FILE_OK);
524 blocking_task_runner_->PostTaskAndReply( 524 blocking_task_runner_->PostTaskAndReply(
525 FROM_HERE, 525 FROM_HERE,
526 base::Bind(&GDataCache::Pin, 526 base::Bind(&DriveCache::Pin,
527 base::Unretained(this), 527 base::Unretained(this),
528 resource_id, 528 resource_id,
529 md5, 529 md5,
530 GDataCache::FILE_OPERATION_MOVE, 530 DriveCache::FILE_OPERATION_MOVE,
531 error), 531 error),
532 base::Bind(&GDataCache::OnPinned, 532 base::Bind(&DriveCache::OnPinned,
533 weak_ptr_factory_.GetWeakPtr(), 533 weak_ptr_factory_.GetWeakPtr(),
534 base::Owned(error), 534 base::Owned(error),
535 resource_id, 535 resource_id,
536 md5, 536 md5,
537 callback)); 537 callback));
538 } 538 }
539 539
540 void GDataCache::UnpinOnUIThread(const std::string& resource_id, 540 void DriveCache::UnpinOnUIThread(const std::string& resource_id,
541 const std::string& md5, 541 const std::string& md5,
542 const CacheOperationCallback& callback) { 542 const CacheOperationCallback& callback) {
543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
544 GDataFileError* error = 544 GDataFileError* error =
545 new GDataFileError(GDATA_FILE_OK); 545 new GDataFileError(GDATA_FILE_OK);
546 blocking_task_runner_->PostTaskAndReply( 546 blocking_task_runner_->PostTaskAndReply(
547 FROM_HERE, 547 FROM_HERE,
548 base::Bind(&GDataCache::Unpin, 548 base::Bind(&DriveCache::Unpin,
549 base::Unretained(this), 549 base::Unretained(this),
550 resource_id, 550 resource_id,
551 md5, 551 md5,
552 GDataCache::FILE_OPERATION_MOVE, 552 DriveCache::FILE_OPERATION_MOVE,
553 error), 553 error),
554 base::Bind(&GDataCache::OnUnpinned, 554 base::Bind(&DriveCache::OnUnpinned,
555 weak_ptr_factory_.GetWeakPtr(), 555 weak_ptr_factory_.GetWeakPtr(),
556 base::Owned(error), 556 base::Owned(error),
557 resource_id, 557 resource_id,
558 md5, 558 md5,
559 callback)); 559 callback));
560 } 560 }
561 561
562 void GDataCache::SetMountedStateOnUIThread( 562 void DriveCache::SetMountedStateOnUIThread(
563 const FilePath& file_path, 563 const FilePath& file_path,
564 bool to_mount, 564 bool to_mount,
565 const ChangeCacheStateCallback& callback) { 565 const ChangeCacheStateCallback& callback) {
566 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 566 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
567 567
568 GDataFileError* error = 568 GDataFileError* error =
569 new GDataFileError(GDATA_FILE_OK); 569 new GDataFileError(GDATA_FILE_OK);
570 FilePath* cache_file_path = new FilePath; 570 FilePath* cache_file_path = new FilePath;
571 blocking_task_runner_->PostTaskAndReply( 571 blocking_task_runner_->PostTaskAndReply(
572 FROM_HERE, 572 FROM_HERE,
573 base::Bind(&GDataCache::SetMountedState, 573 base::Bind(&DriveCache::SetMountedState,
574 base::Unretained(this), 574 base::Unretained(this),
575 file_path, 575 file_path,
576 to_mount, 576 to_mount,
577 error, 577 error,
578 cache_file_path), 578 cache_file_path),
579 base::Bind(&RunChangeCacheStateCallback, 579 base::Bind(&RunChangeCacheStateCallback,
580 callback, 580 callback,
581 base::Owned(error), 581 base::Owned(error),
582 base::Owned(cache_file_path))); 582 base::Owned(cache_file_path)));
583 } 583 }
584 584
585 void GDataCache::MarkDirtyOnUIThread(const std::string& resource_id, 585 void DriveCache::MarkDirtyOnUIThread(const std::string& resource_id,
586 const std::string& md5, 586 const std::string& md5,
587 const GetFileFromCacheCallback& callback) { 587 const GetFileFromCacheCallback& callback) {
588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
589 589
590 GDataFileError* error = 590 GDataFileError* error =
591 new GDataFileError(GDATA_FILE_OK); 591 new GDataFileError(GDATA_FILE_OK);
592 FilePath* cache_file_path = new FilePath; 592 FilePath* cache_file_path = new FilePath;
593 blocking_task_runner_->PostTaskAndReply( 593 blocking_task_runner_->PostTaskAndReply(
594 FROM_HERE, 594 FROM_HERE,
595 base::Bind(&GDataCache::MarkDirty, 595 base::Bind(&DriveCache::MarkDirty,
596 base::Unretained(this), 596 base::Unretained(this),
597 resource_id, 597 resource_id,
598 md5, 598 md5,
599 GDataCache::FILE_OPERATION_MOVE, 599 DriveCache::FILE_OPERATION_MOVE,
600 error, 600 error,
601 cache_file_path), 601 cache_file_path),
602 base::Bind(&RunGetFileFromCacheCallback, 602 base::Bind(&RunGetFileFromCacheCallback,
603 callback, 603 callback,
604 base::Owned(error), 604 base::Owned(error),
605 resource_id, 605 resource_id,
606 md5, 606 md5,
607 base::Owned(cache_file_path))); 607 base::Owned(cache_file_path)));
608 } 608 }
609 609
610 void GDataCache::CommitDirtyOnUIThread(const std::string& resource_id, 610 void DriveCache::CommitDirtyOnUIThread(const std::string& resource_id,
611 const std::string& md5, 611 const std::string& md5,
612 const CacheOperationCallback& callback) { 612 const CacheOperationCallback& callback) {
613 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 613 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
614 614
615 GDataFileError* error = new GDataFileError(GDATA_FILE_OK); 615 GDataFileError* error = new GDataFileError(GDATA_FILE_OK);
616 blocking_task_runner_->PostTaskAndReply( 616 blocking_task_runner_->PostTaskAndReply(
617 FROM_HERE, 617 FROM_HERE,
618 base::Bind(&GDataCache::CommitDirty, 618 base::Bind(&DriveCache::CommitDirty,
619 base::Unretained(this), 619 base::Unretained(this),
620 resource_id, 620 resource_id,
621 md5, 621 md5,
622 GDataCache::FILE_OPERATION_MOVE, 622 DriveCache::FILE_OPERATION_MOVE,
623 error), 623 error),
624 base::Bind(&GDataCache::OnCommitDirty, 624 base::Bind(&DriveCache::OnCommitDirty,
625 weak_ptr_factory_.GetWeakPtr(), 625 weak_ptr_factory_.GetWeakPtr(),
626 base::Owned(error), 626 base::Owned(error),
627 resource_id, 627 resource_id,
628 md5, 628 md5,
629 callback)); 629 callback));
630 } 630 }
631 631
632 void GDataCache::ClearDirtyOnUIThread(const std::string& resource_id, 632 void DriveCache::ClearDirtyOnUIThread(const std::string& resource_id,
633 const std::string& md5, 633 const std::string& md5,
634 const CacheOperationCallback& callback) { 634 const CacheOperationCallback& callback) {
635 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 635 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
636 636
637 GDataFileError* error = 637 GDataFileError* error =
638 new GDataFileError(GDATA_FILE_OK); 638 new GDataFileError(GDATA_FILE_OK);
639 blocking_task_runner_->PostTaskAndReply( 639 blocking_task_runner_->PostTaskAndReply(
640 FROM_HERE, 640 FROM_HERE,
641 base::Bind(&GDataCache::ClearDirty, 641 base::Bind(&DriveCache::ClearDirty,
642 base::Unretained(this), 642 base::Unretained(this),
643 resource_id, 643 resource_id,
644 md5, 644 md5,
645 GDataCache::FILE_OPERATION_MOVE, 645 DriveCache::FILE_OPERATION_MOVE,
646 error), 646 error),
647 base::Bind(&RunCacheOperationCallback, 647 base::Bind(&RunCacheOperationCallback,
648 callback, 648 callback,
649 base::Owned(error), 649 base::Owned(error),
650 resource_id, 650 resource_id,
651 md5)); 651 md5));
652 } 652 }
653 653
654 void GDataCache::RemoveOnUIThread(const std::string& resource_id, 654 void DriveCache::RemoveOnUIThread(const std::string& resource_id,
655 const CacheOperationCallback& callback) { 655 const CacheOperationCallback& callback) {
656 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 656 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
657 657
658 GDataFileError* error = 658 GDataFileError* error =
659 new GDataFileError(GDATA_FILE_OK); 659 new GDataFileError(GDATA_FILE_OK);
660 660
661 blocking_task_runner_->PostTaskAndReply( 661 blocking_task_runner_->PostTaskAndReply(
662 FROM_HERE, 662 FROM_HERE,
663 base::Bind(&GDataCache::Remove, 663 base::Bind(&DriveCache::Remove,
664 base::Unretained(this), 664 base::Unretained(this),
665 resource_id, 665 resource_id,
666 error), 666 error),
667 base::Bind(&RunCacheOperationCallback, 667 base::Bind(&RunCacheOperationCallback,
668 callback, 668 callback,
669 base::Owned(error), 669 base::Owned(error),
670 resource_id, 670 resource_id,
671 "" /* md5 */)); 671 "" /* md5 */));
672 } 672 }
673 673
674 void GDataCache::ClearAllOnUIThread(const ChangeCacheStateCallback& callback) { 674 void DriveCache::ClearAllOnUIThread(const ChangeCacheStateCallback& callback) {
675 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 675 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
676 676
677 GDataFileError* error = new GDataFileError(GDATA_FILE_OK); 677 GDataFileError* error = new GDataFileError(GDATA_FILE_OK);
678 678
679 blocking_task_runner_->PostTaskAndReply( 679 blocking_task_runner_->PostTaskAndReply(
680 FROM_HERE, 680 FROM_HERE,
681 base::Bind(&GDataCache::ClearAll, 681 base::Bind(&DriveCache::ClearAll,
682 base::Unretained(this), 682 base::Unretained(this),
683 error), 683 error),
684 base::Bind(&RunChangeCacheStateCallback, 684 base::Bind(&RunChangeCacheStateCallback,
685 callback, 685 callback,
686 base::Owned(error), 686 base::Owned(error),
687 &cache_root_path_)); 687 &cache_root_path_));
688 } 688 }
689 689
690 void GDataCache::RequestInitializeOnUIThread() { 690 void DriveCache::RequestInitializeOnUIThread() {
691 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 691 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
692 692
693 blocking_task_runner_->PostTask( 693 blocking_task_runner_->PostTask(
694 FROM_HERE, 694 FROM_HERE,
695 base::Bind(&GDataCache::Initialize, base::Unretained(this))); 695 base::Bind(&DriveCache::Initialize, base::Unretained(this)));
696 } 696 }
697 697
698 void GDataCache::RequestInitializeOnUIThreadForTesting() { 698 void DriveCache::RequestInitializeOnUIThreadForTesting() {
699 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 699 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
700 700
701 blocking_task_runner_->PostTask( 701 blocking_task_runner_->PostTask(
702 FROM_HERE, 702 FROM_HERE,
703 base::Bind(&GDataCache::InitializeForTesting, base::Unretained(this))); 703 base::Bind(&DriveCache::InitializeForTesting, base::Unretained(this)));
704 } 704 }
705 705
706 void GDataCache::ForceRescanOnUIThreadForTesting() { 706 void DriveCache::ForceRescanOnUIThreadForTesting() {
707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
708 708
709 blocking_task_runner_->PostTask( 709 blocking_task_runner_->PostTask(
710 FROM_HERE, 710 FROM_HERE,
711 base::Bind(&GDataCache::ForceRescanForTesting, base::Unretained(this))); 711 base::Bind(&DriveCache::ForceRescanForTesting, base::Unretained(this)));
712 } 712 }
713 713
714 bool GDataCache::GetCacheEntry(const std::string& resource_id, 714 bool DriveCache::GetCacheEntry(const std::string& resource_id,
715 const std::string& md5, 715 const std::string& md5,
716 DriveCacheEntry* entry) { 716 DriveCacheEntry* entry) {
717 DCHECK(entry); 717 DCHECK(entry);
718 AssertOnSequencedWorkerPool(); 718 AssertOnSequencedWorkerPool();
719 return metadata_->GetCacheEntry(resource_id, md5, entry); 719 return metadata_->GetCacheEntry(resource_id, md5, entry);
720 } 720 }
721 721
722 // static 722 // static
723 GDataCache* GDataCache::CreateGDataCacheOnUIThread( 723 DriveCache* DriveCache::CreateDriveCacheOnUIThread(
724 const FilePath& cache_root_path, 724 const FilePath& cache_root_path,
725 base::SequencedTaskRunner* blocking_task_runner) { 725 base::SequencedTaskRunner* blocking_task_runner) {
726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
727 return new GDataCache(cache_root_path, blocking_task_runner); 727 return new DriveCache(cache_root_path, blocking_task_runner);
728 } 728 }
729 729
730 void GDataCache::DestroyOnUIThread() { 730 void DriveCache::DestroyOnUIThread() {
731 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 731 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
732 732
733 // Invalidate the weak pointer. 733 // Invalidate the weak pointer.
734 weak_ptr_factory_.InvalidateWeakPtrs(); 734 weak_ptr_factory_.InvalidateWeakPtrs();
735 735
736 // Destroy myself on the blocking pool. 736 // Destroy myself on the blocking pool.
737 blocking_task_runner_->PostTask( 737 blocking_task_runner_->PostTask(
738 FROM_HERE, 738 FROM_HERE,
739 base::Bind(&GDataCache::Destroy, 739 base::Bind(&DriveCache::Destroy,
740 base::Unretained(this))); 740 base::Unretained(this)));
741 } 741 }
742 742
743 void GDataCache::Initialize() { 743 void DriveCache::Initialize() {
744 AssertOnSequencedWorkerPool(); 744 AssertOnSequencedWorkerPool();
745 745
746 InitCachePaths(cache_paths_); 746 InitCachePaths(cache_paths_);
747 metadata_ = GDataCacheMetadata::CreateGDataCacheMetadata( 747 metadata_ = DriveCacheMetadata::CreateDriveCacheMetadata(
748 blocking_task_runner_).Pass(); 748 blocking_task_runner_).Pass();
749 metadata_->Initialize(cache_paths_); 749 metadata_->Initialize(cache_paths_);
750 } 750 }
751 751
752 void GDataCache::InitializeForTesting() { 752 void DriveCache::InitializeForTesting() {
753 AssertOnSequencedWorkerPool(); 753 AssertOnSequencedWorkerPool();
754 754
755 InitCachePaths(cache_paths_); 755 InitCachePaths(cache_paths_);
756 metadata_ = GDataCacheMetadata::CreateGDataCacheMetadataForTesting( 756 metadata_ = DriveCacheMetadata::CreateDriveCacheMetadataForTesting(
757 blocking_task_runner_).Pass(); 757 blocking_task_runner_).Pass();
758 metadata_->Initialize(cache_paths_); 758 metadata_->Initialize(cache_paths_);
759 } 759 }
760 760
761 void GDataCache::Destroy() { 761 void DriveCache::Destroy() {
762 AssertOnSequencedWorkerPool(); 762 AssertOnSequencedWorkerPool();
763 delete this; 763 delete this;
764 } 764 }
765 765
766 void GDataCache::ForceRescanForTesting() { 766 void DriveCache::ForceRescanForTesting() {
767 AssertOnSequencedWorkerPool(); 767 AssertOnSequencedWorkerPool();
768 metadata_->ForceRescanForTesting(cache_paths_); 768 metadata_->ForceRescanForTesting(cache_paths_);
769 } 769 }
770 770
771 void GDataCache::GetResourceIdsOfBacklog( 771 void DriveCache::GetResourceIdsOfBacklog(
772 std::vector<std::string>* to_fetch, 772 std::vector<std::string>* to_fetch,
773 std::vector<std::string>* to_upload) { 773 std::vector<std::string>* to_upload) {
774 AssertOnSequencedWorkerPool(); 774 AssertOnSequencedWorkerPool();
775 DCHECK(to_fetch); 775 DCHECK(to_fetch);
776 DCHECK(to_upload); 776 DCHECK(to_upload);
777 777
778 metadata_->Iterate(base::Bind(&CollectBacklog, to_fetch, to_upload)); 778 metadata_->Iterate(base::Bind(&CollectBacklog, to_fetch, to_upload));
779 } 779 }
780 780
781 void GDataCache::GetResourceIdsOfExistingPinnedFiles( 781 void DriveCache::GetResourceIdsOfExistingPinnedFiles(
782 std::vector<std::string>* resource_ids) { 782 std::vector<std::string>* resource_ids) {
783 AssertOnSequencedWorkerPool(); 783 AssertOnSequencedWorkerPool();
784 DCHECK(resource_ids); 784 DCHECK(resource_ids);
785 785
786 metadata_->Iterate(base::Bind(&CollectExistingPinnedFile, resource_ids)); 786 metadata_->Iterate(base::Bind(&CollectExistingPinnedFile, resource_ids));
787 } 787 }
788 788
789 void GDataCache::GetResourceIdsOfAllFiles( 789 void DriveCache::GetResourceIdsOfAllFiles(
790 std::vector<std::string>* resource_ids) { 790 std::vector<std::string>* resource_ids) {
791 AssertOnSequencedWorkerPool(); 791 AssertOnSequencedWorkerPool();
792 DCHECK(resource_ids); 792 DCHECK(resource_ids);
793 793
794 metadata_->Iterate(base::Bind(&CollectAnyFile, resource_ids)); 794 metadata_->Iterate(base::Bind(&CollectAnyFile, resource_ids));
795 } 795 }
796 796
797 void GDataCache::GetFile(const std::string& resource_id, 797 void DriveCache::GetFile(const std::string& resource_id,
798 const std::string& md5, 798 const std::string& md5,
799 GDataFileError* error, 799 GDataFileError* error,
800 FilePath* cache_file_path) { 800 FilePath* cache_file_path) {
801 AssertOnSequencedWorkerPool(); 801 AssertOnSequencedWorkerPool();
802 DCHECK(error); 802 DCHECK(error);
803 DCHECK(cache_file_path); 803 DCHECK(cache_file_path);
804 804
805 DriveCacheEntry cache_entry; 805 DriveCacheEntry cache_entry;
806 if (GetCacheEntry(resource_id, md5, &cache_entry) && 806 if (GetCacheEntry(resource_id, md5, &cache_entry) &&
807 cache_entry.is_present()) { 807 cache_entry.is_present()) {
808 CachedFileOrigin file_origin; 808 CachedFileOrigin file_origin;
809 if (cache_entry.is_mounted()) { 809 if (cache_entry.is_mounted()) {
810 file_origin = CACHED_FILE_MOUNTED; 810 file_origin = CACHED_FILE_MOUNTED;
811 } else if (cache_entry.is_dirty()) { 811 } else if (cache_entry.is_dirty()) {
812 file_origin = CACHED_FILE_LOCALLY_MODIFIED; 812 file_origin = CACHED_FILE_LOCALLY_MODIFIED;
813 } else { 813 } else {
814 file_origin = CACHED_FILE_FROM_SERVER; 814 file_origin = CACHED_FILE_FROM_SERVER;
815 } 815 }
816 *cache_file_path = GetCacheFilePath( 816 *cache_file_path = GetCacheFilePath(
817 resource_id, 817 resource_id,
818 md5, 818 md5,
819 GetSubDirectoryType(cache_entry), 819 GetSubDirectoryType(cache_entry),
820 file_origin); 820 file_origin);
821 *error = GDATA_FILE_OK; 821 *error = GDATA_FILE_OK;
822 } else { 822 } else {
823 *error = GDATA_FILE_ERROR_NOT_FOUND; 823 *error = GDATA_FILE_ERROR_NOT_FOUND;
824 } 824 }
825 } 825 }
826 826
827 void GDataCache::Store(const std::string& resource_id, 827 void DriveCache::Store(const std::string& resource_id,
828 const std::string& md5, 828 const std::string& md5,
829 const FilePath& source_path, 829 const FilePath& source_path,
830 FileOperationType file_operation_type, 830 FileOperationType file_operation_type,
831 GDataFileError* error) { 831 GDataFileError* error) {
832 AssertOnSequencedWorkerPool(); 832 AssertOnSequencedWorkerPool();
833 DCHECK(error); 833 DCHECK(error);
834 834
835 if (file_operation_type == FILE_OPERATION_COPY) { 835 if (file_operation_type == FILE_OPERATION_COPY) {
836 int64 file_size; 836 int64 file_size;
837 if (!file_util::GetFileSize(source_path, &file_size)) { 837 if (!file_util::GetFileSize(source_path, &file_size)) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 914
915 if (*error == GDATA_FILE_OK) { 915 if (*error == GDATA_FILE_OK) {
916 // Now that file operations have completed, update cache map. 916 // Now that file operations have completed, update cache map.
917 cache_entry.set_md5(md5); 917 cache_entry.set_md5(md5);
918 cache_entry.set_is_present(true); 918 cache_entry.set_is_present(true);
919 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); 919 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
920 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); 920 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry);
921 } 921 }
922 } 922 }
923 923
924 void GDataCache::Pin(const std::string& resource_id, 924 void DriveCache::Pin(const std::string& resource_id,
925 const std::string& md5, 925 const std::string& md5,
926 FileOperationType file_operation_type, 926 FileOperationType file_operation_type,
927 GDataFileError* error) { 927 GDataFileError* error) {
928 AssertOnSequencedWorkerPool(); 928 AssertOnSequencedWorkerPool();
929 DCHECK(error); 929 DCHECK(error);
930 930
931 FilePath source_path; 931 FilePath source_path;
932 FilePath dest_path; 932 FilePath dest_path;
933 FilePath symlink_path; 933 FilePath symlink_path;
934 bool create_symlink = true; 934 bool create_symlink = true;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 1001
1002 if (*error == GDATA_FILE_OK) { 1002 if (*error == GDATA_FILE_OK) {
1003 // Now that file operations have completed, update cache map. 1003 // Now that file operations have completed, update cache map.
1004 cache_entry.set_md5(md5); 1004 cache_entry.set_md5(md5);
1005 cache_entry.set_is_pinned(true); 1005 cache_entry.set_is_pinned(true);
1006 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); 1006 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
1007 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); 1007 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry);
1008 } 1008 }
1009 } 1009 }
1010 1010
1011 void GDataCache::Unpin(const std::string& resource_id, 1011 void DriveCache::Unpin(const std::string& resource_id,
1012 const std::string& md5, 1012 const std::string& md5,
1013 FileOperationType file_operation_type, 1013 FileOperationType file_operation_type,
1014 GDataFileError* error) { 1014 GDataFileError* error) {
1015 AssertOnSequencedWorkerPool(); 1015 AssertOnSequencedWorkerPool();
1016 DCHECK(error); 1016 DCHECK(error);
1017 1017
1018 // Unpinning a file means its entry must exist in cache. 1018 // Unpinning a file means its entry must exist in cache.
1019 DriveCacheEntry cache_entry; 1019 DriveCacheEntry cache_entry;
1020 if (!GetCacheEntry(resource_id, md5, &cache_entry)) { 1020 if (!GetCacheEntry(resource_id, md5, &cache_entry)) {
1021 LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id=" 1021 LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id="
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 cache_entry.set_is_pinned(false); 1086 cache_entry.set_is_pinned(false);
1087 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); 1087 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
1088 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); 1088 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry);
1089 } else { 1089 } else {
1090 // Remove the existing entry if we are unpinning a non-present file. 1090 // Remove the existing entry if we are unpinning a non-present file.
1091 metadata_->RemoveCacheEntry(resource_id); 1091 metadata_->RemoveCacheEntry(resource_id);
1092 } 1092 }
1093 } 1093 }
1094 } 1094 }
1095 1095
1096 void GDataCache::SetMountedState(const FilePath& file_path, 1096 void DriveCache::SetMountedState(const FilePath& file_path,
1097 bool to_mount, 1097 bool to_mount,
1098 GDataFileError *error, 1098 GDataFileError *error,
1099 FilePath* cache_file_path) { 1099 FilePath* cache_file_path) {
1100 AssertOnSequencedWorkerPool(); 1100 AssertOnSequencedWorkerPool();
1101 DCHECK(error); 1101 DCHECK(error);
1102 DCHECK(cache_file_path); 1102 DCHECK(cache_file_path);
1103 1103
1104 // Parse file path to obtain resource_id, md5 and extra_extension. 1104 // Parse file path to obtain resource_id, md5 and extra_extension.
1105 std::string resource_id; 1105 std::string resource_id;
1106 std::string md5; 1106 std::string md5;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 *error = ModifyCacheState(source_path, *cache_file_path, 1150 *error = ModifyCacheState(source_path, *cache_file_path,
1151 FILE_OPERATION_MOVE, FilePath(), false); 1151 FILE_OPERATION_MOVE, FilePath(), false);
1152 if (*error == GDATA_FILE_OK) { 1152 if (*error == GDATA_FILE_OK) {
1153 // Now that cache operation is complete, update cache map 1153 // Now that cache operation is complete, update cache map
1154 cache_entry.set_md5(md5); 1154 cache_entry.set_md5(md5);
1155 cache_entry.set_is_persistent(dest_subdir == CACHE_TYPE_PERSISTENT); 1155 cache_entry.set_is_persistent(dest_subdir == CACHE_TYPE_PERSISTENT);
1156 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); 1156 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry);
1157 } 1157 }
1158 } 1158 }
1159 1159
1160 void GDataCache::MarkDirty(const std::string& resource_id, 1160 void DriveCache::MarkDirty(const std::string& resource_id,
1161 const std::string& md5, 1161 const std::string& md5,
1162 FileOperationType file_operation_type, 1162 FileOperationType file_operation_type,
1163 GDataFileError* error, 1163 GDataFileError* error,
1164 FilePath* cache_file_path) { 1164 FilePath* cache_file_path) {
1165 AssertOnSequencedWorkerPool(); 1165 AssertOnSequencedWorkerPool();
1166 DCHECK(error); 1166 DCHECK(error);
1167 DCHECK(cache_file_path); 1167 DCHECK(cache_file_path);
1168 1168
1169 // If file has already been marked dirty in previous instance of chrome, we 1169 // If file has already been marked dirty in previous instance of chrome, we
1170 // would have lost the md5 info during cache initialization, because the file 1170 // would have lost the md5 info during cache initialization, because the file
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 1255
1256 if (*error == GDATA_FILE_OK) { 1256 if (*error == GDATA_FILE_OK) {
1257 // Now that file operations have completed, update cache map. 1257 // Now that file operations have completed, update cache map.
1258 cache_entry.set_md5(md5); 1258 cache_entry.set_md5(md5);
1259 cache_entry.set_is_dirty(true); 1259 cache_entry.set_is_dirty(true);
1260 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); 1260 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
1261 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); 1261 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry);
1262 } 1262 }
1263 } 1263 }
1264 1264
1265 void GDataCache::CommitDirty(const std::string& resource_id, 1265 void DriveCache::CommitDirty(const std::string& resource_id,
1266 const std::string& md5, 1266 const std::string& md5,
1267 FileOperationType file_operation_type, 1267 FileOperationType file_operation_type,
1268 GDataFileError* error) { 1268 GDataFileError* error) {
1269 AssertOnSequencedWorkerPool(); 1269 AssertOnSequencedWorkerPool();
1270 DCHECK(error); 1270 DCHECK(error);
1271 1271
1272 // If file has already been marked dirty in previous instance of chrome, we 1272 // If file has already been marked dirty in previous instance of chrome, we
1273 // would have lost the md5 info during cache initialization, because the file 1273 // would have lost the md5 info during cache initialization, because the file
1274 // would have been renamed to .local extension. 1274 // would have been renamed to .local extension.
1275 // So, search for entry in cache without comparing md5. 1275 // So, search for entry in cache without comparing md5.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 // Since there's no need to move files, use |target_path| for both 1314 // Since there's no need to move files, use |target_path| for both
1315 // |source_path| and |dest_path|, because ModifyCacheState only moves files 1315 // |source_path| and |dest_path|, because ModifyCacheState only moves files
1316 // if source and destination are different. 1316 // if source and destination are different.
1317 *error = ModifyCacheState(target_path, // source 1317 *error = ModifyCacheState(target_path, // source
1318 target_path, // destination 1318 target_path, // destination
1319 file_operation_type, 1319 file_operation_type,
1320 symlink_path, 1320 symlink_path,
1321 true /* create symlink */); 1321 true /* create symlink */);
1322 } 1322 }
1323 1323
1324 void GDataCache::ClearDirty(const std::string& resource_id, 1324 void DriveCache::ClearDirty(const std::string& resource_id,
1325 const std::string& md5, 1325 const std::string& md5,
1326 FileOperationType file_operation_type, 1326 FileOperationType file_operation_type,
1327 GDataFileError* error) { 1327 GDataFileError* error) {
1328 AssertOnSequencedWorkerPool(); 1328 AssertOnSequencedWorkerPool();
1329 DCHECK(error); 1329 DCHECK(error);
1330 1330
1331 // |md5| is the new .<md5> extension to rename the file to. 1331 // |md5| is the new .<md5> extension to rename the file to.
1332 // So, search for entry in cache without comparing md5. 1332 // So, search for entry in cache without comparing md5.
1333 DriveCacheEntry cache_entry; 1333 DriveCacheEntry cache_entry;
1334 1334
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 1403
1404 if (*error == GDATA_FILE_OK) { 1404 if (*error == GDATA_FILE_OK) {
1405 // Now that file operations have completed, update cache map. 1405 // Now that file operations have completed, update cache map.
1406 cache_entry.set_md5(md5); 1406 cache_entry.set_md5(md5);
1407 cache_entry.set_is_dirty(false); 1407 cache_entry.set_is_dirty(false);
1408 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); 1408 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
1409 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); 1409 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry);
1410 } 1410 }
1411 } 1411 }
1412 1412
1413 void GDataCache::Remove(const std::string& resource_id, 1413 void DriveCache::Remove(const std::string& resource_id,
1414 GDataFileError* error) { 1414 GDataFileError* error) {
1415 AssertOnSequencedWorkerPool(); 1415 AssertOnSequencedWorkerPool();
1416 DCHECK(error); 1416 DCHECK(error);
1417 1417
1418 // MD5 is not passed into RemoveCacheEntry because we would delete all 1418 // MD5 is not passed into RemoveCacheEntry because we would delete all
1419 // cache files corresponding to <resource_id> regardless of the md5. 1419 // cache files corresponding to <resource_id> regardless of the md5.
1420 // So, search for entry in cache without taking md5 into account. 1420 // So, search for entry in cache without taking md5 into account.
1421 DriveCacheEntry cache_entry; 1421 DriveCacheEntry cache_entry;
1422 1422
1423 // If entry doesn't exist or is dirty or mounted in cache, nothing to do. 1423 // If entry doesn't exist or is dirty or mounted in cache, nothing to do.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 for (size_t i = 0; i < paths_to_delete.size(); ++i) { 1466 for (size_t i = 0; i < paths_to_delete.size(); ++i) {
1467 DeleteFilesSelectively(paths_to_delete[i], path_to_keep); 1467 DeleteFilesSelectively(paths_to_delete[i], path_to_keep);
1468 } 1468 }
1469 1469
1470 // Now that all file operations have completed, remove from cache map. 1470 // Now that all file operations have completed, remove from cache map.
1471 metadata_->RemoveCacheEntry(resource_id); 1471 metadata_->RemoveCacheEntry(resource_id);
1472 1472
1473 *error = GDATA_FILE_OK; 1473 *error = GDATA_FILE_OK;
1474 } 1474 }
1475 1475
1476 void GDataCache::ClearAll(GDataFileError* error) { 1476 void DriveCache::ClearAll(GDataFileError* error) {
1477 AssertOnSequencedWorkerPool(); 1477 AssertOnSequencedWorkerPool();
1478 DCHECK(error); 1478 DCHECK(error);
1479 1479
1480 bool success = file_util::Delete(cache_root_path_, true); 1480 bool success = file_util::Delete(cache_root_path_, true);
1481 Initialize(); 1481 Initialize();
1482 1482
1483 *error = success ? GDATA_FILE_OK : GDATA_FILE_ERROR_FAILED; 1483 *error = success ? GDATA_FILE_OK : GDATA_FILE_ERROR_FAILED;
1484 } 1484 }
1485 1485
1486 void GDataCache::OnPinned(GDataFileError* error, 1486 void DriveCache::OnPinned(GDataFileError* error,
1487 const std::string& resource_id, 1487 const std::string& resource_id,
1488 const std::string& md5, 1488 const std::string& md5,
1489 const CacheOperationCallback& callback) { 1489 const CacheOperationCallback& callback) {
1490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1491 DCHECK(error); 1491 DCHECK(error);
1492 1492
1493 if (!callback.is_null()) 1493 if (!callback.is_null())
1494 callback.Run(*error, resource_id, md5); 1494 callback.Run(*error, resource_id, md5);
1495 1495
1496 if (*error == GDATA_FILE_OK) 1496 if (*error == GDATA_FILE_OK)
1497 FOR_EACH_OBSERVER(Observer, observers_, OnCachePinned(resource_id, md5)); 1497 FOR_EACH_OBSERVER(Observer, observers_, OnCachePinned(resource_id, md5));
1498 } 1498 }
1499 1499
1500 void GDataCache::OnUnpinned(GDataFileError* error, 1500 void DriveCache::OnUnpinned(GDataFileError* error,
1501 const std::string& resource_id, 1501 const std::string& resource_id,
1502 const std::string& md5, 1502 const std::string& md5,
1503 const CacheOperationCallback& callback) { 1503 const CacheOperationCallback& callback) {
1504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1505 DCHECK(error); 1505 DCHECK(error);
1506 1506
1507 if (!callback.is_null()) 1507 if (!callback.is_null())
1508 callback.Run(*error, resource_id, md5); 1508 callback.Run(*error, resource_id, md5);
1509 1509
1510 if (*error == GDATA_FILE_OK) 1510 if (*error == GDATA_FILE_OK)
1511 FOR_EACH_OBSERVER(Observer, observers_, OnCacheUnpinned(resource_id, md5)); 1511 FOR_EACH_OBSERVER(Observer, observers_, OnCacheUnpinned(resource_id, md5));
1512 1512
1513 // Now the file is moved from "persistent" to "tmp" directory. 1513 // Now the file is moved from "persistent" to "tmp" directory.
1514 // It's a chance to free up space if needed. 1514 // It's a chance to free up space if needed.
1515 bool* has_enough_space = new bool(false); 1515 bool* has_enough_space = new bool(false);
1516 blocking_task_runner_->PostTask( 1516 blocking_task_runner_->PostTask(
1517 FROM_HERE, 1517 FROM_HERE,
1518 base::Bind(&GDataCache::FreeDiskSpaceIfNeededFor, 1518 base::Bind(&DriveCache::FreeDiskSpaceIfNeededFor,
1519 base::Unretained(this), 1519 base::Unretained(this),
1520 0, 1520 0,
1521 base::Owned(has_enough_space))); 1521 base::Owned(has_enough_space)));
1522 } 1522 }
1523 1523
1524 void GDataCache::OnCommitDirty(GDataFileError* error, 1524 void DriveCache::OnCommitDirty(GDataFileError* error,
1525 const std::string& resource_id, 1525 const std::string& resource_id,
1526 const std::string& md5, 1526 const std::string& md5,
1527 const CacheOperationCallback& callback) { 1527 const CacheOperationCallback& callback) {
1528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1529 DCHECK(error); 1529 DCHECK(error);
1530 1530
1531 if (!callback.is_null()) 1531 if (!callback.is_null())
1532 callback.Run(*error, resource_id, md5); 1532 callback.Run(*error, resource_id, md5);
1533 1533
1534 if (*error == GDATA_FILE_OK) 1534 if (*error == GDATA_FILE_OK)
1535 FOR_EACH_OBSERVER(Observer, observers_, OnCacheCommitted(resource_id)); 1535 FOR_EACH_OBSERVER(Observer, observers_, OnCacheCommitted(resource_id));
1536 } 1536 }
1537 1537
1538 void GDataCache::GetCacheEntryHelper(const std::string& resource_id, 1538 void DriveCache::GetCacheEntryHelper(const std::string& resource_id,
1539 const std::string& md5, 1539 const std::string& md5,
1540 bool* success, 1540 bool* success,
1541 DriveCacheEntry* cache_entry) { 1541 DriveCacheEntry* cache_entry) {
1542 AssertOnSequencedWorkerPool(); 1542 AssertOnSequencedWorkerPool();
1543 DCHECK(success); 1543 DCHECK(success);
1544 DCHECK(cache_entry); 1544 DCHECK(cache_entry);
1545 1545
1546 *success = GetCacheEntry(resource_id, md5, cache_entry); 1546 *success = GetCacheEntry(resource_id, md5, cache_entry);
1547 } 1547 }
1548 1548
1549 // static 1549 // static
1550 FilePath GDataCache::GetCacheRootPath(Profile* profile) { 1550 FilePath DriveCache::GetCacheRootPath(Profile* profile) {
1551 FilePath cache_base_path; 1551 FilePath cache_base_path;
1552 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path); 1552 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path);
1553 FilePath cache_root_path = 1553 FilePath cache_root_path =
1554 cache_base_path.Append(chrome::kGDataCacheDirname); 1554 cache_base_path.Append(chrome::kDriveCacheDirname);
1555 return cache_root_path.Append(kGDataCacheVersionDir); 1555 return cache_root_path.Append(kDriveCacheVersionDir);
1556 } 1556 }
1557 1557
1558 // static 1558 // static
1559 std::vector<FilePath> GDataCache::GetCachePaths( 1559 std::vector<FilePath> DriveCache::GetCachePaths(
1560 const FilePath& cache_root_path) { 1560 const FilePath& cache_root_path) {
1561 std::vector<FilePath> cache_paths; 1561 std::vector<FilePath> cache_paths;
1562 // The order should match GDataCache::CacheSubDirectoryType enum. 1562 // The order should match DriveCache::CacheSubDirectoryType enum.
1563 cache_paths.push_back(cache_root_path.Append(kGDataCacheMetaDir)); 1563 cache_paths.push_back(cache_root_path.Append(kDriveCacheMetaDir));
1564 cache_paths.push_back(cache_root_path.Append(kGDataCachePinnedDir)); 1564 cache_paths.push_back(cache_root_path.Append(kDriveCachePinnedDir));
1565 cache_paths.push_back(cache_root_path.Append(kGDataCacheOutgoingDir)); 1565 cache_paths.push_back(cache_root_path.Append(kDriveCacheOutgoingDir));
1566 cache_paths.push_back(cache_root_path.Append(kGDataCachePersistentDir)); 1566 cache_paths.push_back(cache_root_path.Append(kDriveCachePersistentDir));
1567 cache_paths.push_back(cache_root_path.Append(kGDataCacheTmpDir)); 1567 cache_paths.push_back(cache_root_path.Append(kDriveCacheTmpDir));
1568 cache_paths.push_back(cache_root_path.Append(kGDataCacheTmpDownloadsDir)); 1568 cache_paths.push_back(cache_root_path.Append(kDriveCacheTmpDownloadsDir));
1569 cache_paths.push_back(cache_root_path.Append(kGDataCacheTmpDocumentsDir)); 1569 cache_paths.push_back(cache_root_path.Append(kDriveCacheTmpDocumentsDir));
1570 return cache_paths; 1570 return cache_paths;
1571 } 1571 }
1572 1572
1573 // static 1573 // static
1574 bool GDataCache::CreateCacheDirectories( 1574 bool DriveCache::CreateCacheDirectories(
1575 const std::vector<FilePath>& paths_to_create) { 1575 const std::vector<FilePath>& paths_to_create) {
1576 bool success = true; 1576 bool success = true;
1577 1577
1578 for (size_t i = 0; i < paths_to_create.size(); ++i) { 1578 for (size_t i = 0; i < paths_to_create.size(); ++i) {
1579 if (file_util::DirectoryExists(paths_to_create[i])) 1579 if (file_util::DirectoryExists(paths_to_create[i]))
1580 continue; 1580 continue;
1581 1581
1582 if (!file_util::CreateDirectory(paths_to_create[i])) { 1582 if (!file_util::CreateDirectory(paths_to_create[i])) {
1583 // Error creating this directory, record error and proceed with next one. 1583 // Error creating this directory, record error and proceed with next one.
1584 success = false; 1584 success = false;
1585 PLOG(ERROR) << "Error creating directory " << paths_to_create[i].value(); 1585 PLOG(ERROR) << "Error creating directory " << paths_to_create[i].value();
1586 } else { 1586 } else {
1587 DVLOG(1) << "Created directory " << paths_to_create[i].value(); 1587 DVLOG(1) << "Created directory " << paths_to_create[i].value();
1588 } 1588 }
1589 } 1589 }
1590 return success; 1590 return success;
1591 } 1591 }
1592 1592
1593 // static 1593 // static
1594 GDataCache::CacheSubDirectoryType GDataCache::GetSubDirectoryType( 1594 DriveCache::CacheSubDirectoryType DriveCache::GetSubDirectoryType(
1595 const DriveCacheEntry& cache_entry) { 1595 const DriveCacheEntry& cache_entry) {
1596 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; 1596 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP;
1597 } 1597 }
1598 1598
1599 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 1599 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
1600 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 1600 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
1601 global_free_disk_getter_for_testing = getter; 1601 global_free_disk_getter_for_testing = getter;
1602 } 1602 }
1603 1603
1604 } // namespace gdata 1604 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/drive_cache.h ('k') | chrome/browser/chromeos/gdata/drive_cache_metadata.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698