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" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 void ReadingListDownloadService::Shutdown() { | 51 void ReadingListDownloadService::Shutdown() { |
| 52 reading_list_model_->RemoveObserver(this); | 52 reading_list_model_->RemoveObserver(this); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void ReadingListDownloadService::ReadingListModelLoaded( | 55 void ReadingListDownloadService::ReadingListModelLoaded( |
| 56 const ReadingListModel* model) { | 56 const ReadingListModel* model) { |
| 57 DCHECK_EQ(reading_list_model_, model); | 57 DCHECK_EQ(reading_list_model_, model); |
| 58 DownloadAllEntries(); | 58 DownloadAllEntries(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void ReadingListDownloadService::ReadingListWillRemoveReadEntry( | 61 void ReadingListDownloadService::ReadingListWillRemoveEntry( |
| 62 const ReadingListModel* model, | 62 const ReadingListModel* model, |
| 63 size_t index) { | 63 const GURL& url) { |
| 64 DCHECK_EQ(reading_list_model_, model); | 64 DCHECK_EQ(reading_list_model_, model); |
| 65 RemoveDownloadedEntry(model->GetReadEntryAtIndex(index)); | 65 const ReadingListEntry* entry = model->GetEntryFromURL(url); |
| 66 DCHECK(entry); | |
| 67 RemoveDownloadedEntry(*entry); | |
| 66 } | 68 } |
| 67 | 69 |
| 68 void ReadingListDownloadService::ReadingListWillRemoveUnreadEntry( | 70 void ReadingListDownloadService::ReadingListWillAddEntry( |
| 69 const ReadingListModel* model, | |
| 70 size_t index) { | |
| 71 DCHECK_EQ(reading_list_model_, model); | |
| 72 RemoveDownloadedEntry(model->GetUnreadEntryAtIndex(index)); | |
| 73 } | |
| 74 | |
| 75 void ReadingListDownloadService::ReadingListWillAddUnreadEntry( | |
| 76 const ReadingListModel* model, | 71 const ReadingListModel* model, |
| 77 const ReadingListEntry& entry) { | 72 const ReadingListEntry& entry) { |
| 78 DCHECK_EQ(reading_list_model_, model); | 73 DCHECK_EQ(reading_list_model_, model); |
| 79 ScheduleDownloadEntry(entry); | |
| 80 } | |
| 81 | |
| 82 void ReadingListDownloadService::ReadingListWillAddReadEntry( | |
| 83 const ReadingListModel* model, | |
| 84 const ReadingListEntry& entry) { | |
| 85 DCHECK_EQ(reading_list_model_, model); | |
| 86 ScheduleDownloadEntry(entry); | 74 ScheduleDownloadEntry(entry); |
| 87 } | 75 } |
| 88 | 76 |
| 89 void ReadingListDownloadService::DownloadAllEntries() { | 77 void ReadingListDownloadService::DownloadAllEntries() { |
| 90 DCHECK(reading_list_model_->loaded()); | 78 DCHECK(reading_list_model_->loaded()); |
| 91 size_t size = reading_list_model_->unread_size(); | 79 size_t size = reading_list_model_->unread_size(); |
| 92 for (size_t i = 0; i < size; i++) { | 80 for (size_t i = 0; i < size; i++) { |
| 93 const ReadingListEntry& entry = | 81 const ReadingListEntry* entry = reading_list_model_->GetUnreadEntryAt(i); |
| 94 reading_list_model_->GetUnreadEntryAtIndex(i); | 82 DCHECK(entry); |
| 95 this->ScheduleDownloadEntry(entry); | 83 this->ScheduleDownloadEntry(*entry); |
| 96 } | 84 } |
| 97 size = reading_list_model_->read_size(); | 85 size = reading_list_model_->read_size(); |
| 98 for (size_t i = 0; i < size; i++) { | 86 for (size_t i = 0; i < size; i++) { |
| 99 const ReadingListEntry& entry = reading_list_model_->GetReadEntryAtIndex(i); | 87 const ReadingListEntry* entry = reading_list_model_->GetReadEntryAt(i); |
| 100 this->ScheduleDownloadEntry(entry); | 88 DCHECK(entry); |
| 89 this->ScheduleDownloadEntry(*entry); | |
| 101 } | 90 } |
| 102 } | 91 } |
| 103 | 92 |
| 104 void ReadingListDownloadService::ScheduleDownloadEntry( | 93 void ReadingListDownloadService::ScheduleDownloadEntry( |
| 105 const ReadingListEntry& entry) { | 94 const ReadingListEntry& entry) { |
| 106 DCHECK(reading_list_model_->loaded()); | 95 DCHECK(reading_list_model_->loaded()); |
| 107 if (entry.DistilledState() == ReadingListEntry::ERROR || | 96 if (entry.DistilledState() == ReadingListEntry::ERROR || |
| 108 entry.DistilledState() == ReadingListEntry::PROCESSED) | 97 entry.DistilledState() == ReadingListEntry::PROCESSED) |
| 109 return; | 98 return; |
| 110 | 99 |
| 111 web::WebThread::PostDelayedTask( | 100 web::WebThread::PostDelayedTask( |
| 112 web::WebThread::UI, FROM_HERE, | 101 web::WebThread::UI, FROM_HERE, |
| 113 base::Bind(&ReadingListDownloadService::DownloadEntryFromURL, | 102 base::Bind(&ReadingListDownloadService::DownloadEntryFromURL, |
| 114 weak_ptr_factory_.GetWeakPtr(), entry.URL()), | 103 weak_ptr_factory_.GetWeakPtr(), entry.URL()), |
| 115 entry.TimeUntilNextTry()); | 104 entry.TimeUntilNextTry()); |
| 116 } | 105 } |
| 117 | 106 |
| 118 void ReadingListDownloadService::ScheduleDownloadEntryFromURL(const GURL& url) { | 107 void ReadingListDownloadService::ScheduleDownloadEntryFromURL(const GURL& url) { |
|
gambard
2016/11/23 12:11:06
Exist only because the entry could not been reques
Olivier
2016/11/28 14:54:13
Done.
| |
| 119 auto download_callback = | 108 auto download_callback = |
| 120 base::Bind(&ReadingListDownloadService::ScheduleDownloadEntry, | 109 base::Bind(&ReadingListDownloadService::ScheduleDownloadEntry, |
| 121 base::Unretained(this)); | 110 base::Unretained(this)); |
| 122 reading_list_model_->CallbackEntryURL(url, download_callback); | 111 reading_list_model_->CallbackEntryURL(url, download_callback); |
| 123 } | 112 } |
| 124 | 113 |
| 125 void ReadingListDownloadService::DownloadEntryFromURL(const GURL& url) { | 114 void ReadingListDownloadService::DownloadEntryFromURL(const GURL& url) { |
|
gambard
2016/11/23 12:11:06
Same as above.
Olivier
2016/11/28 14:54:14
Done.
| |
| 126 auto download_callback = base::Bind( | 115 auto download_callback = base::Bind( |
| 127 &ReadingListDownloadService::DownloadEntry, base::Unretained(this)); | 116 &ReadingListDownloadService::DownloadEntry, base::Unretained(this)); |
| 128 reading_list_model_->CallbackEntryURL(url, download_callback); | 117 reading_list_model_->CallbackEntryURL(url, download_callback); |
| 129 } | 118 } |
| 130 | 119 |
| 131 void ReadingListDownloadService::DownloadEntry(const ReadingListEntry& entry) { | 120 void ReadingListDownloadService::DownloadEntry(const ReadingListEntry& entry) { |
| 132 DCHECK(reading_list_model_->loaded()); | 121 DCHECK(reading_list_model_->loaded()); |
| 133 if (entry.DistilledState() == ReadingListEntry::ERROR || | 122 if (entry.DistilledState() == ReadingListEntry::ERROR || |
| 134 entry.DistilledState() == ReadingListEntry::PROCESSED) | 123 entry.DistilledState() == ReadingListEntry::PROCESSED) |
| 135 return; | 124 return; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 162 | 151 |
| 163 } else { | 152 } else { |
| 164 // The connection is not wifi, save it for download when the connection | 153 // The connection is not wifi, save it for download when the connection |
| 165 // changes to wifi. | 154 // changes to wifi. |
| 166 url_to_download_wifi_.push_back(entry.URL()); | 155 url_to_download_wifi_.push_back(entry.URL()); |
| 167 } | 156 } |
| 168 } | 157 } |
| 169 } | 158 } |
| 170 | 159 |
| 171 void ReadingListDownloadService::RemoveDownloadedEntry( | 160 void ReadingListDownloadService::RemoveDownloadedEntry( |
| 172 const ReadingListEntry& entry) { | 161 const ReadingListEntry& entry) { |
|
gambard
2016/11/23 12:11:06
This method only uses the URL. Pass the URL as arg
Olivier
2016/11/28 14:54:14
Done.
| |
| 173 DCHECK(reading_list_model_->loaded()); | 162 DCHECK(reading_list_model_->loaded()); |
| 174 url_downloader_->RemoveOfflineURL(entry.URL()); | 163 url_downloader_->RemoveOfflineURL(entry.URL()); |
| 175 } | 164 } |
| 176 | 165 |
| 177 void ReadingListDownloadService::OnDownloadEnd( | 166 void ReadingListDownloadService::OnDownloadEnd( |
| 178 const GURL& url, | 167 const GURL& url, |
| 179 URLDownloader::SuccessState success, | 168 URLDownloader::SuccessState success, |
| 180 const base::FilePath& distilled_path, | 169 const base::FilePath& distilled_path, |
| 181 const std::string& title) { | 170 const std::string& title) { |
| 182 DCHECK(reading_list_model_->loaded()); | 171 DCHECK(reading_list_model_->loaded()); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 211 for (auto& url : url_to_download_cellular_) { | 200 for (auto& url : url_to_download_cellular_) { |
| 212 ScheduleDownloadEntryFromURL(url); | 201 ScheduleDownloadEntryFromURL(url); |
| 213 } | 202 } |
| 214 } | 203 } |
| 215 if (type == net::NetworkChangeNotifier::CONNECTION_WIFI) { | 204 if (type == net::NetworkChangeNotifier::CONNECTION_WIFI) { |
| 216 for (auto& url : url_to_download_wifi_) { | 205 for (auto& url : url_to_download_wifi_) { |
| 217 ScheduleDownloadEntryFromURL(url); | 206 ScheduleDownloadEntryFromURL(url); |
| 218 } | 207 } |
| 219 } | 208 } |
| 220 } | 209 } |
| OLD | NEW |