OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 REMOTING_HOST_RESIZING_HOST_OBSERVER_H_ | 5 #ifndef REMOTING_HOST_RESIZING_HOST_OBSERVER_H_ |
6 #define REMOTING_HOST_RESIZING_HOST_OBSERVER_H_ | 6 #define REMOTING_HOST_RESIZING_HOST_OBSERVER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/time.h" |
| 13 #include "base/timer.h" |
11 #include "remoting/host/screen_controls.h" | 14 #include "remoting/host/screen_controls.h" |
| 15 #include "remoting/host/screen_resolution.h" |
12 #include "third_party/skia/include/core/SkSize.h" | 16 #include "third_party/skia/include/core/SkSize.h" |
13 | 17 |
14 namespace remoting { | 18 namespace remoting { |
15 | 19 |
16 class DesktopResizer; | 20 class DesktopResizer; |
17 class ScreenResolution; | |
18 | 21 |
19 // TODO(alexeypa): Rename this class to reflect that it is not | 22 // TODO(alexeypa): Rename this class to reflect that it is not |
20 // HostStatusObserver any more. | 23 // HostStatusObserver any more. |
21 | 24 |
22 // Uses the specified DesktopResizer to match host desktop size to the client | 25 // Uses the specified DesktopResizer to match host desktop size to the client |
23 // view size as closely as is possible. When the connection closes, restores | 26 // view size as closely as is possible. When the connection closes, restores |
24 // the original desktop size. | 27 // the original desktop size. |
25 class ResizingHostObserver : public ScreenControls { | 28 class ResizingHostObserver : public ScreenControls { |
26 public: | 29 public: |
27 explicit ResizingHostObserver(scoped_ptr<DesktopResizer> desktop_resizer); | 30 explicit ResizingHostObserver(scoped_ptr<DesktopResizer> desktop_resizer); |
28 virtual ~ResizingHostObserver(); | 31 virtual ~ResizingHostObserver(); |
29 | 32 |
30 // ScreenControls interface. | 33 // ScreenControls interface. |
31 virtual void SetScreenResolution(const ScreenResolution& resolution) OVERRIDE; | 34 virtual void SetScreenResolution(const ScreenResolution& resolution) OVERRIDE; |
32 | 35 |
| 36 // Set the minimum amount of time between resize requests so that this class |
| 37 // can be unit-tested in a timely manner. |
| 38 void SetMinimumResizeIntervalForTesting(const base::TimeDelta& interval); |
| 39 |
33 private: | 40 private: |
34 scoped_ptr<DesktopResizer> desktop_resizer_; | 41 scoped_ptr<DesktopResizer> desktop_resizer_; |
35 SkISize original_size_; | 42 SkISize original_size_; |
36 | 43 |
| 44 // State to manage rate-limiting of desktop resizes. |
| 45 base::OneShotTimer<ResizingHostObserver> deferred_resize_timer_; |
| 46 base::Time previous_resize_time_; |
| 47 base::TimeDelta minimum_resize_interval_; |
| 48 |
| 49 base::WeakPtrFactory<ResizingHostObserver> weak_factory_; |
| 50 |
37 DISALLOW_COPY_AND_ASSIGN(ResizingHostObserver); | 51 DISALLOW_COPY_AND_ASSIGN(ResizingHostObserver); |
38 }; | 52 }; |
39 | 53 |
40 } // namespace remoting | 54 } // namespace remoting |
41 | 55 |
42 #endif // REMOTING_HOST_RESIZING_HOST_OBSERVER_H_ | 56 #endif // REMOTING_HOST_RESIZING_HOST_OBSERVER_H_ |
OLD | NEW |