OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef IPC_IPC_TEST_CHANNEL_LISTENER_H_ | 5 #ifndef IPC_IPC_TEST_CHANNEL_LISTENER_H_ |
6 #define IPC_IPC_TEST_CHANNEL_LISTENER_H_ | 6 #define IPC_IPC_TEST_CHANNEL_LISTENER_H_ |
7 | 7 |
8 #include "ipc/ipc_listener.h" | 8 #include "ipc/ipc_listener.h" |
9 | 9 |
10 namespace IPC { | 10 namespace IPC { |
11 | 11 |
12 class Sender; | 12 class Sender; |
13 | 13 |
14 // A generic listener that expects messages of a certain type (see | 14 // A generic listener that expects messages of a certain type (see |
15 // OnMessageReceived()), and either sends a generic response or quits after the | 15 // OnMessageReceived()), and either sends a generic response or quits after the |
16 // 50th message (or on channel error). | 16 // 50th message (or on channel error). |
17 class TestChannelListener : public Listener { | 17 class TestChannelListener : public Listener { |
18 public: | 18 public: |
19 static const size_t kLongMessageStringNumBytes = 50000; | 19 static const size_t kLongMessageStringNumBytes = 50000; |
20 static void SendOneMessage(Sender* sender, const char* text); | 20 static void SendOneMessage(Sender* sender, const char* text); |
21 | 21 |
22 TestChannelListener() : sender_(NULL), messages_left_(50) {} | 22 TestChannelListener() : sender_(NULL), messages_left_(50) {} |
23 virtual ~TestChannelListener() {} | 23 ~TestChannelListener() override {} |
24 | 24 |
25 virtual bool OnMessageReceived(const Message& message) override; | 25 bool OnMessageReceived(const Message& message) override; |
26 virtual void OnChannelError() override; | 26 void OnChannelError() override; |
27 | 27 |
28 void Init(Sender* s) { | 28 void Init(Sender* s) { |
29 sender_ = s; | 29 sender_ = s; |
30 } | 30 } |
31 | 31 |
32 bool HasSentAll() const { return 0 == messages_left_; } | 32 bool HasSentAll() const { return 0 == messages_left_; } |
33 | 33 |
34 protected: | 34 protected: |
35 void SendNextMessage(); | 35 void SendNextMessage(); |
36 | 36 |
37 private: | 37 private: |
38 Sender* sender_; | 38 Sender* sender_; |
39 int messages_left_; | 39 int messages_left_; |
40 }; | 40 }; |
41 | 41 |
42 } | 42 } |
43 | 43 |
44 #endif // IPC_IPC_TEST_CHANNEL_LISTENER_H_ | 44 #endif // IPC_IPC_TEST_CHANNEL_LISTENER_H_ |
OLD | NEW |