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

Side by Side Diff: ipc/ipc_test_sink.cc

Issue 6387007: Add support for attaching filters to an IPC TestSink. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add some more comments Created 9 years, 11 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
« ipc/ipc_test_sink.h ('K') | « ipc/ipc_test_sink.h ('k') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_test_sink.h" 5 #include "ipc/ipc_test_sink.h"
6 6
7 #include "ipc/ipc_message.h" 7 #include "ipc/ipc_message.h"
8 8
9 namespace IPC { 9 namespace IPC {
10 10
11 TestSink::TestSink() { 11 TestSink::TestSink() {
12 } 12 }
13 13
14 TestSink::~TestSink() { 14 TestSink::~TestSink() {
15 } 15 }
16 16
17 bool TestSink::Send(Message* message) { 17 bool TestSink::Send(Message* message) {
18 OnMessageReceived(*message); 18 OnMessageReceived(*message);
19 delete message; 19 delete message;
20 return true; 20 return true;
21 } 21 }
22 22
23 bool TestSink::OnMessageReceived(const Message& msg) { 23 bool TestSink::OnMessageReceived(const Message& msg) {
24 messages_.push_back(Message(msg)); 24 messages_.push_back(Message(msg));
25 FOR_EACH_OBSERVER(Observer, observer_list_, OnMessageReceived(msg));
25 return true; 26 return true;
26 } 27 }
27 28
28 void TestSink::ClearMessages() { 29 void TestSink::ClearMessages() {
29 messages_.clear(); 30 messages_.clear();
30 } 31 }
31 32
32 const Message* TestSink::GetMessageAt(size_t index) const { 33 const Message* TestSink::GetMessageAt(size_t index) const {
33 if (index >= messages_.size()) 34 if (index >= messages_.size())
34 return NULL; 35 return NULL;
(...skipping 15 matching lines...) Expand all
50 if (messages_[i].type() == id) { 51 if (messages_[i].type() == id) {
51 found_count++; 52 found_count++;
52 found_index = i; 53 found_index = i;
53 } 54 }
54 } 55 }
55 if (found_count != 1) 56 if (found_count != 1)
56 return NULL; // Didn't find a unique one. 57 return NULL; // Didn't find a unique one.
57 return &messages_[found_index]; 58 return &messages_[found_index];
58 } 59 }
59 60
61 void TestSink::AddObserver(Observer* obs) {
62 observer_list_.AddObserver(obs);
63 }
64
65 void TestSink::RemoveObserver(Observer* obs) {
66 observer_list_.RemoveObserver(obs);
noelutz 2011/01/28 02:13:06 Maybe check in the destructor that all observers h
Brian Ryner 2011/01/28 02:19:59 I'm not sure how common this is for observer inter
67 }
68
60 } // namespace IPC 69 } // namespace IPC
OLDNEW
« ipc/ipc_test_sink.h ('K') | « ipc/ipc_test_sink.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698