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 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 } | 550 } |
551 | 551 |
552 const OfflinePageItem* OfflinePageModelImpl::MaybeGetPageByOfflineId( | 552 const OfflinePageItem* OfflinePageModelImpl::MaybeGetPageByOfflineId( |
553 int64_t offline_id) const { | 553 int64_t offline_id) const { |
554 const auto iter = offline_pages_.find(offline_id); | 554 const auto iter = offline_pages_.find(offline_id); |
555 return iter != offline_pages_.end() && !iter->second.IsExpired() | 555 return iter != offline_pages_.end() && !iter->second.IsExpired() |
556 ? &(iter->second) | 556 ? &(iter->second) |
557 : nullptr; | 557 : nullptr; |
558 } | 558 } |
559 | 559 |
560 void OfflinePageModelImpl::GetPageByOfflineURL( | |
561 const GURL& offline_url, | |
562 const SingleOfflinePageItemCallback& callback) { | |
563 RunWhenLoaded( | |
564 base::Bind(&OfflinePageModelImpl::GetPageByOfflineURLWhenLoadDone, | |
565 weak_ptr_factory_.GetWeakPtr(), offline_url, callback)); | |
566 } | |
567 | |
568 void OfflinePageModelImpl::GetPageByOfflineURLWhenLoadDone( | |
569 const GURL& offline_url, | |
570 const SingleOfflinePageItemCallback& callback) const { | |
571 // Getting pages by offline URL does not exclude expired pages, as the caller | |
572 // already holds the offline URL and simply needs to look up a corresponding | |
573 // online URL. | |
574 const OfflinePageItem* result = nullptr; | |
575 | |
576 for (const auto& id_page_pair : offline_pages_) { | |
577 if (id_page_pair.second.GetOfflineURL() == offline_url) { | |
578 result = &id_page_pair.second; | |
579 break; | |
580 } | |
581 } | |
582 | |
583 callback.Run(result); | |
584 } | |
585 | |
586 const OfflinePageItem* OfflinePageModelImpl::MaybeGetPageByOfflineURL( | |
587 const GURL& offline_url) const { | |
588 // Getting pages by offline URL does not exclude expired pages, as the caller | |
589 // already holds the offline URL and simply needs to look up a corresponding | |
590 // online URL. | |
591 for (const auto& id_page_pair : offline_pages_) { | |
592 if (id_page_pair.second.GetOfflineURL() == offline_url) | |
593 return &(id_page_pair.second); | |
594 } | |
595 return nullptr; | |
596 } | |
597 | |
598 void OfflinePageModelImpl::GetPagesByOnlineURL( | 560 void OfflinePageModelImpl::GetPagesByOnlineURL( |
599 const GURL& online_url, | 561 const GURL& online_url, |
600 const MultipleOfflinePageItemCallback& callback) { | 562 const MultipleOfflinePageItemCallback& callback) { |
601 RunWhenLoaded( | 563 RunWhenLoaded( |
602 base::Bind(&OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone, | 564 base::Bind(&OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone, |
603 weak_ptr_factory_.GetWeakPtr(), online_url, callback)); | 565 weak_ptr_factory_.GetWeakPtr(), online_url, callback)); |
604 } | 566 } |
605 | 567 |
606 void OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone( | 568 void OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone( |
607 const GURL& online_url, | 569 const GURL& online_url, |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 } | 1033 } |
1072 | 1034 |
1073 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1035 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
1074 } | 1036 } |
1075 | 1037 |
1076 base::Time OfflinePageModelImpl::GetCurrentTime() const { | 1038 base::Time OfflinePageModelImpl::GetCurrentTime() const { |
1077 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); | 1039 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); |
1078 } | 1040 } |
1079 | 1041 |
1080 } // namespace offline_pages | 1042 } // namespace offline_pages |
OLD | NEW |