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 "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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 weak_ptr_factory_.GetWeakPtr())); | 185 weak_ptr_factory_.GetWeakPtr())); |
186 } | 186 } |
187 | 187 |
188 int64_t DownloadUIAdapter::GetOfflineIdByGuid(const std::string& guid) const { | 188 int64_t DownloadUIAdapter::GetOfflineIdByGuid(const std::string& guid) const { |
189 DownloadUIItems::const_iterator it = items_.find(guid); | 189 DownloadUIItems::const_iterator it = items_.find(guid); |
190 if (it != items_.end()) | 190 if (it != items_.end()) |
191 return it->second->offline_id; | 191 return it->second->offline_id; |
192 return 0; | 192 return 0; |
193 } | 193 } |
194 | 194 |
| 195 void DownloadUIAdapter::UpdateProgress(int64_t offline_id, int64_t bytes) { |
| 196 for (auto& item : items_) { |
| 197 if (item.second->is_request && item.second->offline_id == offline_id) { |
| 198 if (bytes == item.second->ui_item->download_progress_bytes) |
| 199 return; |
| 200 |
| 201 item.second->ui_item->download_progress_bytes = bytes; |
| 202 for (Observer& observer : observers_) |
| 203 observer.ItemUpdated(*(item.second->ui_item)); |
| 204 } |
| 205 } |
| 206 } |
| 207 |
195 // Note that several LoadCache calls may be issued before the async GetAllPages | 208 // Note that several LoadCache calls may be issued before the async GetAllPages |
196 // comes back. | 209 // comes back. |
197 void DownloadUIAdapter::LoadCache() { | 210 void DownloadUIAdapter::LoadCache() { |
198 state_ = State::LOADING_PAGES; | 211 state_ = State::LOADING_PAGES; |
199 model_->GetAllPages(base::Bind(&DownloadUIAdapter::OnOfflinePagesLoaded, | 212 model_->GetAllPages(base::Bind(&DownloadUIAdapter::OnOfflinePagesLoaded, |
200 weak_ptr_factory_.GetWeakPtr())); | 213 weak_ptr_factory_.GetWeakPtr())); |
201 } | 214 } |
202 | 215 |
203 void DownloadUIAdapter::ClearCache() { | 216 void DownloadUIAdapter::ClearCache() { |
204 // Once loaded, this class starts to observe the model. Only remove observer | 217 // Once loaded, this class starts to observe the model. Only remove observer |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 items_.erase(it); | 315 items_.erase(it); |
303 | 316 |
304 if (state_ != State::LOADED) | 317 if (state_ != State::LOADED) |
305 return; | 318 return; |
306 | 319 |
307 for (Observer& observer : observers_) | 320 for (Observer& observer : observers_) |
308 observer.ItemDeleted(guid); | 321 observer.ItemDeleted(guid); |
309 } | 322 } |
310 | 323 |
311 } // namespace offline_pages | 324 } // namespace offline_pages |
OLD | NEW |