| 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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 | 471 |
| 472 std::vector<int64_t> offline_ids; | 472 std::vector<int64_t> offline_ids; |
| 473 for (const auto& id_page_pair : offline_pages_) { | 473 for (const auto& id_page_pair : offline_pages_) { |
| 474 if (!IsUserRequestedPage(id_page_pair.second) && | 474 if (!IsUserRequestedPage(id_page_pair.second) && |
| 475 predicate.Run(id_page_pair.second.url)) | 475 predicate.Run(id_page_pair.second.url)) |
| 476 offline_ids.push_back(id_page_pair.first); | 476 offline_ids.push_back(id_page_pair.first); |
| 477 } | 477 } |
| 478 DoDeletePagesByOfflineId(offline_ids, callback); | 478 DoDeletePagesByOfflineId(offline_ids, callback); |
| 479 } | 479 } |
| 480 | 480 |
| 481 void OfflinePageModelImpl::HasPages(const std::string& name_space, | |
| 482 const HasPagesCallback& callback) { | |
| 483 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::HasPagesAfterLoadDone, | |
| 484 weak_ptr_factory_.GetWeakPtr(), name_space, | |
| 485 callback)); | |
| 486 } | |
| 487 | |
| 488 void OfflinePageModelImpl::HasPagesAfterLoadDone( | |
| 489 const std::string& name_space, | |
| 490 const HasPagesCallback& callback) const { | |
| 491 DCHECK(is_loaded_); | |
| 492 | |
| 493 bool has_pages = false; | |
| 494 | |
| 495 for (const auto& id_page_pair : offline_pages_) { | |
| 496 if (id_page_pair.second.client_id.name_space == name_space && | |
| 497 !id_page_pair.second.IsExpired()) { | |
| 498 has_pages = true; | |
| 499 break; | |
| 500 } | |
| 501 } | |
| 502 | |
| 503 callback.Run(has_pages); | |
| 504 } | |
| 505 | |
| 506 void OfflinePageModelImpl::CheckPagesExistOffline( | 481 void OfflinePageModelImpl::CheckPagesExistOffline( |
| 507 const std::set<GURL>& urls, | 482 const std::set<GURL>& urls, |
| 508 const CheckPagesExistOfflineCallback& callback) { | 483 const CheckPagesExistOfflineCallback& callback) { |
| 509 RunWhenLoaded( | 484 RunWhenLoaded( |
| 510 base::Bind(&OfflinePageModelImpl::CheckPagesExistOfflineAfterLoadDone, | 485 base::Bind(&OfflinePageModelImpl::CheckPagesExistOfflineAfterLoadDone, |
| 511 weak_ptr_factory_.GetWeakPtr(), urls, callback)); | 486 weak_ptr_factory_.GetWeakPtr(), urls, callback)); |
| 512 } | 487 } |
| 513 | 488 |
| 514 void OfflinePageModelImpl::CheckPagesExistOfflineAfterLoadDone( | 489 void OfflinePageModelImpl::CheckPagesExistOfflineAfterLoadDone( |
| 515 const std::set<GURL>& urls, | 490 const std::set<GURL>& urls, |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 } | 1130 } |
| 1156 | 1131 |
| 1157 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1132 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 1158 } | 1133 } |
| 1159 | 1134 |
| 1160 base::Time OfflinePageModelImpl::GetCurrentTime() const { | 1135 base::Time OfflinePageModelImpl::GetCurrentTime() const { |
| 1161 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); | 1136 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); |
| 1162 } | 1137 } |
| 1163 | 1138 |
| 1164 } // namespace offline_pages | 1139 } // namespace offline_pages |
| OLD | NEW |