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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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::ReadingListWillRemoveReadEntry( |
62 const ReadingListModel* model, | 62 const ReadingListModel* model, |
63 size_t index) { | 63 size_t index) { |
64 DCHECK_EQ(reading_list_model_, model); | 64 DCHECK_EQ(reading_list_model_, model); |
65 RemoveDownloadedEntry(model->GetReadEntryAtIndex(index)); | 65 const ReadingListEntry* entry = model->GetReadEntryAtIndex(index); |
66 if (entry) | |
67 RemoveDownloadedEntry(*entry); | |
66 } | 68 } |
67 | 69 |
68 void ReadingListDownloadService::ReadingListWillRemoveUnreadEntry( | 70 void ReadingListDownloadService::ReadingListWillRemoveUnreadEntry( |
69 const ReadingListModel* model, | 71 const ReadingListModel* model, |
70 size_t index) { | 72 size_t index) { |
71 DCHECK_EQ(reading_list_model_, model); | 73 DCHECK_EQ(reading_list_model_, model); |
72 RemoveDownloadedEntry(model->GetUnreadEntryAtIndex(index)); | 74 const ReadingListEntry* entry = model->GetUnreadEntryAtIndex(index); |
75 if (entry) | |
76 RemoveDownloadedEntry(*entry); | |
73 } | 77 } |
74 | 78 |
75 void ReadingListDownloadService::ReadingListWillAddUnreadEntry( | 79 void ReadingListDownloadService::ReadingListWillAddUnreadEntry( |
76 const ReadingListModel* model, | 80 const ReadingListModel* model, |
77 const ReadingListEntry& entry) { | 81 const ReadingListEntry& entry) { |
78 DCHECK_EQ(reading_list_model_, model); | 82 DCHECK_EQ(reading_list_model_, model); |
79 ScheduleDownloadEntry(entry); | 83 ScheduleDownloadEntry(entry); |
80 } | 84 } |
81 | 85 |
82 void ReadingListDownloadService::ReadingListWillAddReadEntry( | 86 void ReadingListDownloadService::ReadingListWillAddReadEntry( |
83 const ReadingListModel* model, | 87 const ReadingListModel* model, |
84 const ReadingListEntry& entry) { | 88 const ReadingListEntry& entry) { |
85 DCHECK_EQ(reading_list_model_, model); | 89 DCHECK_EQ(reading_list_model_, model); |
86 ScheduleDownloadEntry(entry); | 90 ScheduleDownloadEntry(entry); |
87 } | 91 } |
88 | 92 |
89 void ReadingListDownloadService::DownloadAllEntries() { | 93 void ReadingListDownloadService::DownloadAllEntries() { |
90 DCHECK(reading_list_model_->loaded()); | 94 DCHECK(reading_list_model_->loaded()); |
91 size_t size = reading_list_model_->unread_size(); | 95 size_t size = reading_list_model_->unread_size(); |
92 for (size_t i = 0; i < size; i++) { | 96 for (size_t i = 0; i < size; i++) { |
93 const ReadingListEntry& entry = | 97 const ReadingListEntry* entry = |
94 reading_list_model_->GetUnreadEntryAtIndex(i); | 98 reading_list_model_->GetUnreadEntryAtIndex(i); |
95 this->ScheduleDownloadEntry(entry); | 99 if (entry) |
sdefresne
2016/10/04 13:26:46
Can this be null? It look like it iterate over all
| |
100 this->ScheduleDownloadEntry(*entry); | |
96 } | 101 } |
97 size = reading_list_model_->read_size(); | 102 size = reading_list_model_->read_size(); |
98 for (size_t i = 0; i < size; i++) { | 103 for (size_t i = 0; i < size; i++) { |
99 const ReadingListEntry& entry = reading_list_model_->GetReadEntryAtIndex(i); | 104 const ReadingListEntry* entry = reading_list_model_->GetReadEntryAtIndex(i); |
100 this->ScheduleDownloadEntry(entry); | 105 if (entry) |
sdefresne
2016/10/04 13:26:46
ditto
| |
106 this->ScheduleDownloadEntry(*entry); | |
101 } | 107 } |
102 } | 108 } |
103 | 109 |
104 void ReadingListDownloadService::ScheduleDownloadEntry( | 110 void ReadingListDownloadService::ScheduleDownloadEntry( |
105 const ReadingListEntry& entry) { | 111 const ReadingListEntry& entry) { |
106 DCHECK(reading_list_model_->loaded()); | 112 DCHECK(reading_list_model_->loaded()); |
107 if (entry.DistilledState() == ReadingListEntry::ERROR || | 113 if (entry.DistilledState() == ReadingListEntry::ERROR || |
108 entry.DistilledState() == ReadingListEntry::PROCESSED) | 114 entry.DistilledState() == ReadingListEntry::PROCESSED) |
109 return; | 115 return; |
110 | 116 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 for (auto& url : url_to_download_cellular_) { | 217 for (auto& url : url_to_download_cellular_) { |
212 ScheduleDownloadEntryFromURL(url); | 218 ScheduleDownloadEntryFromURL(url); |
213 } | 219 } |
214 } | 220 } |
215 if (type == net::NetworkChangeNotifier::CONNECTION_WIFI) { | 221 if (type == net::NetworkChangeNotifier::CONNECTION_WIFI) { |
216 for (auto& url : url_to_download_wifi_) { | 222 for (auto& url : url_to_download_wifi_) { |
217 ScheduleDownloadEntryFromURL(url); | 223 ScheduleDownloadEntryFromURL(url); |
218 } | 224 } |
219 } | 225 } |
220 } | 226 } |
OLD | NEW |