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

Side by Side Diff: ipc/ipc_channel_proxy.cc

Issue 3869002: Use make_scoped_refptr() instead of manual AddRef()/Release() in ipc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 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 unified diff | Download patch | Annotate | Revision Log
« 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/ref_counted.h" 6 #include "base/ref_counted.h"
7 #include "base/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "base/thread.h" 8 #include "base/thread.h"
9 #include "ipc/ipc_channel_proxy.h" 9 #include "ipc/ipc_channel_proxy.h"
10 #include "ipc/ipc_logging.h" 10 #include "ipc/ipc_logging.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 189 }
190 190
191 // Called on the IPC::Channel thread 191 // Called on the IPC::Channel thread
192 void ChannelProxy::Context::OnAddFilter(MessageFilter* filter) { 192 void ChannelProxy::Context::OnAddFilter(MessageFilter* filter) {
193 filters_.push_back(filter); 193 filters_.push_back(filter);
194 194
195 // If the channel has already been created, then we need to send this message 195 // If the channel has already been created, then we need to send this message
196 // so that the filter gets access to the Channel. 196 // so that the filter gets access to the Channel.
197 if (channel_) 197 if (channel_)
198 filter->OnFilterAdded(channel_); 198 filter->OnFilterAdded(channel_);
199
200 // Balances the AddRef in ChannelProxy::AddFilter.
201 filter->Release();
202 } 199 }
203 200
204 // Called on the IPC::Channel thread 201 // Called on the IPC::Channel thread
205 void ChannelProxy::Context::OnRemoveFilter(MessageFilter* filter) { 202 void ChannelProxy::Context::OnRemoveFilter(MessageFilter* filter) {
206 for (size_t i = 0; i < filters_.size(); ++i) { 203 for (size_t i = 0; i < filters_.size(); ++i) {
207 if (filters_[i].get() == filter) { 204 if (filters_[i].get() == filter) {
208 filter->OnFilterRemoved(); 205 filter->OnFilterRemoved();
209 filters_.erase(filters_.begin() + i); 206 filters_.erase(filters_.begin() + i);
210 return; 207 return;
211 } 208 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 #ifdef IPC_MESSAGE_LOG_ENABLED 307 #ifdef IPC_MESSAGE_LOG_ENABLED
311 Logging::current()->OnSendMessage(message, context_->channel_id()); 308 Logging::current()->OnSendMessage(message, context_->channel_id());
312 #endif 309 #endif
313 310
314 context_->ipc_message_loop()->PostTask(FROM_HERE, 311 context_->ipc_message_loop()->PostTask(FROM_HERE,
315 new SendTask(context_.get(), message)); 312 new SendTask(context_.get(), message));
316 return true; 313 return true;
317 } 314 }
318 315
319 void ChannelProxy::AddFilter(MessageFilter* filter) { 316 void ChannelProxy::AddFilter(MessageFilter* filter) {
320 // We want to addref the filter to prevent it from 317 context_->ipc_message_loop()->PostTask(
321 // being destroyed before the OnAddFilter call is invoked. 318 FROM_HERE,
322 filter->AddRef(); 319 NewRunnableMethod(
323 context_->ipc_message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 320 context_.get(),
324 context_.get(), &Context::OnAddFilter, filter)); 321 &Context::OnAddFilter,
322 make_scoped_refptr(filter)));
325 } 323 }
326 324
327 void ChannelProxy::RemoveFilter(MessageFilter* filter) { 325 void ChannelProxy::RemoveFilter(MessageFilter* filter) {
328 context_->ipc_message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 326 context_->ipc_message_loop()->PostTask(
329 context_.get(), &Context::OnRemoveFilter, filter)); 327 FROM_HERE, NewRunnableMethod(
328 context_.get(),
329 &Context::OnRemoveFilter,
330 make_scoped_refptr(filter)));
330 } 331 }
331 332
332 void ChannelProxy::ClearIPCMessageLoop() { 333 void ChannelProxy::ClearIPCMessageLoop() {
333 context()->ClearIPCMessageLoop(); 334 context()->ClearIPCMessageLoop();
334 } 335 }
335 336
336 #if defined(OS_POSIX) 337 #if defined(OS_POSIX)
337 // See the TODO regarding lazy initialization of the channel in 338 // See the TODO regarding lazy initialization of the channel in
338 // ChannelProxy::Init(). 339 // ChannelProxy::Init().
339 // We assume that IPC::Channel::GetClientFileDescriptorMapping() is thread-safe. 340 // We assume that IPC::Channel::GetClientFileDescriptorMapping() is thread-safe.
340 int ChannelProxy::GetClientFileDescriptor() const { 341 int ChannelProxy::GetClientFileDescriptor() const {
341 Channel *channel = context_.get()->channel_; 342 Channel *channel = context_.get()->channel_;
342 DCHECK(channel); // Channel must have been created first. 343 DCHECK(channel); // Channel must have been created first.
343 return channel->GetClientFileDescriptor(); 344 return channel->GetClientFileDescriptor();
344 } 345 }
345 #endif 346 #endif
346 347
347 //----------------------------------------------------------------------------- 348 //-----------------------------------------------------------------------------
348 349
349 } // namespace IPC 350 } // 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