| 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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 // Getting pages by offline URL does not exclude expired pages, as the caller | 559 // Getting pages by offline URL does not exclude expired pages, as the caller |
| 560 // already holds the offline URL and simply needs to look up a corresponding | 560 // already holds the offline URL and simply needs to look up a corresponding |
| 561 // online URL. | 561 // online URL. |
| 562 for (const auto& id_page_pair : offline_pages_) { | 562 for (const auto& id_page_pair : offline_pages_) { |
| 563 if (id_page_pair.second.GetOfflineURL() == offline_url) | 563 if (id_page_pair.second.GetOfflineURL() == offline_url) |
| 564 return &(id_page_pair.second); | 564 return &(id_page_pair.second); |
| 565 } | 565 } |
| 566 return nullptr; | 566 return nullptr; |
| 567 } | 567 } |
| 568 | 568 |
| 569 void OfflinePageModelImpl::GetBestPageForOnlineURL( | |
| 570 const GURL& online_url, | |
| 571 const SingleOfflinePageItemCallback callback) { | |
| 572 RunWhenLoaded( | |
| 573 base::Bind(&OfflinePageModelImpl::GetBestPageForOnlineURLWhenLoadDone, | |
| 574 weak_ptr_factory_.GetWeakPtr(), online_url, callback)); | |
| 575 } | |
| 576 | |
| 577 void OfflinePageModelImpl::GetBestPageForOnlineURLWhenLoadDone( | |
| 578 const GURL& online_url, | |
| 579 const SingleOfflinePageItemCallback& callback) const { | |
| 580 callback.Run(MaybeGetBestPageForOnlineURL(online_url)); | |
| 581 } | |
| 582 | |
| 583 void OfflinePageModelImpl::GetPagesByOnlineURL( | 569 void OfflinePageModelImpl::GetPagesByOnlineURL( |
| 584 const GURL& online_url, | 570 const GURL& online_url, |
| 585 const MultipleOfflinePageItemCallback& callback) { | 571 const MultipleOfflinePageItemCallback& callback) { |
| 586 RunWhenLoaded( | 572 RunWhenLoaded( |
| 587 base::Bind(&OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone, | 573 base::Bind(&OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone, |
| 588 weak_ptr_factory_.GetWeakPtr(), online_url, callback)); | 574 weak_ptr_factory_.GetWeakPtr(), online_url, callback)); |
| 589 } | 575 } |
| 590 | 576 |
| 591 void OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone( | 577 void OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone( |
| 592 const GURL& online_url, | 578 const GURL& online_url, |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { | 1057 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { |
| 1072 if (!is_loaded_) { | 1058 if (!is_loaded_) { |
| 1073 delayed_tasks_.push_back(task); | 1059 delayed_tasks_.push_back(task); |
| 1074 return; | 1060 return; |
| 1075 } | 1061 } |
| 1076 | 1062 |
| 1077 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1063 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 1078 } | 1064 } |
| 1079 | 1065 |
| 1080 } // namespace offline_pages | 1066 } // namespace offline_pages |
| OLD | NEW |