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

Unified Diff: base/callback_list.h.pump

Issue 273523007: Dispatch geolocation IPCs on the UI thread. Aside from simplifying the code to avoid a lot of threa… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 6 years, 7 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 | « base/callback_list.h ('k') | chrome/browser/chromeos/policy/device_status_collector.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/callback_list.h.pump
===================================================================
--- base/callback_list.h.pump (revision 269778)
+++ base/callback_list.h.pump (working copy)
@@ -94,10 +94,13 @@
}
~Subscription() {
- if (list_->active_iterator_count_)
+ if (list_->active_iterator_count_) {
iter_->Reset();
- else
+ } else {
list_->callbacks_.erase(iter_);
+ if (!list_->removal_callback_.is_null())
+ list_->removal_callback_.Run();
+ }
}
private:
@@ -116,6 +119,18 @@
new Subscription(this, callbacks_.insert(callbacks_.end(), cb)));
}
+ // Sets a callback which will be run when a subscription list is changed.
+ void set_removal_callback(const Closure& callback) {
+ removal_callback_ = callback;
+ }
+
+ // Returns true if there are no subscriptions. This is only valid to call when
+ // not looping through the list.
+ bool empty() {
+ DCHECK_EQ(0, active_iterator_count_);
+ return callbacks_.empty();
+ }
+
protected:
// An iterator class that can be used to access the list of callbacks.
class Iterator {
@@ -172,17 +187,24 @@
// iteration.
void Compact() {
typename std::list<CallbackType>::iterator it = callbacks_.begin();
+ bool updated = false;
while (it != callbacks_.end()) {
- if ((*it).is_null())
+ if ((*it).is_null()) {
+ updated = true;
it = callbacks_.erase(it);
- else
+ } else {
++it;
+ }
+
+ if (updated && !removal_callback_.is_null())
+ removal_callback_.Run();
}
}
private:
std::list<CallbackType> callbacks_;
int active_iterator_count_;
+ Closure removal_callback_;
DISALLOW_COPY_AND_ASSIGN(CallbackListBase);
};
« no previous file with comments | « base/callback_list.h ('k') | chrome/browser/chromeos/policy/device_status_collector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698