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

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

Issue 2444753002: Reduce usage of FOR_EACH_OBSERVER macro in components/ (Closed)
Patch Set: 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 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 } 783 }
784 InformSavePageDone(callback, result, offline_page.client_id, 784 InformSavePageDone(callback, result, offline_page.client_id,
785 offline_page.offline_id); 785 offline_page.offline_id);
786 if (result == SavePageResult::SUCCESS) { 786 if (result == SavePageResult::SUCCESS) {
787 DeleteExistingPagesWithSameURL(offline_page); 787 DeleteExistingPagesWithSameURL(offline_page);
788 } else { 788 } else {
789 PostClearStorageIfNeededTask(); 789 PostClearStorageIfNeededTask();
790 } 790 }
791 791
792 DeletePendingArchiver(archiver); 792 DeletePendingArchiver(archiver);
793 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelChanged(this)); 793 for (Observer& observer : observers_)
794 observer.OfflinePageModelChanged(this);
794 } 795 }
795 796
796 void OfflinePageModelImpl::OnMarkPageAccesseDone( 797 void OfflinePageModelImpl::OnMarkPageAccesseDone(
797 const OfflinePageItem& offline_page_item, 798 const OfflinePageItem& offline_page_item,
798 std::unique_ptr<OfflinePagesUpdateResult> result) { 799 std::unique_ptr<OfflinePagesUpdateResult> result) {
799 // Update the item in the cache only upon success. 800 // Update the item in the cache only upon success.
800 if (result->updated_items.size() > 0) 801 if (result->updated_items.size() > 0)
801 offline_pages_[offline_page_item.offline_id] = offline_page_item; 802 offline_pages_[offline_page_item.offline_id] = offline_page_item;
802 803
803 // No need to fire OfflinePageModelChanged event since updating access info 804 // No need to fire OfflinePageModelChanged event since updating access info
(...skipping 27 matching lines...) Expand all
831 832
832 // Create Storage Manager. 833 // Create Storage Manager.
833 storage_manager_.reset(new OfflinePageStorageManager( 834 storage_manager_.reset(new OfflinePageStorageManager(
834 this, GetPolicyController(), archive_manager_.get())); 835 this, GetPolicyController(), archive_manager_.get()));
835 836
836 // Run all the delayed tasks. 837 // Run all the delayed tasks.
837 for (const auto& delayed_task : delayed_tasks_) 838 for (const auto& delayed_task : delayed_tasks_)
838 delayed_task.Run(); 839 delayed_task.Run();
839 delayed_tasks_.clear(); 840 delayed_tasks_.clear();
840 841
841 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelLoaded(this)); 842 for (Observer& observer : observers_)
843 observer.OfflinePageModelLoaded(this);
842 844
843 CheckMetadataConsistency(); 845 CheckMetadataConsistency();
844 846
845 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 847 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
846 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, 848 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded,
847 weak_ptr_factory_.GetWeakPtr(), 849 weak_ptr_factory_.GetWeakPtr(),
848 base::Bind(&OfflinePageModelImpl::OnStorageCleared, 850 base::Bind(&OfflinePageModelImpl::OnStorageCleared,
849 weak_ptr_factory_.GetWeakPtr())), 851 weak_ptr_factory_.GetWeakPtr())),
850 kStorageManagerStartingDelay); 852 kStorageManagerStartingDelay);
851 } 853 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 for (const auto& page : result->updated_items) { 942 for (const auto& page : result->updated_items) {
941 int64_t offline_id = page.offline_id; 943 int64_t offline_id = page.offline_id;
942 offline_event_logger_.RecordPageDeleted(std::to_string(offline_id)); 944 offline_event_logger_.RecordPageDeleted(std::to_string(offline_id));
943 auto iter = offline_pages_.find(offline_id); 945 auto iter = offline_pages_.find(offline_id);
944 if (iter == offline_pages_.end()) 946 if (iter == offline_pages_.end())
945 continue; 947 continue;
946 offline_pages_.erase(iter); 948 offline_pages_.erase(iter);
947 } 949 }
948 950
949 for (const auto& page : result->updated_items) { 951 for (const auto& page : result->updated_items) {
950 FOR_EACH_OBSERVER(Observer, observers_, 952 for (Observer& observer : observers_)
951 OfflinePageDeleted(page.offline_id, page.client_id)); 953 observer.OfflinePageDeleted(page.offline_id, page.client_id);
952 } 954 }
953 955
954 // TODO(fgorski): React the FAILED_INITIALIZATION, FAILED_RESET here. 956 // TODO(fgorski): React the FAILED_INITIALIZATION, FAILED_RESET here.
955 // TODO(fgorski): We need a better callback interface for the Remove action on 957 // TODO(fgorski): We need a better callback interface for the Remove action on
956 // the this class. Currently removing an item that does not exist is 958 // the this class. Currently removing an item that does not exist is
957 // considered a success, but not called out as such to the caller. 959 // considered a success, but not called out as such to the caller.
958 DeletePageResult delete_result; 960 DeletePageResult delete_result;
959 if (result->store_state == StoreState::LOADED) 961 if (result->store_state == StoreState::LOADED)
960 delete_result = DeletePageResult::SUCCESS; 962 delete_result = DeletePageResult::SUCCESS;
961 else 963 else
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 } 1082 }
1081 1083
1082 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 1084 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
1083 } 1085 }
1084 1086
1085 base::Time OfflinePageModelImpl::GetCurrentTime() const { 1087 base::Time OfflinePageModelImpl::GetCurrentTime() const {
1086 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); 1088 return testing_clock_ ? testing_clock_->Now() : base::Time::Now();
1087 } 1089 }
1088 1090
1089 } // namespace offline_pages 1091 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/downloads/download_ui_adapter.cc ('k') | components/omnibox/browser/omnibox_popup_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698