| 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" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/strings/string_util.h" |
| 15 #include "components/reading_list/ios/offline_url_utils.h" | 16 #include "components/reading_list/ios/offline_url_utils.h" |
| 16 #include "components/reading_list/ios/reading_list_entry.h" | 17 #include "components/reading_list/ios/reading_list_entry.h" |
| 17 #include "components/reading_list/ios/reading_list_model.h" | 18 #include "components/reading_list/ios/reading_list_model.h" |
| 18 #include "ios/chrome/browser/reading_list/reading_list_distiller_page_factory.h" | 19 #include "ios/chrome/browser/reading_list/reading_list_distiller_page_factory.h" |
| 19 #include "ios/web/public/web_thread.h" | 20 #include "ios/web/public/web_thread.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 // Status of the download when it ends, for UMA report. | 23 // Status of the download when it ends, for UMA report. |
| 23 // These match tools/metrics/histograms/histograms.xml. | 24 // These match tools/metrics/histograms/histograms.xml. |
| 24 enum UMADownloadStatus { | 25 enum UMADownloadStatus { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 const GURL& distilled_url, | 233 const GURL& distilled_url, |
| 233 URLDownloader::SuccessState success, | 234 URLDownloader::SuccessState success, |
| 234 const base::FilePath& distilled_path, | 235 const base::FilePath& distilled_path, |
| 235 const std::string& title) { | 236 const std::string& title) { |
| 236 DCHECK(reading_list_model_->loaded()); | 237 DCHECK(reading_list_model_->loaded()); |
| 237 if ((success == URLDownloader::DOWNLOAD_SUCCESS || | 238 if ((success == URLDownloader::DOWNLOAD_SUCCESS || |
| 238 success == URLDownloader::DOWNLOAD_EXISTS) && | 239 success == URLDownloader::DOWNLOAD_EXISTS) && |
| 239 !distilled_path.empty()) { | 240 !distilled_path.empty()) { |
| 240 reading_list_model_->SetEntryDistilledInfo(url, distilled_path, | 241 reading_list_model_->SetEntryDistilledInfo(url, distilled_path, |
| 241 distilled_url); | 242 distilled_url); |
| 242 if (!title.empty()) | 243 |
| 243 reading_list_model_->SetEntryTitle(url, title); | 244 std::string trimmed_title = base::CollapseWhitespaceASCII(title, false); |
| 245 if (!trimmed_title.empty()) |
| 246 reading_list_model_->SetEntryTitle(url, trimmed_title); |
| 244 | 247 |
| 245 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); | 248 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); |
| 246 if (entry) | 249 if (entry) |
| 247 UMA_HISTOGRAM_COUNTS_100("ReadingList.Download.Failures", | 250 UMA_HISTOGRAM_COUNTS_100("ReadingList.Download.Failures", |
| 248 entry->FailedDownloadCounter()); | 251 entry->FailedDownloadCounter()); |
| 249 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", SUCCESS, | 252 UMA_HISTOGRAM_ENUMERATION("ReadingList.Download.Status", SUCCESS, |
| 250 STATUS_MAX); | 253 STATUS_MAX); |
| 251 | 254 |
| 252 } else if (success == URLDownloader::ERROR_RETRY) { | 255 } else if (success == URLDownloader::ERROR_RETRY) { |
| 253 reading_list_model_->SetEntryDistilledState(url, | 256 reading_list_model_->SetEntryDistilledState(url, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 for (auto& url : url_to_download_cellular_) { | 291 for (auto& url : url_to_download_cellular_) { |
| 289 ScheduleDownloadEntry(url); | 292 ScheduleDownloadEntry(url); |
| 290 } | 293 } |
| 291 } | 294 } |
| 292 if (type == net::NetworkChangeNotifier::CONNECTION_WIFI) { | 295 if (type == net::NetworkChangeNotifier::CONNECTION_WIFI) { |
| 293 for (auto& url : url_to_download_wifi_) { | 296 for (auto& url : url_to_download_wifi_) { |
| 294 ScheduleDownloadEntry(url); | 297 ScheduleDownloadEntry(url); |
| 295 } | 298 } |
| 296 } | 299 } |
| 297 } | 300 } |
| OLD | NEW |