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/gdata_cache.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 callback.Run(*success, *cache_entry); | 317 callback.Run(*success, *cache_entry); |
318 } | 318 } |
319 | 319 |
320 } // namespace | 320 } // namespace |
321 | 321 |
322 GDataCache::GDataCache(const FilePath& cache_root_path, | 322 GDataCache::GDataCache(const FilePath& cache_root_path, |
323 base::SequencedTaskRunner* blocking_task_runner) | 323 base::SequencedTaskRunner* blocking_task_runner) |
324 : cache_root_path_(cache_root_path), | 324 : cache_root_path_(cache_root_path), |
325 cache_paths_(GetCachePaths(cache_root_path_)), | 325 cache_paths_(GetCachePaths(cache_root_path_)), |
326 blocking_task_runner_(blocking_task_runner), | 326 blocking_task_runner_(blocking_task_runner), |
327 ui_weak_ptr_factory_(this), | 327 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
328 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()) { | |
329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
330 } | 329 } |
331 | 330 |
332 GDataCache::~GDataCache() { | 331 GDataCache::~GDataCache() { |
333 AssertOnSequencedWorkerPool(); | 332 AssertOnSequencedWorkerPool(); |
334 } | 333 } |
335 | 334 |
336 FilePath GDataCache::GetCacheDirectoryPath( | 335 FilePath GDataCache::GetCacheDirectoryPath( |
337 CacheSubDirectoryType sub_dir_type) const { | 336 CacheSubDirectoryType sub_dir_type) const { |
338 DCHECK_LE(0, sub_dir_type); | 337 DCHECK_LE(0, sub_dir_type); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 new GDataFileError(GDATA_FILE_OK); | 534 new GDataFileError(GDATA_FILE_OK); |
536 blocking_task_runner_->PostTaskAndReply( | 535 blocking_task_runner_->PostTaskAndReply( |
537 FROM_HERE, | 536 FROM_HERE, |
538 base::Bind(&GDataCache::Pin, | 537 base::Bind(&GDataCache::Pin, |
539 base::Unretained(this), | 538 base::Unretained(this), |
540 resource_id, | 539 resource_id, |
541 md5, | 540 md5, |
542 GDataCache::FILE_OPERATION_MOVE, | 541 GDataCache::FILE_OPERATION_MOVE, |
543 error), | 542 error), |
544 base::Bind(&GDataCache::OnPinned, | 543 base::Bind(&GDataCache::OnPinned, |
545 ui_weak_ptr_, | 544 weak_ptr_factory_.GetWeakPtr(), |
546 base::Owned(error), | 545 base::Owned(error), |
547 resource_id, | 546 resource_id, |
548 md5, | 547 md5, |
549 callback)); | 548 callback)); |
550 } | 549 } |
551 | 550 |
552 void GDataCache::UnpinOnUIThread(const std::string& resource_id, | 551 void GDataCache::UnpinOnUIThread(const std::string& resource_id, |
553 const std::string& md5, | 552 const std::string& md5, |
554 const CacheOperationCallback& callback) { | 553 const CacheOperationCallback& callback) { |
555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 554 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
556 GDataFileError* error = | 555 GDataFileError* error = |
557 new GDataFileError(GDATA_FILE_OK); | 556 new GDataFileError(GDATA_FILE_OK); |
558 blocking_task_runner_->PostTaskAndReply( | 557 blocking_task_runner_->PostTaskAndReply( |
559 FROM_HERE, | 558 FROM_HERE, |
560 base::Bind(&GDataCache::Unpin, | 559 base::Bind(&GDataCache::Unpin, |
561 base::Unretained(this), | 560 base::Unretained(this), |
562 resource_id, | 561 resource_id, |
563 md5, | 562 md5, |
564 GDataCache::FILE_OPERATION_MOVE, | 563 GDataCache::FILE_OPERATION_MOVE, |
565 error), | 564 error), |
566 base::Bind(&GDataCache::OnUnpinned, | 565 base::Bind(&GDataCache::OnUnpinned, |
567 ui_weak_ptr_, | 566 weak_ptr_factory_.GetWeakPtr(), |
568 base::Owned(error), | 567 base::Owned(error), |
569 resource_id, | 568 resource_id, |
570 md5, | 569 md5, |
571 callback)); | 570 callback)); |
572 } | 571 } |
573 | 572 |
574 void GDataCache::SetMountedStateOnUIThread( | 573 void GDataCache::SetMountedStateOnUIThread( |
575 const FilePath& file_path, | 574 const FilePath& file_path, |
576 bool to_mount, | 575 bool to_mount, |
577 const SetMountedStateCallback& callback) { | 576 const SetMountedStateCallback& callback) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 GDataFileError* error = new GDataFileError(GDATA_FILE_OK); | 626 GDataFileError* error = new GDataFileError(GDATA_FILE_OK); |
628 blocking_task_runner_->PostTaskAndReply( | 627 blocking_task_runner_->PostTaskAndReply( |
629 FROM_HERE, | 628 FROM_HERE, |
630 base::Bind(&GDataCache::CommitDirty, | 629 base::Bind(&GDataCache::CommitDirty, |
631 base::Unretained(this), | 630 base::Unretained(this), |
632 resource_id, | 631 resource_id, |
633 md5, | 632 md5, |
634 GDataCache::FILE_OPERATION_MOVE, | 633 GDataCache::FILE_OPERATION_MOVE, |
635 error), | 634 error), |
636 base::Bind(&GDataCache::OnCommitDirty, | 635 base::Bind(&GDataCache::OnCommitDirty, |
637 ui_weak_ptr_, | 636 weak_ptr_factory_.GetWeakPtr(), |
638 base::Owned(error), | 637 base::Owned(error), |
639 resource_id, | 638 resource_id, |
640 md5, | 639 md5, |
641 callback)); | 640 callback)); |
642 } | 641 } |
643 | 642 |
644 void GDataCache::ClearDirtyOnUIThread(const std::string& resource_id, | 643 void GDataCache::ClearDirtyOnUIThread(const std::string& resource_id, |
645 const std::string& md5, | 644 const std::string& md5, |
646 const CacheOperationCallback& callback) { | 645 const CacheOperationCallback& callback) { |
647 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 646 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 const FilePath& cache_root_path, | 711 const FilePath& cache_root_path, |
713 base::SequencedTaskRunner* blocking_task_runner) { | 712 base::SequencedTaskRunner* blocking_task_runner) { |
714 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 713 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
715 return new GDataCache(cache_root_path, blocking_task_runner); | 714 return new GDataCache(cache_root_path, blocking_task_runner); |
716 } | 715 } |
717 | 716 |
718 void GDataCache::DestroyOnUIThread() { | 717 void GDataCache::DestroyOnUIThread() { |
719 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
720 | 719 |
721 // Invalidate the weak pointer. | 720 // Invalidate the weak pointer. |
722 ui_weak_ptr_factory_.InvalidateWeakPtrs(); | 721 weak_ptr_factory_.InvalidateWeakPtrs(); |
723 | 722 |
724 // Destroy myself on the blocking pool. | 723 // Destroy myself on the blocking pool. |
725 blocking_task_runner_->PostTask( | 724 blocking_task_runner_->PostTask( |
726 FROM_HERE, | 725 FROM_HERE, |
727 base::Bind(&GDataCache::Destroy, | 726 base::Bind(&GDataCache::Destroy, |
728 base::Unretained(this))); | 727 base::Unretained(this))); |
729 } | 728 } |
730 | 729 |
731 void GDataCache::Initialize() { | 730 void GDataCache::Initialize() { |
732 AssertOnSequencedWorkerPool(); | 731 AssertOnSequencedWorkerPool(); |
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1548 const GDataCacheEntry& cache_entry) { | 1547 const GDataCacheEntry& cache_entry) { |
1549 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1548 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
1550 } | 1549 } |
1551 | 1550 |
1552 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1551 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
1553 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1552 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
1554 global_free_disk_getter_for_testing = getter; | 1553 global_free_disk_getter_for_testing = getter; |
1555 } | 1554 } |
1556 | 1555 |
1557 } // namespace gdata | 1556 } // namespace gdata |
OLD | NEW |