Commit 69031e66 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Chromium LUCI CQ

Migrate might_have_observers to empty in content/

Bug: 1155308

Change-Id: I05d8df24fabbd9c62b1228052aadf69d92f34699
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2598757
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845212}
parent ff59331d
...@@ -299,14 +299,14 @@ void MediaKeysListenerManagerImpl::UpdateMediaKeysListener() { ...@@ -299,14 +299,14 @@ void MediaKeysListenerManagerImpl::UpdateMediaKeysListener() {
bool MediaKeysListenerManagerImpl::ShouldListenToKey( bool MediaKeysListenerManagerImpl::ShouldListenToKey(
const ListeningData& listening_data) const { const ListeningData& listening_data) const {
return listening_data.listeners.might_have_observers() || return !listening_data.listeners.empty() ||
(listening_data.active_media_session_controller_listening && (listening_data.active_media_session_controller_listening &&
CanActiveMediaSessionControllerReceiveEvents()); CanActiveMediaSessionControllerReceiveEvents());
} }
bool MediaKeysListenerManagerImpl::AnyDelegatesListening() const { bool MediaKeysListenerManagerImpl::AnyDelegatesListening() const {
for (const auto& key_code_listening_data : delegate_map_) { for (const auto& key_code_listening_data : delegate_map_) {
if (key_code_listening_data.second->listeners.might_have_observers()) if (!key_code_listening_data.second->listeners.empty())
return true; return true;
} }
return false; return false;
......
...@@ -84,7 +84,7 @@ void NotificationServiceImpl::RemoveObserver(NotificationObserver* observer, ...@@ -84,7 +84,7 @@ void NotificationServiceImpl::RemoveObserver(NotificationObserver* observer,
observers_[type][source.map_key()]; observers_[type][source.map_key()];
if (observer_list) { if (observer_list) {
observer_list->RemoveObserver(observer); observer_list->RemoveObserver(observer);
if (!observer_list->might_have_observers()) { if (observer_list->empty()) {
observers_[type].erase(source.map_key()); observers_[type].erase(source.map_key());
delete observer_list; delete observer_list;
} }
......
...@@ -85,7 +85,7 @@ void RenderWidgetHostViewBase::NotifyObserversAboutShutdown() { ...@@ -85,7 +85,7 @@ void RenderWidgetHostViewBase::NotifyObserversAboutShutdown() {
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnRenderWidgetHostViewBaseDestroyed(this); observer.OnRenderWidgetHostViewBaseDestroyed(this);
// All observers are required to disconnect after they are notified. // All observers are required to disconnect after they are notified.
DCHECK(!observers_.might_have_observers()); DCHECK(observers_.empty());
} }
MouseWheelPhaseHandler* RenderWidgetHostViewBase::GetMouseWheelPhaseHandler() { MouseWheelPhaseHandler* RenderWidgetHostViewBase::GetMouseWheelPhaseHandler() {
......
...@@ -66,13 +66,12 @@ ServiceWorkerRegistration::ServiceWorkerRegistration( ...@@ -66,13 +66,12 @@ ServiceWorkerRegistration::ServiceWorkerRegistration(
ServiceWorkerRegistration::~ServiceWorkerRegistration() { ServiceWorkerRegistration::~ServiceWorkerRegistration() {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
DCHECK(!listeners_.might_have_observers()); DCHECK(listeners_.empty());
// TODO(crbug.com/1159778): Remove once the bug is fixed. // TODO(crbug.com/1159778): Remove once the bug is fixed.
CHECK(!in_activate_waiting_version_) CHECK(!in_activate_waiting_version_)
<< "ServiceWorkerRegistration was destroyed while activating waiting " << "ServiceWorkerRegistration was destroyed while activating waiting "
"version"; "version";
if (context_) if (context_)
context_->RemoveLiveRegistration(registration_id_); context_->RemoveLiveRegistration(registration_id_);
} }
......
...@@ -92,7 +92,7 @@ void SmsProvider::RecordParsingStatus(SmsParsingStatus status) { ...@@ -92,7 +92,7 @@ void SmsProvider::RecordParsingStatus(SmsParsingStatus status) {
} }
bool SmsProvider::HasObservers() { bool SmsProvider::HasObservers() {
return observers_.might_have_observers(); return !observers_.empty();
} }
} // namespace content } // namespace content
...@@ -313,7 +313,7 @@ bool TtsControllerImpl::IsSpeaking() { ...@@ -313,7 +313,7 @@ bool TtsControllerImpl::IsSpeaking() {
} }
void TtsControllerImpl::VoicesChanged() { void TtsControllerImpl::VoicesChanged() {
if (!voices_changed_delegates_.might_have_observers() || TtsPlatformLoading()) if (voices_changed_delegates_.empty() || TtsPlatformLoading())
return; return;
// Existence of platform tts indicates explicit requests to tts. Since // Existence of platform tts indicates explicit requests to tts. Since
......
...@@ -177,7 +177,7 @@ void WebRTCInternals::OnAddPeerConnection(int render_process_id, ...@@ -177,7 +177,7 @@ void WebRTCInternals::OnAddPeerConnection(int render_process_id,
dict->SetBoolean("isOpen", true); dict->SetBoolean("isOpen", true);
dict->SetBoolean("connected", false); dict->SetBoolean("connected", false);
if (observers_.might_have_observers()) if (!observers_.empty())
SendUpdate("addPeerConnection", dict->CreateDeepCopy()); SendUpdate("addPeerConnection", dict->CreateDeepCopy());
peer_connection_data_.Append(std::move(dict)); peer_connection_data_.Append(std::move(dict));
...@@ -199,7 +199,7 @@ void WebRTCInternals::OnRemovePeerConnection(ProcessId pid, int lid) { ...@@ -199,7 +199,7 @@ void WebRTCInternals::OnRemovePeerConnection(ProcessId pid, int lid) {
peer_connection_data_.Remove(index, nullptr); peer_connection_data_.Remove(index, nullptr);
} }
if (observers_.might_have_observers()) { if (!observers_.empty()) {
std::unique_ptr<base::DictionaryValue> id(new base::DictionaryValue()); std::unique_ptr<base::DictionaryValue> id(new base::DictionaryValue());
id->SetInteger("pid", static_cast<int>(pid)); id->SetInteger("pid", static_cast<int>(pid));
id->SetInteger("lid", lid); id->SetInteger("lid", lid);
...@@ -227,7 +227,7 @@ void WebRTCInternals::OnUpdatePeerConnection( ...@@ -227,7 +227,7 @@ void WebRTCInternals::OnUpdatePeerConnection(
} }
// Don't update entries if there aren't any observers. // Don't update entries if there aren't any observers.
if (!observers_.might_have_observers()) if (observers_.empty())
return; return;
auto log_entry = std::make_unique<base::DictionaryValue>(); auto log_entry = std::make_unique<base::DictionaryValue>();
...@@ -252,7 +252,7 @@ void WebRTCInternals::OnUpdatePeerConnection( ...@@ -252,7 +252,7 @@ void WebRTCInternals::OnUpdatePeerConnection(
void WebRTCInternals::OnAddStandardStats(base::ProcessId pid, void WebRTCInternals::OnAddStandardStats(base::ProcessId pid,
int lid, int lid,
base::Value value) { base::Value value) {
if (!observers_.might_have_observers()) if (observers_.empty())
return; return;
auto dict = std::make_unique<base::DictionaryValue>(); auto dict = std::make_unique<base::DictionaryValue>();
...@@ -267,7 +267,7 @@ void WebRTCInternals::OnAddStandardStats(base::ProcessId pid, ...@@ -267,7 +267,7 @@ void WebRTCInternals::OnAddStandardStats(base::ProcessId pid,
void WebRTCInternals::OnAddLegacyStats(base::ProcessId pid, void WebRTCInternals::OnAddLegacyStats(base::ProcessId pid,
int lid, int lid,
base::Value value) { base::Value value) {
if (!observers_.might_have_observers()) if (observers_.empty())
return; return;
auto dict = std::make_unique<base::DictionaryValue>(); auto dict = std::make_unique<base::DictionaryValue>();
...@@ -304,7 +304,7 @@ void WebRTCInternals::OnGetUserMedia(int rid, ...@@ -304,7 +304,7 @@ void WebRTCInternals::OnGetUserMedia(int rid,
if (video) if (video)
dict->SetString("video", video_constraints); dict->SetString("video", video_constraints);
if (observers_.might_have_observers()) if (!observers_.empty())
SendUpdate("addGetUserMedia", dict->CreateDeepCopy()); SendUpdate("addGetUserMedia", dict->CreateDeepCopy());
get_user_media_requests_.Append(std::move(dict)); get_user_media_requests_.Append(std::move(dict));
...@@ -324,7 +324,7 @@ void WebRTCInternals::AddObserver(WebRTCInternalsUIObserver* observer) { ...@@ -324,7 +324,7 @@ void WebRTCInternals::AddObserver(WebRTCInternalsUIObserver* observer) {
void WebRTCInternals::RemoveObserver(WebRTCInternalsUIObserver* observer) { void WebRTCInternals::RemoveObserver(WebRTCInternalsUIObserver* observer) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
observers_.RemoveObserver(observer); observers_.RemoveObserver(observer);
if (observers_.might_have_observers()) if (!observers_.empty())
return; return;
// Disables event log and audio debug recordings if enabled and the last // Disables event log and audio debug recordings if enabled and the last
...@@ -452,7 +452,7 @@ bool WebRTCInternals::CanToggleEventLogRecordings() const { ...@@ -452,7 +452,7 @@ bool WebRTCInternals::CanToggleEventLogRecordings() const {
void WebRTCInternals::SendUpdate(const char* command, void WebRTCInternals::SendUpdate(const char* command,
std::unique_ptr<base::Value> value) { std::unique_ptr<base::Value> value) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(observers_.might_have_observers()); DCHECK(!observers_.empty());
bool queue_was_empty = pending_updates_.empty(); bool queue_was_empty = pending_updates_.empty();
pending_updates_.push(PendingUpdate(command, std::move(value))); pending_updates_.push(PendingUpdate(command, std::move(value)));
...@@ -526,7 +526,7 @@ void WebRTCInternals::OnRendererExit(int render_process_id) { ...@@ -526,7 +526,7 @@ void WebRTCInternals::OnRendererExit(int render_process_id) {
record->GetInteger("rid", &this_rid); record->GetInteger("rid", &this_rid);
if (this_rid == render_process_id) { if (this_rid == render_process_id) {
if (observers_.might_have_observers()) { if (!observers_.empty()) {
int lid = 0, pid = 0; int lid = 0, pid = 0;
record->GetInteger("lid", &lid); record->GetInteger("lid", &lid);
record->GetInteger("pid", &pid); record->GetInteger("pid", &pid);
...@@ -559,7 +559,7 @@ void WebRTCInternals::OnRendererExit(int render_process_id) { ...@@ -559,7 +559,7 @@ void WebRTCInternals::OnRendererExit(int render_process_id) {
} }
} }
if (found_any && observers_.might_have_observers()) { if (found_any && !observers_.empty()) {
std::unique_ptr<base::DictionaryValue> update(new base::DictionaryValue()); std::unique_ptr<base::DictionaryValue> update(new base::DictionaryValue());
update->SetInteger("rid", render_process_id); update->SetInteger("rid", render_process_id);
SendUpdate("removeGetUserMediaForRenderer", std::move(update)); SendUpdate("removeGetUserMediaForRenderer", std::move(update));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment