Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(735)

Side by Side Diff: components/offline_pages/offline_page_model_impl.cc

Issue 2503853004: Support getting offline pages also by original URL (Closed)
Patch Set: Rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 } 601 }
602 }, 602 },
603 callback); 603 callback);
604 604
605 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::GetPagesMatchingQuery, 605 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::GetPagesMatchingQuery,
606 weak_ptr_factory_.GetWeakPtr(), 606 weak_ptr_factory_.GetWeakPtr(),
607 base::Passed(builder.Build(GetPolicyController())), 607 base::Passed(builder.Build(GetPolicyController())),
608 multiple_callback)); 608 multiple_callback));
609 } 609 }
610 610
611 void OfflinePageModelImpl::GetPagesByOnlineURL( 611 void OfflinePageModelImpl::GetPagesByURL(
612 const GURL& online_url, 612 const GURL& url,
613 bool search_by_final_url_only,
613 const MultipleOfflinePageItemCallback& callback) { 614 const MultipleOfflinePageItemCallback& callback) {
614 RunWhenLoaded( 615 RunWhenLoaded(
615 base::Bind(&OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone, 616 base::Bind(&OfflinePageModelImpl::GetPagesByURLWhenLoadDone,
616 weak_ptr_factory_.GetWeakPtr(), online_url, callback)); 617 weak_ptr_factory_.GetWeakPtr(), url,
618 search_by_final_url_only, callback));
617 } 619 }
618 620
619 void OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone( 621 void OfflinePageModelImpl::GetPagesByURLWhenLoadDone(
620 const GURL& online_url, 622 const GURL& url,
623 bool search_by_final_url_only,
621 const MultipleOfflinePageItemCallback& callback) const { 624 const MultipleOfflinePageItemCallback& callback) const {
622 std::vector<OfflinePageItem> result; 625 std::vector<OfflinePageItem> result;
623 626
624 GURL::Replacements remove_params; 627 GURL::Replacements remove_params;
625 remove_params.ClearRef(); 628 remove_params.ClearRef();
626 629
627 GURL online_url_without_fragment = 630 GURL url_without_fragment = url.ReplaceComponents(remove_params);
628 online_url.ReplaceComponents(remove_params);
629 631
630 for (const auto& id_page_pair : offline_pages_) { 632 for (const auto& id_page_pair : offline_pages_) {
631 if (id_page_pair.second.IsExpired()) 633 if (id_page_pair.second.IsExpired())
632 continue; 634 continue;
633 if (online_url == id_page_pair.second.url) { 635 if (url == id_page_pair.second.url ||
fgorski 2016/11/16 23:43:46 this does exact matching, whereas outside of this
jianli 2016/11/17 01:12:14 With more thought, changed to also search against
636 (!search_by_final_url_only && url ==
637 id_page_pair.second.original_url)) {
634 result.push_back(id_page_pair.second); 638 result.push_back(id_page_pair.second);
635 continue; 639 continue;
636 } 640 }
637 // If the full URL does not match, try with the fragment identifier 641 // If the full URL does not match, try with the fragment identifier
638 // stripped. 642 // stripped.
639 if (online_url_without_fragment == 643 if (url_without_fragment ==
640 id_page_pair.second.url.ReplaceComponents(remove_params)) { 644 id_page_pair.second.url.ReplaceComponents(remove_params)) {
641 result.push_back(id_page_pair.second); 645 result.push_back(id_page_pair.second);
642 } 646 }
643 } 647 }
644 648
645 callback.Run(result); 649 callback.Run(result);
646 } 650 }
647 651
648 void OfflinePageModelImpl::CheckMetadataConsistency() { 652 void OfflinePageModelImpl::CheckMetadataConsistency() {
649 DCHECK(is_loaded_); 653 DCHECK(is_loaded_);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 } 874 }
871 875
872 void OfflinePageModelImpl::DeleteExistingPagesWithSameURL( 876 void OfflinePageModelImpl::DeleteExistingPagesWithSameURL(
873 const OfflinePageItem& offline_page) { 877 const OfflinePageItem& offline_page) {
874 // Remove existing pages generated by the same policy and with same url. 878 // Remove existing pages generated by the same policy and with same url.
875 size_t pages_allowed = 879 size_t pages_allowed =
876 policy_controller_->GetPolicy(offline_page.client_id.name_space) 880 policy_controller_->GetPolicy(offline_page.client_id.name_space)
877 .pages_allowed_per_url; 881 .pages_allowed_per_url;
878 if (pages_allowed == kUnlimitedPages) 882 if (pages_allowed == kUnlimitedPages)
879 return; 883 return;
880 GetPagesByOnlineURL( 884 GetPagesByURL(
881 offline_page.url, 885 offline_page.url,
886 true /* search_by_final_url_only */,
882 base::Bind(&OfflinePageModelImpl::OnPagesFoundWithSameURL, 887 base::Bind(&OfflinePageModelImpl::OnPagesFoundWithSameURL,
883 weak_ptr_factory_.GetWeakPtr(), offline_page, pages_allowed)); 888 weak_ptr_factory_.GetWeakPtr(), offline_page, pages_allowed));
884 } 889 }
885 890
886 void OfflinePageModelImpl::OnPagesFoundWithSameURL( 891 void OfflinePageModelImpl::OnPagesFoundWithSameURL(
887 const OfflinePageItem& offline_page, 892 const OfflinePageItem& offline_page,
888 size_t pages_allowed, 893 size_t pages_allowed,
889 const MultipleOfflinePageItemResult& items) { 894 const MultipleOfflinePageItemResult& items) {
890 std::vector<OfflinePageItem> pages_to_delete; 895 std::vector<OfflinePageItem> pages_to_delete;
891 for (const auto& item : items) { 896 for (const auto& item : items) {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 } 1094 }
1090 1095
1091 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 1096 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
1092 } 1097 }
1093 1098
1094 base::Time OfflinePageModelImpl::GetCurrentTime() const { 1099 base::Time OfflinePageModelImpl::GetCurrentTime() const {
1095 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); 1100 return testing_clock_ ? testing_clock_->Now() : base::Time::Now();
1096 } 1101 }
1097 1102
1098 } // namespace offline_pages 1103 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698