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