Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 unread_.insert(unread_.begin(), std::move(entry)); | 130 unread_.insert(unread_.begin(), std::move(entry)); |
| 131 hasUnseen_ = true; | 131 hasUnseen_ = true; |
| 132 if (storageLayer_ && !IsPerformingBatchUpdates()) { | 132 if (storageLayer_ && !IsPerformingBatchUpdates()) { |
| 133 storageLayer_->SavePersistentUnreadList(unread_); | 133 storageLayer_->SavePersistentUnreadList(unread_); |
| 134 storageLayer_->SavePersistentHasUnseen(true); | 134 storageLayer_->SavePersistentHasUnseen(true); |
| 135 } | 135 } |
| 136 for (auto& observer : observers_) | 136 for (auto& observer : observers_) |
| 137 observer.ReadingListDidApplyChanges(this); | 137 observer.ReadingListDidApplyChanges(this); |
| 138 return *unread_.begin(); | 138 return *unread_.begin(); |
| 139 } | 139 } |
| 140 void ReadingListModelImpl::MarkUnreadByURL(const GURL& url) { | |
|
Olivier
2016/10/20 11:25:39
new line
gambard
2016/10/20 11:51:35
Done.
| |
| 141 DCHECK(loaded()); | |
| 142 ReadingListEntry entry(url, std::string()); | |
| 143 auto result = std::find(read_.begin(), read_.end(), entry); | |
| 144 if (result == read_.end()) | |
| 145 return; | |
| 146 | |
| 147 for (ReadingListModelObserver& observer : observers_) { | |
| 148 observer.ReadingListWillMoveEntry(this, | |
|
Olivier
2016/10/20 11:25:39
Comment on ReadingListWillMoveEntry is explicitly
gambard
2016/10/20 11:51:35
I changed the comment. I don't like using the remo
| |
| 149 std::distance(read_.begin(), result)); | |
| 150 } | |
| 151 | |
| 152 unread_.insert(unread_.begin(), std::move(*result)); | |
| 153 read_.erase(result); | |
| 154 | |
| 155 if (storageLayer_ && !IsPerformingBatchUpdates()) { | |
| 156 storageLayer_->SavePersistentUnreadList(read_); | |
| 157 storageLayer_->SavePersistentReadList(unread_); | |
| 158 } | |
| 159 for (ReadingListModelObserver& observer : observers_) { | |
| 160 observer.ReadingListDidApplyChanges(this); | |
| 161 } | |
| 162 } | |
| 140 | 163 |
| 141 void ReadingListModelImpl::MarkReadByURL(const GURL& url) { | 164 void ReadingListModelImpl::MarkReadByURL(const GURL& url) { |
| 142 DCHECK(loaded()); | 165 DCHECK(loaded()); |
| 143 ReadingListEntry entry(url, std::string()); | 166 ReadingListEntry entry(url, std::string()); |
| 144 auto result = std::find(unread_.begin(), unread_.end(), entry); | 167 auto result = std::find(unread_.begin(), unread_.end(), entry); |
| 145 if (result == unread_.end()) | 168 if (result == unread_.end()) |
| 146 return; | 169 return; |
| 147 | 170 |
| 148 for (auto& observer : observers_) { | 171 for (auto& observer : observers_) { |
| 149 observer.ReadingListWillMoveEntry(this, | 172 observer.ReadingListWillMoveEntry(this, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 | 289 |
| 267 void ReadingListModelImpl::EndBatchUpdates() { | 290 void ReadingListModelImpl::EndBatchUpdates() { |
| 268 ReadingListModel::EndBatchUpdates(); | 291 ReadingListModel::EndBatchUpdates(); |
| 269 if (IsPerformingBatchUpdates() || !storageLayer_) { | 292 if (IsPerformingBatchUpdates() || !storageLayer_) { |
| 270 return; | 293 return; |
| 271 } | 294 } |
| 272 storageLayer_->SavePersistentUnreadList(unread_); | 295 storageLayer_->SavePersistentUnreadList(unread_); |
| 273 storageLayer_->SavePersistentReadList(read_); | 296 storageLayer_->SavePersistentReadList(read_); |
| 274 storageLayer_->SavePersistentHasUnseen(hasUnseen_); | 297 storageLayer_->SavePersistentHasUnseen(hasUnseen_); |
| 275 } | 298 } |
| 299 | |
| 300 void ReadingListModelImpl::ClearModelForTest() { | |
| 301 for (auto& entry : read_) { | |
| 302 this->RemoveEntryByUrl(entry.URL()); | |
| 303 } | |
| 304 for (auto& entry : unread_) { | |
| 305 this->RemoveEntryByUrl(entry.URL()); | |
| 306 } | |
| 307 } | |
| OLD | NEW |