Record UMA metrics to track content area sizes

Reocrd content area sizes when a new browser window is opened and when
the user resizes a browser window.

This is part of preliminary metrics collection for vision-based
phishing protection.

Bug: 882942
Change-Id: Ib6db98bf13193784b89029f467906ed4e0b3ffc4
Reviewed-on: https://chromium-review.googlesource.com/1228957
Commit-Queue: Jialiu Lin <jialiul@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Reviewed-by: Steven Holte <holte@chromium.org>
Reviewed-by: Bret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594031}
diff --git a/chrome/browser/ui/BUILD.gn b/chrome/browser/ui/BUILD.gn
index 6a8ba77..5c5f964 100644
--- a/chrome/browser/ui/BUILD.gn
+++ b/chrome/browser/ui/BUILD.gn
@@ -3663,6 +3663,7 @@
       "//chrome/browser/ui/webui/reset_password:mojo_bindings",
       "//chrome/common/safe_browsing:proto",
       "//components/safe_browsing:csd_proto",
+      "//components/safe_browsing/password_protection:password_protection_metrics_util",
     ]
   }
 
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index 4c94a680..65881ea 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -119,6 +119,7 @@
 #include "components/omnibox/browser/omnibox_popup_view.h"
 #include "components/omnibox/browser/omnibox_view.h"
 #include "components/prefs/pref_service.h"
+#include "components/safe_browsing/password_protection/metrics_util.h"
 #include "components/sessions/core/tab_restore_service.h"
 #include "components/signin/core/browser/profile_management_switches.h"
 #include "components/translate/core/browser/language_state.h"
@@ -2085,6 +2086,7 @@
 void BrowserView::OnWindowEndUserBoundsChange() {
   if (!interactive_resize_)
     return;
+  safe_browsing::LogContentsSize(GetContentsSize());
   auto now = base::TimeTicks::Now();
   DCHECK(!interactive_resize_->begin_timestamp.is_null());
   UMA_HISTOGRAM_TIMES("BrowserWindow.Resize.Duration",
diff --git a/chrome/browser/ui/views/frame/browser_window_factory.cc b/chrome/browser/ui/views/frame/browser_window_factory.cc
index 98cd0ad..f3a3c00 100644
--- a/chrome/browser/ui/views/frame/browser_window_factory.cc
+++ b/chrome/browser/ui/views/frame/browser_window_factory.cc
@@ -10,6 +10,7 @@
 #include "chrome/browser/ui/views/frame/native_browser_frame_factory.h"
 #include "chrome/browser/ui/views_mode_controller.h"
 #include "chrome/grit/chromium_strings.h"
+#include "components/safe_browsing/password_protection/metrics_util.h"
 #if defined(USE_AURA)
 #include "ui/aura/client/aura_constants.h"
 #include "ui/aura/window.h"
@@ -40,5 +41,6 @@
   view->GetWidget()->GetNativeWindow()->SetProperty(
       aura::client::kCreatedByUserGesture, user_gesture);
 #endif
+  safe_browsing::LogContentsSize(view->GetContentsSize());
   return view;
 }
diff --git a/components/safe_browsing/password_protection/BUILD.gn b/components/safe_browsing/password_protection/BUILD.gn
index c1d76c9..87b9e3f5 100644
--- a/components/safe_browsing/password_protection/BUILD.gn
+++ b/components/safe_browsing/password_protection/BUILD.gn
@@ -50,6 +50,7 @@
     "//base",
     "//components/safe_browsing:csd_proto",
     "//net:net",
+    "//ui/gfx/geometry:geometry",
   ]
 }
 
diff --git a/components/safe_browsing/password_protection/DEPS b/components/safe_browsing/password_protection/DEPS
index 0aea96d..c305e06 100644
--- a/components/safe_browsing/password_protection/DEPS
+++ b/components/safe_browsing/password_protection/DEPS
@@ -9,5 +9,6 @@
   "+net",
   "+services/network/public",
   "+services/network/test",
+  "+ui/gfx/geometry",
 ]
 
diff --git a/components/safe_browsing/password_protection/metrics_util.cc b/components/safe_browsing/password_protection/metrics_util.cc
index 9f5655de..6e6bfa2 100644
--- a/components/safe_browsing/password_protection/metrics_util.cc
+++ b/components/safe_browsing/password_protection/metrics_util.cc
@@ -238,4 +238,11 @@
       reuse_count);
 }
 
+void LogContentsSize(const gfx::Size& size) {
+  if (size.width() <= 0 || size.height() <= 0)
+    return;
+  UMA_HISTOGRAM_COUNTS_10000("SafeBrowsing.ContentsSize.Width", size.width());
+  UMA_HISTOGRAM_COUNTS_10000("SafeBrowsing.ContentsSize.Height", size.height());
+}
+
 }  // namespace safe_browsing
diff --git a/components/safe_browsing/password_protection/metrics_util.h b/components/safe_browsing/password_protection/metrics_util.h
index 07577e8..4ffbc45 100644
--- a/components/safe_browsing/password_protection/metrics_util.h
+++ b/components/safe_browsing/password_protection/metrics_util.h
@@ -7,6 +7,7 @@
 
 #include "base/macros.h"
 #include "components/safe_browsing/proto/csd.pb.h"
+#include "ui/gfx/geometry/size.h"
 
 namespace base {
 class TimeTicks;
@@ -183,6 +184,9 @@
     LoginReputationClientResponse::VerdictType verdict_type,
     int referrer_chain_size);
 
+// Logs the content area size in DIPs.
+void LogContentsSize(const gfx::Size& size);
+
 }  // namespace safe_browsing
 
 #endif  // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_METRICS_UTIL_H_
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index f830099..58c10c7 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -86748,6 +86748,26 @@
   </summary>
 </histogram>
 
+<histogram name="SafeBrowsing.ContentsSize.Height" units="DIPs"
+    expires_after="M73">
+  <owner>jialiul@chrormium.org</owner>
+  <owner>nparker@chromium.org</owner>
+  <summary>
+    Records the height of content area when the user opens a new browser window
+    or when the user finishes resizing a browser window.
+  </summary>
+</histogram>
+
+<histogram name="SafeBrowsing.ContentsSize.Width" units="DIPs"
+    expires_after="M73">
+  <owner>jialiul@chrormium.org</owner>
+  <owner>nparker@chromium.org</owner>
+  <summary>
+    Records the width of content area when the user opens a new browser window
+    or when the user finishes resizing a browser window.
+  </summary>
+</histogram>
+
 <histogram name="SafeBrowsing.EnabledSettingChanged" enum="BooleanEnabled">
   <obsolete>
     Not in the code anymore (10/2015).