OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 BLIMP_NET_BLIMP_CONNECTION_H_ | 5 #ifndef BLIMP_NET_BLIMP_CONNECTION_H_ |
6 #define BLIMP_NET_BLIMP_CONNECTION_H_ | 6 #define BLIMP_NET_BLIMP_CONNECTION_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/observer_list.h" |
10 #include "blimp/net/blimp_net_export.h" | 11 #include "blimp/net/blimp_net_export.h" |
| 12 #include "blimp/net/connection_error_observer.h" |
11 | 13 |
12 namespace blimp { | 14 namespace blimp { |
13 | 15 |
14 class BlimpMessageProcessor; | 16 class BlimpMessageProcessor; |
15 class BlimpMessagePump; | 17 class BlimpMessagePump; |
16 class ConnectionErrorObserver; | |
17 class PacketReader; | 18 class PacketReader; |
18 class PacketWriter; | 19 class PacketWriter; |
19 | 20 |
20 // Encapsulates the state and logic used to exchange BlimpMessages over | 21 // Encapsulates the state and logic used to exchange BlimpMessages over |
21 // a network connection. | 22 // a network connection. |
22 class BLIMP_NET_EXPORT BlimpConnection { | 23 class BLIMP_NET_EXPORT BlimpConnection : public ConnectionErrorObserver { |
23 public: | 24 public: |
24 BlimpConnection(scoped_ptr<PacketReader> reader, | 25 BlimpConnection(scoped_ptr<PacketReader> reader, |
25 scoped_ptr<PacketWriter> writer); | 26 scoped_ptr<PacketWriter> writer); |
26 | 27 |
27 virtual ~BlimpConnection(); | 28 ~BlimpConnection() override; |
28 | 29 |
29 // Lets |observer| know when the network connection encounters an error. | 30 // Adds |observer| to the connection's error observer list. |
30 virtual void SetConnectionErrorObserver(ConnectionErrorObserver* observer); | 31 virtual void AddConnectionErrorObserver(ConnectionErrorObserver* observer); |
| 32 |
| 33 // Removes |observer| from the connection's error observer list. |
| 34 virtual void RemoveConnectionErrorObserver(ConnectionErrorObserver* observer); |
31 | 35 |
32 // Sets the processor which will take incoming messages for this connection. | 36 // Sets the processor which will take incoming messages for this connection. |
33 // Can be set multiple times, but previously set processors are discarded. | 37 // Can be set multiple times, but previously set processors are discarded. |
34 // Caller retains the ownership of |processor|. | 38 // Caller retains the ownership of |processor|. |
35 virtual void SetIncomingMessageProcessor(BlimpMessageProcessor* processor); | 39 virtual void SetIncomingMessageProcessor(BlimpMessageProcessor* processor); |
36 | 40 |
37 // Gets a processor for BrowserSession->BlimpConnection message routing. | 41 // Gets a processor for BrowserSession->BlimpConnection message routing. |
38 virtual BlimpMessageProcessor* GetOutgoingMessageProcessor(); | 42 virtual BlimpMessageProcessor* GetOutgoingMessageProcessor(); |
39 | 43 |
40 protected: | 44 protected: |
41 BlimpConnection(); | 45 BlimpConnection(); |
42 | 46 |
| 47 // ConnectionErrorObserver implementation. |
| 48 void OnConnectionError(int error) override; |
| 49 |
43 private: | 50 private: |
44 scoped_ptr<PacketReader> reader_; | 51 scoped_ptr<PacketReader> reader_; |
45 scoped_ptr<BlimpMessagePump> message_pump_; | 52 scoped_ptr<BlimpMessagePump> message_pump_; |
46 scoped_ptr<PacketWriter> writer_; | 53 scoped_ptr<PacketWriter> writer_; |
47 scoped_ptr<BlimpMessageProcessor> outgoing_msg_processor_; | 54 scoped_ptr<BlimpMessageProcessor> outgoing_msg_processor_; |
| 55 base::ObserverList<ConnectionErrorObserver> error_observers_; |
48 | 56 |
49 DISALLOW_COPY_AND_ASSIGN(BlimpConnection); | 57 DISALLOW_COPY_AND_ASSIGN(BlimpConnection); |
50 }; | 58 }; |
51 | 59 |
52 } // namespace blimp | 60 } // namespace blimp |
53 | 61 |
54 #endif // BLIMP_NET_BLIMP_CONNECTION_H_ | 62 #endif // BLIMP_NET_BLIMP_CONNECTION_H_ |
OLD | NEW |