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

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

Issue 2565753002: Only distill unread items (Closed)
Patch Set: past tense in comments Created 4 years 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_download_service.h" 5 #include "ios/chrome/browser/reading_list/reading_list_download_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 const GURL& url) { 77 const GURL& url) {
78 DCHECK_EQ(reading_list_model_, model); 78 DCHECK_EQ(reading_list_model_, model);
79 DCHECK(model->GetEntryByURL(url)); 79 DCHECK(model->GetEntryByURL(url));
80 RemoveDownloadedEntry(url); 80 RemoveDownloadedEntry(url);
81 } 81 }
82 82
83 void ReadingListDownloadService::ReadingListDidAddEntry( 83 void ReadingListDownloadService::ReadingListDidAddEntry(
84 const ReadingListModel* model, 84 const ReadingListModel* model,
85 const GURL& url) { 85 const GURL& url) {
86 DCHECK_EQ(reading_list_model_, model); 86 DCHECK_EQ(reading_list_model_, model);
87 ScheduleDownloadEntry(url); 87 ProcessNewEntry(url);
88 }
89
90 void ReadingListDownloadService::ReadingListDidMoveEntry(
91 const ReadingListModel* model,
92 const GURL& url) {
93 DCHECK_EQ(reading_list_model_, model);
94 ProcessNewEntry(url);
95 }
96
97 void ReadingListDownloadService::ProcessNewEntry(const GURL& url) {
98 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url);
99 if (!entry || entry->IsRead()) {
100 url_downloader_->CancelDownloadOfflineURL(url);
101 } else {
102 ScheduleDownloadEntry(url);
103 }
88 } 104 }
89 105
90 void ReadingListDownloadService::DownloadAllEntries() { 106 void ReadingListDownloadService::DownloadAllEntries() {
91 DCHECK(reading_list_model_->loaded()); 107 DCHECK(reading_list_model_->loaded());
92 for (const auto& url : reading_list_model_->Keys()) { 108 for (const auto& url : reading_list_model_->Keys()) {
93 this->ScheduleDownloadEntry(url); 109 this->ScheduleDownloadEntry(url);
94 } 110 }
95 } 111 }
96 112
97 void ReadingListDownloadService::ScheduleDownloadEntry(const GURL& url) { 113 void ReadingListDownloadService::ScheduleDownloadEntry(const GURL& url) {
98 DCHECK(reading_list_model_->loaded()); 114 DCHECK(reading_list_model_->loaded());
99 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); 115 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url);
100 if (!entry || entry->DistilledState() == ReadingListEntry::ERROR || 116 if (!entry || entry->DistilledState() == ReadingListEntry::ERROR ||
101 entry->DistilledState() == ReadingListEntry::PROCESSED) 117 entry->DistilledState() == ReadingListEntry::PROCESSED || entry->IsRead())
102 return; 118 return;
103 GURL local_url(url); 119 GURL local_url(url);
104 web::WebThread::PostDelayedTask( 120 web::WebThread::PostDelayedTask(
105 web::WebThread::UI, FROM_HERE, 121 web::WebThread::UI, FROM_HERE,
106 base::Bind(&ReadingListDownloadService::DownloadEntry, 122 base::Bind(&ReadingListDownloadService::DownloadEntry,
107 weak_ptr_factory_.GetWeakPtr(), local_url), 123 weak_ptr_factory_.GetWeakPtr(), local_url),
108 entry->TimeUntilNextTry()); 124 entry->TimeUntilNextTry());
109 } 125 }
110 126
111 void ReadingListDownloadService::DownloadEntry(const GURL& url) { 127 void ReadingListDownloadService::DownloadEntry(const GURL& url) {
112 DCHECK(reading_list_model_->loaded()); 128 DCHECK(reading_list_model_->loaded());
113 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); 129 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url);
114 if (!entry || entry->DistilledState() == ReadingListEntry::ERROR || 130 if (!entry || entry->DistilledState() == ReadingListEntry::ERROR ||
115 entry->DistilledState() == ReadingListEntry::PROCESSED) 131 entry->DistilledState() == ReadingListEntry::PROCESSED || entry->IsRead())
116 return; 132 return;
117 133
118 if (net::NetworkChangeNotifier::IsOffline()) { 134 if (net::NetworkChangeNotifier::IsOffline()) {
119 // There is no connection, save it for download only if we did not exceed 135 // There is no connection, save it for download only if we did not exceed
120 // the maximaxum number of tries. 136 // the maximaxum number of tries.
121 if (entry->FailedDownloadCounter() < kNumberOfFailsBeforeWifiOnly) 137 if (entry->FailedDownloadCounter() < kNumberOfFailsBeforeWifiOnly)
122 url_to_download_cellular_.push_back(entry->URL()); 138 url_to_download_cellular_.push_back(entry->URL());
123 if (entry->FailedDownloadCounter() < kNumberOfFailsBeforeStop) 139 if (entry->FailedDownloadCounter() < kNumberOfFailsBeforeStop)
124 url_to_download_wifi_.push_back(entry->URL()); 140 url_to_download_wifi_.push_back(entry->URL());
125 return; 141 return;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 for (auto& url : url_to_download_cellular_) { 227 for (auto& url : url_to_download_cellular_) {
212 ScheduleDownloadEntry(url); 228 ScheduleDownloadEntry(url);
213 } 229 }
214 } 230 }
215 if (type == net::NetworkChangeNotifier::CONNECTION_WIFI) { 231 if (type == net::NetworkChangeNotifier::CONNECTION_WIFI) {
216 for (auto& url : url_to_download_wifi_) { 232 for (auto& url : url_to_download_wifi_) {
217 ScheduleDownloadEntry(url); 233 ScheduleDownloadEntry(url);
218 } 234 }
219 } 235 }
220 } 236 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/reading_list/reading_list_download_service.h ('k') | ios/chrome/browser/reading_list/url_downloader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698