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/callback.h" |
9 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/time.h" |
| 14 #include "base/timer.h" |
11 #include "remoting/host/screen_controls.h" | 15 #include "remoting/host/screen_controls.h" |
| 16 #include "remoting/host/screen_resolution.h" |
12 #include "third_party/skia/include/core/SkSize.h" | 17 #include "third_party/skia/include/core/SkSize.h" |
13 | 18 |
14 namespace remoting { | 19 namespace remoting { |
15 | 20 |
16 class DesktopResizer; | 21 class DesktopResizer; |
17 class ScreenResolution; | |
18 | 22 |
19 // TODO(alexeypa): Rename this class to reflect that it is not | 23 // TODO(alexeypa): Rename this class to reflect that it is not |
20 // HostStatusObserver any more. | 24 // HostStatusObserver any more. |
21 | 25 |
22 // Uses the specified DesktopResizer to match host desktop size to the client | 26 // 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 | 27 // view size as closely as is possible. When the connection closes, restores |
24 // the original desktop size. | 28 // the original desktop size. |
25 class ResizingHostObserver : public ScreenControls { | 29 class ResizingHostObserver : public ScreenControls { |
26 public: | 30 public: |
27 explicit ResizingHostObserver(scoped_ptr<DesktopResizer> desktop_resizer); | 31 explicit ResizingHostObserver(scoped_ptr<DesktopResizer> desktop_resizer); |
28 virtual ~ResizingHostObserver(); | 32 virtual ~ResizingHostObserver(); |
29 | 33 |
30 // ScreenControls interface. | 34 // ScreenControls interface. |
31 virtual void SetScreenResolution(const ScreenResolution& resolution) OVERRIDE; | 35 virtual void SetScreenResolution(const ScreenResolution& resolution) OVERRIDE; |
32 | 36 |
| 37 // Provide a replacement for base::Time::Now so that this class can be |
| 38 // unit-tested in a timely manner. This function will be called exactly |
| 39 // once for each call to SetScreenResolution. |
| 40 void SetNowFunctionForTesting( |
| 41 const base::Callback<base::Time(void)>& now_function); |
| 42 |
33 private: | 43 private: |
34 scoped_ptr<DesktopResizer> desktop_resizer_; | 44 scoped_ptr<DesktopResizer> desktop_resizer_; |
35 SkISize original_size_; | 45 SkISize original_size_; |
36 | 46 |
| 47 // State to manage rate-limiting of desktop resizes. |
| 48 base::OneShotTimer<ResizingHostObserver> deferred_resize_timer_; |
| 49 base::Time previous_resize_time_; |
| 50 base::Callback<base::Time(void)> now_function_; |
| 51 |
| 52 base::WeakPtrFactory<ResizingHostObserver> weak_factory_; |
| 53 |
37 DISALLOW_COPY_AND_ASSIGN(ResizingHostObserver); | 54 DISALLOW_COPY_AND_ASSIGN(ResizingHostObserver); |
38 }; | 55 }; |
39 | 56 |
40 } // namespace remoting | 57 } // namespace remoting |
41 | 58 |
42 #endif // REMOTING_HOST_RESIZING_HOST_OBSERVER_H_ | 59 #endif // REMOTING_HOST_RESIZING_HOST_OBSERVER_H_ |
OLD | NEW |