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

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

Issue 2429943002: Remove all synchronous methods from OfflinePageBridge. (Closed)
Patch Set: Add some test, and remove unused functions. Created 4 years, 2 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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 InformDeletePageDone(callback, DeletePageResult::SUCCESS); 421 InformDeletePageDone(callback, DeletePageResult::SUCCESS);
422 return; 422 return;
423 } 423 }
424 424
425 archive_manager_->DeleteMultipleArchives( 425 archive_manager_->DeleteMultipleArchives(
426 paths_to_delete, 426 paths_to_delete,
427 base::Bind(&OfflinePageModelImpl::OnDeleteArchiveFilesDone, 427 base::Bind(&OfflinePageModelImpl::OnDeleteArchiveFilesDone,
428 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); 428 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback));
429 } 429 }
430 430
431 void OfflinePageModelImpl::DeletePagesByClientIds(
432 const std::vector<ClientId>& client_ids,
433 const DeletePageCallback& callback) {
434 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::DoDeletePagesByClientIds,
435 weak_ptr_factory_.GetWeakPtr(), client_ids,
436 callback));
437 }
438
439 void OfflinePageModelImpl::DoDeletePagesByClientIds(
440 const std::vector<ClientId>& client_ids,
441 const DeletePageCallback& callback) {
442 std::vector<ClientId> sorted_client_ids = client_ids;
443 std::sort(sorted_client_ids.begin(), sorted_client_ids.end());
jianli 2016/10/19 00:21:37 Why not using a set?
dewittj 2016/10/19 16:18:33 Done. The b-tree seemed like too much overhead fo
444
445 std::vector<int64_t> offline_ids;
446 for (const auto& page_pair : offline_pages_) {
447 if (std::binary_search(sorted_client_ids.begin(), sorted_client_ids.end(),
448 page_pair.second.client_id)) {
449 offline_ids.emplace_back(page_pair.first);
450 }
451 }
452
453 DoDeletePagesByOfflineId(offline_ids, callback);
454 }
455
456 void OfflinePageModelImpl::GetPagesByClientIds(
457 const std::vector<ClientId>& client_ids,
458 const MultipleOfflinePageItemCallback& callback) {
459 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::DoGetPagesByClientIds,
460 weak_ptr_factory_.GetWeakPtr(), client_ids,
461 callback));
462 }
463
464 void OfflinePageModelImpl::DoGetPagesByClientIds(
465 const std::vector<ClientId>& client_ids,
466 const MultipleOfflinePageItemCallback& callback) {
467 std::vector<ClientId> sorted_client_ids = client_ids;
468 std::sort(sorted_client_ids.begin(), sorted_client_ids.end());
jianli 2016/10/19 00:21:37 ditto
dewittj 2016/10/19 16:18:33 Done.
469
470 std::vector<OfflinePageItem> result;
471 for (const auto& page_pair : offline_pages_) {
472 if (std::binary_search(sorted_client_ids.begin(), sorted_client_ids.end(),
473 page_pair.second.client_id) &&
474 !page_pair.second.IsExpired()) {
475 result.emplace_back(page_pair.second);
476 }
477 }
478 callback.Run(result);
479 }
480
431 void OfflinePageModelImpl::DeleteCachedPagesByURLPredicate( 481 void OfflinePageModelImpl::DeleteCachedPagesByURLPredicate(
432 const UrlPredicate& predicate, 482 const UrlPredicate& predicate,
433 const DeletePageCallback& callback) { 483 const DeletePageCallback& callback) {
434 RunWhenLoaded( 484 RunWhenLoaded(
435 base::Bind(&OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate, 485 base::Bind(&OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate,
436 weak_ptr_factory_.GetWeakPtr(), predicate, callback)); 486 weak_ptr_factory_.GetWeakPtr(), predicate, callback));
437 } 487 }
438 488
439 void OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate( 489 void OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate(
440 const UrlPredicate& predicate, 490 const UrlPredicate& predicate,
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 // stripped. 638 // stripped.
589 if (online_url_without_fragment == 639 if (online_url_without_fragment ==
590 id_page_pair.second.url.ReplaceComponents(remove_params)) { 640 id_page_pair.second.url.ReplaceComponents(remove_params)) {
591 result.push_back(id_page_pair.second); 641 result.push_back(id_page_pair.second);
592 } 642 }
593 } 643 }
594 644
595 callback.Run(result); 645 callback.Run(result);
596 } 646 }
597 647
598 const OfflinePageItem* OfflinePageModelImpl::MaybeGetBestPageForOnlineURL(
599 const GURL& online_url) const {
600 const OfflinePageItem* result = nullptr;
601 for (const auto& id_page_pair : offline_pages_) {
602 if (id_page_pair.second.url == online_url &&
603 !id_page_pair.second.IsExpired()) {
604 if (!result || id_page_pair.second.creation_time > result->creation_time)
605 result = &(id_page_pair.second);
606 }
607 }
608 return result;
609 }
610
611 void OfflinePageModelImpl::CheckMetadataConsistency() { 648 void OfflinePageModelImpl::CheckMetadataConsistency() {
612 DCHECK(is_loaded_); 649 DCHECK(is_loaded_);
613 archive_manager_->GetAllArchives( 650 archive_manager_->GetAllArchives(
614 base::Bind(&OfflinePageModelImpl::CheckMetadataConsistencyForArchivePaths, 651 base::Bind(&OfflinePageModelImpl::CheckMetadataConsistencyForArchivePaths,
615 weak_ptr_factory_.GetWeakPtr())); 652 weak_ptr_factory_.GetWeakPtr()));
616 } 653 }
617 654
618 void OfflinePageModelImpl::ExpirePages( 655 void OfflinePageModelImpl::ExpirePages(
619 const std::vector<int64_t>& offline_ids, 656 const std::vector<int64_t>& offline_ids,
620 const base::Time& expiration_time, 657 const base::Time& expiration_time,
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 } 1085 }
1049 1086
1050 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 1087 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
1051 } 1088 }
1052 1089
1053 base::Time OfflinePageModelImpl::GetCurrentTime() const { 1090 base::Time OfflinePageModelImpl::GetCurrentTime() const {
1054 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); 1091 return testing_clock_ ? testing_clock_->Now() : base::Time::Now();
1055 } 1092 }
1056 1093
1057 } // namespace offline_pages 1094 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698