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

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

Issue 1968563003: [Offline pages] Extracting callbacks from the Offline Page Model (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding a missing fix to gypi file Created 4 years, 7 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 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"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/optional.h" 15 #include "base/optional.h"
16 #include "base/rand_util.h" 16 #include "base/rand_util.h"
17 #include "base/sequenced_task_runner.h" 17 #include "base/sequenced_task_runner.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
20 #include "base/time/time.h" 20 #include "base/time/time.h"
21 #include "components/offline_pages/client_policy_controller.h" 21 #include "components/offline_pages/client_policy_controller.h"
22 #include "components/offline_pages/offline_page_item.h" 22 #include "components/offline_pages/offline_page_item.h"
23 #include "components/offline_pages/offline_page_storage_manager.h" 23 #include "components/offline_pages/offline_page_storage_manager.h"
24 #include "components/offline_pages/proto/offline_pages.pb.h" 24 #include "components/offline_pages/proto/offline_pages.pb.h"
25 #include "url/gurl.h" 25 #include "url/gurl.h"
26 26
27 using ArchiverResult = offline_pages::OfflinePageArchiver::ArchiverResult; 27 using ArchiverResult = offline_pages::OfflinePageArchiver::ArchiverResult;
28 using SavePageResult = offline_pages::OfflinePageModel::SavePageResult;
29 28
30 namespace offline_pages { 29 namespace offline_pages {
31 30
32 namespace { 31 namespace {
33 32
34 // This enum is used in an UMA histogram. Hence the entries here shouldn't 33 // This enum is used in an UMA histogram. Hence the entries here shouldn't
35 // be deleted or re-ordered and new ones should be added to the end. 34 // be deleted or re-ordered and new ones should be added to the end.
36 enum ClearAllStatus { 35 enum ClearAllStatus {
37 CLEAR_ALL_SUCCEEDED, 36 CLEAR_ALL_SUCCEEDED,
38 STORE_RESET_FAILED, 37 STORE_RESET_FAILED,
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 std::vector<int64_t> offline_ids; 249 std::vector<int64_t> offline_ids;
251 for (const auto& id_page_pair : offline_pages_) 250 for (const auto& id_page_pair : offline_pages_)
252 offline_ids.push_back(id_page_pair.first); 251 offline_ids.push_back(id_page_pair.first);
253 DeletePagesByOfflineId( 252 DeletePagesByOfflineId(
254 offline_ids, 253 offline_ids,
255 base::Bind(&OfflinePageModel::OnRemoveAllFilesDoneForClearAll, 254 base::Bind(&OfflinePageModel::OnRemoveAllFilesDoneForClearAll,
256 weak_ptr_factory_.GetWeakPtr(), callback)); 255 weak_ptr_factory_.GetWeakPtr(), callback));
257 } 256 }
258 257
259 void OfflinePageModel::DeletePagesByURLPredicate( 258 void OfflinePageModel::DeletePagesByURLPredicate(
260 const base::Callback<bool(const GURL&)>& predicate, 259 const UrlPredicate& predicate,
261 const DeletePageCallback& callback) { 260 const DeletePageCallback& callback) {
262 if (!is_loaded_) { 261 if (!is_loaded_) {
263 delayed_tasks_.push_back( 262 delayed_tasks_.push_back(
264 base::Bind(&OfflinePageModel::DoDeletePagesByURLPredicate, 263 base::Bind(&OfflinePageModel::DoDeletePagesByURLPredicate,
265 weak_ptr_factory_.GetWeakPtr(), predicate, callback)); 264 weak_ptr_factory_.GetWeakPtr(), predicate, callback));
266 265
267 return; 266 return;
268 } 267 }
269 DoDeletePagesByURLPredicate(predicate, callback); 268 DoDeletePagesByURLPredicate(predicate, callback);
270 } 269 }
271 270
272 void OfflinePageModel::DoDeletePagesByURLPredicate( 271 void OfflinePageModel::DoDeletePagesByURLPredicate(
273 const base::Callback<bool(const GURL&)>& predicate, 272 const UrlPredicate& predicate,
274 const DeletePageCallback& callback) { 273 const DeletePageCallback& callback) {
275 DCHECK(is_loaded_); 274 DCHECK(is_loaded_);
276 275
277 std::vector<int64_t> offline_ids; 276 std::vector<int64_t> offline_ids;
278 for (const auto& id_page_pair : offline_pages_) { 277 for (const auto& id_page_pair : offline_pages_) {
279 if (predicate.Run(id_page_pair.second.url)) 278 if (predicate.Run(id_page_pair.second.url))
280 offline_ids.push_back(id_page_pair.first); 279 offline_ids.push_back(id_page_pair.first);
281 } 280 }
282 DoDeletePagesByOfflineId(offline_ids, callback); 281 DoDeletePagesByOfflineId(offline_ids, callback);
283 } 282 }
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 store_->RemoveOfflinePages( 742 store_->RemoveOfflinePages(
744 *ids_of_pages_missing_archive_file, 743 *ids_of_pages_missing_archive_file,
745 base::Bind(&OfflinePageModel::OnRemoveOfflinePagesDone, 744 base::Bind(&OfflinePageModel::OnRemoveOfflinePagesDone,
746 weak_ptr_factory_.GetWeakPtr(), 745 weak_ptr_factory_.GetWeakPtr(),
747 *ids_of_pages_missing_archive_file, 746 *ids_of_pages_missing_archive_file,
748 done_callback)); 747 done_callback));
749 } 748 }
750 749
751 void OfflinePageModel::OnRemoveOfflinePagesMissingArchiveFileDone( 750 void OfflinePageModel::OnRemoveOfflinePagesMissingArchiveFileDone(
752 const std::vector<std::pair<int64_t, ClientId>>& offline_client_id_pairs, 751 const std::vector<std::pair<int64_t, ClientId>>& offline_client_id_pairs,
753 OfflinePageModel::DeletePageResult /* result */) { 752 DeletePageResult /* result */) {
754 for (const auto& id_pair : offline_client_id_pairs) { 753 for (const auto& id_pair : offline_client_id_pairs) {
755 FOR_EACH_OBSERVER(Observer, observers_, 754 FOR_EACH_OBSERVER(Observer, observers_,
756 OfflinePageDeleted(id_pair.first, id_pair.second)); 755 OfflinePageDeleted(id_pair.first, id_pair.second));
757 } 756 }
758 } 757 }
759 758
760 void OfflinePageModel::OnRemoveAllFilesDoneForClearAll( 759 void OfflinePageModel::OnRemoveAllFilesDoneForClearAll(
761 const base::Closure& callback, 760 const base::Closure& callback,
762 DeletePageResult result) { 761 DeletePageResult result) {
763 store_->Reset(base::Bind(&OfflinePageModel::OnResetStoreDoneForClearAll, 762 store_->Reset(base::Bind(&OfflinePageModel::OnResetStoreDoneForClearAll,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { 808 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) {
810 if (!is_loaded_) { 809 if (!is_loaded_) {
811 delayed_tasks_.push_back(task); 810 delayed_tasks_.push_back(task);
812 return; 811 return;
813 } 812 }
814 813
815 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 814 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
816 } 815 }
817 816
818 } // namespace offline_pages 817 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model.h ('k') | components/offline_pages/offline_page_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698