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

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

Issue 2275833002: [Offline Pages] Don't remove user-requested pages when deleting cache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments. Created 4 years, 3 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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 372
373 std::vector<int64_t> offline_ids; 373 std::vector<int64_t> offline_ids;
374 for (const auto& id_page_pair : offline_pages_) 374 for (const auto& id_page_pair : offline_pages_)
375 offline_ids.push_back(id_page_pair.first); 375 offline_ids.push_back(id_page_pair.first);
376 DeletePagesByOfflineId( 376 DeletePagesByOfflineId(
377 offline_ids, 377 offline_ids,
378 base::Bind(&OfflinePageModelImpl::OnRemoveAllFilesDoneForClearAll, 378 base::Bind(&OfflinePageModelImpl::OnRemoveAllFilesDoneForClearAll,
379 weak_ptr_factory_.GetWeakPtr(), callback)); 379 weak_ptr_factory_.GetWeakPtr(), callback));
380 } 380 }
381 381
382 void OfflinePageModelImpl::DeletePagesByURLPredicate( 382 void OfflinePageModelImpl::DeleteCachedPagesByURLPredicate(
383 const UrlPredicate& predicate, 383 const UrlPredicate& predicate,
384 const DeletePageCallback& callback) { 384 const DeletePageCallback& callback) {
385 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::DoDeletePagesByURLPredicate, 385 RunWhenLoaded(
386 weak_ptr_factory_.GetWeakPtr(), predicate, 386 base::Bind(&OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate,
387 callback)); 387 weak_ptr_factory_.GetWeakPtr(), predicate, callback));
388 } 388 }
389 389
390 void OfflinePageModelImpl::DoDeletePagesByURLPredicate( 390 void OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate(
391 const UrlPredicate& predicate, 391 const UrlPredicate& predicate,
392 const DeletePageCallback& callback) { 392 const DeletePageCallback& callback) {
393 DCHECK(is_loaded_); 393 DCHECK(is_loaded_);
394 394
395 std::vector<int64_t> offline_ids; 395 std::vector<int64_t> offline_ids;
396 for (const auto& id_page_pair : offline_pages_) { 396 for (const auto& id_page_pair : offline_pages_) {
397 if (predicate.Run(id_page_pair.second.url)) 397 if (!IsUserRequestedPage(id_page_pair.second) &&
398 predicate.Run(id_page_pair.second.url))
398 offline_ids.push_back(id_page_pair.first); 399 offline_ids.push_back(id_page_pair.first);
399 } 400 }
400 DoDeletePagesByOfflineId(offline_ids, callback); 401 DoDeletePagesByOfflineId(offline_ids, callback);
401 } 402 }
402 403
403 void OfflinePageModelImpl::HasPages(const std::string& name_space, 404 void OfflinePageModelImpl::HasPages(const std::string& name_space,
404 const HasPagesCallback& callback) { 405 const HasPagesCallback& callback) {
405 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::HasPagesAfterLoadDone, 406 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::HasPagesAfterLoadDone,
406 weak_ptr_factory_.GetWeakPtr(), name_space, 407 weak_ptr_factory_.GetWeakPtr(), name_space,
407 callback)); 408 callback));
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 } 1054 }
1054 1055
1055 void OfflinePageModelImpl::PostClearStorageIfNeededTask() { 1056 void OfflinePageModelImpl::PostClearStorageIfNeededTask() {
1056 base::ThreadTaskRunnerHandle::Get()->PostTask( 1057 base::ThreadTaskRunnerHandle::Get()->PostTask(
1057 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, 1058 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded,
1058 weak_ptr_factory_.GetWeakPtr(), 1059 weak_ptr_factory_.GetWeakPtr(),
1059 base::Bind(&OfflinePageModelImpl::OnStorageCleared, 1060 base::Bind(&OfflinePageModelImpl::OnStorageCleared,
1060 weak_ptr_factory_.GetWeakPtr()))); 1061 weak_ptr_factory_.GetWeakPtr())));
1061 } 1062 }
1062 1063
1064 bool OfflinePageModelImpl::IsUserRequestedPage(
1065 const OfflinePageItem& offline_page) const {
1066 return (offline_page.client_id.name_space == kAsyncNamespace ||
1067 offline_page.client_id.name_space == kDownloadNamespace);
1068 }
1069
1063 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { 1070 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) {
1064 if (!is_loaded_) { 1071 if (!is_loaded_) {
1065 delayed_tasks_.push_back(task); 1072 delayed_tasks_.push_back(task);
1066 return; 1073 return;
1067 } 1074 }
1068 1075
1069 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 1076 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
1070 } 1077 }
1071 1078
1072 } // namespace offline_pages 1079 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model_impl.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