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

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: Fixed ResizingHostObserver unit-tests. 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..87ecf46cd1adca8dec90bf79d01d0741da2cf59b 100644
--- a/remoting/host/resizing_host_observer.cc
+++ b/remoting/host/resizing_host_observer.cc
@@ -6,12 +6,18 @@
#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"
namespace {
+// Minimum amount of time to wait between desktop resizes. Can be overridden
+// for testing.
+const int kDefaultMinimumResizeIntervalMs = 1000;
+
class CandidateSize {
public:
CandidateSize(const SkISize& candidate, const SkISize& preferred)
@@ -101,7 +107,10 @@ namespace remoting {
ResizingHostObserver::ResizingHostObserver(
scoped_ptr<DesktopResizer> desktop_resizer)
: desktop_resizer_(desktop_resizer.Pass()),
- original_size_(desktop_resizer_->GetCurrentSize()) {
+ original_size_(desktop_resizer_->GetCurrentSize()),
+ minimum_resize_interval_(
+ base::TimeDelta::FromMilliseconds(kDefaultMinimumResizeIntervalMs)),
+ weak_factory_(this) {
}
ResizingHostObserver::~ResizingHostObserver() {
@@ -114,17 +123,30 @@ void ResizingHostObserver::SetScreenResolution(
if (resolution.IsEmpty())
return;
+ // Resizing the desktop too often is probably not a good idea, so apply a
+ // simple rate-limiting scheme.
+ base::Time next_allowed_resize =
+ previous_resize_time_ + minimum_resize_interval_;
+ if (base::Time::Now() < next_allowed_resize) {
+ deferred_resize_timer_.Start(
+ FROM_HERE,
+ next_allowed_resize - base::Time::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 +154,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_ = base::Time::Now();
+}
+
+void ResizingHostObserver::SetMinimumResizeIntervalForTesting(
+ const base::TimeDelta& interval) {
+ minimum_resize_interval_ = interval;
}
} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698