| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 // comes back. | 196 // comes back. |
| 197 void DownloadUIAdapter::LoadCache() { | 197 void DownloadUIAdapter::LoadCache() { |
| 198 state_ = State::LOADING_PAGES; | 198 state_ = State::LOADING_PAGES; |
| 199 model_->GetAllPages(base::Bind(&DownloadUIAdapter::OnOfflinePagesLoaded, | 199 model_->GetAllPages(base::Bind(&DownloadUIAdapter::OnOfflinePagesLoaded, |
| 200 weak_ptr_factory_.GetWeakPtr())); | 200 weak_ptr_factory_.GetWeakPtr())); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void DownloadUIAdapter::ClearCache() { | 203 void DownloadUIAdapter::ClearCache() { |
| 204 // Once loaded, this class starts to observe the model. Only remove observer | 204 // Once loaded, this class starts to observe the model. Only remove observer |
| 205 // if it was added. | 205 // if it was added. |
| 206 if (state_ == State::LOADED) | 206 if (state_ == State::LOADED) { |
| 207 model_->RemoveObserver(this); | 207 model_->RemoveObserver(this); |
| 208 request_coordinator_->RemoveObserver(this); |
| 209 } |
| 208 items_.clear(); | 210 items_.clear(); |
| 209 state_ = State::NOT_LOADED; | 211 state_ = State::NOT_LOADED; |
| 210 } | 212 } |
| 211 | 213 |
| 212 void DownloadUIAdapter::OnOfflinePagesLoaded( | 214 void DownloadUIAdapter::OnOfflinePagesLoaded( |
| 213 const MultipleOfflinePageItemResult& pages) { | 215 const MultipleOfflinePageItemResult& pages) { |
| 214 // If multiple observers register quickly, the cache might be already loaded | 216 // If multiple observers register quickly, the cache might be already loaded |
| 215 // by the previous LoadCache call. At the same time, if all observers already | 217 // by the previous LoadCache call. At the same time, if all observers already |
| 216 // left, there is no reason to populate the cache. | 218 // left, there is no reason to populate the cache. |
| 217 if (state_ != State::LOADING_PAGES) | 219 if (state_ != State::LOADING_PAGES) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 items_.erase(it); | 304 items_.erase(it); |
| 303 | 305 |
| 304 if (state_ != State::LOADED) | 306 if (state_ != State::LOADED) |
| 305 return; | 307 return; |
| 306 | 308 |
| 307 for (Observer& observer : observers_) | 309 for (Observer& observer : observers_) |
| 308 observer.ItemDeleted(guid); | 310 observer.ItemDeleted(guid); |
| 309 } | 311 } |
| 310 | 312 |
| 311 } // namespace offline_pages | 313 } // namespace offline_pages |
| OLD | NEW |