| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/offline_pages/offline_page_model.h" | 5 #include "components/offline_pages/offline_page_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 } | 239 } |
| 240 | 240 |
| 241 void OfflinePageModel::DoDeletePagesByOfflineId( | 241 void OfflinePageModel::DoDeletePagesByOfflineId( |
| 242 const std::vector<int64_t>& offline_ids, | 242 const std::vector<int64_t>& offline_ids, |
| 243 const DeletePageCallback& callback) { | 243 const DeletePageCallback& callback) { |
| 244 DCHECK(is_loaded_); | 244 DCHECK(is_loaded_); |
| 245 | 245 |
| 246 std::vector<base::FilePath> paths_to_delete; | 246 std::vector<base::FilePath> paths_to_delete; |
| 247 for (const auto& offline_id : offline_ids) { | 247 for (const auto& offline_id : offline_ids) { |
| 248 auto iter = offline_pages_.find(offline_id); | 248 auto iter = offline_pages_.find(offline_id); |
| 249 if (iter != offline_pages_.end()) { | 249 if (iter != offline_pages_.end() && !iter->second.IsExpired()) { |
| 250 paths_to_delete.push_back(iter->second.file_path); | 250 paths_to_delete.push_back(iter->second.file_path); |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 if (paths_to_delete.empty()) { | 254 if (paths_to_delete.empty()) { |
| 255 InformDeletePageDone(callback, DeletePageResult::NOT_FOUND); | 255 InformDeletePageDone(callback, DeletePageResult::NOT_FOUND); |
| 256 return; | 256 return; |
| 257 } | 257 } |
| 258 | 258 |
| 259 archive_manager_->DeleteMultipleArchives( | 259 archive_manager_->DeleteMultipleArchives( |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 | 501 |
| 502 void OfflinePageModel::CheckForExternalFileDeletion() { | 502 void OfflinePageModel::CheckForExternalFileDeletion() { |
| 503 DCHECK(is_loaded_); | 503 DCHECK(is_loaded_); |
| 504 | 504 |
| 505 archive_manager_->GetAllArchives( | 505 archive_manager_->GetAllArchives( |
| 506 base::Bind(&OfflinePageModel::ScanForMissingArchiveFiles, | 506 base::Bind(&OfflinePageModel::ScanForMissingArchiveFiles, |
| 507 weak_ptr_factory_.GetWeakPtr())); | 507 weak_ptr_factory_.GetWeakPtr())); |
| 508 } | 508 } |
| 509 | 509 |
| 510 void OfflinePageModel::ExpirePages(const std::vector<int64_t>& offline_ids, | 510 void OfflinePageModel::ExpirePages(const std::vector<int64_t>& offline_ids, |
| 511 const base::Time& expiration_time) { | 511 const base::Time& expiration_time, |
| 512 const base::Callback<void(bool)>& callback) { |
| 513 std::vector<base::FilePath> paths_to_delete; |
| 512 for (int64_t offline_id : offline_ids) { | 514 for (int64_t offline_id : offline_ids) { |
| 513 auto iter = offline_pages_.find(offline_id); | 515 auto iter = offline_pages_.find(offline_id); |
| 514 if (iter == offline_pages_.end()) | 516 if (iter == offline_pages_.end()) |
| 515 continue; | 517 continue; |
| 516 | 518 |
| 517 OfflinePageItem offline_page = iter->second; | 519 OfflinePageItem offline_page = iter->second; |
| 520 paths_to_delete.push_back(offline_page.file_path); |
| 518 offline_page.expiration_time = expiration_time; | 521 offline_page.expiration_time = expiration_time; |
| 519 | 522 |
| 520 store_->AddOrUpdateOfflinePage( | 523 store_->AddOrUpdateOfflinePage( |
| 521 offline_page, base::Bind(&OfflinePageModel::OnExpirePageDone, | 524 offline_page, base::Bind(&OfflinePageModel::OnExpirePageDone, |
| 522 weak_ptr_factory_.GetWeakPtr(), offline_id, | 525 weak_ptr_factory_.GetWeakPtr(), offline_id, |
| 523 expiration_time)); | 526 expiration_time)); |
| 524 } | 527 } |
| 528 if (paths_to_delete.empty()) { |
| 529 callback.Run(true); |
| 530 return; |
| 531 } |
| 532 archive_manager_->DeleteMultipleArchives(paths_to_delete, callback); |
| 525 } | 533 } |
| 526 | 534 |
| 527 void OfflinePageModel::OnExpirePageDone(int64_t offline_id, | 535 void OfflinePageModel::OnExpirePageDone(int64_t offline_id, |
| 528 const base::Time& expiration_time, | 536 const base::Time& expiration_time, |
| 529 bool success) { | 537 bool success) { |
| 530 // TODO(romax): Report UMA about successful expiration. | 538 // TODO(romax): Report UMA about successful expiration. |
| 531 if (success) { | 539 if (success) { |
| 532 auto iter = offline_pages_.find(offline_id); | 540 auto iter = offline_pages_.find(offline_id); |
| 533 if (iter != offline_pages_.end()) | 541 if (iter != offline_pages_.end()) |
| 534 iter->second.expiration_time = expiration_time; | 542 iter->second.expiration_time = expiration_time; |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { | 862 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { |
| 855 if (!is_loaded_) { | 863 if (!is_loaded_) { |
| 856 delayed_tasks_.push_back(task); | 864 delayed_tasks_.push_back(task); |
| 857 return; | 865 return; |
| 858 } | 866 } |
| 859 | 867 |
| 860 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 868 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 861 } | 869 } |
| 862 | 870 |
| 863 } // namespace offline_pages | 871 } // namespace offline_pages |
| OLD | NEW |