diff options
author | blundell <blundell@chromium.org> | 2015-10-12 04:46:12 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-12 11:48:02 +0000 |
commit | 8e66adc013e56533cd493139c1a067eb8df7345c (patch) | |
tree | 40e20fa73813e316dc3cec920006f7910c318db7 | |
parent | 3d9a9fc2d3a9944d34980750fbc748b1e4cc19a4 (diff) | |
download | chromium_src-8e66adc013e56533cd493139c1a067eb8df7345c.zip chromium_src-8e66adc013e56533cd493139c1a067eb8df7345c.tar.gz chromium_src-8e66adc013e56533cd493139c1a067eb8df7345c.tar.bz2 |
Split screen info metrics out of GpuMetricsProvider
GpuMetricsProvider has two functions:
(1) Provide GPU metrics (dependent on //content)
(2) Provide screen info metrics (independent of //content)
This CL splits (2) into ScreenInfoMetricsProvider so that the iOS port
can depend cleanly on it.
BUG=527718
TBR=halliwell, jochen
Review URL: https://codereview.chromium.org/1380953004
Cr-Commit-Position: refs/heads/master@{#353510}
-rw-r--r-- | chrome/browser/BUILD.gn | 1 | ||||
-rw-r--r-- | chrome/browser/metrics/chrome_metrics_service_client.cc | 4 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 1 | ||||
-rw-r--r-- | chromecast/browser/BUILD.gn | 4 | ||||
-rw-r--r-- | chromecast/browser/metrics/cast_metrics_service_client.cc | 7 | ||||
-rw-r--r-- | chromecast/chromecast.gyp | 4 | ||||
-rw-r--r-- | components/components_tests.gyp | 3 | ||||
-rw-r--r-- | components/metrics.gypi | 18 | ||||
-rw-r--r-- | components/metrics/BUILD.gn | 20 | ||||
-rw-r--r-- | components/metrics/gpu/DEPS | 1 | ||||
-rw-r--r-- | components/metrics/gpu/gpu_metrics_provider.cc | 70 | ||||
-rw-r--r-- | components/metrics/gpu/gpu_metrics_provider.h | 13 | ||||
-rw-r--r-- | components/metrics/ui/DEPS | 3 | ||||
-rw-r--r-- | components/metrics/ui/screen_info_metrics_provider.cc | 93 | ||||
-rw-r--r-- | components/metrics/ui/screen_info_metrics_provider.h | 42 | ||||
-rw-r--r-- | components/metrics/ui/screen_info_metrics_provider_unittest.cc (renamed from components/metrics/gpu/gpu_metrics_provider_unittest.cc) | 24 |
16 files changed, 208 insertions, 100 deletions
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn index 36990e6..b85eb2d5 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -133,6 +133,7 @@ source_set("browser") { "//components/metrics:net", "//components/metrics:profiler", "//components/metrics/proto:proto", + "//components/metrics:ui", "//components/mime_util", "//components/navigation_metrics", "//components/network_time", diff --git a/chrome/browser/metrics/chrome_metrics_service_client.cc b/chrome/browser/metrics/chrome_metrics_service_client.cc index 67dec95..cb43094 100644 --- a/chrome/browser/metrics/chrome_metrics_service_client.cc +++ b/chrome/browser/metrics/chrome_metrics_service_client.cc @@ -40,6 +40,7 @@ #include "components/metrics/profiler/profiler_metrics_provider.h" #include "components/metrics/profiler/tracking_synchronizer.h" #include "components/metrics/stability_metrics_helper.h" +#include "components/metrics/ui/screen_info_metrics_provider.h" #include "components/metrics/url_constants.h" #include "components/omnibox/browser/omnibox_metrics_provider.h" #include "components/variations/variations_associated_data.h" @@ -321,6 +322,9 @@ void ChromeMetricsServiceClient::Initialize() { g_browser_process->local_state()))); metrics_service_->RegisterMetricsProvider( scoped_ptr<metrics::MetricsProvider>(new metrics::GPUMetricsProvider)); + metrics_service_->RegisterMetricsProvider( + scoped_ptr<metrics::MetricsProvider>( + new metrics::ScreenInfoMetricsProvider)); drive_metrics_provider_ = new metrics::DriveMetricsProvider( content::BrowserThread::GetMessageLoopProxyForThread( diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index b4558dd..e5545b5 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3115,6 +3115,7 @@ '../components/components.gyp:invalidation_impl', '../components/components.gyp:metrics', '../components/components.gyp:metrics_net', + '../components/components.gyp:metrics_ui', '../components/components.gyp:navigation_metrics', '../components/components.gyp:network_time', '../components/components.gyp:offline_pages', diff --git a/chromecast/browser/BUILD.gn b/chromecast/browser/BUILD.gn index c0bc4b7..358bff1 100644 --- a/chromecast/browser/BUILD.gn +++ b/chromecast/browser/BUILD.gn @@ -81,6 +81,10 @@ source_set("browser") { "//components/metrics:gpu", "//components/metrics:net", "//components/metrics:profiler", + + # TODO(gfhuang): Eliminate this dependency if ScreenInfoMetricsProvider + # isn't needed. crbug.com/541577 + "//components/metrics:ui", "//components/network_hints/browser", "//content", "//content/public/browser", diff --git a/chromecast/browser/metrics/cast_metrics_service_client.cc b/chromecast/browser/metrics/cast_metrics_service_client.cc index ba878fc..5090ba4 100644 --- a/chromecast/browser/metrics/cast_metrics_service_client.cc +++ b/chromecast/browser/metrics/cast_metrics_service_client.cc @@ -29,6 +29,7 @@ #include "components/metrics/net/net_metrics_log_uploader.h" #include "components/metrics/net/network_metrics_provider.h" #include "components/metrics/profiler/profiler_metrics_provider.h" +#include "components/metrics/ui/screen_info_metrics_provider.h" #include "components/metrics/url_constants.h" #include "content/public/common/content_switches.h" @@ -334,6 +335,12 @@ void CastMetricsServiceClient::Initialize(CastService* cast_service) { metrics_service_->RegisterMetricsProvider( scoped_ptr< ::metrics::MetricsProvider>( new ::metrics::GPUMetricsProvider)); + + // TODO(gfhuang): Does ChromeCast actually need metrics about screen info? + // crbug.com/541577 + metrics_service_->RegisterMetricsProvider( + scoped_ptr< ::metrics::MetricsProvider>( + new ::metrics::ScreenInfoMetricsProvider)); } metrics_service_->RegisterMetricsProvider( scoped_ptr< ::metrics::MetricsProvider>( diff --git a/chromecast/chromecast.gyp b/chromecast/chromecast.gyp index ef0027c..ee7afaa 100644 --- a/chromecast/chromecast.gyp +++ b/chromecast/chromecast.gyp @@ -335,6 +335,10 @@ '../components/components.gyp:metrics_gpu', '../components/components.gyp:metrics_net', '../components/components.gyp:metrics_profiler', + + # TODO(gfhuang): Eliminate this dependency if ScreenInfoMetricsProvider + # isn't needed. crbug.com/541577 + '../components/components.gyp:metrics_ui', '../content/content.gyp:content', '../content/content.gyp:content_app_both', '../skia/skia.gyp:skia', diff --git a/components/components_tests.gyp b/components/components_tests.gyp index 513fc7f..21bf32a 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -333,7 +333,6 @@ 'metrics/call_stack_profile_metrics_provider_unittest.cc', 'metrics/daily_event_unittest.cc', 'metrics/drive_metrics_provider_unittest.cc', - 'metrics/gpu/gpu_metrics_provider_unittest.cc', 'metrics/histogram_encoder_unittest.cc', 'metrics/machine_id_provider_win_unittest.cc', 'metrics/metrics_hashes_unittest.cc', @@ -347,6 +346,7 @@ 'metrics/profiler/profiler_metrics_provider_unittest.cc', 'metrics/profiler/tracking_synchronizer_unittest.cc', 'metrics/stability_metrics_helper_unittest.cc', + 'metrics/ui/screen_info_metrics_provider_unittest.cc', ], 'mime_util_unittest_sources': [ 'mime_util/mime_util_unittest.cc', @@ -959,6 +959,7 @@ 'components.gyp:metrics', 'components.gyp:metrics_net', 'components.gyp:metrics_test_support', + 'components.gyp:metrics_ui', 'components.gyp:net_log', 'components.gyp:network_time', 'components.gyp:offline_pages', diff --git a/components/metrics.gypi b/components/metrics.gypi index 5910f74..1004449 100644 --- a/components/metrics.gypi +++ b/components/metrics.gypi @@ -122,6 +122,23 @@ ], }, { + # GN version: //components/metrics:ui + 'target_name': 'metrics_ui', + 'type': 'static_library', + 'include_dirs': [ + '..', + ], + 'dependencies': [ + '../base/base.gyp:base', + '../ui/gfx/gfx.gyp:gfx', + 'metrics', + ], + 'sources': [ + 'metrics/ui/screen_info_metrics_provider.cc', + 'metrics/ui/screen_info_metrics_provider.h', + ], + }, + { # Protobuf compiler / generator for UMA (User Metrics Analysis). # # GN version: //components/metrics/proto:proto @@ -201,7 +218,6 @@ 'dependencies': [ '../base/base.gyp:base', '../content/content.gyp:content_browser', - '../ui/gfx/gfx.gyp:gfx', 'component_metrics_proto', 'metrics', ], diff --git a/components/metrics/BUILD.gn b/components/metrics/BUILD.gn index 52ab51d..52d7528 100644 --- a/components/metrics/BUILD.gn +++ b/components/metrics/BUILD.gn @@ -97,7 +97,6 @@ if (!is_ios) { "//base", "//content/public/browser", "//gpu/config", - "//ui/gfx", ] } } @@ -129,6 +128,22 @@ static_library("net") { ] } +# GYP version: components/metrics.gypi:metrics_ui +source_set("ui") { + sources = [ + "ui/screen_info_metrics_provider.cc", + "ui/screen_info_metrics_provider.h", + ] + + public_deps = [ + ":metrics", + ] + deps = [ + "//base", + "//ui/gfx", + ] +} + if (!is_ios) { # GYP version: components/metrics.gypi:metrics_profiler source_set("profiler") { @@ -202,12 +217,14 @@ source_set("unit_tests") { "net/net_metrics_log_uploader_unittest.cc", "persisted_logs_unittest.cc", "stability_metrics_helper_unittest.cc", + "ui/screen_info_metrics_provider_unittest.cc", ] deps = [ ":metrics", ":net", ":test_support", + ":ui", "//base:prefs_test_support", "//base/test:test_support", "//components/variations", @@ -221,7 +238,6 @@ source_set("unit_tests") { ":profiler", ] sources += [ - "gpu/gpu_metrics_provider_unittest.cc", "profiler/profiler_metrics_provider_unittest.cc", "profiler/tracking_synchronizer_unittest.cc", ] diff --git a/components/metrics/gpu/DEPS b/components/metrics/gpu/DEPS index 537521e..c2ff8a0 100644 --- a/components/metrics/gpu/DEPS +++ b/components/metrics/gpu/DEPS @@ -1,5 +1,4 @@ include_rules = [ "+content/public/browser", "+gpu/config", - "+ui/gfx", ] diff --git a/components/metrics/gpu/gpu_metrics_provider.cc b/components/metrics/gpu/gpu_metrics_provider.cc index f6c4d08..19cf9b4 100644 --- a/components/metrics/gpu/gpu_metrics_provider.cc +++ b/components/metrics/gpu/gpu_metrics_provider.cc @@ -7,55 +7,9 @@ #include "components/metrics/proto/system_profile.pb.h" #include "content/public/browser/gpu_data_manager.h" #include "gpu/config/gpu_info.h" -#include "ui/gfx/screen.h" namespace metrics { -#if defined(OS_WIN) - -#include <windows.h> - -namespace { - -struct ScreenDPIInformation { - double max_dpi_x; - double max_dpi_y; -}; - -// Called once for each connected monitor. -BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) { - const double kMillimetersPerInch = 25.4; - ScreenDPIInformation* screen_info = - reinterpret_cast<ScreenDPIInformation*>(dwData); - // Size of screen, in mm. - DWORD size_x = GetDeviceCaps(hdc, HORZSIZE); - DWORD size_y = GetDeviceCaps(hdc, VERTSIZE); - double dpi_x = (size_x > 0) ? - GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0; - double dpi_y = (size_y > 0) ? - GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0; - screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x); - screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y); - return TRUE; -} - -void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) { - HDC desktop_dc = GetDC(NULL); - if (desktop_dc) { - ScreenDPIInformation si = {0, 0}; - if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback, - reinterpret_cast<LPARAM>(&si))) { - hardware->set_max_dpi_x(si.max_dpi_x); - hardware->set_max_dpi_y(si.max_dpi_y); - } - ReleaseDC(GetDesktopWindow(), desktop_dc); - } -} - -} // namespace - -#endif // defined(OS_WIN) - GPUMetricsProvider::GPUMetricsProvider() { } @@ -77,30 +31,6 @@ void GPUMetricsProvider::ProvideSystemProfileMetrics( gpu->set_driver_date(gpu_info.driver_date); gpu->set_gl_vendor(gpu_info.gl_vendor); gpu->set_gl_renderer(gpu_info.gl_renderer); - - const gfx::Size display_size = GetScreenSize(); - hardware->set_primary_screen_width(display_size.width()); - hardware->set_primary_screen_height(display_size.height()); - hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor()); - hardware->set_screen_count(GetScreenCount()); - -#if defined(OS_WIN) - WriteScreenDPIInformationProto(hardware); -#endif -} - -gfx::Size GPUMetricsProvider::GetScreenSize() const { - return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel(); -} - -float GPUMetricsProvider::GetScreenDeviceScaleFactor() const { - return gfx::Screen::GetNativeScreen()-> - GetPrimaryDisplay().device_scale_factor(); -} - -int GPUMetricsProvider::GetScreenCount() const { - // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312 - return gfx::Screen::GetNativeScreen()->GetNumDisplays(); } } // namespace metrics diff --git a/components/metrics/gpu/gpu_metrics_provider.h b/components/metrics/gpu/gpu_metrics_provider.h index 4ca2a96..9cbdd96 100644 --- a/components/metrics/gpu/gpu_metrics_provider.h +++ b/components/metrics/gpu/gpu_metrics_provider.h @@ -7,7 +7,6 @@ #include "base/basictypes.h" #include "components/metrics/metrics_provider.h" -#include "ui/gfx/geometry/size.h" namespace metrics { @@ -21,18 +20,6 @@ class GPUMetricsProvider : public MetricsProvider { void ProvideSystemProfileMetrics( SystemProfileProto* system_profile_proto) override; - protected: - // Exposed for the sake of mocking in test code. - - // Returns the screen size for the primary monitor. - virtual gfx::Size GetScreenSize() const; - - // Returns the device scale factor for the primary monitor. - virtual float GetScreenDeviceScaleFactor() const; - - // Returns the number of monitors the user is using. - virtual int GetScreenCount() const; - private: DISALLOW_COPY_AND_ASSIGN(GPUMetricsProvider); }; diff --git a/components/metrics/ui/DEPS b/components/metrics/ui/DEPS new file mode 100644 index 0000000..b273ae3 --- /dev/null +++ b/components/metrics/ui/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+ui/gfx", +] diff --git a/components/metrics/ui/screen_info_metrics_provider.cc b/components/metrics/ui/screen_info_metrics_provider.cc new file mode 100644 index 0000000..b832542 --- /dev/null +++ b/components/metrics/ui/screen_info_metrics_provider.cc @@ -0,0 +1,93 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/metrics/ui/screen_info_metrics_provider.h" + +#include "components/metrics/proto/system_profile.pb.h" +#include "ui/gfx/screen.h" + +namespace metrics { + +#if defined(OS_WIN) + +#include <windows.h> + +namespace { + +struct ScreenDPIInformation { + double max_dpi_x; + double max_dpi_y; +}; + +// Called once for each connected monitor. +BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) { + const double kMillimetersPerInch = 25.4; + ScreenDPIInformation* screen_info = + reinterpret_cast<ScreenDPIInformation*>(dwData); + // Size of screen, in mm. + DWORD size_x = GetDeviceCaps(hdc, HORZSIZE); + DWORD size_y = GetDeviceCaps(hdc, VERTSIZE); + double dpi_x = (size_x > 0) ? + GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0; + double dpi_y = (size_y > 0) ? + GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0; + screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x); + screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y); + return TRUE; +} + +void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) { + HDC desktop_dc = GetDC(NULL); + if (desktop_dc) { + ScreenDPIInformation si = {0, 0}; + if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback, + reinterpret_cast<LPARAM>(&si))) { + hardware->set_max_dpi_x(si.max_dpi_x); + hardware->set_max_dpi_y(si.max_dpi_y); + } + ReleaseDC(GetDesktopWindow(), desktop_dc); + } +} + +} // namespace + +#endif // defined(OS_WIN) + +ScreenInfoMetricsProvider::ScreenInfoMetricsProvider() { +} + +ScreenInfoMetricsProvider::~ScreenInfoMetricsProvider() { +} + +void ScreenInfoMetricsProvider::ProvideSystemProfileMetrics( + SystemProfileProto* system_profile_proto) { + SystemProfileProto::Hardware* hardware = + system_profile_proto->mutable_hardware(); + + const gfx::Size display_size = GetScreenSize(); + hardware->set_primary_screen_width(display_size.width()); + hardware->set_primary_screen_height(display_size.height()); + hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor()); + hardware->set_screen_count(GetScreenCount()); + +#if defined(OS_WIN) + WriteScreenDPIInformationProto(hardware); +#endif +} + +gfx::Size ScreenInfoMetricsProvider::GetScreenSize() const { + return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel(); +} + +float ScreenInfoMetricsProvider::GetScreenDeviceScaleFactor() const { + return gfx::Screen::GetNativeScreen()-> + GetPrimaryDisplay().device_scale_factor(); +} + +int ScreenInfoMetricsProvider::GetScreenCount() const { + // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312 + return gfx::Screen::GetNativeScreen()->GetNumDisplays(); +} + +} // namespace metrics diff --git a/components/metrics/ui/screen_info_metrics_provider.h b/components/metrics/ui/screen_info_metrics_provider.h new file mode 100644 index 0000000..1d4b759 --- /dev/null +++ b/components/metrics/ui/screen_info_metrics_provider.h @@ -0,0 +1,42 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_METRICS_UI_SCREEN_INFO_METRICS_PROVIDER_H_ +#define COMPONENTS_METRICS_UI_SCREEN_INFO_METRICS_PROVIDER_H_ + +#include "base/basictypes.h" +#include "components/metrics/metrics_provider.h" +#include "ui/gfx/geometry/size.h" + +namespace metrics { + +// ScreenInfoMetricsProvider provides metrics related to screen info. +class ScreenInfoMetricsProvider : public MetricsProvider { + public: + ScreenInfoMetricsProvider(); + ~ScreenInfoMetricsProvider() override; + + // MetricsProvider: + void ProvideSystemProfileMetrics( + SystemProfileProto* system_profile_proto) override; + + protected: + // Exposed for the sake of mocking in test code. + + // Returns the screen size for the primary monitor. + virtual gfx::Size GetScreenSize() const; + + // Returns the device scale factor for the primary monitor. + virtual float GetScreenDeviceScaleFactor() const; + + // Returns the number of monitors the user is using. + virtual int GetScreenCount() const; + + private: + DISALLOW_COPY_AND_ASSIGN(ScreenInfoMetricsProvider); +}; + +} // namespace metrics + +#endif // COMPONENTS_METRICS_UI_SCREEN_INFO_METRICS_PROVIDER_H_ diff --git a/components/metrics/gpu/gpu_metrics_provider_unittest.cc b/components/metrics/ui/screen_info_metrics_provider_unittest.cc index 83d345d..7077078 100644 --- a/components/metrics/gpu/gpu_metrics_provider_unittest.cc +++ b/components/metrics/ui/screen_info_metrics_provider_unittest.cc @@ -1,8 +1,8 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "components/metrics/gpu/gpu_metrics_provider.h" +#include "components/metrics/ui/screen_info_metrics_provider.h" #include "base/basictypes.h" #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" @@ -18,10 +18,10 @@ const int kScreenHeight = 768; const int kScreenCount = 3; const float kScreenScaleFactor = 2; -class TestGPUMetricsProvider : public GPUMetricsProvider { +class TestScreenInfoMetricsProvider : public ScreenInfoMetricsProvider { public: - TestGPUMetricsProvider() {} - ~TestGPUMetricsProvider() override {} + TestScreenInfoMetricsProvider() {} + ~TestScreenInfoMetricsProvider() override {} private: gfx::Size GetScreenSize() const override { @@ -34,22 +34,22 @@ class TestGPUMetricsProvider : public GPUMetricsProvider { int GetScreenCount() const override { return kScreenCount; } - DISALLOW_COPY_AND_ASSIGN(TestGPUMetricsProvider); + DISALLOW_COPY_AND_ASSIGN(TestScreenInfoMetricsProvider); }; } // namespace -class GPUMetricsProviderTest : public testing::Test { +class ScreenInfoMetricsProviderTest : public testing::Test { public: - GPUMetricsProviderTest() {} - ~GPUMetricsProviderTest() override {} + ScreenInfoMetricsProviderTest() {} + ~ScreenInfoMetricsProviderTest() override {} private: - DISALLOW_COPY_AND_ASSIGN(GPUMetricsProviderTest); + DISALLOW_COPY_AND_ASSIGN(ScreenInfoMetricsProviderTest); }; -TEST_F(GPUMetricsProviderTest, ProvideSystemProfileMetrics) { - TestGPUMetricsProvider provider; +TEST_F(ScreenInfoMetricsProviderTest, ProvideSystemProfileMetrics) { + TestScreenInfoMetricsProvider provider; ChromeUserMetricsExtension uma_proto; provider.ProvideSystemProfileMetrics(uma_proto.mutable_system_profile()); |