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

Side by Side Diff: ipc/ipc_channel_proxy.cc

Issue 10008108: RefCounted types should not have public destructors, ipc/ edition (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Really fix Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ipc/ipc_channel_proxy.h ('k') | ipc/ipc_sync_channel_unittest.cc » ('j') | 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "ipc/ipc_channel_proxy.h" 11 #include "ipc/ipc_channel_proxy.h"
12 #include "ipc/ipc_logging.h" 12 #include "ipc/ipc_logging.h"
13 #include "ipc/ipc_message_utils.h" 13 #include "ipc/ipc_message_utils.h"
14 14
15 namespace IPC { 15 namespace IPC {
16 16
17 // This helper ensures the message is deleted if the task is deleted without
18 // having been run.
19 class SendCallbackHelper
20 : public base::RefCountedThreadSafe<SendCallbackHelper> {
21 public:
22 SendCallbackHelper(ChannelProxy::Context* context, Message* message)
23 : context_(context),
24 message_(message) {
25 }
26
27 void Send() {
28 context_->OnSendMessage(message_.release());
29 }
30
31 private:
32 scoped_refptr<ChannelProxy::Context> context_;
33 scoped_ptr<Message> message_;
34
35 DISALLOW_COPY_AND_ASSIGN(SendCallbackHelper);
36 };
37
38 //------------------------------------------------------------------------------ 17 //------------------------------------------------------------------------------
39 18
40 ChannelProxy::MessageFilter::MessageFilter() {} 19 ChannelProxy::MessageFilter::MessageFilter() {}
41 20
42 ChannelProxy::MessageFilter::~MessageFilter() {}
43
44 void ChannelProxy::MessageFilter::OnFilterAdded(Channel* channel) {} 21 void ChannelProxy::MessageFilter::OnFilterAdded(Channel* channel) {}
45 22
46 void ChannelProxy::MessageFilter::OnFilterRemoved() {} 23 void ChannelProxy::MessageFilter::OnFilterRemoved() {}
47 24
48 void ChannelProxy::MessageFilter::OnChannelConnected(int32 peer_pid) {} 25 void ChannelProxy::MessageFilter::OnChannelConnected(int32 peer_pid) {}
49 26
50 void ChannelProxy::MessageFilter::OnChannelError() {} 27 void ChannelProxy::MessageFilter::OnChannelError() {}
51 28
52 void ChannelProxy::MessageFilter::OnChannelClosing() {} 29 void ChannelProxy::MessageFilter::OnChannelClosing() {}
53 30
54 bool ChannelProxy::MessageFilter::OnMessageReceived(const Message& message) { 31 bool ChannelProxy::MessageFilter::OnMessageReceived(const Message& message) {
55 return false; 32 return false;
56 } 33 }
57 34
58 void ChannelProxy::MessageFilter::OnDestruct() const { 35 void ChannelProxy::MessageFilter::OnDestruct() const {
59 delete this; 36 delete this;
60 } 37 }
61 38
39 ChannelProxy::MessageFilter::~MessageFilter() {}
40
62 //------------------------------------------------------------------------------ 41 //------------------------------------------------------------------------------
63 42
64 ChannelProxy::Context::Context(Channel::Listener* listener, 43 ChannelProxy::Context::Context(Channel::Listener* listener,
65 base::MessageLoopProxy* ipc_message_loop) 44 base::MessageLoopProxy* ipc_message_loop)
66 : listener_message_loop_(base::MessageLoopProxy::current()), 45 : listener_message_loop_(base::MessageLoopProxy::current()),
67 listener_(listener), 46 listener_(listener),
68 ipc_message_loop_(ipc_message_loop), 47 ipc_message_loop_(ipc_message_loop),
69 channel_connected_called_(false), 48 channel_connected_called_(false),
70 peer_pid_(base::kNullProcessId) { 49 peer_pid_(base::kNullProcessId) {
71 } 50 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 filters_.clear(); 158 filters_.clear();
180 159
181 channel_.reset(); 160 channel_.reset();
182 161
183 // Balance with the reference taken during startup. This may result in 162 // Balance with the reference taken during startup. This may result in
184 // self-destruction. 163 // self-destruction.
185 Release(); 164 Release();
186 } 165 }
187 166
188 // Called on the IPC::Channel thread 167 // Called on the IPC::Channel thread
189 void ChannelProxy::Context::OnSendMessage(Message* message) { 168 void ChannelProxy::Context::OnSendMessage(scoped_ptr<Message> message) {
190 if (!channel_.get()) { 169 if (!channel_.get()) {
191 delete message;
192 OnChannelClosed(); 170 OnChannelClosed();
193 return; 171 return;
194 } 172 }
195 if (!channel_->Send(message)) 173 if (!channel_->Send(message.release()))
196 OnChannelError(); 174 OnChannelError();
197 } 175 }
198 176
199 // Called on the IPC::Channel thread 177 // Called on the IPC::Channel thread
200 void ChannelProxy::Context::OnAddFilter() { 178 void ChannelProxy::Context::OnAddFilter() {
201 std::vector<scoped_refptr<MessageFilter> > new_filters; 179 std::vector<scoped_refptr<MessageFilter> > new_filters;
202 { 180 {
203 base::AutoLock auto_lock(pending_filters_lock_); 181 base::AutoLock auto_lock(pending_filters_lock_);
204 new_filters.swap(pending_filters_); 182 new_filters.swap(pending_filters_);
205 } 183 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 DCHECK(did_init_); 339 DCHECK(did_init_);
362 if (outgoing_message_filter()) 340 if (outgoing_message_filter())
363 message = outgoing_message_filter()->Rewrite(message); 341 message = outgoing_message_filter()->Rewrite(message);
364 342
365 #ifdef IPC_MESSAGE_LOG_ENABLED 343 #ifdef IPC_MESSAGE_LOG_ENABLED
366 Logging::GetInstance()->OnSendMessage(message, context_->channel_id()); 344 Logging::GetInstance()->OnSendMessage(message, context_->channel_id());
367 #endif 345 #endif
368 346
369 context_->ipc_message_loop()->PostTask( 347 context_->ipc_message_loop()->PostTask(
370 FROM_HERE, 348 FROM_HERE,
371 base::Bind(&SendCallbackHelper::Send, 349 base::Bind(&ChannelProxy::Context::OnSendMessage,
372 new SendCallbackHelper(context_.get(), message))); 350 context_, base::Passed(scoped_ptr<Message>(message))));
373 return true; 351 return true;
374 } 352 }
375 353
376 void ChannelProxy::AddFilter(MessageFilter* filter) { 354 void ChannelProxy::AddFilter(MessageFilter* filter) {
377 context_->AddFilter(filter); 355 context_->AddFilter(filter);
378 } 356 }
379 357
380 void ChannelProxy::RemoveFilter(MessageFilter* filter) { 358 void ChannelProxy::RemoveFilter(MessageFilter* filter) {
381 context_->ipc_message_loop()->PostTask( 359 context_->ipc_message_loop()->PostTask(
382 FROM_HERE, base::Bind(&Context::OnRemoveFilter, context_.get(), 360 FROM_HERE, base::Bind(&Context::OnRemoveFilter, context_.get(),
(...skipping 25 matching lines...) Expand all
408 Channel* channel = context_.get()->channel_.get(); 386 Channel* channel = context_.get()->channel_.get();
409 // Channel must have been created first. 387 // Channel must have been created first.
410 DCHECK(channel) << context_.get()->channel_id_; 388 DCHECK(channel) << context_.get()->channel_id_;
411 return channel->GetClientEuid(client_euid); 389 return channel->GetClientEuid(client_euid);
412 } 390 }
413 #endif 391 #endif
414 392
415 //----------------------------------------------------------------------------- 393 //-----------------------------------------------------------------------------
416 394
417 } // namespace IPC 395 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_channel_proxy.h ('k') | ipc/ipc_sync_channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698