[go: up one dir, main page]

Skip recodring UMA stats if the WindowResizer is destroyed during drag.

Resizer can be destroyed during drag when the dragging window is attached to the browser.
Exact repro step is still unknown though. I've tried various scenario but the bounds'
size was always same as original bounds' size.

(cherry picked from commit abae051fa676f620766e2cb1d15674cd2e6719ad)

Bug: 970911
Test: None. Repro step is unknown and this is speculative fix.
Change-Id: I92c8ad1307ae14f1c0d2cad8b77678da3b61690e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1658679
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#669376}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1662536
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/branch-heads/3809@{#346}
Cr-Branched-From: d82dec1a818f378c464ba307ddd9c92133eac355-refs/heads/master@{#665002}
diff --git a/ash/wm/window_resizer.cc b/ash/wm/window_resizer.cc
index c9ea3c8..879538d 100644
--- a/ash/wm/window_resizer.cc
+++ b/ash/wm/window_resizer.cc
@@ -13,7 +13,6 @@
 #include "ui/aura/client/aura_constants.h"
 #include "ui/aura/window.h"
 #include "ui/aura/window_delegate.h"
-#include "ui/aura/window_tracker.h"
 #include "ui/aura/window_tree_host.h"
 #include "ui/base/hit_test.h"
 #include "ui/base/ui_base_types.h"
@@ -269,12 +268,15 @@
 void WindowResizer::SetBoundsDuringResize(const gfx::Rect& bounds) {
   aura::Window* window = GetTarget();
   DCHECK(window);
+  auto ptr = weak_ptr_factory_.GetWeakPtr();
   const gfx::Rect original_bounds = window->bounds();
   window->SetBounds(bounds);
-  aura::WindowTracker tracker;
-  tracker.Add(window);
-  if (tracker.windows().empty())
-    return;  // Assume we've been destroyed.
+
+  // Resizer can be destroyed when a window is attached during tab dragging.
+  // crbug.com/970911.
+  if (!ptr)
+    return;
+
   if (bounds.size() == original_bounds.size())
     return;
   recorder_->RequestNext();
diff --git a/ash/wm/window_resizer.h b/ash/wm/window_resizer.h
index 35e9899..bd3495a1 100644
--- a/ash/wm/window_resizer.h
+++ b/ash/wm/window_resizer.h
@@ -12,6 +12,7 @@
 #include "ash/wm/drag_details.h"
 #include "ash/wm/window_state.h"
 #include "base/macros.h"
+#include "base/memory/weak_ptr.h"
 #include "ui/wm/public/window_move_client.h"
 
 namespace aura {
@@ -113,6 +114,8 @@
 
   std::unique_ptr<PresentationTimeRecorder> recorder_;
 
+  base::WeakPtrFactory<WindowResizer> weak_ptr_factory_{this};
+
   DISALLOW_COPY_AND_ASSIGN(WindowResizer);
 };