| 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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 RunWhenLoaded( | 629 RunWhenLoaded( |
| 630 base::Bind(&OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone, | 630 base::Bind(&OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone, |
| 631 weak_ptr_factory_.GetWeakPtr(), online_url, callback)); | 631 weak_ptr_factory_.GetWeakPtr(), online_url, callback)); |
| 632 } | 632 } |
| 633 | 633 |
| 634 void OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone( | 634 void OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone( |
| 635 const GURL& online_url, | 635 const GURL& online_url, |
| 636 const MultipleOfflinePageItemCallback& callback) const { | 636 const MultipleOfflinePageItemCallback& callback) const { |
| 637 std::vector<OfflinePageItem> result; | 637 std::vector<OfflinePageItem> result; |
| 638 | 638 |
| 639 GURL::Replacements remove_params; |
| 640 remove_params.ClearRef(); |
| 641 |
| 642 GURL online_url_without_fragment = |
| 643 online_url.ReplaceComponents(remove_params); |
| 644 |
| 639 for (const auto& id_page_pair : offline_pages_) { | 645 for (const auto& id_page_pair : offline_pages_) { |
| 640 if (id_page_pair.second.url == online_url && | 646 if (id_page_pair.second.IsExpired()) |
| 641 !id_page_pair.second.IsExpired()) { | 647 continue; |
| 648 if (online_url == id_page_pair.second.url) { |
| 649 result.push_back(id_page_pair.second); |
| 650 continue; |
| 651 } |
| 652 // If the full URL does not match, try with the fragment identifier |
| 653 // stripped. |
| 654 if (online_url_without_fragment == |
| 655 id_page_pair.second.url.ReplaceComponents(remove_params)) { |
| 642 result.push_back(id_page_pair.second); | 656 result.push_back(id_page_pair.second); |
| 643 } | 657 } |
| 644 } | 658 } |
| 645 | 659 |
| 646 callback.Run(result); | 660 callback.Run(result); |
| 647 } | 661 } |
| 648 | 662 |
| 649 const OfflinePageItem* OfflinePageModelImpl::MaybeGetBestPageForOnlineURL( | 663 const OfflinePageItem* OfflinePageModelImpl::MaybeGetBestPageForOnlineURL( |
| 650 const GURL& online_url) const { | 664 const GURL& online_url) const { |
| 651 const OfflinePageItem* result = nullptr; | 665 const OfflinePageItem* result = nullptr; |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 } | 1155 } |
| 1142 | 1156 |
| 1143 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1157 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 1144 } | 1158 } |
| 1145 | 1159 |
| 1146 base::Time OfflinePageModelImpl::GetCurrentTime() const { | 1160 base::Time OfflinePageModelImpl::GetCurrentTime() const { |
| 1147 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); | 1161 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); |
| 1148 } | 1162 } |
| 1149 | 1163 |
| 1150 } // namespace offline_pages | 1164 } // namespace offline_pages |
| OLD | NEW |