Skip to content

Commit

Permalink
Remove usage of FOR_EACH_OBSERVER macro in ios/
Browse files Browse the repository at this point in the history
Observer lists now support range-based for loops.

BUG=655021

Review-Url: https://codereview.chromium.org/2420013005
Cr-Commit-Position: refs/heads/master@{#425835}
  • Loading branch information
ericwilligers authored and Commit bot committed Oct 18, 2016
1 parent 4039fd5 commit ff4feda
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 134 deletions.
8 changes: 4 additions & 4 deletions ios/chrome/browser/browser_state/browser_state_info_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ void BrowserStateInfoCache::AddBrowserState(
cache->SetWithoutPathExpansion(key, info.release());
AddBrowserStateCacheKey(key);

FOR_EACH_OBSERVER(BrowserStateInfoCacheObserver, observer_list_,
OnBrowserStateAdded(browser_state_path));
for (auto& observer : observer_list_)
observer.OnBrowserStateAdded(browser_state_path);
}

void BrowserStateInfoCache::AddObserver(
Expand All @@ -82,8 +82,8 @@ void BrowserStateInfoCache::RemoveBrowserState(
cache->Remove(key, nullptr);
sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key));

FOR_EACH_OBSERVER(BrowserStateInfoCacheObserver, observer_list_,
OnBrowserStateWasRemoved(browser_state_path));
for (auto& observer : observer_list_)
observer.OnBrowserStateWasRemoved(browser_state_path);
}

size_t BrowserStateInfoCache::GetNumberOfBrowserStates() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ bool AllDomainsPredicate(const std::string& domain) {

GetOnBrowsingDataRemovedCallbacks()->Notify(details);

FOR_EACH_OBSERVER(Observer, observer_list_,
OnIOSChromeBrowsingDataRemoverDone());
for (auto& observer : observer_list_)
observer.OnIOSChromeBrowsingDataRemoverDone();

// History requests aren't happy if you delete yourself from the callback.
// As such, we do a delete later.
Expand Down
8 changes: 4 additions & 4 deletions ios/chrome/browser/reading_list/reading_list_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ ReadingListModel::BeginBatchUpdates() {

++current_batch_updates_count_;
if (current_batch_updates_count_ == 1) {
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListModelBeganBatchUpdates(this));
for (auto& observer : observers_)
observer.ReadingListModelBeganBatchUpdates(this);
}
return token;
}
Expand All @@ -42,7 +42,7 @@ void ReadingListModel::EndBatchUpdates() {
DCHECK(IsPerformingBatchUpdates());
--current_batch_updates_count_;
if (current_batch_updates_count_ == 0) {
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListModelCompletedBatchUpdates(this));
for (auto& observer : observers_)
observer.ReadingListModelCompletedBatchUpdates(this);
}
}
111 changes: 60 additions & 51 deletions ios/chrome/browser/reading_list/reading_list_model_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ ReadingListModelImpl::ReadingListModelImpl(
ReadingListModelImpl::~ReadingListModelImpl() {}

void ReadingListModelImpl::Shutdown() {
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListModelBeingDeleted(this));
for (auto& observer : observers_)
observer.ReadingListModelBeingDeleted(this);
loaded_ = false;
}

Expand Down Expand Up @@ -92,27 +92,29 @@ void ReadingListModelImpl::RemoveEntryByUrl(const GURL& url) {

auto result = std::find(unread_.begin(), unread_.end(), entry);
if (result != unread_.end()) {
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListWillRemoveUnreadEntry(
this, std::distance(unread_.begin(), result)));
for (auto& observer : observers_) {
observer.ReadingListWillRemoveUnreadEntry(
this, std::distance(unread_.begin(), result));
}
unread_.erase(result);
if (storageLayer_ && !IsPerformingBatchUpdates())
storageLayer_->SavePersistentUnreadList(unread_);
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListDidApplyChanges(this));
for (auto& observer : observers_)
observer.ReadingListDidApplyChanges(this);
return;
}

result = std::find(read_.begin(), read_.end(), entry);
if (result != read_.end()) {
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListWillRemoveReadEntry(
this, std::distance(read_.begin(), result)));
for (auto& observer : observers_) {
observer.ReadingListWillRemoveReadEntry(
this, std::distance(read_.begin(), result));
}
read_.erase(result);
if (storageLayer_ && !IsPerformingBatchUpdates())
storageLayer_->SavePersistentReadList(read_);
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListDidApplyChanges(this));
for (auto& observer : observers_)
observer.ReadingListDidApplyChanges(this);
return;
}
}
Expand All @@ -123,16 +125,16 @@ const ReadingListEntry& ReadingListModelImpl::AddEntry(
DCHECK(loaded());
RemoveEntryByUrl(url);
ReadingListEntry entry(url, title);
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListWillAddUnreadEntry(this, entry));
for (auto& observer : observers_)
observer.ReadingListWillAddUnreadEntry(this, entry);
unread_.insert(unread_.begin(), std::move(entry));
hasUnseen_ = true;
if (storageLayer_ && !IsPerformingBatchUpdates()) {
storageLayer_->SavePersistentUnreadList(unread_);
storageLayer_->SavePersistentHasUnseen(true);
}
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListDidApplyChanges(this));
for (auto& observer : observers_)
observer.ReadingListDidApplyChanges(this);
return *unread_.begin();
}

Expand All @@ -143,9 +145,10 @@ void ReadingListModelImpl::MarkReadByURL(const GURL& url) {
if (result == unread_.end())
return;

FOR_EACH_OBSERVER(
ReadingListModelObserver, observers_,
ReadingListWillMoveEntry(this, std::distance(unread_.begin(), result)));
for (auto& observer : observers_) {
observer.ReadingListWillMoveEntry(this,
std::distance(unread_.begin(), result));
}

read_.insert(read_.begin(), std::move(*result));
unread_.erase(result);
Expand All @@ -154,8 +157,8 @@ void ReadingListModelImpl::MarkReadByURL(const GURL& url) {
storageLayer_->SavePersistentUnreadList(unread_);
storageLayer_->SavePersistentReadList(read_);
}
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListDidApplyChanges(this));
for (auto& observer : observers_)
observer.ReadingListDidApplyChanges(this);
}

void ReadingListModelImpl::SetEntryTitle(const GURL& url,
Expand All @@ -165,27 +168,29 @@ void ReadingListModelImpl::SetEntryTitle(const GURL& url,

auto result = std::find(unread_.begin(), unread_.end(), entry);
if (result != unread_.end()) {
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListWillUpdateUnreadEntry(
this, std::distance(unread_.begin(), result)));
for (auto& observer : observers_) {
observer.ReadingListWillUpdateUnreadEntry(
this, std::distance(unread_.begin(), result));
}
result->SetTitle(title);
if (storageLayer_ && !IsPerformingBatchUpdates())
storageLayer_->SavePersistentUnreadList(unread_);
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListDidApplyChanges(this));
for (auto& observer : observers_)
observer.ReadingListDidApplyChanges(this);
return;
}

result = std::find(read_.begin(), read_.end(), entry);
if (result != read_.end()) {
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListWillUpdateReadEntry(
this, std::distance(read_.begin(), result)));
for (auto& observer : observers_) {
observer.ReadingListWillUpdateReadEntry(
this, std::distance(read_.begin(), result));
}
result->SetTitle(title);
if (storageLayer_ && !IsPerformingBatchUpdates())
storageLayer_->SavePersistentReadList(read_);
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListDidApplyChanges(this));
for (auto& observer : observers_)
observer.ReadingListDidApplyChanges(this);
return;
}
}
Expand All @@ -197,27 +202,29 @@ void ReadingListModelImpl::SetEntryDistilledURL(const GURL& url,

auto result = std::find(unread_.begin(), unread_.end(), entry);
if (result != unread_.end()) {
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListWillUpdateUnreadEntry(
this, std::distance(unread_.begin(), result)));
for (auto& observer : observers_) {
observer.ReadingListWillUpdateUnreadEntry(
this, std::distance(unread_.begin(), result));
}
result->SetDistilledURL(distilled_url);
if (storageLayer_ && !IsPerformingBatchUpdates())
storageLayer_->SavePersistentUnreadList(unread_);
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListDidApplyChanges(this));
for (auto& observer : observers_)
observer.ReadingListDidApplyChanges(this);
return;
}

result = std::find(read_.begin(), read_.end(), entry);
if (result != read_.end()) {
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListWillUpdateReadEntry(
this, std::distance(read_.begin(), result)));
for (auto& observer : observers_) {
observer.ReadingListWillUpdateReadEntry(
this, std::distance(read_.begin(), result));
}
result->SetDistilledURL(distilled_url);
if (storageLayer_ && !IsPerformingBatchUpdates())
storageLayer_->SavePersistentReadList(read_);
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListDidApplyChanges(this));
for (auto& observer : observers_)
observer.ReadingListDidApplyChanges(this);
return;
}
}
Expand All @@ -230,27 +237,29 @@ void ReadingListModelImpl::SetEntryDistilledState(

auto result = std::find(unread_.begin(), unread_.end(), entry);
if (result != unread_.end()) {
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListWillUpdateUnreadEntry(
this, std::distance(unread_.begin(), result)));
for (auto& observer : observers_) {
observer.ReadingListWillUpdateUnreadEntry(
this, std::distance(unread_.begin(), result));
}
result->SetDistilledState(state);
if (storageLayer_ && !IsPerformingBatchUpdates())
storageLayer_->SavePersistentUnreadList(unread_);
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListDidApplyChanges(this));
for (auto& observer : observers_)
observer.ReadingListDidApplyChanges(this);
return;
}

result = std::find(read_.begin(), read_.end(), entry);
if (result != read_.end()) {
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListWillUpdateReadEntry(
this, std::distance(read_.begin(), result)));
for (auto& observer : observers_) {
observer.ReadingListWillUpdateReadEntry(
this, std::distance(read_.begin(), result));
}
result->SetDistilledState(state);
if (storageLayer_ && !IsPerformingBatchUpdates())
storageLayer_->SavePersistentReadList(read_);
FOR_EACH_OBSERVER(ReadingListModelObserver, observers_,
ReadingListDidApplyChanges(this));
for (auto& observer : observers_)
observer.ReadingListDidApplyChanges(this);
return;
}
};
Expand Down
15 changes: 8 additions & 7 deletions ios/chrome/browser/signin/signin_manager_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ void SigninManagerFactory::RemoveObserver(

void SigninManagerFactory::NotifyObserversOfSigninManagerCreationForTesting(
SigninManager* manager) {
FOR_EACH_OBSERVER(SigninManagerFactoryObserver, observer_list_,
SigninManagerCreated(manager));
for (auto& observer : observer_list_)
observer.SigninManagerCreated(manager);
}

std::unique_ptr<KeyedService> SigninManagerFactory::BuildServiceInstanceFor(
Expand All @@ -91,17 +91,18 @@ std::unique_ptr<KeyedService> SigninManagerFactory::BuildServiceInstanceFor(
ios::GaiaCookieManagerServiceFactory::GetForBrowserState(
chrome_browser_state)));
service->Initialize(GetApplicationContext()->GetLocalState());
FOR_EACH_OBSERVER(SigninManagerFactoryObserver, observer_list_,
SigninManagerCreated(service.get()));
for (auto& observer : observer_list_)
observer.SigninManagerCreated(service.get());
return std::move(service);
}

void SigninManagerFactory::BrowserStateShutdown(web::BrowserState* context) {
SigninManager* manager =
static_cast<SigninManager*>(GetServiceForBrowserState(context, false));
if (manager)
FOR_EACH_OBSERVER(SigninManagerFactoryObserver, observer_list_,
SigninManagerShutdown(manager));
if (manager) {
for (auto& observer : observer_list_)
observer.SigninManagerShutdown(manager);
}
BrowserStateKeyedServiceFactory::BrowserStateShutdown(context);
}

Expand Down
8 changes: 4 additions & 4 deletions ios/net/cookies/cookie_store_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@
}

void NotificationTrampoline::NotifyCookiesChanged() {
FOR_EACH_OBSERVER(CookieNotificationObserver, observer_list_,
OnSystemCookiesChanged());
for (auto& observer : observer_list_)
observer.OnSystemCookiesChanged();
}

void NotificationTrampoline::NotifyCookiePolicyChanged() {
FOR_EACH_OBSERVER(CookieNotificationObserver, observer_list_,
OnSystemCookiePolicyChanged());
for (auto& observer : observer_list_)
observer.OnSystemCookiePolicyChanged();
}

NotificationTrampoline::NotificationTrampoline() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
ChromeIdentityService::ChromeIdentityService() {}

ChromeIdentityService::~ChromeIdentityService() {
FOR_EACH_OBSERVER(Observer, observer_list_,
OnChromeIdentityServiceWillBeDestroyed());
for (auto& observer : observer_list_)
observer.OnChromeIdentityServiceWillBeDestroyed();
}

void ChromeIdentityService::DismissDialogs() {}
Expand Down Expand Up @@ -131,18 +131,20 @@
}

void ChromeIdentityService::FireIdentityListChanged() {
FOR_EACH_OBSERVER(Observer, observer_list_, OnIdentityListChanged());
for (auto& observer : observer_list_)
observer.OnIdentityListChanged();
}

void ChromeIdentityService::FireAccessTokenRefreshFailed(
ChromeIdentity* identity,
NSDictionary* user_info) {
FOR_EACH_OBSERVER(Observer, observer_list_,
OnAccessTokenRefreshFailed(identity, user_info));
for (auto& observer : observer_list_)
observer.OnAccessTokenRefreshFailed(identity, user_info);
}

void ChromeIdentityService::FireProfileDidUpdate(ChromeIdentity* identity) {
FOR_EACH_OBSERVER(Observer, observer_list_, OnProfileUpdate(identity));
for (auto& observer : observer_list_)
observer.OnProfileUpdate(identity);
}

} // namespace ios
9 changes: 6 additions & 3 deletions ios/web/active_state_manager_impl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
}

ActiveStateManagerImpl::~ActiveStateManagerImpl() {
FOR_EACH_OBSERVER(Observer, observer_list_, WillBeDestroyed());
for (auto& observer : observer_list_)
observer.WillBeDestroyed();
DCHECK(!IsActive());
}

Expand All @@ -46,9 +47,11 @@
active_ = active;

if (active) {
FOR_EACH_OBSERVER(Observer, observer_list_, OnActive());
for (auto& observer : observer_list_)
observer.OnActive();
} else {
FOR_EACH_OBSERVER(Observer, observer_list_, OnInactive());
for (auto& observer : observer_list_)
observer.OnInactive();
}
}

Expand Down
Loading

0 comments on commit ff4feda

Please sign in to comment.