diff options
author | haibinlu <haibinlu@chromium.org> | 2016-01-08 11:09:06 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-08 19:10:16 +0000 |
commit | 587c7a95790231d2021d1b4e8dfe8853bc16a531 (patch) | |
tree | c3d4f685b3c74f0edaa140b5a6de0c2624f16551 /blimp | |
parent | 7fe28ea1c28121d7a595353a5b2a571686721a97 (diff) | |
download | chromium_src-587c7a95790231d2021d1b4e8dfe8853bc16a531.zip chromium_src-587c7a95790231d2021d1b4e8dfe8853bc16a531.tar.gz chromium_src-587c7a95790231d2021d1b4e8dfe8853bc16a531.tar.bz2 |
[Blimp Client] Avoids sending resize messages to engine with the same size info.
BUG=575297
Review URL: https://codereview.chromium.org/1569123002
Cr-Commit-Position: refs/heads/master@{#368394}
Diffstat (limited to 'blimp')
-rw-r--r-- | blimp/client/session/tab_control_feature.cc | 8 | ||||
-rw-r--r-- | blimp/client/session/tab_control_feature.h | 5 | ||||
-rw-r--r-- | blimp/client/session/tab_control_feature_unittest.cc | 35 |
3 files changed, 46 insertions, 2 deletions
diff --git a/blimp/client/session/tab_control_feature.cc b/blimp/client/session/tab_control_feature.cc index fc64b66..5b1ccd9 100644 --- a/blimp/client/session/tab_control_feature.cc +++ b/blimp/client/session/tab_control_feature.cc @@ -9,7 +9,6 @@ #include "blimp/common/proto/size.pb.h" #include "blimp/common/proto/tab_control.pb.h" #include "blimp/net/blimp_message_processor.h" -#include "ui/gfx/geometry/size.h" namespace blimp { @@ -24,6 +23,13 @@ void TabControlFeature::set_outgoing_message_processor( void TabControlFeature::SetSizeAndScale(const gfx::Size& size, float device_pixel_ratio) { + if (last_size_ == size && last_device_pixel_ratio_ == device_pixel_ratio) { + return; + } + + last_size_ = size; + last_device_pixel_ratio_ = device_pixel_ratio; + SizeMessage* size_details; scoped_ptr<BlimpMessage> message = CreateBlimpMessage(&size_details); size_details->set_width(size.width()); diff --git a/blimp/client/session/tab_control_feature.h b/blimp/client/session/tab_control_feature.h index ad62c6a..f439812 100644 --- a/blimp/client/session/tab_control_feature.h +++ b/blimp/client/session/tab_control_feature.h @@ -9,6 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "blimp/client/blimp_client_export.h" #include "blimp/net/blimp_message_processor.h" +#include "ui/gfx/geometry/size.h" namespace gfx { class Size; @@ -41,6 +42,10 @@ class BLIMP_CLIENT_EXPORT TabControlFeature : public BlimpMessageProcessor { // Used to send BlimpMessage::TAB_CONTROL messages to the engine. scoped_ptr<BlimpMessageProcessor> outgoing_message_processor_; + // Used to avoid sending unnecessary messages to engine. + gfx::Size last_size_; + float last_device_pixel_ratio_ = -1; + DISALLOW_COPY_AND_ASSIGN(TabControlFeature); }; diff --git a/blimp/client/session/tab_control_feature_unittest.cc b/blimp/client/session/tab_control_feature_unittest.cc index c2969f5..8c60e2cc 100644 --- a/blimp/client/session/tab_control_feature_unittest.cc +++ b/blimp/client/session/tab_control_feature_unittest.cc @@ -51,7 +51,40 @@ TEST_F(TabControlFeatureTest, CreatesCorrectSizeMessage) { *out_processor_, MockableProcessMessage(EqualsSizeMessage(width, height, dp_to_px), _)) .Times(1); - feature_.SetSizeAndScale(gfx::Size(width, height), 1.23f); + feature_.SetSizeAndScale(gfx::Size(width, height), dp_to_px); +} + +TEST_F(TabControlFeatureTest, NoDuplicateSizeMessage) { + uint64_t width = 10; + uint64_t height = 15; + float dp_to_px = 1.23f; + + EXPECT_CALL( + *out_processor_, + MockableProcessMessage(EqualsSizeMessage(width, height, dp_to_px), _)) + .Times(1) + .RetiresOnSaturation(); + EXPECT_CALL( + *out_processor_, + MockableProcessMessage(EqualsSizeMessage(width, height, dp_to_px + 1), _)) + .Times(1) + .RetiresOnSaturation(); + EXPECT_CALL(*out_processor_, + MockableProcessMessage( + EqualsSizeMessage(width + 1, height, dp_to_px + 1), _)) + .Times(1) + .RetiresOnSaturation(); + EXPECT_CALL(*out_processor_, + MockableProcessMessage( + EqualsSizeMessage(width + 1, height + 1, dp_to_px + 1), _)) + .Times(1) + .RetiresOnSaturation(); + + feature_.SetSizeAndScale(gfx::Size(width, height), dp_to_px); + feature_.SetSizeAndScale(gfx::Size(width, height), dp_to_px); + feature_.SetSizeAndScale(gfx::Size(width, height), dp_to_px + 1); + feature_.SetSizeAndScale(gfx::Size(width + 1, height), dp_to_px + 1); + feature_.SetSizeAndScale(gfx::Size(width + 1, height + 1), dp_to_px + 1); } } // namespace blimp |