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

Side by Side Diff: components/offline_pages/offline_page_model_impl.cc

Issue 2086733002: [Offline Pages] Fix cases where returning NOT_FOUND when deleting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments. Created 4 years, 6 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_impl.h" 5 #include "components/offline_pages/offline_page_model_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 DCHECK(is_loaded_); 342 DCHECK(is_loaded_);
343 343
344 std::vector<base::FilePath> paths_to_delete; 344 std::vector<base::FilePath> paths_to_delete;
345 for (const auto& offline_id : offline_ids) { 345 for (const auto& offline_id : offline_ids) {
346 auto iter = offline_pages_.find(offline_id); 346 auto iter = offline_pages_.find(offline_id);
347 if (iter != offline_pages_.end() && !iter->second.IsExpired()) { 347 if (iter != offline_pages_.end() && !iter->second.IsExpired()) {
348 paths_to_delete.push_back(iter->second.file_path); 348 paths_to_delete.push_back(iter->second.file_path);
349 } 349 }
350 } 350 }
351 351
352 // If there're no pages to delete, return early.
352 if (paths_to_delete.empty()) { 353 if (paths_to_delete.empty()) {
353 InformDeletePageDone(callback, DeletePageResult::NOT_FOUND); 354 InformDeletePageDone(callback, DeletePageResult::SUCCESS);
354 return; 355 return;
355 } 356 }
356 357
357 archive_manager_->DeleteMultipleArchives( 358 archive_manager_->DeleteMultipleArchives(
358 paths_to_delete, 359 paths_to_delete,
359 base::Bind(&OfflinePageModelImpl::OnDeleteArchiveFilesDone, 360 base::Bind(&OfflinePageModelImpl::OnDeleteArchiveFilesDone,
360 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); 361 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback));
361 } 362 }
362 363
363 void OfflinePageModelImpl::ClearAll(const base::Closure& callback) { 364 void OfflinePageModelImpl::ClearAll(const base::Closure& callback) {
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 base::Bind(&OfflinePageModelImpl::OnRemoveOfflinePagesDone, 825 base::Bind(&OfflinePageModelImpl::OnRemoveOfflinePagesDone,
825 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); 826 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback));
826 } 827 }
827 828
828 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( 829 void OfflinePageModelImpl::OnRemoveOfflinePagesDone(
829 const std::vector<int64_t>& offline_ids, 830 const std::vector<int64_t>& offline_ids,
830 const DeletePageCallback& callback, 831 const DeletePageCallback& callback,
831 bool success) { 832 bool success) {
832 ReportPageHistogramsAfterDelete(offline_pages_, offline_ids); 833 ReportPageHistogramsAfterDelete(offline_pages_, offline_ids);
833 834
834 // Delete the offline page from the in memory cache regardless of success in
835 // store.
836 for (int64_t offline_id : offline_ids) { 835 for (int64_t offline_id : offline_ids) {
837 auto iter = offline_pages_.find(offline_id); 836 auto iter = offline_pages_.find(offline_id);
838 if (iter == offline_pages_.end()) 837 if (iter == offline_pages_.end())
839 continue; 838 continue;
840 FOR_EACH_OBSERVER( 839 FOR_EACH_OBSERVER(
841 Observer, observers_, 840 Observer, observers_,
842 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id)); 841 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id));
843 offline_pages_.erase(iter); 842 offline_pages_.erase(iter);
844 } 843 }
844
845 // Deleting multiple pages always succeeds when it gets to this point. 845 // Deleting multiple pages always succeeds when it gets to this point.
846 InformDeletePageDone(callback, (success || offline_ids.size() > 1) 846 InformDeletePageDone(callback, (success || offline_ids.size() > 1)
847 ? DeletePageResult::SUCCESS 847 ? DeletePageResult::SUCCESS
848 : DeletePageResult::STORE_FAILURE); 848 : DeletePageResult::STORE_FAILURE);
849 } 849 }
850 850
851 void OfflinePageModelImpl::InformDeletePageDone( 851 void OfflinePageModelImpl::InformDeletePageDone(
852 const DeletePageCallback& callback, 852 const DeletePageCallback& callback,
853 DeletePageResult result) { 853 DeletePageResult result) {
854 UMA_HISTOGRAM_ENUMERATION("OfflinePages.DeletePageResult", 854 UMA_HISTOGRAM_ENUMERATION("OfflinePages.DeletePageResult",
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { 983 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) {
984 if (!is_loaded_) { 984 if (!is_loaded_) {
985 delayed_tasks_.push_back(task); 985 delayed_tasks_.push_back(task);
986 return; 986 return;
987 } 987 }
988 988
989 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 989 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
990 } 990 }
991 991
992 } // namespace offline_pages 992 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model.h ('k') | components/offline_pages/offline_page_model_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698