| 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/offline_page_model_impl.h" | 5 #include "components/offline_pages/offline_page_model_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 auto iter = urls.find(id_page_pair.second.url); | 443 auto iter = urls.find(id_page_pair.second.url); |
| 444 if (iter != urls.end()) | 444 if (iter != urls.end()) |
| 445 result.insert(*iter); | 445 result.insert(*iter); |
| 446 } | 446 } |
| 447 callback.Run(result); | 447 callback.Run(result); |
| 448 } | 448 } |
| 449 | 449 |
| 450 void OfflinePageModelImpl::GetAllPages( | 450 void OfflinePageModelImpl::GetAllPages( |
| 451 const MultipleOfflinePageItemCallback& callback) { | 451 const MultipleOfflinePageItemCallback& callback) { |
| 452 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::GetAllPagesAfterLoadDone, | 452 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::GetAllPagesAfterLoadDone, |
| 453 weak_ptr_factory_.GetWeakPtr(), callback)); | 453 weak_ptr_factory_.GetWeakPtr(), GetAllPageMode::ALL, |
| 454 callback)); |
| 455 } |
| 456 |
| 457 void OfflinePageModelImpl::GetAllPagesWithExpired( |
| 458 const MultipleOfflinePageItemCallback& callback) { |
| 459 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::GetAllPagesAfterLoadDone, |
| 460 weak_ptr_factory_.GetWeakPtr(), |
| 461 GetAllPageMode::ALL_WITH_EXPIRED, callback)); |
| 454 } | 462 } |
| 455 | 463 |
| 456 void OfflinePageModelImpl::GetAllPagesAfterLoadDone( | 464 void OfflinePageModelImpl::GetAllPagesAfterLoadDone( |
| 465 GetAllPageMode mode, |
| 457 const MultipleOfflinePageItemCallback& callback) const { | 466 const MultipleOfflinePageItemCallback& callback) const { |
| 458 DCHECK(is_loaded_); | 467 DCHECK(is_loaded_); |
| 459 | 468 |
| 460 MultipleOfflinePageItemResult offline_pages; | 469 MultipleOfflinePageItemResult offline_pages; |
| 461 for (const auto& id_page_pair : offline_pages_) { | 470 for (const auto& id_page_pair : offline_pages_) { |
| 462 if (!id_page_pair.second.IsExpired()) | 471 if (mode == GetAllPageMode::ALL_WITH_EXPIRED || |
| 472 !id_page_pair.second.IsExpired()) |
| 463 offline_pages.push_back(id_page_pair.second); | 473 offline_pages.push_back(id_page_pair.second); |
| 464 } | 474 } |
| 465 | 475 |
| 466 callback.Run(offline_pages); | 476 callback.Run(offline_pages); |
| 467 } | 477 } |
| 468 | 478 |
| 469 void OfflinePageModelImpl::GetOfflineIdsForClientId( | 479 void OfflinePageModelImpl::GetOfflineIdsForClientId( |
| 470 const ClientId& client_id, | 480 const ClientId& client_id, |
| 471 const MultipleOfflineIdCallback& callback) { | 481 const MultipleOfflineIdCallback& callback) { |
| 472 RunWhenLoaded( | 482 RunWhenLoaded( |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { | 1069 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { |
| 1060 if (!is_loaded_) { | 1070 if (!is_loaded_) { |
| 1061 delayed_tasks_.push_back(task); | 1071 delayed_tasks_.push_back(task); |
| 1062 return; | 1072 return; |
| 1063 } | 1073 } |
| 1064 | 1074 |
| 1065 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1075 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 1066 } | 1076 } |
| 1067 | 1077 |
| 1068 } // namespace offline_pages | 1078 } // namespace offline_pages |
| OLD | NEW |