| 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_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "components/reading_list/ios/offline_url_utils.h" | 13 #include "components/reading_list/ios/offline_url_utils.h" |
| 14 #include "components/reading_list/ios/reading_list_entry.h" | 14 #include "components/reading_list/ios/reading_list_entry.h" |
| 15 #include "components/reading_list/ios/reading_list_model.h" | 15 #include "components/reading_list/ios/reading_list_model.h" |
| 16 #include "ios/chrome/browser/reading_list/reading_list_distiller_page_factory.h" |
| 16 #include "ios/web/public/web_thread.h" | 17 #include "ios/web/public/web_thread.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 // Status of the download when it ends, for UMA report. | 20 // Status of the download when it ends, for UMA report. |
| 20 // These match tools/metrics/histograms/histograms.xml. | 21 // These match tools/metrics/histograms/histograms.xml. |
| 21 enum UMADownloadStatus { | 22 enum UMADownloadStatus { |
| 22 // The download was successful. | 23 // The download was successful. |
| 23 SUCCESS = 0, | 24 SUCCESS = 0, |
| 24 // The download failed and it won't be retried. | 25 // The download failed and it won't be retried. |
| 25 FAILURE = 1, | 26 FAILURE = 1, |
| 26 // The download failed and it will be retried. | 27 // The download failed and it will be retried. |
| 27 RETRY = 2, | 28 RETRY = 2, |
| 28 // Add new enum above STATUS_MAX. | 29 // Add new enum above STATUS_MAX. |
| 29 STATUS_MAX | 30 STATUS_MAX |
| 30 }; | 31 }; |
| 31 | 32 |
| 32 // Number of time the download must fail before the download occurs only in | 33 // Number of time the download must fail before the download occurs only in |
| 33 // wifi. | 34 // wifi. |
| 34 const int kNumberOfFailsBeforeWifiOnly = 5; | 35 const int kNumberOfFailsBeforeWifiOnly = 5; |
| 35 // Number of time the download must fail before we give up trying to download | 36 // Number of time the download must fail before we give up trying to download |
| 36 // it. | 37 // it. |
| 37 const int kNumberOfFailsBeforeStop = 7; | 38 const int kNumberOfFailsBeforeStop = 7; |
| 38 } // namespace | 39 } // namespace |
| 39 | 40 |
| 40 ReadingListDownloadService::ReadingListDownloadService( | 41 ReadingListDownloadService::ReadingListDownloadService( |
| 41 ReadingListModel* reading_list_model, | 42 ReadingListModel* reading_list_model, |
| 42 dom_distiller::DomDistillerService* distiller_service, | 43 dom_distiller::DomDistillerService* distiller_service, |
| 43 PrefService* prefs, | 44 PrefService* prefs, |
| 44 base::FilePath chrome_profile_path) | 45 base::FilePath chrome_profile_path, |
| 46 std::unique_ptr<reading_list::ReadingListDistillerPageFactory> |
| 47 distiller_page_factory) |
| 45 : reading_list_model_(reading_list_model), | 48 : reading_list_model_(reading_list_model), |
| 46 chrome_profile_path_(chrome_profile_path), | 49 chrome_profile_path_(chrome_profile_path), |
| 47 had_connection_(!net::NetworkChangeNotifier::IsOffline()), | 50 had_connection_(!net::NetworkChangeNotifier::IsOffline()), |
| 51 distiller_page_factory_(std::move(distiller_page_factory)), |
| 48 weak_ptr_factory_(this) { | 52 weak_ptr_factory_(this) { |
| 49 DCHECK(reading_list_model); | 53 DCHECK(reading_list_model); |
| 54 |
| 50 url_downloader_ = base::MakeUnique<URLDownloader>( | 55 url_downloader_ = base::MakeUnique<URLDownloader>( |
| 51 distiller_service, prefs, chrome_profile_path, | 56 distiller_service, distiller_page_factory_.get(), prefs, |
| 57 chrome_profile_path, |
| 52 base::Bind(&ReadingListDownloadService::OnDownloadEnd, | 58 base::Bind(&ReadingListDownloadService::OnDownloadEnd, |
| 53 base::Unretained(this)), | 59 base::Unretained(this)), |
| 54 base::Bind(&ReadingListDownloadService::OnDeleteEnd, | 60 base::Bind(&ReadingListDownloadService::OnDeleteEnd, |
| 55 base::Unretained(this))); | 61 base::Unretained(this))); |
| 56 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 62 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 57 } | 63 } |
| 58 | 64 |
| 59 ReadingListDownloadService::~ReadingListDownloadService() { | 65 ReadingListDownloadService::~ReadingListDownloadService() { |
| 60 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 66 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 61 } | 67 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 for (auto& url : url_to_download_cellular_) { | 239 for (auto& url : url_to_download_cellular_) { |
| 234 ScheduleDownloadEntry(url); | 240 ScheduleDownloadEntry(url); |
| 235 } | 241 } |
| 236 } | 242 } |
| 237 if (type == net::NetworkChangeNotifier::CONNECTION_WIFI) { | 243 if (type == net::NetworkChangeNotifier::CONNECTION_WIFI) { |
| 238 for (auto& url : url_to_download_wifi_) { | 244 for (auto& url : url_to_download_wifi_) { |
| 239 ScheduleDownloadEntry(url); | 245 ScheduleDownloadEntry(url); |
| 240 } | 246 } |
| 241 } | 247 } |
| 242 } | 248 } |
| OLD | NEW |