OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/offline_pages/core/downloads/download_ui_adapter.h" | 5 #include "components/offline_pages/core/downloads/download_ui_adapter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/guid.h" | 8 #include "base/guid.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 items_[guid] = base::MakeUnique<ItemInfo>(request, temporarily_hidden); | 157 items_[guid] = base::MakeUnique<ItemInfo>(request, temporarily_hidden); |
158 | 158 |
159 if (state_ != State::LOADED) | 159 if (state_ != State::LOADED) |
160 return; | 160 return; |
161 | 161 |
162 const DownloadUIItem& download_ui_item = *(items_[guid]->ui_item); | 162 const DownloadUIItem& download_ui_item = *(items_[guid]->ui_item); |
163 for (Observer& observer : observers_) | 163 for (Observer& observer : observers_) |
164 observer.ItemUpdated(download_ui_item); | 164 observer.ItemUpdated(download_ui_item); |
165 } | 165 } |
166 | 166 |
| 167 void DownloadUIAdapter::OnNetworkProgress(const SavePageRequest& request, |
| 168 int64_t received_bytes) { |
| 169 for (auto& item : items_) { |
| 170 if (item.second->is_request && |
| 171 item.second->offline_id == request.request_id()) { |
| 172 if (received_bytes == item.second->ui_item->download_progress_bytes) |
| 173 return; |
| 174 |
| 175 item.second->ui_item->download_progress_bytes = received_bytes; |
| 176 for (Observer& observer : observers_) |
| 177 observer.ItemUpdated(*(item.second->ui_item)); |
| 178 return; |
| 179 } |
| 180 } |
| 181 } |
| 182 |
167 void DownloadUIAdapter::TemporaryHiddenStatusChanged( | 183 void DownloadUIAdapter::TemporaryHiddenStatusChanged( |
168 const ClientId& client_id) { | 184 const ClientId& client_id) { |
169 bool hidden = delegate_->IsTemporarilyHiddenInUI(client_id); | 185 bool hidden = delegate_->IsTemporarilyHiddenInUI(client_id); |
170 | 186 |
171 for (const auto& item : items_) { | 187 for (const auto& item : items_) { |
172 if (item.second->client_id == client_id) { | 188 if (item.second->client_id == client_id) { |
173 if (item.second->temporarily_hidden == hidden) | 189 if (item.second->temporarily_hidden == hidden) |
174 continue; | 190 continue; |
175 item.second->temporarily_hidden = hidden; | 191 item.second->temporarily_hidden = hidden; |
176 if (hidden) { | 192 if (hidden) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 int64_t DownloadUIAdapter::GetOfflineIdByGuid(const std::string& guid) const { | 235 int64_t DownloadUIAdapter::GetOfflineIdByGuid(const std::string& guid) const { |
220 if (deleting_item_ && deleting_item_->ui_item->guid == guid) | 236 if (deleting_item_ && deleting_item_->ui_item->guid == guid) |
221 return deleting_item_->offline_id; | 237 return deleting_item_->offline_id; |
222 | 238 |
223 DownloadUIItems::const_iterator it = items_.find(guid); | 239 DownloadUIItems::const_iterator it = items_.find(guid); |
224 if (it != items_.end()) | 240 if (it != items_.end()) |
225 return it->second->offline_id; | 241 return it->second->offline_id; |
226 return 0; | 242 return 0; |
227 } | 243 } |
228 | 244 |
229 void DownloadUIAdapter::UpdateProgress(int64_t offline_id, int64_t bytes) { | |
230 for (auto& item : items_) { | |
231 if (item.second->is_request && item.second->offline_id == offline_id) { | |
232 if (bytes == item.second->ui_item->download_progress_bytes) | |
233 return; | |
234 | |
235 item.second->ui_item->download_progress_bytes = bytes; | |
236 for (Observer& observer : observers_) | |
237 observer.ItemUpdated(*(item.second->ui_item)); | |
238 } | |
239 } | |
240 } | |
241 | |
242 // Note that several LoadCache calls may be issued before the async GetAllPages | 245 // Note that several LoadCache calls may be issued before the async GetAllPages |
243 // comes back. | 246 // comes back. |
244 void DownloadUIAdapter::LoadCache() { | 247 void DownloadUIAdapter::LoadCache() { |
245 state_ = State::LOADING_PAGES; | 248 state_ = State::LOADING_PAGES; |
246 model_->GetAllPages(base::Bind(&DownloadUIAdapter::OnOfflinePagesLoaded, | 249 model_->GetAllPages(base::Bind(&DownloadUIAdapter::OnOfflinePagesLoaded, |
247 weak_ptr_factory_.GetWeakPtr())); | 250 weak_ptr_factory_.GetWeakPtr())); |
248 } | 251 } |
249 | 252 |
250 void DownloadUIAdapter::ClearCache() { | 253 void DownloadUIAdapter::ClearCache() { |
251 // Once loaded, this class starts to observe the model. Only remove observer | 254 // Once loaded, this class starts to observe the model. Only remove observer |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 | 363 |
361 if (!deleting_item_->temporarily_hidden && state_ == State::LOADED) { | 364 if (!deleting_item_->temporarily_hidden && state_ == State::LOADED) { |
362 for (Observer& observer : observers_) | 365 for (Observer& observer : observers_) |
363 observer.ItemDeleted(guid); | 366 observer.ItemDeleted(guid); |
364 } | 367 } |
365 | 368 |
366 deleting_item_.reset(); | 369 deleting_item_.reset(); |
367 } | 370 } |
368 | 371 |
369 } // namespace offline_pages | 372 } // namespace offline_pages |
OLD | NEW |