Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(718)

Unified Diff: remoting/host/resizing_host_observer.cc

Issue 15927033: Add host-side rate-limiting to desktop resize events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Made unit-test less sensitive to timing. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/host/resizing_host_observer.cc
diff --git a/remoting/host/resizing_host_observer.cc b/remoting/host/resizing_host_observer.cc
index ccb141feb205caa6f588268b42701235c0976053..1330612c12c774d91606cf15611da60530360dee 100644
--- a/remoting/host/resizing_host_observer.cc
+++ b/remoting/host/resizing_host_observer.cc
@@ -6,7 +6,9 @@
#include <list>
+#include "base/bind.h"
#include "base/logging.h"
+#include "base/message_loop.h"
#include "remoting/host/desktop_resizer.h"
#include "remoting/host/screen_resolution.h"
@@ -101,7 +103,9 @@ namespace remoting {
ResizingHostObserver::ResizingHostObserver(
scoped_ptr<DesktopResizer> desktop_resizer)
: desktop_resizer_(desktop_resizer.Pass()),
- original_size_(desktop_resizer_->GetCurrentSize()) {
+ original_size_(desktop_resizer_->GetCurrentSize()),
+ now_function_(base::Bind(base::Time::Now)),
+ weak_factory_(this) {
}
ResizingHostObserver::~ResizingHostObserver() {
@@ -111,20 +115,39 @@ ResizingHostObserver::~ResizingHostObserver() {
void ResizingHostObserver::SetScreenResolution(
const ScreenResolution& resolution) {
+ // Get the current time. This function is called exactly once for each call
+ // to SetScreenResolution to simplify the implementation of unit-tests.
+ base::Time now = now_function_.Run();
+
if (resolution.IsEmpty())
return;
+ // Resizing the desktop too often is probably not a good idea, so apply a
+ // simple rate-limiting scheme.
+ base::TimeDelta minimum_resize_interval = base::TimeDelta::FromSeconds(1);
alexeypa (please no reviews) 2013/06/07 19:50:25 I think it was better with kDefaultMinimumResizeIn
Jamie 2013/06/07 20:20:14 Done (without the Default, since it can't be overr
+ base::Time next_allowed_resize =
+ previous_resize_time_ + minimum_resize_interval;
+
+ if (now < next_allowed_resize) {
+ deferred_resize_timer_.Start(
+ FROM_HERE,
+ next_allowed_resize - now,
+ base::Bind(&ResizingHostObserver::SetScreenResolution,
+ weak_factory_.GetWeakPtr(), resolution));
+ return;
+ }
+
// If the implementation returns any sizes, pick the best one according to
// the algorithm described in CandidateSize::IsBetterThen.
- SkISize dimentions = SkISize::Make(
+ SkISize dimensions = SkISize::Make(
resolution.dimensions().width(), resolution.dimensions().height());
- std::list<SkISize> sizes = desktop_resizer_->GetSupportedSizes(dimentions);
+ std::list<SkISize> sizes = desktop_resizer_->GetSupportedSizes(dimensions);
if (sizes.empty())
return;
- CandidateSize best_size(sizes.front(), dimentions);
+ CandidateSize best_size(sizes.front(), dimensions);
for (std::list<SkISize>::const_iterator i = ++sizes.begin();
i != sizes.end(); ++i) {
- CandidateSize candidate_size(*i, dimentions);
+ CandidateSize candidate_size(*i, dimensions);
if (candidate_size.IsBetterThan(best_size)) {
best_size = candidate_size;
}
@@ -132,6 +155,14 @@ void ResizingHostObserver::SetScreenResolution(
SkISize current_size = desktop_resizer_->GetCurrentSize();
if (best_size.size() != current_size)
desktop_resizer_->SetSize(best_size.size());
+
+ // Update the time of last resize to allow it to be rate-limited.
+ previous_resize_time_ = now;
+}
+
+void ResizingHostObserver::SetNowFunctionForTesting(
+ const base::Callback<base::Time(void)>& now_function) {
+ now_function_ = now_function;
}
} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698