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

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

Issue 2703773002: [IOS Reading List] Change handling of distillation error. (Closed)
Patch Set: feedback Created 3 years, 10 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
« no previous file with comments | « no previous file | ios/chrome/browser/reading_list/url_downloader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_enumerator.h" 10 #include "base/files/file_enumerator.h"
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 url_downloader_->RemoveOfflineURL(url); 228 url_downloader_->RemoveOfflineURL(url);
229 } 229 }
230 230
231 void ReadingListDownloadService::OnDownloadEnd( 231 void ReadingListDownloadService::OnDownloadEnd(
232 const GURL& url, 232 const GURL& url,
233 const GURL& distilled_url, 233 const GURL& distilled_url,
234 URLDownloader::SuccessState success, 234 URLDownloader::SuccessState success,
235 const base::FilePath& distilled_path, 235 const base::FilePath& distilled_path,
236 const std::string& title) { 236 const std::string& title) {
237 DCHECK(reading_list_model_->loaded()); 237 DCHECK(reading_list_model_->loaded());
238 if ((success == URLDownloader::DOWNLOAD_SUCCESS || 238 URLDownloader::SuccessState real_success_value = success;
239 success == URLDownloader::DOWNLOAD_EXISTS) && 239 if (distilled_path.empty()) {
240 !distilled_path.empty()) { 240 real_success_value = URLDownloader::ERROR;
241 reading_list_model_->SetEntryDistilledInfo(url, distilled_path, 241 }
242 distilled_url); 242 switch (real_success_value) {
243 case URLDownloader::DOWNLOAD_SUCCESS:
244 case URLDownloader::DOWNLOAD_EXISTS: {
245 reading_list_model_->SetEntryDistilledInfo(url, distilled_path,
246 distilled_url);
243 247
244 std::string trimmed_title = base::CollapseWhitespaceASCII(title, false); 248 std::string trimmed_title = base::CollapseWhitespaceASCII(title, false);
245 if (!trimmed_title.empty()) 249 if (!trimmed_title.empty())
246 reading_list_model_->SetEntryTitle(url, trimmed_title); 250 reading_list_model_->SetEntryTitle(url, trimmed_title);
247 251
248 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); 252 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url);
249 if (entry) 253 if (entry)
250 UMA_HISTOGRAM_COUNTS_100("ReadingList.Download.Failures", 254 UMA_HISTOGRAM_COUNTS_100("ReadingList.Download.Failures",
251 entry->FailedDownloadCounter()); 255 entry->FailedDownloadCounter());
252 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", SUCCESS, 256 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", SUCCESS,
253 STATUS_MAX); 257 STATUS_MAX);
254 258 break;
255 } else if (success == URLDownloader::ERROR_RETRY) { 259 }
256 reading_list_model_->SetEntryDistilledState(url, 260 case URLDownloader::ERROR: {
257 ReadingListEntry::WILL_RETRY); 261 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url);
258 ScheduleDownloadEntry(url); 262 // Add this failure to the total failure count.
259 263 if (entry &&
260 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); 264 entry->FailedDownloadCounter() + 1 < kNumberOfFailsBeforeStop) {
261 if (entry) { 265 reading_list_model_->SetEntryDistilledState(
262 if (entry->FailedDownloadCounter() < kNumberOfFailsBeforeStop) { 266 url, ReadingListEntry::WILL_RETRY);
267 ScheduleDownloadEntry(url);
263 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", RETRY, 268 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", RETRY,
264 STATUS_MAX); 269 STATUS_MAX);
265 } else { 270 } else {
266 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", FAILURE, 271 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", FAILURE,
267 STATUS_MAX); 272 STATUS_MAX);
273 reading_list_model_->SetEntryDistilledState(url,
274 ReadingListEntry::ERROR);
268 } 275 }
276 break;
269 } 277 }
270
271 } else if (success == URLDownloader::ERROR_PERMANENT) {
272 reading_list_model_->SetEntryDistilledState(url, ReadingListEntry::ERROR);
273 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", FAILURE,
274 STATUS_MAX);
275 } 278 }
276 } 279 }
277 280
278 void ReadingListDownloadService::OnDeleteEnd(const GURL& url, bool success) { 281 void ReadingListDownloadService::OnDeleteEnd(const GURL& url, bool success) {
279 // Nothing to update as this is only called when deleting reading list entries 282 // Nothing to update as this is only called when deleting reading list entries
280 } 283 }
281 284
282 void ReadingListDownloadService::OnConnectionTypeChanged( 285 void ReadingListDownloadService::OnConnectionTypeChanged(
283 net::NetworkChangeNotifier::ConnectionType type) { 286 net::NetworkChangeNotifier::ConnectionType type) {
284 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) { 287 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) {
285 had_connection_ = false; 288 had_connection_ = false;
286 return; 289 return;
287 } 290 }
288 291
289 if (!had_connection_) { 292 if (!had_connection_) {
290 had_connection_ = true; 293 had_connection_ = true;
291 for (auto& url : url_to_download_cellular_) { 294 for (auto& url : url_to_download_cellular_) {
292 ScheduleDownloadEntry(url); 295 ScheduleDownloadEntry(url);
293 } 296 }
294 } 297 }
295 if (type == net::NetworkChangeNotifier::CONNECTION_WIFI) { 298 if (type == net::NetworkChangeNotifier::CONNECTION_WIFI) {
296 for (auto& url : url_to_download_wifi_) { 299 for (auto& url : url_to_download_wifi_) {
297 ScheduleDownloadEntry(url); 300 ScheduleDownloadEntry(url);
298 } 301 }
299 } 302 }
300 } 303 }
OLDNEW
« no previous file with comments | « no previous file | ios/chrome/browser/reading_list/url_downloader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698