Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: components/offline_pages/core/downloads/download_ui_adapter.cc

Issue 2711693002: [Offline Pages] Make prerenderer notify us of network progress. (Closed)
Patch Set: last minute fixes Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 items_.erase(it); 317 items_.erase(it);
305 318
306 if (state_ != State::LOADED) 319 if (state_ != State::LOADED)
307 return; 320 return;
308 321
309 for (Observer& observer : observers_) 322 for (Observer& observer : observers_)
310 observer.ItemDeleted(guid); 323 observer.ItemDeleted(guid);
311 } 324 }
312 325
313 } // namespace offline_pages 326 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698