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

Unified Diff: ipc/attachment_broker.cc

Issue 1405253010: ipc: Add a lock to guard modifications of state of the AttachmentBroker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 | « ipc/attachment_broker.h ('k') | ipc/attachment_broker_privileged.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/attachment_broker.cc
diff --git a/ipc/attachment_broker.cc b/ipc/attachment_broker.cc
index d708602e45dbec21119946ca06ccac2467e59fc1..148e0d5b45883f8a26a7ca17372de75b6160f0ea 100644
--- a/ipc/attachment_broker.cc
+++ b/ipc/attachment_broker.cc
@@ -31,6 +31,7 @@ AttachmentBroker::~AttachmentBroker() {}
bool AttachmentBroker::GetAttachmentWithId(
BrokerableAttachment::AttachmentId id,
scoped_refptr<BrokerableAttachment>* out_attachment) {
+ base::AutoLock auto_lock(*get_lock());
for (AttachmentVector::iterator it = attachments_.begin();
it != attachments_.end(); ++it) {
if ((*it)->GetIdentifier() == id) {
@@ -43,12 +44,14 @@ bool AttachmentBroker::GetAttachmentWithId(
}
void AttachmentBroker::AddObserver(AttachmentBroker::Observer* observer) {
+ base::AutoLock auto_lock(*get_lock());
auto it = std::find(observers_.begin(), observers_.end(), observer);
if (it == observers_.end())
observers_.push_back(observer);
}
void AttachmentBroker::RemoveObserver(AttachmentBroker::Observer* observer) {
+ base::AutoLock auto_lock(*get_lock());
auto it = std::find(observers_.begin(), observers_.end(), observer);
if (it != observers_.end())
observers_.erase(it);
@@ -64,14 +67,22 @@ void AttachmentBroker::DeregisterCommunicationChannel(Endpoint* endpoint) {
void AttachmentBroker::HandleReceivedAttachment(
const scoped_refptr<BrokerableAttachment>& attachment) {
- attachments_.push_back(attachment);
+ {
+ base::AutoLock auto_lock(*get_lock());
+ attachments_.push_back(attachment);
+ }
NotifyObservers(attachment->GetIdentifier());
}
void AttachmentBroker::NotifyObservers(
const BrokerableAttachment::AttachmentId& id) {
// Make a copy of observers_ to avoid mutations during iteration.
- std::vector<Observer*> observers = observers_;
+ std::vector<Observer*> observers;
+ {
+ base::AutoLock auto_lock(*get_lock());
+ observers = observers_;
+ }
+
for (Observer* observer : observers) {
observer->ReceivedBrokerableAttachmentWithId(id);
}
« no previous file with comments | « ipc/attachment_broker.h ('k') | ipc/attachment_broker_privileged.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698