Disable session invalidations on Android with a flag.
[chromium-blink-merge.git] / remoting / protocol / monitored_video_stub.h
blob713878c48db9c85a01127d71f515d3794b853c94
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
3 // found in the LICENSE file.
5 #ifndef REMOTING_PROTOCOL_MONITORED_VIDEO_STUB_H_
6 #define REMOTING_PROTOCOL_MONITORED_VIDEO_STUB_H_
8 #include "base/callback.h"
9 #include "base/threading/thread_checker.h"
10 #include "base/timer/timer.h"
11 #include "remoting/protocol/video_stub.h"
13 namespace base {
14 class ThreadChecker;
15 } // namespace base
17 namespace remoting {
18 namespace protocol {
20 // MonitoredVideoStub is responsible for notifying the event handler if no
21 // frames have been received within |connectivity_check_delay|.
22 // The implementation uses the decorator pattern in which the MonitoredVideoStub
23 // implements the same interface as the VideoStub. It overrides the
24 // ProcessVideoPacket function to provide notification to the client when the
25 // video channel is connected and forward the packet to the underlying
26 // VideoStub. Multiple decorators can be stacked on top of each other if more
27 // functionality is needed in the future.
28 class MonitoredVideoStub : public VideoStub {
29 public:
30 // Callback to be called when channel state changes. The Callback should not
31 // destroy the MonitoredVideoStub object.
32 typedef base::Callback<void(bool connected)> ChannelStateCallback;
34 static const int kConnectivityCheckDelaySeconds = 2;
36 MonitoredVideoStub(
37 VideoStub* video_stub,
38 base::TimeDelta connectivity_check_delay,
39 const ChannelStateCallback& callback);
40 virtual ~MonitoredVideoStub();
42 // VideoStub implementation.
43 virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> packet,
44 const base::Closure& done) OVERRIDE;
46 private:
47 void OnConnectivityCheckTimeout();
48 void NotifyChannelState(bool connected);
50 VideoStub* video_stub_;
51 ChannelStateCallback callback_;
52 base::ThreadChecker thread_checker_;
53 bool is_connected_;
54 base::DelayTimer<MonitoredVideoStub> connectivity_check_timer_;
56 DISALLOW_COPY_AND_ASSIGN(MonitoredVideoStub);
59 } // namespace protocol
60 } // namespace remoting
62 #endif // REMOTING_PROTOCOL_MONITORED_VIDEO_STUB_H_