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 all error observers from the observer list. | |
34 // Should be used to suppress error output in cases where an expected error | |
35 // code should be suppressed, e.g. on graceful disconnects. | |
36 virtual void ClearConnectionErrorObservers(); | |
haibinlu
2016/01/04 19:45:45
per offline discussion, this can be removed.
Kevin M
2016/01/04 20:42:13
Removed this and relocated error observers to the
| |
37 | |
38 // Removes |observer| from the connection's error observer list. | |
39 virtual void RemoveConnectionErrorObserver(ConnectionErrorObserver* observer); | |
31 | 40 |
32 // Sets the processor which will take incoming messages for this connection. | 41 // Sets the processor which will take incoming messages for this connection. |
33 // Can be set multiple times, but previously set processors are discarded. | 42 // Can be set multiple times, but previously set processors are discarded. |
34 // Caller retains the ownership of |processor|. | 43 // Caller retains the ownership of |processor|. |
35 virtual void SetIncomingMessageProcessor(BlimpMessageProcessor* processor); | 44 virtual void SetIncomingMessageProcessor(BlimpMessageProcessor* processor); |
36 | 45 |
37 // Gets a processor for BrowserSession->BlimpConnection message routing. | 46 // Gets a processor for BrowserSession->BlimpConnection message routing. |
38 virtual BlimpMessageProcessor* GetOutgoingMessageProcessor(); | 47 virtual BlimpMessageProcessor* GetOutgoingMessageProcessor(); |
39 | 48 |
49 // ConnectionErrorObserver implementation. | |
50 void OnConnectionError(int error) override; | |
haibinlu
2016/01/04 19:45:45
move this to private
Kevin M
2016/01/04 20:42:13
Done.
| |
51 | |
40 protected: | 52 protected: |
41 BlimpConnection(); | 53 BlimpConnection(); |
42 | 54 |
43 private: | 55 private: |
56 base::ObserverList<ConnectionErrorObserver> error_observers_; | |
44 scoped_ptr<PacketReader> reader_; | 57 scoped_ptr<PacketReader> reader_; |
45 scoped_ptr<BlimpMessagePump> message_pump_; | 58 scoped_ptr<BlimpMessagePump> message_pump_; |
46 scoped_ptr<PacketWriter> writer_; | 59 scoped_ptr<PacketWriter> writer_; |
47 scoped_ptr<BlimpMessageProcessor> outgoing_msg_processor_; | 60 scoped_ptr<BlimpMessageProcessor> outgoing_msg_processor_; |
48 | 61 |
49 DISALLOW_COPY_AND_ASSIGN(BlimpConnection); | 62 DISALLOW_COPY_AND_ASSIGN(BlimpConnection); |
50 }; | 63 }; |
51 | 64 |
52 } // namespace blimp | 65 } // namespace blimp |
53 | 66 |
54 #endif // BLIMP_NET_BLIMP_CONNECTION_H_ | 67 #endif // BLIMP_NET_BLIMP_CONNECTION_H_ |
OLD | NEW |