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