Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics_mac.h" | |
| 6 | |
| 7 #include <Cocoa/Cocoa.h> | |
| 8 | |
| 9 #include "base/metrics/histogram.h" | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 // The maximum number of screens to record in UMA. | |
| 14 NSUInteger kMaxScreens = 10; | |
| 15 | |
| 16 } // namespace | |
| 17 | |
| 18 @interface MetricsBridge : NSObject { | |
| 19 NSUInteger screenCount_; | |
| 20 } | |
| 21 @end | |
| 22 | |
| 23 @implementation MetricsBridge | |
|
Robert Sesek
2014/10/08 19:25:20
Could you instead use gfx::Screen::AddObserver(gfx
erikchen
2014/10/08 22:49:19
I went with your suggestion and also switched to G
| |
| 24 - (instancetype)init { | |
| 25 self = [super init]; | |
| 26 if (self) { | |
| 27 screenCount_ = [[NSScreen screens] count]; | |
| 28 [[NSNotificationCenter defaultCenter] | |
| 29 addObserver:self | |
| 30 selector:@selector(didChangeScreenParameters:) | |
| 31 name:NSApplicationDidChangeScreenParametersNotification | |
| 32 object:nil]; | |
| 33 | |
| 34 UMA_HISTOGRAM_ENUMERATION("OSX.DisplayCount.StartUp", | |
| 35 std::min(kMaxScreens, screenCount_), | |
| 36 kMaxScreens + 1); | |
| 37 } | |
| 38 return self; | |
| 39 } | |
| 40 | |
| 41 - (void)dealloc { | |
| 42 [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
| 43 [super dealloc]; | |
| 44 } | |
| 45 | |
| 46 - (void)didChangeScreenParameters:(NSNotification*)notification { | |
| 47 NSUInteger screenCount = [[NSScreen screens] count]; | |
| 48 if (screenCount != screenCount_) { | |
| 49 screenCount_ = screenCount; | |
| 50 UMA_HISTOGRAM_ENUMERATION("OSX.DisplayCount.Changed", | |
|
Robert Sesek
2014/10/08 19:25:20
This seems like a _COUNTS instead of an _ENUMERATI
erikchen
2014/10/08 22:49:19
_COUNTS uses an exponential histogram (even _COUNT
| |
| 51 std::min(kMaxScreens, screenCount_), | |
| 52 kMaxScreens + 1); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 @end | |
| 57 | |
| 58 ChromeBrowserMainExtraPartsMetricsMac::ChromeBrowserMainExtraPartsMetricsMac() { | |
| 59 metrics_bridge_ = static_cast<void*>([[MetricsBridge alloc] init]); | |
| 60 } | |
| 61 | |
| 62 ChromeBrowserMainExtraPartsMetricsMac:: | |
| 63 ~ChromeBrowserMainExtraPartsMetricsMac() { | |
| 64 [static_cast<NSObject*>(metrics_bridge_) release]; | |
| 65 } | |
| OLD | NEW |