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_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "ios/chrome/browser/reading_list/reading_list_entry.h" | 11 #include "ios/chrome/browser/reading_list/reading_list_entry.h" |
| 12 #include "ios/chrome/browser/reading_list/reading_list_model.h" | 12 #include "ios/chrome/browser/reading_list/reading_list_model.h" |
| 13 #include "ios/chrome/browser/reading_list/url_downloader.h" | |
| 14 | 13 |
| 15 ReadingListDownloadService::ReadingListDownloadService( | 14 ReadingListDownloadService::ReadingListDownloadService( |
| 16 ReadingListModel* reading_list_model, | 15 ReadingListModel* reading_list_model, |
| 17 dom_distiller::DomDistillerService* distiller_service, | 16 dom_distiller::DomDistillerService* distiller_service, |
| 18 PrefService* prefs, | 17 PrefService* prefs, |
| 19 base::FilePath chrome_profile_path) | 18 base::FilePath chrome_profile_path) |
| 20 : reading_list_model_(reading_list_model) { | 19 : reading_list_model_(reading_list_model) { |
| 21 DCHECK(reading_list_model); | 20 DCHECK(reading_list_model); |
| 22 url_downloader_ = std::unique_ptr<URLDownloader>( | 21 url_downloader_ = std::unique_ptr<URLDownloader>( |
| 23 new URLDownloader(distiller_service, prefs, chrome_profile_path, | 22 new URLDownloader(distiller_service, prefs, chrome_profile_path, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 } | 79 } |
| 81 size = reading_list_model_->read_size(); | 80 size = reading_list_model_->read_size(); |
| 82 for (size_t i = 0; i < size; i++) { | 81 for (size_t i = 0; i < size; i++) { |
| 83 ReadingListEntry entry = reading_list_model_->GetReadEntryAtIndex(i); | 82 ReadingListEntry entry = reading_list_model_->GetReadEntryAtIndex(i); |
| 84 this->DownloadEntry(entry); | 83 this->DownloadEntry(entry); |
| 85 } | 84 } |
| 86 } | 85 } |
| 87 | 86 |
| 88 void ReadingListDownloadService::DownloadEntry(const ReadingListEntry& entry) { | 87 void ReadingListDownloadService::DownloadEntry(const ReadingListEntry& entry) { |
| 89 DCHECK(reading_list_model_->loaded()); | 88 DCHECK(reading_list_model_->loaded()); |
| 90 url_downloader_->DownloadOfflineURL(entry.URL()); | 89 if (entry.DistilledState() != ReadingListEntry::ERROR) { |
| 90 reading_list_model_->SetEntryDistilledState(entry.URL(), | |
| 91 ReadingListEntry::PROCESSING); | |
| 92 url_downloader_->DownloadOfflineURL(entry.URL()); | |
| 93 } | |
| 91 } | 94 } |
| 92 | 95 |
| 93 void ReadingListDownloadService::RemoveDownloadedEntry( | 96 void ReadingListDownloadService::RemoveDownloadedEntry( |
| 94 const ReadingListEntry& entry) { | 97 const ReadingListEntry& entry) { |
| 95 DCHECK(reading_list_model_->loaded()); | 98 DCHECK(reading_list_model_->loaded()); |
| 96 url_downloader_->RemoveOfflineURL(entry.URL()); | 99 url_downloader_->RemoveOfflineURL(entry.URL()); |
| 97 } | 100 } |
| 98 | 101 |
| 99 void ReadingListDownloadService::OnDownloadEnd(const GURL& url, bool success) { | 102 void ReadingListDownloadService::OnDownloadEnd( |
| 100 // TODO(crbug.com/616747) update entry with offline info | 103 const GURL& url, |
| 104 URLDownloader::SuccessState success, | |
| 105 const GURL& distilledURL, | |
|
sdefresne
2016/09/09 09:58:57
style: s/distilledURL/distilled_url/
lody
2016/09/09 12:17:53
Done.
| |
| 106 const std::string& title) { | |
| 107 DCHECK(reading_list_model_->loaded()); | |
| 108 if ((success == URLDownloader::DOWNLOAD_SUCCESS || | |
| 109 success == URLDownloader::DOWNLOAD_EXISTS) && | |
| 110 distilledURL.is_valid()) { | |
| 111 reading_list_model_->SetEntryDistilledURL(url, distilledURL); | |
| 112 } else if (success == URLDownloader::ERROR_RETRY) { | |
| 113 reading_list_model_->SetEntryDistilledState(url, | |
| 114 ReadingListEntry::WILL_RETRY); | |
| 115 } else if (success == URLDownloader::ERROR_PERMANENT) { | |
| 116 reading_list_model_->SetEntryDistilledState(url, ReadingListEntry::ERROR); | |
| 117 } | |
| 101 } | 118 } |
| 102 | 119 |
| 103 void ReadingListDownloadService::OnDeleteEnd(const GURL& url, bool success) { | 120 void ReadingListDownloadService::OnDeleteEnd(const GURL& url, bool success) { |
| 104 // TODO(crbug.com/616747) update entry with offline info | 121 // Nothing to update as this is only called when deleting reading list entries |
| 105 } | 122 } |
| OLD | NEW |