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

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

Issue 2469933002: Offline Pages: Replace Observer::OfflinePageModelChanged with OfflinePageAdded. (Closed)
Patch Set: Test fix 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 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 weak_ptr_factory_.GetWeakPtr(), archiver, 767 weak_ptr_factory_.GetWeakPtr(), archiver,
768 callback, offline_page_item)); 768 callback, offline_page_item));
769 } 769 }
770 770
771 void OfflinePageModelImpl::OnAddOfflinePageDone( 771 void OfflinePageModelImpl::OnAddOfflinePageDone(
772 OfflinePageArchiver* archiver, 772 OfflinePageArchiver* archiver,
773 const SavePageCallback& callback, 773 const SavePageCallback& callback,
774 const OfflinePageItem& offline_page, 774 const OfflinePageItem& offline_page,
775 ItemActionStatus status) { 775 ItemActionStatus status) {
776 SavePageResult result; 776 SavePageResult result;
777
777 if (status == ItemActionStatus::SUCCESS) { 778 if (status == ItemActionStatus::SUCCESS) {
778 offline_pages_[offline_page.offline_id] = offline_page; 779 offline_pages_[offline_page.offline_id] = offline_page;
779 result = SavePageResult::SUCCESS; 780 result = SavePageResult::SUCCESS;
780 ReportPageHistogramAfterSave(offline_pages_, offline_page, 781 ReportPageHistogramAfterSave(offline_pages_, offline_page,
781 GetCurrentTime()); 782 GetCurrentTime());
782 offline_event_logger_.RecordPageSaved( 783 offline_event_logger_.RecordPageSaved(
783 offline_page.client_id.name_space, offline_page.url.spec(), 784 offline_page.client_id.name_space, offline_page.url.spec(),
784 std::to_string(offline_page.offline_id)); 785 std::to_string(offline_page.offline_id));
785 } else if (status == ItemActionStatus::ALREADY_EXISTS) { 786 } else if (status == ItemActionStatus::ALREADY_EXISTS) {
786 result = SavePageResult::ALREADY_EXISTS; 787 result = SavePageResult::ALREADY_EXISTS;
787 } else { 788 } else {
788 result = SavePageResult::STORE_FAILURE; 789 result = SavePageResult::STORE_FAILURE;
789 } 790 }
790 InformSavePageDone(callback, result, offline_page.client_id, 791 InformSavePageDone(callback, result, offline_page.client_id,
791 offline_page.offline_id); 792 offline_page.offline_id);
792 if (result == SavePageResult::SUCCESS) { 793 if (result == SavePageResult::SUCCESS) {
793 DeleteExistingPagesWithSameURL(offline_page); 794 DeleteExistingPagesWithSameURL(offline_page);
794 } else { 795 } else {
795 PostClearStorageIfNeededTask(); 796 PostClearStorageIfNeededTask();
796 } 797 }
797 798
798 DeletePendingArchiver(archiver); 799 DeletePendingArchiver(archiver);
800
801 // We don't want to notify observers if the add failed.
802 if (result != SavePageResult::SUCCESS)
803 return;
804
799 for (Observer& observer : observers_) 805 for (Observer& observer : observers_)
800 observer.OfflinePageModelChanged(this); 806 observer.OfflinePageAdded(this, offline_page);
801 } 807 }
802 808
803 void OfflinePageModelImpl::OnMarkPageAccesseDone( 809 void OfflinePageModelImpl::OnMarkPageAccesseDone(
804 const OfflinePageItem& offline_page_item, 810 const OfflinePageItem& offline_page_item,
805 std::unique_ptr<OfflinePagesUpdateResult> result) { 811 std::unique_ptr<OfflinePagesUpdateResult> result) {
806 // Update the item in the cache only upon success. 812 // Update the item in the cache only upon success.
807 if (result->updated_items.size() > 0) 813 if (result->updated_items.size() > 0)
808 offline_pages_[offline_page_item.offline_id] = offline_page_item; 814 offline_pages_[offline_page_item.offline_id] = offline_page_item;
809 815
810 // No need to fire OfflinePageModelChanged event since updating access info 816 // No need to fire OfflinePageModelChanged event since updating access info
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 } 1094 }
1089 1095
1090 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 1096 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
1091 } 1097 }
1092 1098
1093 base::Time OfflinePageModelImpl::GetCurrentTime() const { 1099 base::Time OfflinePageModelImpl::GetCurrentTime() const {
1094 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); 1100 return testing_clock_ ? testing_clock_->Now() : base::Time::Now();
1095 } 1101 }
1096 1102
1097 } // namespace offline_pages 1103 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698