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

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

Issue 2607523002: Reading List: Open distilled article first if no network. (Closed)
Patch Set: add guards Created 3 years, 12 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/reading_list/ios/reading_list_model_impl.h" 5 #include "components/reading_list/ios/reading_list_model_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 return keys; 163 return keys;
164 } 164 }
165 165
166 const ReadingListEntry* ReadingListModelImpl::GetEntryByURL( 166 const ReadingListEntry* ReadingListModelImpl::GetEntryByURL(
167 const GURL& gurl) const { 167 const GURL& gurl) const {
168 DCHECK(CalledOnValidThread()); 168 DCHECK(CalledOnValidThread());
169 DCHECK(loaded()); 169 DCHECK(loaded());
170 return GetMutableEntryFromURL(gurl); 170 return GetMutableEntryFromURL(gurl);
171 } 171 }
172 172
173 const ReadingListEntry* ReadingListModelImpl::GetFirstUnreadEntry(
174 bool distilled) const {
175 DCHECK(CalledOnValidThread());
176 DCHECK(loaded());
177 if (unread_entry_count_ == 0) {
178 return nullptr;
179 }
180 int64_t update_time_all = 0;
181 const ReadingListEntry* first_entry_all = nullptr;
182 int64_t update_time_distilled = 0;
183 const ReadingListEntry* first_entry_distilled = nullptr;
184 for (auto& iterator : *entries_) {
185 ReadingListEntry& entry = iterator.second;
186 if (entry.IsRead()) {
187 continue;
188 }
189 if (entry.UpdateTime() > update_time_all) {
190 update_time_all = entry.UpdateTime();
191 first_entry_all = &entry;
192 }
193 if (entry.DistilledState() == ReadingListEntry::PROCESSED &&
194 entry.UpdateTime() > update_time_distilled) {
195 update_time_distilled = entry.UpdateTime();
196 first_entry_distilled = &entry;
197 }
198 }
199 DCHECK(first_entry_all);
200 DCHECK_GT(update_time_all, 0);
201 if (distilled && first_entry_distilled) {
202 return first_entry_distilled;
203 }
204 return first_entry_all;
205 }
206
173 ReadingListEntry* ReadingListModelImpl::GetMutableEntryFromURL( 207 ReadingListEntry* ReadingListModelImpl::GetMutableEntryFromURL(
174 const GURL& url) const { 208 const GURL& url) const {
175 DCHECK(CalledOnValidThread()); 209 DCHECK(CalledOnValidThread());
176 DCHECK(loaded()); 210 DCHECK(loaded());
177 auto iterator = entries_->find(url); 211 auto iterator = entries_->find(url);
178 if (iterator == entries_->end()) { 212 if (iterator == entries_->end()) {
179 return nullptr; 213 return nullptr;
180 } 214 }
181 return &(iterator->second); 215 return &(iterator->second);
182 } 216 }
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 syncer::ModelTypeSyncBridge* ReadingListModelImpl::GetModelTypeSyncBridge() { 476 syncer::ModelTypeSyncBridge* ReadingListModelImpl::GetModelTypeSyncBridge() {
443 DCHECK(loaded()); 477 DCHECK(loaded());
444 if (!storage_layer_) 478 if (!storage_layer_)
445 return nullptr; 479 return nullptr;
446 return storage_layer_.get(); 480 return storage_layer_.get();
447 } 481 }
448 482
449 ReadingListModelStorage* ReadingListModelImpl::StorageLayer() { 483 ReadingListModelStorage* ReadingListModelImpl::StorageLayer() {
450 return storage_layer_.get(); 484 return storage_layer_.get();
451 } 485 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698