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

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

Issue 2469933002: Offline Pages: Replace Observer::OfflinePageModelChanged with OfflinePageAdded. (Closed)
Patch Set: Rebase. Created 4 years 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 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 weak_ptr_factory_.GetWeakPtr(), archiver, 712 weak_ptr_factory_.GetWeakPtr(), archiver,
713 callback, offline_page_item)); 713 callback, offline_page_item));
714 } 714 }
715 715
716 void OfflinePageModelImpl::OnAddOfflinePageDone( 716 void OfflinePageModelImpl::OnAddOfflinePageDone(
717 OfflinePageArchiver* archiver, 717 OfflinePageArchiver* archiver,
718 const SavePageCallback& callback, 718 const SavePageCallback& callback,
719 const OfflinePageItem& offline_page, 719 const OfflinePageItem& offline_page,
720 ItemActionStatus status) { 720 ItemActionStatus status) {
721 SavePageResult result; 721 SavePageResult result;
722
722 if (status == ItemActionStatus::SUCCESS) { 723 if (status == ItemActionStatus::SUCCESS) {
723 offline_pages_[offline_page.offline_id] = offline_page; 724 offline_pages_[offline_page.offline_id] = offline_page;
724 result = SavePageResult::SUCCESS; 725 result = SavePageResult::SUCCESS;
725 ReportPageHistogramAfterSave(policy_controller_.get(), offline_pages_, 726 ReportPageHistogramAfterSave(policy_controller_.get(), offline_pages_,
726 offline_page, GetCurrentTime()); 727 offline_page, GetCurrentTime());
727 offline_event_logger_.RecordPageSaved( 728 offline_event_logger_.RecordPageSaved(
728 offline_page.client_id.name_space, offline_page.url.spec(), 729 offline_page.client_id.name_space, offline_page.url.spec(),
729 std::to_string(offline_page.offline_id)); 730 std::to_string(offline_page.offline_id));
730 } else if (status == ItemActionStatus::ALREADY_EXISTS) { 731 } else if (status == ItemActionStatus::ALREADY_EXISTS) {
731 result = SavePageResult::ALREADY_EXISTS; 732 result = SavePageResult::ALREADY_EXISTS;
732 } else { 733 } else {
733 result = SavePageResult::STORE_FAILURE; 734 result = SavePageResult::STORE_FAILURE;
734 } 735 }
735 InformSavePageDone(callback, result, offline_page.client_id, 736 InformSavePageDone(callback, result, offline_page.client_id,
736 offline_page.offline_id); 737 offline_page.offline_id);
737 if (result == SavePageResult::SUCCESS) { 738 if (result == SavePageResult::SUCCESS) {
738 DeleteExistingPagesWithSameURL(offline_page); 739 DeleteExistingPagesWithSameURL(offline_page);
739 } else { 740 } else {
740 PostClearStorageIfNeededTask(false /* delayed */); 741 PostClearStorageIfNeededTask(false /* delayed */);
741 } 742 }
742 743
743 DeletePendingArchiver(archiver); 744 DeletePendingArchiver(archiver);
745
746 // We don't want to notify observers if the add failed.
747 if (result != SavePageResult::SUCCESS)
748 return;
749
744 for (Observer& observer : observers_) 750 for (Observer& observer : observers_)
745 observer.OfflinePageModelChanged(this); 751 observer.OfflinePageAdded(this, offline_page);
746 } 752 }
747 753
748 void OfflinePageModelImpl::OnMarkPageAccesseDone( 754 void OfflinePageModelImpl::OnMarkPageAccesseDone(
749 const OfflinePageItem& offline_page_item, 755 const OfflinePageItem& offline_page_item,
750 std::unique_ptr<OfflinePagesUpdateResult> result) { 756 std::unique_ptr<OfflinePagesUpdateResult> result) {
751 // Update the item in the cache only upon success. 757 // Update the item in the cache only upon success.
752 if (result->updated_items.size() > 0) 758 if (result->updated_items.size() > 0)
753 offline_pages_[offline_page_item.offline_id] = offline_page_item; 759 offline_pages_[offline_page_item.offline_id] = offline_page_item;
754 760
755 // No need to fire OfflinePageModelChanged event since updating access info 761 // No need to fire OfflinePageModelChanged event since updating access info
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 } 1087 }
1082 1088
1083 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 1089 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
1084 } 1090 }
1085 1091
1086 base::Time OfflinePageModelImpl::GetCurrentTime() const { 1092 base::Time OfflinePageModelImpl::GetCurrentTime() const {
1087 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); 1093 return testing_clock_ ? testing_clock_->Now() : base::Time::Now();
1088 } 1094 }
1089 1095
1090 } // namespace offline_pages 1096 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698