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_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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 if (!trimmed_title.empty()) | 245 if (!trimmed_title.empty()) |
| 246 reading_list_model_->SetEntryTitle(url, trimmed_title); | 246 reading_list_model_->SetEntryTitle(url, trimmed_title); |
| 247 | 247 |
| 248 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); | 248 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); |
| 249 if (entry) | 249 if (entry) |
| 250 UMA_HISTOGRAM_COUNTS_100("ReadingList.Download.Failures", | 250 UMA_HISTOGRAM_COUNTS_100("ReadingList.Download.Failures", |
| 251 entry->FailedDownloadCounter()); | 251 entry->FailedDownloadCounter()); |
| 252 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", SUCCESS, | 252 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", SUCCESS, |
| 253 STATUS_MAX); | 253 STATUS_MAX); |
| 254 | 254 |
| 255 } else if (success == URLDownloader::ERROR_RETRY) { | 255 } else if (success == URLDownloader::ERROR) { |
| 256 reading_list_model_->SetEntryDistilledState(url, | |
| 257 ReadingListEntry::WILL_RETRY); | |
| 258 ScheduleDownloadEntry(url); | |
| 259 | |
| 260 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); | 256 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); |
| 257 bool will_retry = false; | |
| 261 if (entry) { | 258 if (entry) { |
| 262 if (entry->FailedDownloadCounter() < kNumberOfFailsBeforeStop) { | 259 // Add this failure to the total failure count. |
| 260 if (entry->FailedDownloadCounter() + 1 < kNumberOfFailsBeforeStop) { | |
| 263 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", RETRY, | 261 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", RETRY, |
| 264 STATUS_MAX); | 262 STATUS_MAX); |
| 263 will_retry = true; | |
| 265 } else { | 264 } else { |
| 266 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", FAILURE, | 265 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", FAILURE, |
| 267 STATUS_MAX); | 266 STATUS_MAX); |
| 268 } | 267 } |
| 269 } | 268 } |
| 269 if (will_retry) { | |
|
gambard
2017/02/17 14:07:47
Why this is not merged with the metrics?
Is there
Olivier
2017/02/17 14:27:15
It is not merged precisely to not retry if entry d
| |
| 270 reading_list_model_->SetEntryDistilledState(url, | |
| 271 ReadingListEntry::WILL_RETRY); | |
| 272 ScheduleDownloadEntry(url); | |
| 273 } else { | |
| 274 reading_list_model_->SetEntryDistilledState(url, ReadingListEntry::ERROR); | |
| 275 } | |
| 270 | 276 |
| 271 } else if (success == URLDownloader::ERROR_PERMANENT) { | 277 } else { |
| 272 reading_list_model_->SetEntryDistilledState(url, ReadingListEntry::ERROR); | 278 // Catch if another status is added. |
|
gambard
2017/02/17 14:07:47
Use a switch?
Olivier
2017/02/17 14:27:15
Done.
| |
| 273 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", FAILURE, | 279 NOTREACHED(); |
| 274 STATUS_MAX); | |
| 275 } | 280 } |
| 276 } | 281 } |
| 277 | 282 |
| 278 void ReadingListDownloadService::OnDeleteEnd(const GURL& url, bool success) { | 283 void ReadingListDownloadService::OnDeleteEnd(const GURL& url, bool success) { |
| 279 // Nothing to update as this is only called when deleting reading list entries | 284 // Nothing to update as this is only called when deleting reading list entries |
| 280 } | 285 } |
| 281 | 286 |
| 282 void ReadingListDownloadService::OnConnectionTypeChanged( | 287 void ReadingListDownloadService::OnConnectionTypeChanged( |
| 283 net::NetworkChangeNotifier::ConnectionType type) { | 288 net::NetworkChangeNotifier::ConnectionType type) { |
| 284 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) { | 289 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) { |
| 285 had_connection_ = false; | 290 had_connection_ = false; |
| 286 return; | 291 return; |
| 287 } | 292 } |
| 288 | 293 |
| 289 if (!had_connection_) { | 294 if (!had_connection_) { |
| 290 had_connection_ = true; | 295 had_connection_ = true; |
| 291 for (auto& url : url_to_download_cellular_) { | 296 for (auto& url : url_to_download_cellular_) { |
| 292 ScheduleDownloadEntry(url); | 297 ScheduleDownloadEntry(url); |
| 293 } | 298 } |
| 294 } | 299 } |
| 295 if (type == net::NetworkChangeNotifier::CONNECTION_WIFI) { | 300 if (type == net::NetworkChangeNotifier::CONNECTION_WIFI) { |
| 296 for (auto& url : url_to_download_wifi_) { | 301 for (auto& url : url_to_download_wifi_) { |
| 297 ScheduleDownloadEntry(url); | 302 ScheduleDownloadEntry(url); |
| 298 } | 303 } |
| 299 } | 304 } |
| 300 } | 305 } |
| OLD | NEW |