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

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

Issue 2284933002: Remove OfflineURL from offline page (Closed)
Patch Set: Fix trybot Created 4 years, 3 months 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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 } 526 }
527 527
528 const OfflinePageItem* OfflinePageModelImpl::MaybeGetPageByOfflineId( 528 const OfflinePageItem* OfflinePageModelImpl::MaybeGetPageByOfflineId(
529 int64_t offline_id) const { 529 int64_t offline_id) const {
530 const auto iter = offline_pages_.find(offline_id); 530 const auto iter = offline_pages_.find(offline_id);
531 return iter != offline_pages_.end() && !iter->second.IsExpired() 531 return iter != offline_pages_.end() && !iter->second.IsExpired()
532 ? &(iter->second) 532 ? &(iter->second)
533 : nullptr; 533 : nullptr;
534 } 534 }
535 535
536 void OfflinePageModelImpl::GetPageByOfflineURL(
537 const GURL& offline_url,
538 const SingleOfflinePageItemCallback& callback) {
539 RunWhenLoaded(
540 base::Bind(&OfflinePageModelImpl::GetPageByOfflineURLWhenLoadDone,
541 weak_ptr_factory_.GetWeakPtr(), offline_url, callback));
542 }
543
544 void OfflinePageModelImpl::GetPageByOfflineURLWhenLoadDone(
545 const GURL& offline_url,
546 const SingleOfflinePageItemCallback& callback) const {
547 // Getting pages by offline URL does not exclude expired pages, as the caller
548 // already holds the offline URL and simply needs to look up a corresponding
549 // online URL.
550 const OfflinePageItem* result = nullptr;
551
552 for (const auto& id_page_pair : offline_pages_) {
553 if (id_page_pair.second.GetOfflineURL() == offline_url) {
554 result = &id_page_pair.second;
555 break;
556 }
557 }
558
559 callback.Run(result);
560 }
561
562 const OfflinePageItem* OfflinePageModelImpl::MaybeGetPageByOfflineURL(
563 const GURL& offline_url) const {
564 // Getting pages by offline URL does not exclude expired pages, as the caller
565 // already holds the offline URL and simply needs to look up a corresponding
566 // online URL.
567 for (const auto& id_page_pair : offline_pages_) {
568 if (id_page_pair.second.GetOfflineURL() == offline_url)
569 return &(id_page_pair.second);
570 }
571 return nullptr;
572 }
573
574 void OfflinePageModelImpl::GetPagesByOnlineURL( 536 void OfflinePageModelImpl::GetPagesByOnlineURL(
575 const GURL& online_url, 537 const GURL& online_url,
576 const MultipleOfflinePageItemCallback& callback) { 538 const MultipleOfflinePageItemCallback& callback) {
577 RunWhenLoaded( 539 RunWhenLoaded(
578 base::Bind(&OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone, 540 base::Bind(&OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone,
579 weak_ptr_factory_.GetWeakPtr(), online_url, callback)); 541 weak_ptr_factory_.GetWeakPtr(), online_url, callback));
580 } 542 }
581 543
582 void OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone( 544 void OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone(
583 const GURL& online_url, 545 const GURL& online_url,
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { 1032 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) {
1071 if (!is_loaded_) { 1033 if (!is_loaded_) {
1072 delayed_tasks_.push_back(task); 1034 delayed_tasks_.push_back(task);
1073 return; 1035 return;
1074 } 1036 }
1075 1037
1076 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 1038 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
1077 } 1039 }
1078 1040
1079 } // namespace offline_pages 1041 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698