OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef BLIMP_NET_BLIMP_MESSAGE_CHECKPOINTER_H_ | |
6 #define BLIMP_NET_BLIMP_MESSAGE_CHECKPOINTER_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/timer/timer.h" | |
12 #include "blimp/net/blimp_message_processor.h" | |
13 #include "blimp/net/blimp_net_export.h" | |
14 | |
15 namespace blimp { | |
16 | |
17 class BlimpMessage; | |
18 class BlimpMessageCheckpointObserver; | |
19 | |
20 // Utility class configured with incoming & outgoing MessageProcessors, | |
21 // responsible for dispatching checkpoint/ACK messages to the outgoing | |
22 // processor, as the incoming processor completes processing them. | |
23 // Checkpoint/ACK message dispatch may be deferred for a second or | |
24 // two to avoid saturating the link with ACK traffic; feature implementations | |
25 // need to account for this latency in their design. | |
26 // BlimpMessageCheckpointer is created on the UI thread, and then used and | |
27 // destroyed on the IO thread. | |
28 class BLIMP_NET_EXPORT BlimpMessageCheckpointer : public BlimpMessageProcessor { | |
29 public: | |
30 BlimpMessageCheckpointer(BlimpMessageProcessor* incoming_processor, | |
31 BlimpMessageProcessor* outgoing_processor, | |
32 BlimpMessageCheckpointObserver* checkpoint_observer); | |
33 ~BlimpMessageCheckpointer() override; | |
34 | |
35 // BlimpMessageProcessor interface. | |
36 void ProcessMessage(std::unique_ptr<BlimpMessage> message, | |
37 const net::CompletionCallback& callback) override; | |
38 | |
39 private: | |
40 void InvokeCompletionCallback(const net::CompletionCallback& callback, | |
41 int result); | |
42 void SendCheckpointAck(); | |
43 | |
44 BlimpMessageProcessor* incoming_processor_; | |
45 BlimpMessageProcessor* outgoing_processor_; | |
46 BlimpMessageCheckpointObserver* checkpoint_observer_; | |
47 | |
48 // Holds the Id of the message that most recently completed processing. | |
49 int64_t checkpoint_id_ = 0; | |
50 | |
51 // Used to batch multiple processed messages into a single ACK. | |
52 base::OneShotTimer defer_timer_; | |
53 | |
54 // Used to abandon pending ProcessMessage completion callbacks on deletion. | |
55 base::WeakPtrFactory<BlimpMessageCheckpointer> weak_factory_; | |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(BlimpMessageCheckpointer); | |
58 }; | |
59 | |
60 } // namespace blimp | |
61 | |
62 #endif // BLIMP_NET_BLIMP_MESSAGE_CHECKPOINTER_H_ | |
OLD | NEW |