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

Side by Side Diff: ios/chrome/browser/reading_list/reading_list_model_impl.cc

Issue 2350663003: Make reading list entry movable only (Closed)
Patch Set: indentation 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 "ios/chrome/browser/reading_list/reading_list_model_impl.h" 5 #include "ios/chrome/browser/reading_list/reading_list_model_impl.h"
6 6
7 #include "ios/chrome/browser/reading_list/reading_list_model_storage.h" 7 #include "ios/chrome/browser/reading_list/reading_list_model_storage.h"
8 #include "url/gurl.h" 8 #include "url/gurl.h"
9 9
10 ReadingListModelImpl::ReadingListModelImpl() : ReadingListModelImpl(NULL) {} 10 ReadingListModelImpl::ReadingListModelImpl() : ReadingListModelImpl(NULL) {}
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 ReadingListDidApplyChanges(this)); 96 ReadingListDidApplyChanges(this));
97 return; 97 return;
98 } 98 }
99 } 99 }
100 100
101 const ReadingListEntry& ReadingListModelImpl::AddEntry( 101 const ReadingListEntry& ReadingListModelImpl::AddEntry(
102 const GURL& url, 102 const GURL& url,
103 const std::string& title) { 103 const std::string& title) {
104 DCHECK(loaded()); 104 DCHECK(loaded());
105 RemoveEntryByUrl(url); 105 RemoveEntryByUrl(url);
106 const ReadingListEntry entry(url, title); 106 ReadingListEntry entry(url, title);
107 FOR_EACH_OBSERVER(ReadingListModelObserver, observers_, 107 FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
108 ReadingListWillAddUnreadEntry(this, entry)); 108 ReadingListWillAddUnreadEntry(this, entry));
109 unread_.insert(unread_.begin(), entry); 109 unread_.insert(unread_.begin(), std::move(entry));
110 hasUnseen_ = true; 110 hasUnseen_ = true;
111 if (storageLayer_ && !IsPerformingBatchUpdates()) { 111 if (storageLayer_ && !IsPerformingBatchUpdates()) {
112 storageLayer_->SavePersistentUnreadList(unread_); 112 storageLayer_->SavePersistentUnreadList(unread_);
113 storageLayer_->SavePersistentHasUnseen(true); 113 storageLayer_->SavePersistentHasUnseen(true);
114 } 114 }
115 FOR_EACH_OBSERVER(ReadingListModelObserver, observers_, 115 FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
116 ReadingListDidApplyChanges(this)); 116 ReadingListDidApplyChanges(this));
117 return *unread_.begin(); 117 return *unread_.begin();
118 } 118 }
119 119
120 void ReadingListModelImpl::MarkReadByURL(const GURL& url) { 120 void ReadingListModelImpl::MarkReadByURL(const GURL& url) {
121 DCHECK(loaded()); 121 DCHECK(loaded());
122 const ReadingListEntry entry(url, std::string()); 122 ReadingListEntry entry(url, std::string());
123
124 auto result = std::find(unread_.begin(), unread_.end(), entry); 123 auto result = std::find(unread_.begin(), unread_.end(), entry);
125 if (result == unread_.end()) 124 if (result == unread_.end())
126 return; 125 return;
127 126
128 FOR_EACH_OBSERVER( 127 FOR_EACH_OBSERVER(
129 ReadingListModelObserver, observers_, 128 ReadingListModelObserver, observers_,
130 ReadingListWillMoveEntry(this, std::distance(unread_.begin(), result))); 129 ReadingListWillMoveEntry(this, std::distance(unread_.begin(), result)));
131 130
132 read_.insert(read_.begin(), *result); 131 read_.insert(read_.begin(), std::move(*result));
133 unread_.erase(result); 132 unread_.erase(result);
133
134 if (storageLayer_ && !IsPerformingBatchUpdates()) { 134 if (storageLayer_ && !IsPerformingBatchUpdates()) {
135 storageLayer_->SavePersistentUnreadList(unread_); 135 storageLayer_->SavePersistentUnreadList(unread_);
136 storageLayer_->SavePersistentReadList(read_); 136 storageLayer_->SavePersistentReadList(read_);
137 } 137 }
138 FOR_EACH_OBSERVER(ReadingListModelObserver, observers_, 138 FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
139 ReadingListDidApplyChanges(this)); 139 ReadingListDidApplyChanges(this));
140 } 140 }
141 141
142 void ReadingListModelImpl::SetEntryTitle(const GURL& url, 142 void ReadingListModelImpl::SetEntryTitle(const GURL& url,
143 const std::string& title) { 143 const std::string& title) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 238
239 void ReadingListModelImpl::EndBatchUpdates() { 239 void ReadingListModelImpl::EndBatchUpdates() {
240 ReadingListModel::EndBatchUpdates(); 240 ReadingListModel::EndBatchUpdates();
241 if (IsPerformingBatchUpdates() || !storageLayer_) { 241 if (IsPerformingBatchUpdates() || !storageLayer_) {
242 return; 242 return;
243 } 243 }
244 storageLayer_->SavePersistentUnreadList(unread_); 244 storageLayer_->SavePersistentUnreadList(unread_);
245 storageLayer_->SavePersistentReadList(read_); 245 storageLayer_->SavePersistentReadList(read_);
246 storageLayer_->SavePersistentHasUnseen(hasUnseen_); 246 storageLayer_->SavePersistentHasUnseen(hasUnseen_);
247 } 247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698