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

Unified Diff: chrome/browser/extensions/api/idle/idle_manager.cc

Issue 251173003: Don't fire idle active event when listener re-added (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: self nit Created 6 years, 8 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/api/idle/idle_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/idle/idle_manager.cc
diff --git a/chrome/browser/extensions/api/idle/idle_manager.cc b/chrome/browser/extensions/api/idle/idle_manager.cc
index e9fa969c049ad4eed20a9e7ccc5d22754d7576d6..6e97ec0bca44a863295a9a00854472a4fea2401a 100644
--- a/chrome/browser/extensions/api/idle/idle_manager.cc
+++ b/chrome/browser/extensions/api/idle/idle_manager.cc
@@ -171,6 +171,9 @@ void IdleManager::OnListenerRemoved(const EventListenerInfo& details) {
MonitorMap::iterator it = monitors_.find(details.extension_id);
if (it != monitors_.end()) {
DCHECK_GT(it->second.listeners, 0);
+ // Note: Deliberately leave the listener count as 0 rather than erase()ing
+ // this record so that the threshold doesn't get reset when all listeners
+ // are removed.
--it->second.listeners;
}
}
@@ -259,24 +262,18 @@ void IdleManager::UpdateIdleStateCallback(int idle_time) {
for (MonitorMap::iterator it = monitors_.begin();
it != monitors_.end(); ++it) {
- if (it->second.listeners < 1)
- continue;
-
- ++listener_count;
-
- IdleState new_state = IdleTimeToIdleState(locked,
- idle_time,
- it->second.threshold);
-
- if (new_state != it->second.last_state) {
- it->second.last_state = new_state;
+ IdleMonitor& monitor = it->second;
+ IdleState new_state =
+ IdleTimeToIdleState(locked, idle_time, monitor.threshold);
+ // TODO(kalman): Use EventRouter::HasListeners for these sorts of checks.
+ if (monitor.listeners > 0 && monitor.last_state != new_state)
event_delegate_->OnStateChanged(it->first, new_state);
- }
+ monitor.last_state = new_state;
+ listener_count += monitor.listeners;
}
- if (listener_count == 0) {
+ if (listener_count == 0)
StopPolling();
- }
}
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/idle/idle_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698