Commit 2d070936 authored by Qiang Xu's avatar Qiang Xu Committed by Commit Bot

cros: record nums of window restored for persistent restore

changes:
According to the design doc: go/cros-persistent-window-bounds, add UMA
for recording the number of windows restored for persistent window
restore in multi-display scenario.

Bug: 805046
Test: tested on device, checked chrome://histograms and added test coverage
Change-Id: I4f8c815c1b88dd605a02b509b27311d567998da1
Reviewed-on: https://chromium-review.googlesource.com/942186Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarMark Pearson <mpearson@chromium.org>
Commit-Queue: Qiang Xu <warx@google.com>
Cr-Commit-Position: refs/heads/master@{#540339}
parent 5ac5785a
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "ash/wm/mru_window_tracker.h" #include "ash/wm/mru_window_tracker.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/metrics/histogram_macros.h"
#include "ui/display/manager/display_manager.h" #include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
...@@ -49,6 +50,7 @@ void MaybeRestorePersistentWindowBounds() { ...@@ -49,6 +50,7 @@ void MaybeRestorePersistentWindowBounds() {
return; return;
display::Screen* screen = display::Screen::GetScreen(); display::Screen* screen = display::Screen::GetScreen();
int window_restored_count = 0;
for (auto* window : GetWindowList()) { for (auto* window : GetWindowList()) {
wm::WindowState* window_state = wm::GetWindowState(window); wm::WindowState* window_state = wm::GetWindowState(window);
if (!window_state->persistent_window_info()) if (!window_state->persistent_window_info())
...@@ -80,11 +82,21 @@ void MaybeRestorePersistentWindowBounds() { ...@@ -80,11 +82,21 @@ void MaybeRestorePersistentWindowBounds() {
window->SetBoundsInScreen(persistent_window_bounds, display); window->SetBoundsInScreen(persistent_window_bounds, display);
// Reset persistent window info everytime the window bounds have restored. // Reset persistent window info everytime the window bounds have restored.
window_state->ResetPersistentWindowInfo(); window_state->ResetPersistentWindowInfo();
++window_restored_count;
}
if (window_restored_count != 0) {
UMA_HISTOGRAM_COUNTS_100(
PersistentWindowController::kNumOfWindowsRestoredHistogramName,
window_restored_count);
} }
} }
} // namespace } // namespace
constexpr char PersistentWindowController::kNumOfWindowsRestoredHistogramName[];
PersistentWindowController::PersistentWindowController() { PersistentWindowController::PersistentWindowController() {
display::Screen::GetScreen()->AddObserver(this); display::Screen::GetScreen()->AddObserver(this);
Shell::Get()->session_controller()->AddObserver(this); Shell::Get()->session_controller()->AddObserver(this);
......
...@@ -20,6 +20,10 @@ class ASH_EXPORT PersistentWindowController ...@@ -20,6 +20,10 @@ class ASH_EXPORT PersistentWindowController
public SessionObserver, public SessionObserver,
public WindowTreeHostManager::Observer { public WindowTreeHostManager::Observer {
public: public:
// Public so it can be used by unit tests.
constexpr static char kNumOfWindowsRestoredHistogramName[] =
"Ash.PersistentWindow.NumOfWindowsRestored";
PersistentWindowController(); PersistentWindowController();
~PersistentWindowController() override; ~PersistentWindowController() override;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/test/histogram_tester.h"
using session_manager::SessionState; using session_manager::SessionState;
...@@ -355,4 +356,42 @@ TEST_F(PersistentWindowControllerTest, ReconnectOnLockScreen) { ...@@ -355,4 +356,42 @@ TEST_F(PersistentWindowControllerTest, ReconnectOnLockScreen) {
EXPECT_EQ(gfx::Rect(501, 0, 200, 100), w2->GetBoundsInScreen()); EXPECT_EQ(gfx::Rect(501, 0, 200, 100), w2->GetBoundsInScreen());
} }
TEST_F(PersistentWindowControllerTest, RecordNumOfWindowsRestored) {
UpdateDisplay("0+0-500x500,0+501-500x500");
aura::Window* w1 =
CreateTestWindowInShellWithBounds(gfx::Rect(200, 0, 100, 200));
aura::Window* w2 =
CreateTestWindowInShellWithBounds(gfx::Rect(501, 0, 200, 100));
EXPECT_EQ(gfx::Rect(200, 0, 100, 200), w1->GetBoundsInScreen());
EXPECT_EQ(gfx::Rect(501, 0, 200, 100), w2->GetBoundsInScreen());
const int64_t primary_id = WindowTreeHostManager::GetPrimaryDisplayId();
const int64_t secondary_id = display_manager()->GetSecondaryDisplay().id();
display::ManagedDisplayInfo primary_info =
display_manager()->GetDisplayInfo(primary_id);
display::ManagedDisplayInfo secondary_info =
display_manager()->GetDisplayInfo(secondary_id);
// Disconnects secondary display.
std::vector<display::ManagedDisplayInfo> display_info_list;
display_info_list.push_back(primary_info);
display_manager()->OnNativeDisplaysChanged(display_info_list);
EXPECT_EQ(gfx::Rect(200, 0, 100, 200), w1->GetBoundsInScreen());
EXPECT_EQ(gfx::Rect(1, 0, 200, 100), w2->GetBoundsInScreen());
base::HistogramTester histogram_tester;
histogram_tester.ExpectTotalCount(
PersistentWindowController::kNumOfWindowsRestoredHistogramName, 0);
// Reconnects secondary display.
display_info_list.push_back(secondary_info);
display_manager()->OnNativeDisplaysChanged(display_info_list);
EXPECT_EQ(gfx::Rect(200, 0, 100, 200), w1->GetBoundsInScreen());
EXPECT_EQ(gfx::Rect(501, 0, 200, 100), w2->GetBoundsInScreen());
histogram_tester.ExpectTotalCount(
PersistentWindowController::kNumOfWindowsRestoredHistogramName, 1);
}
} // namespace ash } // namespace ash
...@@ -3477,6 +3477,15 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. ...@@ -3477,6 +3477,15 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary> </summary>
</histogram> </histogram>
<histogram name="Ash.PersistentWindow.NumOfWindowsRestored">
<owner>warx@chromium.org</owner>
<summary>
The number of windows restored in multi-display scenario, such as due to
disconnecting and reconnecting display, enabling and disabling mirror mode,
entering and leaving dock mode. Zero is not recorded.
</summary>
</histogram>
<histogram name="Ash.PowerButtonScreenshot.DelayBetweenAccelKeyPressed" <histogram name="Ash.PowerButtonScreenshot.DelayBetweenAccelKeyPressed"
units="ms"> units="ms">
<owner>warx@chromium.org</owner> <owner>warx@chromium.org</owner>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment