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

Side by Side Diff: components/reading_list/ios/reading_list_model.cc

Issue 2763233003: Move ReadingList model to components/reading_list/core (Closed)
Patch Set: feedback Created 3 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/reading_list/ios/reading_list_model.h"
6
7 #include "base/logging.h"
8 #include "base/memory/ptr_util.h"
9
10 ReadingListModel::ReadingListModel() : current_batch_updates_count_(0) {}
11
12 ReadingListModel::~ReadingListModel() {
13 for (auto& observer : observers_) {
14 observer.ReadingListModelBeingDeleted(this);
15 }
16 }
17
18 // Observer methods.
19 void ReadingListModel::AddObserver(ReadingListModelObserver* observer) {
20 DCHECK(CalledOnValidThread());
21 DCHECK(observer);
22 observers_.AddObserver(observer);
23 if (loaded()) {
24 observer->ReadingListModelLoaded(this);
25 }
26 }
27
28 void ReadingListModel::RemoveObserver(ReadingListModelObserver* observer) {
29 DCHECK(CalledOnValidThread());
30 observers_.RemoveObserver(observer);
31 }
32
33 // Batch update methods.
34 bool ReadingListModel::IsPerformingBatchUpdates() const {
35 DCHECK(CalledOnValidThread());
36 return current_batch_updates_count_ > 0;
37 }
38
39 std::unique_ptr<ReadingListModel::ScopedReadingListBatchUpdate>
40 ReadingListModel::CreateBatchToken() {
41 return base::MakeUnique<ReadingListModel::ScopedReadingListBatchUpdate>(this);
42 }
43
44 std::unique_ptr<ReadingListModel::ScopedReadingListBatchUpdate>
45 ReadingListModel::BeginBatchUpdates() {
46 DCHECK(CalledOnValidThread());
47 auto token = CreateBatchToken();
48
49 ++current_batch_updates_count_;
50 if (current_batch_updates_count_ == 1) {
51 EnteringBatchUpdates();
52 }
53 return token;
54 }
55
56 void ReadingListModel::EnteringBatchUpdates() {
57 DCHECK(CalledOnValidThread());
58 for (auto& observer : observers_)
59 observer.ReadingListModelBeganBatchUpdates(this);
60 }
61
62 void ReadingListModel::EndBatchUpdates() {
63 DCHECK(CalledOnValidThread());
64 DCHECK(IsPerformingBatchUpdates());
65 DCHECK(current_batch_updates_count_ > 0);
66 --current_batch_updates_count_;
67 if (current_batch_updates_count_ == 0) {
68 LeavingBatchUpdates();
69 }
70 }
71
72 void ReadingListModel::LeavingBatchUpdates() {
73 DCHECK(CalledOnValidThread());
74 for (auto& observer : observers_)
75 observer.ReadingListModelCompletedBatchUpdates(this);
76 }
77
78 ReadingListModel::ScopedReadingListBatchUpdate::
79 ~ScopedReadingListBatchUpdate() {
80 model_->EndBatchUpdates();
81 }
OLDNEW
« no previous file with comments | « components/reading_list/ios/reading_list_model.h ('k') | components/reading_list/ios/reading_list_model_bridge_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698