| 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 "ios/chrome/browser/reading_list/reading_list_entry.h" | 12 #include "ios/chrome/browser/reading_list/reading_list_entry.h" |
| 12 #include "ios/chrome/browser/reading_list/reading_list_model.h" | 13 #include "ios/chrome/browser/reading_list/reading_list_model.h" |
| 13 | 14 |
| 14 ReadingListDownloadService::ReadingListDownloadService( | 15 ReadingListDownloadService::ReadingListDownloadService( |
| 15 ReadingListModel* reading_list_model, | 16 ReadingListModel* reading_list_model, |
| 16 dom_distiller::DomDistillerService* distiller_service, | 17 dom_distiller::DomDistillerService* distiller_service, |
| 17 PrefService* prefs, | 18 PrefService* prefs, |
| 18 base::FilePath chrome_profile_path) | 19 base::FilePath chrome_profile_path) |
| 19 : reading_list_model_(reading_list_model) { | 20 : reading_list_model_(reading_list_model) { |
| 20 DCHECK(reading_list_model); | 21 DCHECK(reading_list_model); |
| 21 url_downloader_ = std::unique_ptr<URLDownloader>( | 22 url_downloader_ = base::MakeUnique<URLDownloader>( |
| 22 new URLDownloader(distiller_service, prefs, chrome_profile_path, | 23 distiller_service, prefs, chrome_profile_path, |
| 23 base::Bind(&ReadingListDownloadService::OnDownloadEnd, | 24 base::Bind(&ReadingListDownloadService::OnDownloadEnd, |
| 24 base::Unretained(this)), | 25 base::Unretained(this)), |
| 25 base::Bind(&ReadingListDownloadService::OnDeleteEnd, | 26 base::Bind(&ReadingListDownloadService::OnDeleteEnd, |
| 26 base::Unretained(this)))); | 27 base::Unretained(this))); |
| 27 } | 28 } |
| 28 | 29 |
| 29 ReadingListDownloadService::~ReadingListDownloadService() {} | 30 ReadingListDownloadService::~ReadingListDownloadService() {} |
| 30 | 31 |
| 31 void ReadingListDownloadService::Initialize() { | 32 void ReadingListDownloadService::Initialize() { |
| 32 reading_list_model_->AddObserver(this); | 33 reading_list_model_->AddObserver(this); |
| 33 } | 34 } |
| 34 | 35 |
| 35 void ReadingListDownloadService::Shutdown() { | 36 void ReadingListDownloadService::Shutdown() { |
| 36 reading_list_model_->RemoveObserver(this); | 37 reading_list_model_->RemoveObserver(this); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 67 const ReadingListModel* model, | 68 const ReadingListModel* model, |
| 68 const ReadingListEntry& entry) { | 69 const ReadingListEntry& entry) { |
| 69 DCHECK_EQ(reading_list_model_, model); | 70 DCHECK_EQ(reading_list_model_, model); |
| 70 DownloadEntry(entry); | 71 DownloadEntry(entry); |
| 71 } | 72 } |
| 72 | 73 |
| 73 void ReadingListDownloadService::DownloadAllEntries() { | 74 void ReadingListDownloadService::DownloadAllEntries() { |
| 74 DCHECK(reading_list_model_->loaded()); | 75 DCHECK(reading_list_model_->loaded()); |
| 75 size_t size = reading_list_model_->unread_size(); | 76 size_t size = reading_list_model_->unread_size(); |
| 76 for (size_t i = 0; i < size; i++) { | 77 for (size_t i = 0; i < size; i++) { |
| 77 ReadingListEntry entry = reading_list_model_->GetUnreadEntryAtIndex(i); | 78 const ReadingListEntry& entry = |
| 79 reading_list_model_->GetUnreadEntryAtIndex(i); |
| 78 this->DownloadEntry(entry); | 80 this->DownloadEntry(entry); |
| 79 } | 81 } |
| 80 size = reading_list_model_->read_size(); | 82 size = reading_list_model_->read_size(); |
| 81 for (size_t i = 0; i < size; i++) { | 83 for (size_t i = 0; i < size; i++) { |
| 82 ReadingListEntry entry = reading_list_model_->GetReadEntryAtIndex(i); | 84 const ReadingListEntry& entry = reading_list_model_->GetReadEntryAtIndex(i); |
| 83 this->DownloadEntry(entry); | 85 this->DownloadEntry(entry); |
| 84 } | 86 } |
| 85 } | 87 } |
| 86 | 88 |
| 87 void ReadingListDownloadService::DownloadEntry(const ReadingListEntry& entry) { | 89 void ReadingListDownloadService::DownloadEntry(const ReadingListEntry& entry) { |
| 88 DCHECK(reading_list_model_->loaded()); | 90 DCHECK(reading_list_model_->loaded()); |
| 89 if (entry.DistilledState() != ReadingListEntry::ERROR) { | 91 if (entry.DistilledState() != ReadingListEntry::ERROR) { |
| 90 reading_list_model_->SetEntryDistilledState(entry.URL(), | 92 reading_list_model_->SetEntryDistilledState(entry.URL(), |
| 91 ReadingListEntry::PROCESSING); | 93 ReadingListEntry::PROCESSING); |
| 92 url_downloader_->DownloadOfflineURL(entry.URL()); | 94 url_downloader_->DownloadOfflineURL(entry.URL()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 113 reading_list_model_->SetEntryDistilledState(url, | 115 reading_list_model_->SetEntryDistilledState(url, |
| 114 ReadingListEntry::WILL_RETRY); | 116 ReadingListEntry::WILL_RETRY); |
| 115 } else if (success == URLDownloader::ERROR_PERMANENT) { | 117 } else if (success == URLDownloader::ERROR_PERMANENT) { |
| 116 reading_list_model_->SetEntryDistilledState(url, ReadingListEntry::ERROR); | 118 reading_list_model_->SetEntryDistilledState(url, ReadingListEntry::ERROR); |
| 117 } | 119 } |
| 118 } | 120 } |
| 119 | 121 |
| 120 void ReadingListDownloadService::OnDeleteEnd(const GURL& url, bool success) { | 122 void ReadingListDownloadService::OnDeleteEnd(const GURL& url, bool success) { |
| 121 // Nothing to update as this is only called when deleting reading list entries | 123 // Nothing to update as this is only called when deleting reading list entries |
| 122 } | 124 } |
| OLD | NEW |