| OLD | NEW |
| 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/drive_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" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 LOG(WARNING) << "Failed to delete " << file_path.value(); | 100 LOG(WARNING) << "Failed to delete " << file_path.value(); |
| 101 } | 101 } |
| 102 } | 102 } |
| 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 DriveFileError ModifyCacheState( |
| 111 const FilePath& source_path, | 111 const FilePath& source_path, |
| 112 const FilePath& dest_path, | 112 const FilePath& dest_path, |
| 113 DriveCache::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 == DriveCache::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 == DriveCache::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 == DriveCache::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 DRIVE_FILE_ERROR_FAILED; |
| 130 } else { | 130 } else { |
| 131 DVLOG(1) << (file_operation_type == DriveCache::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 DRIVE_FILE_OK; |
| 142 | 142 |
| 143 // Remove symlink regardless of |create_symlink| because creating a link will | 143 // Remove symlink regardless of |create_symlink| because creating a link will |
| 144 // not overwrite an existing one. | 144 // not overwrite an existing one. |
| 145 // We try to save one file operation by not checking if link exists before | 145 // We try to save one file operation by not checking if link exists before |
| 146 // deleting it, so unlink may return error if link doesn't exist, but it | 146 // deleting it, so unlink may return error if link doesn't exist, but it |
| 147 // doesn't really matter to us. | 147 // doesn't really matter to us. |
| 148 file_util::Delete(symlink_path, false); | 148 file_util::Delete(symlink_path, false); |
| 149 | 149 |
| 150 if (!create_symlink) | 150 if (!create_symlink) |
| 151 return GDATA_FILE_OK; | 151 return DRIVE_FILE_OK; |
| 152 | 152 |
| 153 // Create new symlink to |dest_path|. | 153 // Create new symlink to |dest_path|. |
| 154 if (!file_util::CreateSymbolicLink(dest_path, symlink_path)) { | 154 if (!file_util::CreateSymbolicLink(dest_path, symlink_path)) { |
| 155 LOG(ERROR) << "Failed to create a symlink from " << symlink_path.value() | 155 LOG(ERROR) << "Failed to create a symlink from " << symlink_path.value() |
| 156 << " to " << dest_path.value(); | 156 << " to " << dest_path.value(); |
| 157 return GDATA_FILE_ERROR_FAILED; | 157 return DRIVE_FILE_ERROR_FAILED; |
| 158 } | 158 } |
| 159 | 159 |
| 160 return GDATA_FILE_OK; | 160 return DRIVE_FILE_OK; |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Deletes all files that match |path_to_delete_pattern| except for | 163 // Deletes all files that match |path_to_delete_pattern| except for |
| 164 // |path_to_keep| on blocking pool. | 164 // |path_to_keep| on blocking pool. |
| 165 // If |path_to_keep| is empty, all files in |path_to_delete_pattern| are | 165 // If |path_to_keep| is empty, all files in |path_to_delete_pattern| are |
| 166 // deleted. | 166 // deleted. |
| 167 void DeleteFilesSelectively(const FilePath& path_to_delete_pattern, | 167 void DeleteFilesSelectively(const FilePath& path_to_delete_pattern, |
| 168 const FilePath& path_to_keep) { | 168 const FilePath& path_to_keep) { |
| 169 // Enumerate all files in directory of |path_to_delete_pattern| that match | 169 // Enumerate all files in directory of |path_to_delete_pattern| that match |
| 170 // base name of |path_to_delete_pattern|. | 170 // base name of |path_to_delete_pattern|. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 const std::string& resource_id, | 222 const std::string& resource_id, |
| 223 const DriveCacheEntry& /* cache_entry */) { | 223 const DriveCacheEntry& /* cache_entry */) { |
| 224 DCHECK(resource_ids); | 224 DCHECK(resource_ids); |
| 225 | 225 |
| 226 resource_ids->push_back(resource_id); | 226 resource_ids->push_back(resource_id); |
| 227 } | 227 } |
| 228 | 228 |
| 229 // Runs callback with pointers dereferenced. | 229 // Runs callback with pointers dereferenced. |
| 230 // Used to implement SetMountedStateOnUIThread and ClearAllOnUIThread. | 230 // Used to implement SetMountedStateOnUIThread and ClearAllOnUIThread. |
| 231 void RunChangeCacheStateCallback(const ChangeCacheStateCallback& callback, | 231 void RunChangeCacheStateCallback(const ChangeCacheStateCallback& callback, |
| 232 const GDataFileError* error, | 232 const DriveFileError* error, |
| 233 const FilePath* cache_file_path) { | 233 const FilePath* cache_file_path) { |
| 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 235 DCHECK(error); | 235 DCHECK(error); |
| 236 DCHECK(cache_file_path); | 236 DCHECK(cache_file_path); |
| 237 | 237 |
| 238 if (!callback.is_null()) | 238 if (!callback.is_null()) |
| 239 callback.Run(*error, *cache_file_path); | 239 callback.Run(*error, *cache_file_path); |
| 240 } | 240 } |
| 241 | 241 |
| 242 // Runs callback with pointers dereferenced. | 242 // Runs callback with pointers dereferenced. |
| 243 // Used to implement *OnUIThread methods. | 243 // Used to implement *OnUIThread methods. |
| 244 void RunCacheOperationCallback(const CacheOperationCallback& callback, | 244 void RunCacheOperationCallback(const CacheOperationCallback& callback, |
| 245 GDataFileError* error, | 245 DriveFileError* error, |
| 246 const std::string& resource_id, | 246 const std::string& resource_id, |
| 247 const std::string& md5) { | 247 const std::string& md5) { |
| 248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 249 DCHECK(error); | 249 DCHECK(error); |
| 250 | 250 |
| 251 if (!callback.is_null()) | 251 if (!callback.is_null()) |
| 252 callback.Run(*error, resource_id, md5); | 252 callback.Run(*error, resource_id, md5); |
| 253 } | 253 } |
| 254 | 254 |
| 255 // Runs callback with pointers dereferenced. | 255 // Runs callback with pointers dereferenced. |
| 256 // Used to implement *OnUIThread methods. | 256 // Used to implement *OnUIThread methods. |
| 257 void RunGetFileFromCacheCallback(const GetFileFromCacheCallback& callback, | 257 void RunGetFileFromCacheCallback(const GetFileFromCacheCallback& callback, |
| 258 GDataFileError* error, | 258 DriveFileError* error, |
| 259 const std::string& resource_id, | 259 const std::string& resource_id, |
| 260 const std::string& md5, | 260 const std::string& md5, |
| 261 FilePath* cache_file_path) { | 261 FilePath* cache_file_path) { |
| 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 263 DCHECK(error); | 263 DCHECK(error); |
| 264 DCHECK(cache_file_path); | 264 DCHECK(cache_file_path); |
| 265 | 265 |
| 266 if (!callback.is_null()) | 266 if (!callback.is_null()) |
| 267 callback.Run(*error, resource_id, md5, *cache_file_path); | 267 callback.Run(*error, resource_id, md5, *cache_file_path); |
| 268 } | 268 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 DriveCache::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 DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); |
| 474 new GDataFileError(GDATA_FILE_OK); | |
| 475 FilePath* cache_file_path = new FilePath; | 474 FilePath* cache_file_path = new FilePath; |
| 476 blocking_task_runner_->PostTaskAndReply( | 475 blocking_task_runner_->PostTaskAndReply( |
| 477 FROM_HERE, | 476 FROM_HERE, |
| 478 base::Bind(&DriveCache::GetFile, | 477 base::Bind(&DriveCache::GetFile, |
| 479 base::Unretained(this), | 478 base::Unretained(this), |
| 480 resource_id, | 479 resource_id, |
| 481 md5, | 480 md5, |
| 482 error, | 481 error, |
| 483 cache_file_path), | 482 cache_file_path), |
| 484 base::Bind(&RunGetFileFromCacheCallback, | 483 base::Bind(&RunGetFileFromCacheCallback, |
| 485 callback, | 484 callback, |
| 486 base::Owned(error), | 485 base::Owned(error), |
| 487 resource_id, | 486 resource_id, |
| 488 md5, | 487 md5, |
| 489 base::Owned(cache_file_path))); | 488 base::Owned(cache_file_path))); |
| 490 } | 489 } |
| 491 | 490 |
| 492 void DriveCache::StoreOnUIThread(const std::string& resource_id, | 491 void DriveCache::StoreOnUIThread(const std::string& resource_id, |
| 493 const std::string& md5, | 492 const std::string& md5, |
| 494 const FilePath& source_path, | 493 const FilePath& source_path, |
| 495 FileOperationType file_operation_type, | 494 FileOperationType file_operation_type, |
| 496 const CacheOperationCallback& callback) { | 495 const CacheOperationCallback& callback) { |
| 497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 496 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 498 | 497 |
| 499 GDataFileError* error = | 498 DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); |
| 500 new GDataFileError(GDATA_FILE_OK); | |
| 501 blocking_task_runner_->PostTaskAndReply( | 499 blocking_task_runner_->PostTaskAndReply( |
| 502 FROM_HERE, | 500 FROM_HERE, |
| 503 base::Bind(&DriveCache::Store, | 501 base::Bind(&DriveCache::Store, |
| 504 base::Unretained(this), | 502 base::Unretained(this), |
| 505 resource_id, | 503 resource_id, |
| 506 md5, | 504 md5, |
| 507 source_path, | 505 source_path, |
| 508 file_operation_type, | 506 file_operation_type, |
| 509 error), | 507 error), |
| 510 base::Bind(&RunCacheOperationCallback, | 508 base::Bind(&RunCacheOperationCallback, |
| 511 callback, | 509 callback, |
| 512 base::Owned(error), | 510 base::Owned(error), |
| 513 resource_id, | 511 resource_id, |
| 514 md5)); | 512 md5)); |
| 515 } | 513 } |
| 516 | 514 |
| 517 void DriveCache::PinOnUIThread(const std::string& resource_id, | 515 void DriveCache::PinOnUIThread(const std::string& resource_id, |
| 518 const std::string& md5, | 516 const std::string& md5, |
| 519 const CacheOperationCallback& callback) { | 517 const CacheOperationCallback& callback) { |
| 520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 521 | 519 |
| 522 GDataFileError* error = | 520 DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); |
| 523 new GDataFileError(GDATA_FILE_OK); | |
| 524 blocking_task_runner_->PostTaskAndReply( | 521 blocking_task_runner_->PostTaskAndReply( |
| 525 FROM_HERE, | 522 FROM_HERE, |
| 526 base::Bind(&DriveCache::Pin, | 523 base::Bind(&DriveCache::Pin, |
| 527 base::Unretained(this), | 524 base::Unretained(this), |
| 528 resource_id, | 525 resource_id, |
| 529 md5, | 526 md5, |
| 530 DriveCache::FILE_OPERATION_MOVE, | 527 DriveCache::FILE_OPERATION_MOVE, |
| 531 error), | 528 error), |
| 532 base::Bind(&DriveCache::OnPinned, | 529 base::Bind(&DriveCache::OnPinned, |
| 533 weak_ptr_factory_.GetWeakPtr(), | 530 weak_ptr_factory_.GetWeakPtr(), |
| 534 base::Owned(error), | 531 base::Owned(error), |
| 535 resource_id, | 532 resource_id, |
| 536 md5, | 533 md5, |
| 537 callback)); | 534 callback)); |
| 538 } | 535 } |
| 539 | 536 |
| 540 void DriveCache::UnpinOnUIThread(const std::string& resource_id, | 537 void DriveCache::UnpinOnUIThread(const std::string& resource_id, |
| 541 const std::string& md5, | 538 const std::string& md5, |
| 542 const CacheOperationCallback& callback) { | 539 const CacheOperationCallback& callback) { |
| 543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 540 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 544 GDataFileError* error = | 541 DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); |
| 545 new GDataFileError(GDATA_FILE_OK); | |
| 546 blocking_task_runner_->PostTaskAndReply( | 542 blocking_task_runner_->PostTaskAndReply( |
| 547 FROM_HERE, | 543 FROM_HERE, |
| 548 base::Bind(&DriveCache::Unpin, | 544 base::Bind(&DriveCache::Unpin, |
| 549 base::Unretained(this), | 545 base::Unretained(this), |
| 550 resource_id, | 546 resource_id, |
| 551 md5, | 547 md5, |
| 552 DriveCache::FILE_OPERATION_MOVE, | 548 DriveCache::FILE_OPERATION_MOVE, |
| 553 error), | 549 error), |
| 554 base::Bind(&DriveCache::OnUnpinned, | 550 base::Bind(&DriveCache::OnUnpinned, |
| 555 weak_ptr_factory_.GetWeakPtr(), | 551 weak_ptr_factory_.GetWeakPtr(), |
| 556 base::Owned(error), | 552 base::Owned(error), |
| 557 resource_id, | 553 resource_id, |
| 558 md5, | 554 md5, |
| 559 callback)); | 555 callback)); |
| 560 } | 556 } |
| 561 | 557 |
| 562 void DriveCache::SetMountedStateOnUIThread( | 558 void DriveCache::SetMountedStateOnUIThread( |
| 563 const FilePath& file_path, | 559 const FilePath& file_path, |
| 564 bool to_mount, | 560 bool to_mount, |
| 565 const ChangeCacheStateCallback& callback) { | 561 const ChangeCacheStateCallback& callback) { |
| 566 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 567 | 563 |
| 568 GDataFileError* error = | 564 DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); |
| 569 new GDataFileError(GDATA_FILE_OK); | |
| 570 FilePath* cache_file_path = new FilePath; | 565 FilePath* cache_file_path = new FilePath; |
| 571 blocking_task_runner_->PostTaskAndReply( | 566 blocking_task_runner_->PostTaskAndReply( |
| 572 FROM_HERE, | 567 FROM_HERE, |
| 573 base::Bind(&DriveCache::SetMountedState, | 568 base::Bind(&DriveCache::SetMountedState, |
| 574 base::Unretained(this), | 569 base::Unretained(this), |
| 575 file_path, | 570 file_path, |
| 576 to_mount, | 571 to_mount, |
| 577 error, | 572 error, |
| 578 cache_file_path), | 573 cache_file_path), |
| 579 base::Bind(&RunChangeCacheStateCallback, | 574 base::Bind(&RunChangeCacheStateCallback, |
| 580 callback, | 575 callback, |
| 581 base::Owned(error), | 576 base::Owned(error), |
| 582 base::Owned(cache_file_path))); | 577 base::Owned(cache_file_path))); |
| 583 } | 578 } |
| 584 | 579 |
| 585 void DriveCache::MarkDirtyOnUIThread(const std::string& resource_id, | 580 void DriveCache::MarkDirtyOnUIThread(const std::string& resource_id, |
| 586 const std::string& md5, | 581 const std::string& md5, |
| 587 const GetFileFromCacheCallback& callback) { | 582 const GetFileFromCacheCallback& callback) { |
| 588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 583 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 589 | 584 |
| 590 GDataFileError* error = | 585 DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); |
| 591 new GDataFileError(GDATA_FILE_OK); | |
| 592 FilePath* cache_file_path = new FilePath; | 586 FilePath* cache_file_path = new FilePath; |
| 593 blocking_task_runner_->PostTaskAndReply( | 587 blocking_task_runner_->PostTaskAndReply( |
| 594 FROM_HERE, | 588 FROM_HERE, |
| 595 base::Bind(&DriveCache::MarkDirty, | 589 base::Bind(&DriveCache::MarkDirty, |
| 596 base::Unretained(this), | 590 base::Unretained(this), |
| 597 resource_id, | 591 resource_id, |
| 598 md5, | 592 md5, |
| 599 DriveCache::FILE_OPERATION_MOVE, | 593 DriveCache::FILE_OPERATION_MOVE, |
| 600 error, | 594 error, |
| 601 cache_file_path), | 595 cache_file_path), |
| 602 base::Bind(&RunGetFileFromCacheCallback, | 596 base::Bind(&RunGetFileFromCacheCallback, |
| 603 callback, | 597 callback, |
| 604 base::Owned(error), | 598 base::Owned(error), |
| 605 resource_id, | 599 resource_id, |
| 606 md5, | 600 md5, |
| 607 base::Owned(cache_file_path))); | 601 base::Owned(cache_file_path))); |
| 608 } | 602 } |
| 609 | 603 |
| 610 void DriveCache::CommitDirtyOnUIThread(const std::string& resource_id, | 604 void DriveCache::CommitDirtyOnUIThread(const std::string& resource_id, |
| 611 const std::string& md5, | 605 const std::string& md5, |
| 612 const CacheOperationCallback& callback) { | 606 const CacheOperationCallback& callback) { |
| 613 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 607 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 614 | 608 |
| 615 GDataFileError* error = new GDataFileError(GDATA_FILE_OK); | 609 DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); |
| 616 blocking_task_runner_->PostTaskAndReply( | 610 blocking_task_runner_->PostTaskAndReply( |
| 617 FROM_HERE, | 611 FROM_HERE, |
| 618 base::Bind(&DriveCache::CommitDirty, | 612 base::Bind(&DriveCache::CommitDirty, |
| 619 base::Unretained(this), | 613 base::Unretained(this), |
| 620 resource_id, | 614 resource_id, |
| 621 md5, | 615 md5, |
| 622 DriveCache::FILE_OPERATION_MOVE, | 616 DriveCache::FILE_OPERATION_MOVE, |
| 623 error), | 617 error), |
| 624 base::Bind(&DriveCache::OnCommitDirty, | 618 base::Bind(&DriveCache::OnCommitDirty, |
| 625 weak_ptr_factory_.GetWeakPtr(), | 619 weak_ptr_factory_.GetWeakPtr(), |
| 626 base::Owned(error), | 620 base::Owned(error), |
| 627 resource_id, | 621 resource_id, |
| 628 md5, | 622 md5, |
| 629 callback)); | 623 callback)); |
| 630 } | 624 } |
| 631 | 625 |
| 632 void DriveCache::ClearDirtyOnUIThread(const std::string& resource_id, | 626 void DriveCache::ClearDirtyOnUIThread(const std::string& resource_id, |
| 633 const std::string& md5, | 627 const std::string& md5, |
| 634 const CacheOperationCallback& callback) { | 628 const CacheOperationCallback& callback) { |
| 635 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 629 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 636 | 630 |
| 637 GDataFileError* error = | 631 DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); |
| 638 new GDataFileError(GDATA_FILE_OK); | |
| 639 blocking_task_runner_->PostTaskAndReply( | 632 blocking_task_runner_->PostTaskAndReply( |
| 640 FROM_HERE, | 633 FROM_HERE, |
| 641 base::Bind(&DriveCache::ClearDirty, | 634 base::Bind(&DriveCache::ClearDirty, |
| 642 base::Unretained(this), | 635 base::Unretained(this), |
| 643 resource_id, | 636 resource_id, |
| 644 md5, | 637 md5, |
| 645 DriveCache::FILE_OPERATION_MOVE, | 638 DriveCache::FILE_OPERATION_MOVE, |
| 646 error), | 639 error), |
| 647 base::Bind(&RunCacheOperationCallback, | 640 base::Bind(&RunCacheOperationCallback, |
| 648 callback, | 641 callback, |
| 649 base::Owned(error), | 642 base::Owned(error), |
| 650 resource_id, | 643 resource_id, |
| 651 md5)); | 644 md5)); |
| 652 } | 645 } |
| 653 | 646 |
| 654 void DriveCache::RemoveOnUIThread(const std::string& resource_id, | 647 void DriveCache::RemoveOnUIThread(const std::string& resource_id, |
| 655 const CacheOperationCallback& callback) { | 648 const CacheOperationCallback& callback) { |
| 656 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 649 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 657 | 650 |
| 658 GDataFileError* error = | 651 DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); |
| 659 new GDataFileError(GDATA_FILE_OK); | |
| 660 | |
| 661 blocking_task_runner_->PostTaskAndReply( | 652 blocking_task_runner_->PostTaskAndReply( |
| 662 FROM_HERE, | 653 FROM_HERE, |
| 663 base::Bind(&DriveCache::Remove, | 654 base::Bind(&DriveCache::Remove, |
| 664 base::Unretained(this), | 655 base::Unretained(this), |
| 665 resource_id, | 656 resource_id, |
| 666 error), | 657 error), |
| 667 base::Bind(&RunCacheOperationCallback, | 658 base::Bind(&RunCacheOperationCallback, |
| 668 callback, | 659 callback, |
| 669 base::Owned(error), | 660 base::Owned(error), |
| 670 resource_id, | 661 resource_id, |
| 671 "" /* md5 */)); | 662 "" /* md5 */)); |
| 672 } | 663 } |
| 673 | 664 |
| 674 void DriveCache::ClearAllOnUIThread(const ChangeCacheStateCallback& callback) { | 665 void DriveCache::ClearAllOnUIThread(const ChangeCacheStateCallback& callback) { |
| 675 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 666 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 676 | 667 |
| 677 GDataFileError* error = new GDataFileError(GDATA_FILE_OK); | 668 DriveFileError* error = new DriveFileError(DRIVE_FILE_OK); |
| 678 | |
| 679 blocking_task_runner_->PostTaskAndReply( | 669 blocking_task_runner_->PostTaskAndReply( |
| 680 FROM_HERE, | 670 FROM_HERE, |
| 681 base::Bind(&DriveCache::ClearAll, | 671 base::Bind(&DriveCache::ClearAll, |
| 682 base::Unretained(this), | 672 base::Unretained(this), |
| 683 error), | 673 error), |
| 684 base::Bind(&RunChangeCacheStateCallback, | 674 base::Bind(&RunChangeCacheStateCallback, |
| 685 callback, | 675 callback, |
| 686 base::Owned(error), | 676 base::Owned(error), |
| 687 &cache_root_path_)); | 677 &cache_root_path_)); |
| 688 } | 678 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 void DriveCache::GetResourceIdsOfAllFiles( | 779 void DriveCache::GetResourceIdsOfAllFiles( |
| 790 std::vector<std::string>* resource_ids) { | 780 std::vector<std::string>* resource_ids) { |
| 791 AssertOnSequencedWorkerPool(); | 781 AssertOnSequencedWorkerPool(); |
| 792 DCHECK(resource_ids); | 782 DCHECK(resource_ids); |
| 793 | 783 |
| 794 metadata_->Iterate(base::Bind(&CollectAnyFile, resource_ids)); | 784 metadata_->Iterate(base::Bind(&CollectAnyFile, resource_ids)); |
| 795 } | 785 } |
| 796 | 786 |
| 797 void DriveCache::GetFile(const std::string& resource_id, | 787 void DriveCache::GetFile(const std::string& resource_id, |
| 798 const std::string& md5, | 788 const std::string& md5, |
| 799 GDataFileError* error, | 789 DriveFileError* error, |
| 800 FilePath* cache_file_path) { | 790 FilePath* cache_file_path) { |
| 801 AssertOnSequencedWorkerPool(); | 791 AssertOnSequencedWorkerPool(); |
| 802 DCHECK(error); | 792 DCHECK(error); |
| 803 DCHECK(cache_file_path); | 793 DCHECK(cache_file_path); |
| 804 | 794 |
| 805 DriveCacheEntry cache_entry; | 795 DriveCacheEntry cache_entry; |
| 806 if (GetCacheEntry(resource_id, md5, &cache_entry) && | 796 if (GetCacheEntry(resource_id, md5, &cache_entry) && |
| 807 cache_entry.is_present()) { | 797 cache_entry.is_present()) { |
| 808 CachedFileOrigin file_origin; | 798 CachedFileOrigin file_origin; |
| 809 if (cache_entry.is_mounted()) { | 799 if (cache_entry.is_mounted()) { |
| 810 file_origin = CACHED_FILE_MOUNTED; | 800 file_origin = CACHED_FILE_MOUNTED; |
| 811 } else if (cache_entry.is_dirty()) { | 801 } else if (cache_entry.is_dirty()) { |
| 812 file_origin = CACHED_FILE_LOCALLY_MODIFIED; | 802 file_origin = CACHED_FILE_LOCALLY_MODIFIED; |
| 813 } else { | 803 } else { |
| 814 file_origin = CACHED_FILE_FROM_SERVER; | 804 file_origin = CACHED_FILE_FROM_SERVER; |
| 815 } | 805 } |
| 816 *cache_file_path = GetCacheFilePath( | 806 *cache_file_path = GetCacheFilePath( |
| 817 resource_id, | 807 resource_id, |
| 818 md5, | 808 md5, |
| 819 GetSubDirectoryType(cache_entry), | 809 GetSubDirectoryType(cache_entry), |
| 820 file_origin); | 810 file_origin); |
| 821 *error = GDATA_FILE_OK; | 811 *error = DRIVE_FILE_OK; |
| 822 } else { | 812 } else { |
| 823 *error = GDATA_FILE_ERROR_NOT_FOUND; | 813 *error = DRIVE_FILE_ERROR_NOT_FOUND; |
| 824 } | 814 } |
| 825 } | 815 } |
| 826 | 816 |
| 827 void DriveCache::Store(const std::string& resource_id, | 817 void DriveCache::Store(const std::string& resource_id, |
| 828 const std::string& md5, | 818 const std::string& md5, |
| 829 const FilePath& source_path, | 819 const FilePath& source_path, |
| 830 FileOperationType file_operation_type, | 820 FileOperationType file_operation_type, |
| 831 GDataFileError* error) { | 821 DriveFileError* error) { |
| 832 AssertOnSequencedWorkerPool(); | 822 AssertOnSequencedWorkerPool(); |
| 833 DCHECK(error); | 823 DCHECK(error); |
| 834 | 824 |
| 835 if (file_operation_type == FILE_OPERATION_COPY) { | 825 if (file_operation_type == FILE_OPERATION_COPY) { |
| 836 int64 file_size; | 826 int64 file_size; |
| 837 if (!file_util::GetFileSize(source_path, &file_size)) { | 827 if (!file_util::GetFileSize(source_path, &file_size)) { |
| 838 LOG(WARNING) << "Couldn't get file size for: " << source_path.value(); | 828 LOG(WARNING) << "Couldn't get file size for: " << source_path.value(); |
| 839 *error = GDATA_FILE_ERROR_FAILED; | 829 *error = DRIVE_FILE_ERROR_FAILED; |
| 840 return; | 830 return; |
| 841 } | 831 } |
| 842 | 832 |
| 843 bool enough_space = false; | 833 bool enough_space = false; |
| 844 FreeDiskSpaceIfNeededFor(file_size, &enough_space); | 834 FreeDiskSpaceIfNeededFor(file_size, &enough_space); |
| 845 if (!enough_space) { | 835 if (!enough_space) { |
| 846 *error = GDATA_FILE_ERROR_NO_SPACE; | 836 *error = DRIVE_FILE_ERROR_NO_SPACE; |
| 847 return; | 837 return; |
| 848 } | 838 } |
| 849 } | 839 } |
| 850 | 840 |
| 851 FilePath dest_path; | 841 FilePath dest_path; |
| 852 FilePath symlink_path; | 842 FilePath symlink_path; |
| 853 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; | 843 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; |
| 854 | 844 |
| 855 // If file was previously pinned, store it in persistent dir and create | 845 // If file was previously pinned, store it in persistent dir and create |
| 856 // symlink in pinned dir. | 846 // symlink in pinned dir. |
| 857 DriveCacheEntry cache_entry; | 847 DriveCacheEntry cache_entry; |
| 858 if (GetCacheEntry(resource_id, md5, &cache_entry)) { // File exists in cache. | 848 if (GetCacheEntry(resource_id, md5, &cache_entry)) { // File exists in cache. |
| 859 // If file is dirty or mounted, return error. | 849 // If file is dirty or mounted, return error. |
| 860 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { | 850 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { |
| 861 LOG(WARNING) << "Can't store a file to replace a " | 851 LOG(WARNING) << "Can't store a file to replace a " |
| 862 << (cache_entry.is_dirty() ? "dirty" : "mounted") | 852 << (cache_entry.is_dirty() ? "dirty" : "mounted") |
| 863 << " file: res_id=" << resource_id | 853 << " file: res_id=" << resource_id |
| 864 << ", md5=" << md5; | 854 << ", md5=" << md5; |
| 865 *error = GDATA_FILE_ERROR_IN_USE; | 855 *error = DRIVE_FILE_ERROR_IN_USE; |
| 866 return; | 856 return; |
| 867 } | 857 } |
| 868 | 858 |
| 869 // If file is pinned, determines destination path. | 859 // If file is pinned, determines destination path. |
| 870 if (cache_entry.is_pinned()) { | 860 if (cache_entry.is_pinned()) { |
| 871 sub_dir_type = CACHE_TYPE_PERSISTENT; | 861 sub_dir_type = CACHE_TYPE_PERSISTENT; |
| 872 dest_path = GetCacheFilePath(resource_id, md5, sub_dir_type, | 862 dest_path = GetCacheFilePath(resource_id, md5, sub_dir_type, |
| 873 CACHED_FILE_FROM_SERVER); | 863 CACHED_FILE_FROM_SERVER); |
| 874 symlink_path = GetCacheFilePath( | 864 symlink_path = GetCacheFilePath( |
| 875 resource_id, std::string(), CACHE_TYPE_PINNED, | 865 resource_id, std::string(), CACHE_TYPE_PINNED, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 905 } else { | 895 } else { |
| 906 // Replace md5 extension with '*' i.e. "<resource_id>.*". | 896 // Replace md5 extension with '*' i.e. "<resource_id>.*". |
| 907 // Note that ReplaceExtension automatically prefixes the extension with the | 897 // Note that ReplaceExtension automatically prefixes the extension with the |
| 908 // extension separator '.'. | 898 // extension separator '.'. |
| 909 stale_filenames_pattern = dest_path.ReplaceExtension(util::kWildCard); | 899 stale_filenames_pattern = dest_path.ReplaceExtension(util::kWildCard); |
| 910 } | 900 } |
| 911 | 901 |
| 912 // Delete files that match |stale_filenames_pattern| except for |dest_path|. | 902 // Delete files that match |stale_filenames_pattern| except for |dest_path|. |
| 913 DeleteFilesSelectively(stale_filenames_pattern, dest_path); | 903 DeleteFilesSelectively(stale_filenames_pattern, dest_path); |
| 914 | 904 |
| 915 if (*error == GDATA_FILE_OK) { | 905 if (*error == DRIVE_FILE_OK) { |
| 916 // Now that file operations have completed, update cache map. | 906 // Now that file operations have completed, update cache map. |
| 917 cache_entry.set_md5(md5); | 907 cache_entry.set_md5(md5); |
| 918 cache_entry.set_is_present(true); | 908 cache_entry.set_is_present(true); |
| 919 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); | 909 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); |
| 920 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); | 910 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); |
| 921 } | 911 } |
| 922 } | 912 } |
| 923 | 913 |
| 924 void DriveCache::Pin(const std::string& resource_id, | 914 void DriveCache::Pin(const std::string& resource_id, |
| 925 const std::string& md5, | 915 const std::string& md5, |
| 926 FileOperationType file_operation_type, | 916 FileOperationType file_operation_type, |
| 927 GDataFileError* error) { | 917 DriveFileError* error) { |
| 928 AssertOnSequencedWorkerPool(); | 918 AssertOnSequencedWorkerPool(); |
| 929 DCHECK(error); | 919 DCHECK(error); |
| 930 | 920 |
| 931 FilePath source_path; | 921 FilePath source_path; |
| 932 FilePath dest_path; | 922 FilePath dest_path; |
| 933 FilePath symlink_path; | 923 FilePath symlink_path; |
| 934 bool create_symlink = true; | 924 bool create_symlink = true; |
| 935 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; | 925 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; |
| 936 | 926 |
| 937 DriveCacheEntry cache_entry; | 927 DriveCacheEntry cache_entry; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 CACHE_TYPE_PINNED, | 982 CACHE_TYPE_PINNED, |
| 993 CACHED_FILE_FROM_SERVER); | 983 CACHED_FILE_FROM_SERVER); |
| 994 } | 984 } |
| 995 | 985 |
| 996 *error = ModifyCacheState(source_path, | 986 *error = ModifyCacheState(source_path, |
| 997 dest_path, | 987 dest_path, |
| 998 file_operation_type, | 988 file_operation_type, |
| 999 symlink_path, | 989 symlink_path, |
| 1000 create_symlink); | 990 create_symlink); |
| 1001 | 991 |
| 1002 if (*error == GDATA_FILE_OK) { | 992 if (*error == DRIVE_FILE_OK) { |
| 1003 // Now that file operations have completed, update cache map. | 993 // Now that file operations have completed, update cache map. |
| 1004 cache_entry.set_md5(md5); | 994 cache_entry.set_md5(md5); |
| 1005 cache_entry.set_is_pinned(true); | 995 cache_entry.set_is_pinned(true); |
| 1006 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); | 996 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); |
| 1007 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); | 997 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); |
| 1008 } | 998 } |
| 1009 } | 999 } |
| 1010 | 1000 |
| 1011 void DriveCache::Unpin(const std::string& resource_id, | 1001 void DriveCache::Unpin(const std::string& resource_id, |
| 1012 const std::string& md5, | 1002 const std::string& md5, |
| 1013 FileOperationType file_operation_type, | 1003 FileOperationType file_operation_type, |
| 1014 GDataFileError* error) { | 1004 DriveFileError* error) { |
| 1015 AssertOnSequencedWorkerPool(); | 1005 AssertOnSequencedWorkerPool(); |
| 1016 DCHECK(error); | 1006 DCHECK(error); |
| 1017 | 1007 |
| 1018 // Unpinning a file means its entry must exist in cache. | 1008 // Unpinning a file means its entry must exist in cache. |
| 1019 DriveCacheEntry cache_entry; | 1009 DriveCacheEntry cache_entry; |
| 1020 if (!GetCacheEntry(resource_id, md5, &cache_entry)) { | 1010 if (!GetCacheEntry(resource_id, md5, &cache_entry)) { |
| 1021 LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id=" | 1011 LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id=" |
| 1022 << resource_id | 1012 << resource_id |
| 1023 << ", md5=" << md5; | 1013 << ", md5=" << md5; |
| 1024 *error = GDATA_FILE_ERROR_NOT_FOUND; | 1014 *error = DRIVE_FILE_ERROR_NOT_FOUND; |
| 1025 return; | 1015 return; |
| 1026 } | 1016 } |
| 1027 | 1017 |
| 1028 // Entry exists in cache, determines source and destination paths. | 1018 // Entry exists in cache, determines source and destination paths. |
| 1029 | 1019 |
| 1030 FilePath source_path; | 1020 FilePath source_path; |
| 1031 FilePath dest_path; | 1021 FilePath dest_path; |
| 1032 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; | 1022 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; |
| 1033 | 1023 |
| 1034 // If file is dirty or mounted, don't move it, so determine |dest_path| and | 1024 // If file is dirty or mounted, don't move it, so determine |dest_path| and |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 CACHED_FILE_FROM_SERVER); | 1062 CACHED_FILE_FROM_SERVER); |
| 1073 } | 1063 } |
| 1074 | 1064 |
| 1075 *error = ModifyCacheState( | 1065 *error = ModifyCacheState( |
| 1076 source_path, | 1066 source_path, |
| 1077 dest_path, | 1067 dest_path, |
| 1078 file_operation_type, | 1068 file_operation_type, |
| 1079 symlink_path, // This will be deleted if it exists. | 1069 symlink_path, // This will be deleted if it exists. |
| 1080 false /* don't create symlink*/); | 1070 false /* don't create symlink*/); |
| 1081 | 1071 |
| 1082 if (*error == GDATA_FILE_OK) { | 1072 if (*error == DRIVE_FILE_OK) { |
| 1083 // Now that file operations have completed, update cache map. | 1073 // Now that file operations have completed, update cache map. |
| 1084 if (cache_entry.is_present()) { | 1074 if (cache_entry.is_present()) { |
| 1085 cache_entry.set_md5(md5); | 1075 cache_entry.set_md5(md5); |
| 1086 cache_entry.set_is_pinned(false); | 1076 cache_entry.set_is_pinned(false); |
| 1087 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); | 1077 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); |
| 1088 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); | 1078 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); |
| 1089 } else { | 1079 } else { |
| 1090 // Remove the existing entry if we are unpinning a non-present file. | 1080 // Remove the existing entry if we are unpinning a non-present file. |
| 1091 metadata_->RemoveCacheEntry(resource_id); | 1081 metadata_->RemoveCacheEntry(resource_id); |
| 1092 } | 1082 } |
| 1093 } | 1083 } |
| 1094 } | 1084 } |
| 1095 | 1085 |
| 1096 void DriveCache::SetMountedState(const FilePath& file_path, | 1086 void DriveCache::SetMountedState(const FilePath& file_path, |
| 1097 bool to_mount, | 1087 bool to_mount, |
| 1098 GDataFileError *error, | 1088 DriveFileError *error, |
| 1099 FilePath* cache_file_path) { | 1089 FilePath* cache_file_path) { |
| 1100 AssertOnSequencedWorkerPool(); | 1090 AssertOnSequencedWorkerPool(); |
| 1101 DCHECK(error); | 1091 DCHECK(error); |
| 1102 DCHECK(cache_file_path); | 1092 DCHECK(cache_file_path); |
| 1103 | 1093 |
| 1104 // Parse file path to obtain resource_id, md5 and extra_extension. | 1094 // Parse file path to obtain resource_id, md5 and extra_extension. |
| 1105 std::string resource_id; | 1095 std::string resource_id; |
| 1106 std::string md5; | 1096 std::string md5; |
| 1107 std::string extra_extension; | 1097 std::string extra_extension; |
| 1108 util::ParseCacheFilePath(file_path, &resource_id, &md5, &extra_extension); | 1098 util::ParseCacheFilePath(file_path, &resource_id, &md5, &extra_extension); |
| 1109 // The extra_extension shall be ".mounted" iff we're unmounting. | 1099 // The extra_extension shall be ".mounted" iff we're unmounting. |
| 1110 DCHECK(!to_mount == (extra_extension == util::kMountedArchiveFileExtension)); | 1100 DCHECK(!to_mount == (extra_extension == util::kMountedArchiveFileExtension)); |
| 1111 | 1101 |
| 1112 // Get cache entry associated with the resource_id and md5 | 1102 // Get cache entry associated with the resource_id and md5 |
| 1113 DriveCacheEntry cache_entry; | 1103 DriveCacheEntry cache_entry; |
| 1114 if (!GetCacheEntry(resource_id, md5, &cache_entry)) { | 1104 if (!GetCacheEntry(resource_id, md5, &cache_entry)) { |
| 1115 *error = GDATA_FILE_ERROR_NOT_FOUND; | 1105 *error = DRIVE_FILE_ERROR_NOT_FOUND; |
| 1116 return; | 1106 return; |
| 1117 } | 1107 } |
| 1118 if (to_mount == cache_entry.is_mounted()) { | 1108 if (to_mount == cache_entry.is_mounted()) { |
| 1119 *error = GDATA_FILE_ERROR_INVALID_OPERATION; | 1109 *error = DRIVE_FILE_ERROR_INVALID_OPERATION; |
| 1120 return; | 1110 return; |
| 1121 } | 1111 } |
| 1122 | 1112 |
| 1123 // Get the subdir type and path for the unmounted state. | 1113 // Get the subdir type and path for the unmounted state. |
| 1124 CacheSubDirectoryType unmounted_subdir = | 1114 CacheSubDirectoryType unmounted_subdir = |
| 1125 cache_entry.is_pinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1115 cache_entry.is_pinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
| 1126 FilePath unmounted_path = GetCacheFilePath( | 1116 FilePath unmounted_path = GetCacheFilePath( |
| 1127 resource_id, md5, unmounted_subdir, CACHED_FILE_FROM_SERVER); | 1117 resource_id, md5, unmounted_subdir, CACHED_FILE_FROM_SERVER); |
| 1128 | 1118 |
| 1129 // Get the subdir type and path for the mounted state. | 1119 // Get the subdir type and path for the mounted state. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1142 } else { | 1132 } else { |
| 1143 source_path = mounted_path; | 1133 source_path = mounted_path; |
| 1144 *cache_file_path = unmounted_path; | 1134 *cache_file_path = unmounted_path; |
| 1145 dest_subdir = unmounted_subdir; | 1135 dest_subdir = unmounted_subdir; |
| 1146 cache_entry.set_is_mounted(false); | 1136 cache_entry.set_is_mounted(false); |
| 1147 } | 1137 } |
| 1148 | 1138 |
| 1149 // Move cache blob from source path to destination path. | 1139 // Move cache blob from source path to destination path. |
| 1150 *error = ModifyCacheState(source_path, *cache_file_path, | 1140 *error = ModifyCacheState(source_path, *cache_file_path, |
| 1151 FILE_OPERATION_MOVE, FilePath(), false); | 1141 FILE_OPERATION_MOVE, FilePath(), false); |
| 1152 if (*error == GDATA_FILE_OK) { | 1142 if (*error == DRIVE_FILE_OK) { |
| 1153 // Now that cache operation is complete, update cache map | 1143 // Now that cache operation is complete, update cache map |
| 1154 cache_entry.set_md5(md5); | 1144 cache_entry.set_md5(md5); |
| 1155 cache_entry.set_is_persistent(dest_subdir == CACHE_TYPE_PERSISTENT); | 1145 cache_entry.set_is_persistent(dest_subdir == CACHE_TYPE_PERSISTENT); |
| 1156 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); | 1146 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); |
| 1157 } | 1147 } |
| 1158 } | 1148 } |
| 1159 | 1149 |
| 1160 void DriveCache::MarkDirty(const std::string& resource_id, | 1150 void DriveCache::MarkDirty(const std::string& resource_id, |
| 1161 const std::string& md5, | 1151 const std::string& md5, |
| 1162 FileOperationType file_operation_type, | 1152 FileOperationType file_operation_type, |
| 1163 GDataFileError* error, | 1153 DriveFileError* error, |
| 1164 FilePath* cache_file_path) { | 1154 FilePath* cache_file_path) { |
| 1165 AssertOnSequencedWorkerPool(); | 1155 AssertOnSequencedWorkerPool(); |
| 1166 DCHECK(error); | 1156 DCHECK(error); |
| 1167 DCHECK(cache_file_path); | 1157 DCHECK(cache_file_path); |
| 1168 | 1158 |
| 1169 // If file has already been marked dirty in previous instance of chrome, we | 1159 // 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 | 1160 // would have lost the md5 info during cache initialization, because the file |
| 1171 // would have been renamed to .local extension. | 1161 // would have been renamed to .local extension. |
| 1172 // So, search for entry in cache without comparing md5. | 1162 // So, search for entry in cache without comparing md5. |
| 1173 | 1163 |
| 1174 // Marking a file dirty means its entry and actual file blob must exist in | 1164 // Marking a file dirty means its entry and actual file blob must exist in |
| 1175 // cache. | 1165 // cache. |
| 1176 DriveCacheEntry cache_entry; | 1166 DriveCacheEntry cache_entry; |
| 1177 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || | 1167 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || |
| 1178 !cache_entry.is_present()) { | 1168 !cache_entry.is_present()) { |
| 1179 LOG(WARNING) << "Can't mark dirty a file that wasn't cached: res_id=" | 1169 LOG(WARNING) << "Can't mark dirty a file that wasn't cached: res_id=" |
| 1180 << resource_id | 1170 << resource_id |
| 1181 << ", md5=" << md5; | 1171 << ", md5=" << md5; |
| 1182 *error = GDATA_FILE_ERROR_NOT_FOUND; | 1172 *error = DRIVE_FILE_ERROR_NOT_FOUND; |
| 1183 return; | 1173 return; |
| 1184 } | 1174 } |
| 1185 | 1175 |
| 1186 // If a file is already dirty (i.e. MarkDirtyInCache was called before), | 1176 // If a file is already dirty (i.e. MarkDirtyInCache was called before), |
| 1187 // delete outgoing symlink if it exists. | 1177 // delete outgoing symlink if it exists. |
| 1188 // TODO(benchan): We should only delete outgoing symlink if file is currently | 1178 // TODO(benchan): We should only delete outgoing symlink if file is currently |
| 1189 // not being uploaded. However, for now, cache doesn't know if uploading of a | 1179 // not being uploaded. However, for now, cache doesn't know if uploading of a |
| 1190 // file is in progress. Per zel, the upload process should be canceled before | 1180 // file is in progress. Per zel, the upload process should be canceled before |
| 1191 // MarkDirtyInCache is called again. | 1181 // MarkDirtyInCache is called again. |
| 1192 if (cache_entry.is_dirty()) { | 1182 if (cache_entry.is_dirty()) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1204 // |source_path| and |dest_path| because ModifyCacheState only move files | 1194 // |source_path| and |dest_path| because ModifyCacheState only move files |
| 1205 // if source and destination are different. | 1195 // if source and destination are different. |
| 1206 *error = ModifyCacheState( | 1196 *error = ModifyCacheState( |
| 1207 FilePath(), // non-applicable source path | 1197 FilePath(), // non-applicable source path |
| 1208 FilePath(), // non-applicable dest path | 1198 FilePath(), // non-applicable dest path |
| 1209 file_operation_type, | 1199 file_operation_type, |
| 1210 symlink_path, | 1200 symlink_path, |
| 1211 false /* don't create symlink */); | 1201 false /* don't create symlink */); |
| 1212 | 1202 |
| 1213 // Determine current path of dirty file. | 1203 // Determine current path of dirty file. |
| 1214 if (*error == GDATA_FILE_OK) { | 1204 if (*error == DRIVE_FILE_OK) { |
| 1215 *cache_file_path = GetCacheFilePath( | 1205 *cache_file_path = GetCacheFilePath( |
| 1216 resource_id, | 1206 resource_id, |
| 1217 md5, | 1207 md5, |
| 1218 CACHE_TYPE_PERSISTENT, | 1208 CACHE_TYPE_PERSISTENT, |
| 1219 CACHED_FILE_LOCALLY_MODIFIED); | 1209 CACHED_FILE_LOCALLY_MODIFIED); |
| 1220 } | 1210 } |
| 1221 return; | 1211 return; |
| 1222 } | 1212 } |
| 1223 | 1213 |
| 1224 // Move file to persistent dir with new .local extension. | 1214 // Move file to persistent dir with new .local extension. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1246 CACHED_FILE_FROM_SERVER); | 1236 CACHED_FILE_FROM_SERVER); |
| 1247 } | 1237 } |
| 1248 | 1238 |
| 1249 *error = ModifyCacheState( | 1239 *error = ModifyCacheState( |
| 1250 source_path, | 1240 source_path, |
| 1251 *cache_file_path, | 1241 *cache_file_path, |
| 1252 file_operation_type, | 1242 file_operation_type, |
| 1253 symlink_path, | 1243 symlink_path, |
| 1254 !symlink_path.empty() /* create symlink */); | 1244 !symlink_path.empty() /* create symlink */); |
| 1255 | 1245 |
| 1256 if (*error == GDATA_FILE_OK) { | 1246 if (*error == DRIVE_FILE_OK) { |
| 1257 // Now that file operations have completed, update cache map. | 1247 // Now that file operations have completed, update cache map. |
| 1258 cache_entry.set_md5(md5); | 1248 cache_entry.set_md5(md5); |
| 1259 cache_entry.set_is_dirty(true); | 1249 cache_entry.set_is_dirty(true); |
| 1260 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); | 1250 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); |
| 1261 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); | 1251 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); |
| 1262 } | 1252 } |
| 1263 } | 1253 } |
| 1264 | 1254 |
| 1265 void DriveCache::CommitDirty(const std::string& resource_id, | 1255 void DriveCache::CommitDirty(const std::string& resource_id, |
| 1266 const std::string& md5, | 1256 const std::string& md5, |
| 1267 FileOperationType file_operation_type, | 1257 FileOperationType file_operation_type, |
| 1268 GDataFileError* error) { | 1258 DriveFileError* error) { |
| 1269 AssertOnSequencedWorkerPool(); | 1259 AssertOnSequencedWorkerPool(); |
| 1270 DCHECK(error); | 1260 DCHECK(error); |
| 1271 | 1261 |
| 1272 // If file has already been marked dirty in previous instance of chrome, we | 1262 // 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 | 1263 // would have lost the md5 info during cache initialization, because the file |
| 1274 // would have been renamed to .local extension. | 1264 // would have been renamed to .local extension. |
| 1275 // So, search for entry in cache without comparing md5. | 1265 // So, search for entry in cache without comparing md5. |
| 1276 | 1266 |
| 1277 // Committing a file dirty means its entry and actual file blob must exist in | 1267 // Committing a file dirty means its entry and actual file blob must exist in |
| 1278 // cache. | 1268 // cache. |
| 1279 DriveCacheEntry cache_entry; | 1269 DriveCacheEntry cache_entry; |
| 1280 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || | 1270 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || |
| 1281 !cache_entry.is_present()) { | 1271 !cache_entry.is_present()) { |
| 1282 LOG(WARNING) << "Can't commit dirty a file that wasn't cached: res_id=" | 1272 LOG(WARNING) << "Can't commit dirty a file that wasn't cached: res_id=" |
| 1283 << resource_id | 1273 << resource_id |
| 1284 << ", md5=" << md5; | 1274 << ", md5=" << md5; |
| 1285 *error = GDATA_FILE_ERROR_NOT_FOUND; | 1275 *error = DRIVE_FILE_ERROR_NOT_FOUND; |
| 1286 return; | 1276 return; |
| 1287 } | 1277 } |
| 1288 | 1278 |
| 1289 // If a file is not dirty (it should have been marked dirty via | 1279 // If a file is not dirty (it should have been marked dirty via |
| 1290 // MarkDirtyInCache), committing it dirty is an invalid operation. | 1280 // MarkDirtyInCache), committing it dirty is an invalid operation. |
| 1291 if (!cache_entry.is_dirty()) { | 1281 if (!cache_entry.is_dirty()) { |
| 1292 LOG(WARNING) << "Can't commit a non-dirty file: res_id=" | 1282 LOG(WARNING) << "Can't commit a non-dirty file: res_id=" |
| 1293 << resource_id | 1283 << resource_id |
| 1294 << ", md5=" << md5; | 1284 << ", md5=" << md5; |
| 1295 *error = GDATA_FILE_ERROR_INVALID_OPERATION; | 1285 *error = DRIVE_FILE_ERROR_INVALID_OPERATION; |
| 1296 return; | 1286 return; |
| 1297 } | 1287 } |
| 1298 | 1288 |
| 1299 // Dirty files must be in persistent dir. | 1289 // Dirty files must be in persistent dir. |
| 1300 DCHECK(cache_entry.is_persistent()); | 1290 DCHECK(cache_entry.is_persistent()); |
| 1301 | 1291 |
| 1302 // Create symlink in outgoing dir. | 1292 // Create symlink in outgoing dir. |
| 1303 FilePath symlink_path = GetCacheFilePath(resource_id, | 1293 FilePath symlink_path = GetCacheFilePath(resource_id, |
| 1304 std::string(), | 1294 std::string(), |
| 1305 CACHE_TYPE_OUTGOING, | 1295 CACHE_TYPE_OUTGOING, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1317 *error = ModifyCacheState(target_path, // source | 1307 *error = ModifyCacheState(target_path, // source |
| 1318 target_path, // destination | 1308 target_path, // destination |
| 1319 file_operation_type, | 1309 file_operation_type, |
| 1320 symlink_path, | 1310 symlink_path, |
| 1321 true /* create symlink */); | 1311 true /* create symlink */); |
| 1322 } | 1312 } |
| 1323 | 1313 |
| 1324 void DriveCache::ClearDirty(const std::string& resource_id, | 1314 void DriveCache::ClearDirty(const std::string& resource_id, |
| 1325 const std::string& md5, | 1315 const std::string& md5, |
| 1326 FileOperationType file_operation_type, | 1316 FileOperationType file_operation_type, |
| 1327 GDataFileError* error) { | 1317 DriveFileError* error) { |
| 1328 AssertOnSequencedWorkerPool(); | 1318 AssertOnSequencedWorkerPool(); |
| 1329 DCHECK(error); | 1319 DCHECK(error); |
| 1330 | 1320 |
| 1331 // |md5| is the new .<md5> extension to rename the file to. | 1321 // |md5| is the new .<md5> extension to rename the file to. |
| 1332 // So, search for entry in cache without comparing md5. | 1322 // So, search for entry in cache without comparing md5. |
| 1333 DriveCacheEntry cache_entry; | 1323 DriveCacheEntry cache_entry; |
| 1334 | 1324 |
| 1335 // Clearing a dirty file means its entry and actual file blob must exist in | 1325 // Clearing a dirty file means its entry and actual file blob must exist in |
| 1336 // cache. | 1326 // cache. |
| 1337 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || | 1327 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || |
| 1338 !cache_entry.is_present()) { | 1328 !cache_entry.is_present()) { |
| 1339 LOG(WARNING) << "Can't clear dirty state of a file that wasn't cached: " | 1329 LOG(WARNING) << "Can't clear dirty state of a file that wasn't cached: " |
| 1340 << "res_id=" << resource_id | 1330 << "res_id=" << resource_id |
| 1341 << ", md5=" << md5; | 1331 << ", md5=" << md5; |
| 1342 *error = GDATA_FILE_ERROR_NOT_FOUND; | 1332 *error = DRIVE_FILE_ERROR_NOT_FOUND; |
| 1343 return; | 1333 return; |
| 1344 } | 1334 } |
| 1345 | 1335 |
| 1346 // If a file is not dirty (it should have been marked dirty via | 1336 // If a file is not dirty (it should have been marked dirty via |
| 1347 // MarkDirtyInCache), clearing its dirty state is an invalid operation. | 1337 // MarkDirtyInCache), clearing its dirty state is an invalid operation. |
| 1348 if (!cache_entry.is_dirty()) { | 1338 if (!cache_entry.is_dirty()) { |
| 1349 LOG(WARNING) << "Can't clear dirty state of a non-dirty file: res_id=" | 1339 LOG(WARNING) << "Can't clear dirty state of a non-dirty file: res_id=" |
| 1350 << resource_id | 1340 << resource_id |
| 1351 << ", md5=" << md5; | 1341 << ", md5=" << md5; |
| 1352 *error = GDATA_FILE_ERROR_INVALID_OPERATION; | 1342 *error = DRIVE_FILE_ERROR_INVALID_OPERATION; |
| 1353 return; | 1343 return; |
| 1354 } | 1344 } |
| 1355 | 1345 |
| 1356 // File must be dirty and hence in persistent dir. | 1346 // File must be dirty and hence in persistent dir. |
| 1357 DCHECK(cache_entry.is_persistent()); | 1347 DCHECK(cache_entry.is_persistent()); |
| 1358 | 1348 |
| 1359 // Get the current path of the file in cache. | 1349 // Get the current path of the file in cache. |
| 1360 FilePath source_path = GetCacheFilePath(resource_id, | 1350 FilePath source_path = GetCacheFilePath(resource_id, |
| 1361 md5, | 1351 md5, |
| 1362 GetSubDirectoryType(cache_entry), | 1352 GetSubDirectoryType(cache_entry), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1378 CACHE_TYPE_OUTGOING, | 1368 CACHE_TYPE_OUTGOING, |
| 1379 CACHED_FILE_FROM_SERVER); | 1369 CACHED_FILE_FROM_SERVER); |
| 1380 | 1370 |
| 1381 *error = ModifyCacheState(source_path, | 1371 *error = ModifyCacheState(source_path, |
| 1382 dest_path, | 1372 dest_path, |
| 1383 file_operation_type, | 1373 file_operation_type, |
| 1384 symlink_path, | 1374 symlink_path, |
| 1385 false /* don't create symlink */); | 1375 false /* don't create symlink */); |
| 1386 | 1376 |
| 1387 // If file is pinned, update symlink in pinned dir. | 1377 // If file is pinned, update symlink in pinned dir. |
| 1388 if (*error == GDATA_FILE_OK && cache_entry.is_pinned()) { | 1378 if (*error == DRIVE_FILE_OK && cache_entry.is_pinned()) { |
| 1389 symlink_path = GetCacheFilePath(resource_id, | 1379 symlink_path = GetCacheFilePath(resource_id, |
| 1390 std::string(), | 1380 std::string(), |
| 1391 CACHE_TYPE_PINNED, | 1381 CACHE_TYPE_PINNED, |
| 1392 CACHED_FILE_FROM_SERVER); | 1382 CACHED_FILE_FROM_SERVER); |
| 1393 | 1383 |
| 1394 // Since there's no moving of files here, use |dest_path| for both | 1384 // Since there's no moving of files here, use |dest_path| for both |
| 1395 // |source_path| and |dest_path|, because ModifyCacheState only moves files | 1385 // |source_path| and |dest_path|, because ModifyCacheState only moves files |
| 1396 // if source and destination are different. | 1386 // if source and destination are different. |
| 1397 *error = ModifyCacheState(dest_path, // source path | 1387 *error = ModifyCacheState(dest_path, // source path |
| 1398 dest_path, // destination path | 1388 dest_path, // destination path |
| 1399 file_operation_type, | 1389 file_operation_type, |
| 1400 symlink_path, | 1390 symlink_path, |
| 1401 true /* create symlink */); | 1391 true /* create symlink */); |
| 1402 } | 1392 } |
| 1403 | 1393 |
| 1404 if (*error == GDATA_FILE_OK) { | 1394 if (*error == DRIVE_FILE_OK) { |
| 1405 // Now that file operations have completed, update cache map. | 1395 // Now that file operations have completed, update cache map. |
| 1406 cache_entry.set_md5(md5); | 1396 cache_entry.set_md5(md5); |
| 1407 cache_entry.set_is_dirty(false); | 1397 cache_entry.set_is_dirty(false); |
| 1408 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); | 1398 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); |
| 1409 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); | 1399 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); |
| 1410 } | 1400 } |
| 1411 } | 1401 } |
| 1412 | 1402 |
| 1413 void DriveCache::Remove(const std::string& resource_id, | 1403 void DriveCache::Remove(const std::string& resource_id, |
| 1414 GDataFileError* error) { | 1404 DriveFileError* error) { |
| 1415 AssertOnSequencedWorkerPool(); | 1405 AssertOnSequencedWorkerPool(); |
| 1416 DCHECK(error); | 1406 DCHECK(error); |
| 1417 | 1407 |
| 1418 // MD5 is not passed into RemoveCacheEntry because we would delete all | 1408 // MD5 is not passed into RemoveCacheEntry because we would delete all |
| 1419 // cache files corresponding to <resource_id> regardless of the md5. | 1409 // cache files corresponding to <resource_id> regardless of the md5. |
| 1420 // So, search for entry in cache without taking md5 into account. | 1410 // So, search for entry in cache without taking md5 into account. |
| 1421 DriveCacheEntry cache_entry; | 1411 DriveCacheEntry cache_entry; |
| 1422 | 1412 |
| 1423 // If entry doesn't exist or is dirty or mounted in cache, nothing to do. | 1413 // If entry doesn't exist or is dirty or mounted in cache, nothing to do. |
| 1424 const bool entry_found = | 1414 const bool entry_found = |
| 1425 GetCacheEntry(resource_id, std::string(), &cache_entry); | 1415 GetCacheEntry(resource_id, std::string(), &cache_entry); |
| 1426 if (!entry_found || cache_entry.is_dirty() || cache_entry.is_mounted()) { | 1416 if (!entry_found || cache_entry.is_dirty() || cache_entry.is_mounted()) { |
| 1427 DVLOG(1) << "Entry is " | 1417 DVLOG(1) << "Entry is " |
| 1428 << (entry_found ? | 1418 << (entry_found ? |
| 1429 (cache_entry.is_dirty() ? "dirty" : "mounted") : | 1419 (cache_entry.is_dirty() ? "dirty" : "mounted") : |
| 1430 "non-existent") | 1420 "non-existent") |
| 1431 << " in cache, not removing"; | 1421 << " in cache, not removing"; |
| 1432 *error = GDATA_FILE_OK; | 1422 *error = DRIVE_FILE_OK; |
| 1433 return; | 1423 return; |
| 1434 } | 1424 } |
| 1435 | 1425 |
| 1436 // Determine paths to delete all cache versions of |resource_id| in | 1426 // Determine paths to delete all cache versions of |resource_id| in |
| 1437 // persistent, tmp and pinned directories. | 1427 // persistent, tmp and pinned directories. |
| 1438 std::vector<FilePath> paths_to_delete; | 1428 std::vector<FilePath> paths_to_delete; |
| 1439 | 1429 |
| 1440 // For files in persistent and tmp dirs, delete files that match | 1430 // For files in persistent and tmp dirs, delete files that match |
| 1441 // "<resource_id>.*". | 1431 // "<resource_id>.*". |
| 1442 paths_to_delete.push_back(GetCacheFilePath(resource_id, | 1432 paths_to_delete.push_back(GetCacheFilePath(resource_id, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1463 CACHE_TYPE_PERSISTENT, | 1453 CACHE_TYPE_PERSISTENT, |
| 1464 CACHED_FILE_LOCALLY_MODIFIED); | 1454 CACHED_FILE_LOCALLY_MODIFIED); |
| 1465 | 1455 |
| 1466 for (size_t i = 0; i < paths_to_delete.size(); ++i) { | 1456 for (size_t i = 0; i < paths_to_delete.size(); ++i) { |
| 1467 DeleteFilesSelectively(paths_to_delete[i], path_to_keep); | 1457 DeleteFilesSelectively(paths_to_delete[i], path_to_keep); |
| 1468 } | 1458 } |
| 1469 | 1459 |
| 1470 // Now that all file operations have completed, remove from cache map. | 1460 // Now that all file operations have completed, remove from cache map. |
| 1471 metadata_->RemoveCacheEntry(resource_id); | 1461 metadata_->RemoveCacheEntry(resource_id); |
| 1472 | 1462 |
| 1473 *error = GDATA_FILE_OK; | 1463 *error = DRIVE_FILE_OK; |
| 1474 } | 1464 } |
| 1475 | 1465 |
| 1476 void DriveCache::ClearAll(GDataFileError* error) { | 1466 void DriveCache::ClearAll(DriveFileError* error) { |
| 1477 AssertOnSequencedWorkerPool(); | 1467 AssertOnSequencedWorkerPool(); |
| 1478 DCHECK(error); | 1468 DCHECK(error); |
| 1479 | 1469 |
| 1480 bool success = file_util::Delete(cache_root_path_, true); | 1470 bool success = file_util::Delete(cache_root_path_, true); |
| 1481 Initialize(); | 1471 Initialize(); |
| 1482 | 1472 |
| 1483 *error = success ? GDATA_FILE_OK : GDATA_FILE_ERROR_FAILED; | 1473 *error = success ? DRIVE_FILE_OK : DRIVE_FILE_ERROR_FAILED; |
| 1484 } | 1474 } |
| 1485 | 1475 |
| 1486 void DriveCache::OnPinned(GDataFileError* error, | 1476 void DriveCache::OnPinned(DriveFileError* error, |
| 1487 const std::string& resource_id, | 1477 const std::string& resource_id, |
| 1488 const std::string& md5, | 1478 const std::string& md5, |
| 1489 const CacheOperationCallback& callback) { | 1479 const CacheOperationCallback& callback) { |
| 1490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1480 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1491 DCHECK(error); | 1481 DCHECK(error); |
| 1492 | 1482 |
| 1493 if (!callback.is_null()) | 1483 if (!callback.is_null()) |
| 1494 callback.Run(*error, resource_id, md5); | 1484 callback.Run(*error, resource_id, md5); |
| 1495 | 1485 |
| 1496 if (*error == GDATA_FILE_OK) | 1486 if (*error == DRIVE_FILE_OK) |
| 1497 FOR_EACH_OBSERVER(Observer, observers_, OnCachePinned(resource_id, md5)); | 1487 FOR_EACH_OBSERVER(Observer, observers_, OnCachePinned(resource_id, md5)); |
| 1498 } | 1488 } |
| 1499 | 1489 |
| 1500 void DriveCache::OnUnpinned(GDataFileError* error, | 1490 void DriveCache::OnUnpinned(DriveFileError* error, |
| 1501 const std::string& resource_id, | 1491 const std::string& resource_id, |
| 1502 const std::string& md5, | 1492 const std::string& md5, |
| 1503 const CacheOperationCallback& callback) { | 1493 const CacheOperationCallback& callback) { |
| 1504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1505 DCHECK(error); | 1495 DCHECK(error); |
| 1506 | 1496 |
| 1507 if (!callback.is_null()) | 1497 if (!callback.is_null()) |
| 1508 callback.Run(*error, resource_id, md5); | 1498 callback.Run(*error, resource_id, md5); |
| 1509 | 1499 |
| 1510 if (*error == GDATA_FILE_OK) | 1500 if (*error == DRIVE_FILE_OK) |
| 1511 FOR_EACH_OBSERVER(Observer, observers_, OnCacheUnpinned(resource_id, md5)); | 1501 FOR_EACH_OBSERVER(Observer, observers_, OnCacheUnpinned(resource_id, md5)); |
| 1512 | 1502 |
| 1513 // Now the file is moved from "persistent" to "tmp" directory. | 1503 // Now the file is moved from "persistent" to "tmp" directory. |
| 1514 // It's a chance to free up space if needed. | 1504 // It's a chance to free up space if needed. |
| 1515 bool* has_enough_space = new bool(false); | 1505 bool* has_enough_space = new bool(false); |
| 1516 blocking_task_runner_->PostTask( | 1506 blocking_task_runner_->PostTask( |
| 1517 FROM_HERE, | 1507 FROM_HERE, |
| 1518 base::Bind(&DriveCache::FreeDiskSpaceIfNeededFor, | 1508 base::Bind(&DriveCache::FreeDiskSpaceIfNeededFor, |
| 1519 base::Unretained(this), | 1509 base::Unretained(this), |
| 1520 0, | 1510 0, |
| 1521 base::Owned(has_enough_space))); | 1511 base::Owned(has_enough_space))); |
| 1522 } | 1512 } |
| 1523 | 1513 |
| 1524 void DriveCache::OnCommitDirty(GDataFileError* error, | 1514 void DriveCache::OnCommitDirty(DriveFileError* error, |
| 1525 const std::string& resource_id, | 1515 const std::string& resource_id, |
| 1526 const std::string& md5, | 1516 const std::string& md5, |
| 1527 const CacheOperationCallback& callback) { | 1517 const CacheOperationCallback& callback) { |
| 1528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1529 DCHECK(error); | 1519 DCHECK(error); |
| 1530 | 1520 |
| 1531 if (!callback.is_null()) | 1521 if (!callback.is_null()) |
| 1532 callback.Run(*error, resource_id, md5); | 1522 callback.Run(*error, resource_id, md5); |
| 1533 | 1523 |
| 1534 if (*error == GDATA_FILE_OK) | 1524 if (*error == DRIVE_FILE_OK) |
| 1535 FOR_EACH_OBSERVER(Observer, observers_, OnCacheCommitted(resource_id)); | 1525 FOR_EACH_OBSERVER(Observer, observers_, OnCacheCommitted(resource_id)); |
| 1536 } | 1526 } |
| 1537 | 1527 |
| 1538 void DriveCache::GetCacheEntryHelper(const std::string& resource_id, | 1528 void DriveCache::GetCacheEntryHelper(const std::string& resource_id, |
| 1539 const std::string& md5, | 1529 const std::string& md5, |
| 1540 bool* success, | 1530 bool* success, |
| 1541 DriveCacheEntry* cache_entry) { | 1531 DriveCacheEntry* cache_entry) { |
| 1542 AssertOnSequencedWorkerPool(); | 1532 AssertOnSequencedWorkerPool(); |
| 1543 DCHECK(success); | 1533 DCHECK(success); |
| 1544 DCHECK(cache_entry); | 1534 DCHECK(cache_entry); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1595 const DriveCacheEntry& cache_entry) { | 1585 const DriveCacheEntry& cache_entry) { |
| 1596 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1586 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
| 1597 } | 1587 } |
| 1598 | 1588 |
| 1599 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1589 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
| 1600 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1590 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
| 1601 global_free_disk_getter_for_testing = getter; | 1591 global_free_disk_getter_for_testing = getter; |
| 1602 } | 1592 } |
| 1603 | 1593 |
| 1604 } // namespace gdata | 1594 } // namespace gdata |
| OLD | NEW |