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

Side by Side Diff: ipc/ipc_sync_message_filter.cc

Issue 1311043009: Add missing locking for the |sender_| member in IPC::SyncMessageFilter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move lock. Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ipc/ipc_sync_message_filter.h" 5 #include "ipc/ipc_sync_message_filter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 { 64 {
65 base::AutoLock auto_lock(lock_); 65 base::AutoLock auto_lock(lock_);
66 delete pending_message.deserializer; 66 delete pending_message.deserializer;
67 pending_sync_messages_.erase(&pending_message); 67 pending_sync_messages_.erase(&pending_message);
68 } 68 }
69 69
70 return pending_message.send_result; 70 return pending_message.send_result;
71 } 71 }
72 72
73 void SyncMessageFilter::OnFilterAdded(Sender* sender) { 73 void SyncMessageFilter::OnFilterAdded(Sender* sender) {
74 sender_ = sender;
75 std::vector<Message*> pending_messages; 74 std::vector<Message*> pending_messages;
76 { 75 {
77 base::AutoLock auto_lock(lock_); 76 base::AutoLock auto_lock(lock_);
77 sender_ = sender;
78 io_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 78 io_task_runner_ = base::ThreadTaskRunnerHandle::Get();
79 pending_messages_.release(&pending_messages); 79 pending_messages_.release(&pending_messages);
80 } 80 }
81 for (auto* msg : pending_messages) 81 for (auto* msg : pending_messages)
82 SendOnIOThread(msg); 82 SendOnIOThread(msg);
83 } 83 }
84 84
85 void SyncMessageFilter::OnChannelError() { 85 void SyncMessageFilter::OnChannelError() {
86 base::AutoLock auto_lock(lock_);
86 sender_ = NULL; 87 sender_ = NULL;
87 SignalAllEvents(); 88 SignalAllEvents();
88 } 89 }
89 90
90 void SyncMessageFilter::OnChannelClosing() { 91 void SyncMessageFilter::OnChannelClosing() {
92 base::AutoLock auto_lock(lock_);
91 sender_ = NULL; 93 sender_ = NULL;
92 SignalAllEvents(); 94 SignalAllEvents();
93 } 95 }
94 96
95 bool SyncMessageFilter::OnMessageReceived(const Message& message) { 97 bool SyncMessageFilter::OnMessageReceived(const Message& message) {
96 base::AutoLock auto_lock(lock_); 98 base::AutoLock auto_lock(lock_);
97 for (PendingSyncMessages::iterator iter = pending_sync_messages_.begin(); 99 for (PendingSyncMessages::iterator iter = pending_sync_messages_.begin();
98 iter != pending_sync_messages_.end(); ++iter) { 100 iter != pending_sync_messages_.end(); ++iter) {
99 if (SyncMessage::IsMessageReplyTo(message, (*iter)->id)) { 101 if (SyncMessage::IsMessageReplyTo(message, (*iter)->id)) {
100 if (!message.is_reply_error()) { 102 if (!message.is_reply_error()) {
(...skipping 21 matching lines...) Expand all
122 124
123 void SyncMessageFilter::SendOnIOThread(Message* message) { 125 void SyncMessageFilter::SendOnIOThread(Message* message) {
124 if (sender_) { 126 if (sender_) {
125 sender_->Send(message); 127 sender_->Send(message);
126 return; 128 return;
127 } 129 }
128 130
129 if (message->is_sync()) { 131 if (message->is_sync()) {
130 // We don't know which thread sent it, but it doesn't matter, just signal 132 // We don't know which thread sent it, but it doesn't matter, just signal
131 // them all. 133 // them all.
134 base::AutoLock auto_lock(lock_);
132 SignalAllEvents(); 135 SignalAllEvents();
133 } 136 }
134 137
135 delete message; 138 delete message;
136 } 139 }
137 140
138 void SyncMessageFilter::SignalAllEvents() { 141 void SyncMessageFilter::SignalAllEvents() {
139 base::AutoLock auto_lock(lock_); 142 lock_.AssertAcquired();
140 for (PendingSyncMessages::iterator iter = pending_sync_messages_.begin(); 143 for (PendingSyncMessages::iterator iter = pending_sync_messages_.begin();
141 iter != pending_sync_messages_.end(); ++iter) { 144 iter != pending_sync_messages_.end(); ++iter) {
142 (*iter)->done_event->Signal(); 145 (*iter)->done_event->Signal();
143 } 146 }
144 } 147 }
145 148
146 } // namespace IPC 149 } // namespace IPC
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698