Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/offline_page_model.h" | 5 #include "components/offline_pages/offline_page_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 for (const auto& id_page_pair : offline_pages_) | 277 for (const auto& id_page_pair : offline_pages_) |
| 278 bookmark_ids.push_back(id_page_pair.first); | 278 bookmark_ids.push_back(id_page_pair.first); |
| 279 DeletePagesByBookmarkId( | 279 DeletePagesByBookmarkId( |
| 280 bookmark_ids, | 280 bookmark_ids, |
| 281 base::Bind(&OfflinePageModel::OnRemoveAllFilesDoneForClearAll, | 281 base::Bind(&OfflinePageModel::OnRemoveAllFilesDoneForClearAll, |
| 282 weak_ptr_factory_.GetWeakPtr(), | 282 weak_ptr_factory_.GetWeakPtr(), |
| 283 callback)); | 283 callback)); |
| 284 } | 284 } |
| 285 | 285 |
| 286 bool OfflinePageModel::HasOfflinePages() const { | 286 bool OfflinePageModel::HasOfflinePages() const { |
| 287 DCHECK(is_loaded_); | 287 // Since offline pages feature is enabled by default, |
| 288 // NetErrorTabHelper::SetHasOfflinePages might call this before the model is | |
| 289 // fully loaded. If so, just bail out since this is most likely due to tests. | |
|
Dmitry Titov
2016/03/04 01:33:10
lets change the comment as discussed.
jianli
2016/03/04 02:01:07
Done.
| |
| 290 if (!is_loaded_) | |
| 291 return false; | |
| 292 | |
| 288 // Check that at least one page is not marked for deletion. Because we have | 293 // Check that at least one page is not marked for deletion. Because we have |
| 289 // pages marked for deletion, we cannot simply invert result of |empty()|. | 294 // pages marked for deletion, we cannot simply invert result of |empty()|. |
| 290 for (const auto& id_page_pair : offline_pages_) { | 295 for (const auto& id_page_pair : offline_pages_) { |
| 291 if (!id_page_pair.second.IsMarkedForDeletion()) | 296 if (!id_page_pair.second.IsMarkedForDeletion()) |
| 292 return true; | 297 return true; |
| 293 } | 298 } |
| 294 return false; | 299 return false; |
| 295 } | 300 } |
| 296 | 301 |
| 297 const std::vector<OfflinePageItem> OfflinePageModel::GetAllPages() const { | 302 const std::vector<OfflinePageItem> OfflinePageModel::GetAllPages() const { |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 } | 736 } |
| 732 | 737 |
| 733 void OfflinePageModel::CacheLoadedData( | 738 void OfflinePageModel::CacheLoadedData( |
| 734 const std::vector<OfflinePageItem>& offline_pages) { | 739 const std::vector<OfflinePageItem>& offline_pages) { |
| 735 offline_pages_.clear(); | 740 offline_pages_.clear(); |
| 736 for (const auto& offline_page : offline_pages) | 741 for (const auto& offline_page : offline_pages) |
| 737 offline_pages_[offline_page.bookmark_id] = offline_page; | 742 offline_pages_[offline_page.bookmark_id] = offline_page; |
| 738 } | 743 } |
| 739 | 744 |
| 740 } // namespace offline_pages | 745 } // namespace offline_pages |
| OLD | NEW |