Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/media/router/media_router_metrics.h" | 5 #include "chrome/browser/media/router/media_router_metrics.h" |
| 6 | 6 |
| 7 #include <limits.h> | |
| 8 | |
| 7 #include "base/macros.h" | 9 #include "base/macros.h" |
| 8 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/version.h" | |
| 12 #include "components/version_info/version_info.h" | |
| 13 #include "extensions/common/extension.h" | |
| 9 | 14 |
| 10 namespace media_router { | 15 namespace media_router { |
| 11 | 16 |
| 12 // static | 17 // static |
| 13 void MediaRouterMetrics::RecordMediaRouterDialogOrigin( | 18 void MediaRouterMetrics::RecordMediaRouterDialogOrigin( |
| 14 MediaRouterDialogOpenOrigin origin) { | 19 MediaRouterDialogOpenOrigin origin) { |
| 15 DCHECK_NE(static_cast<int>(origin), | 20 DCHECK_NE(static_cast<int>(origin), |
| 16 static_cast<int>(MediaRouterDialogOpenOrigin::TOTAL_COUNT)); | 21 static_cast<int>(MediaRouterDialogOpenOrigin::TOTAL_COUNT)); |
| 17 UMA_HISTOGRAM_ENUMERATION( | 22 UMA_HISTOGRAM_ENUMERATION( |
| 18 "MediaRouter.Icon.Click.Location", static_cast<int>(origin), | 23 "MediaRouter.Icon.Click.Location", static_cast<int>(origin), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 void MediaRouterMetrics::RecordRouteCreationOutcome( | 62 void MediaRouterMetrics::RecordRouteCreationOutcome( |
| 58 MediaRouterRouteCreationOutcome outcome) { | 63 MediaRouterRouteCreationOutcome outcome) { |
| 59 DCHECK_NE(static_cast<int>(outcome), | 64 DCHECK_NE(static_cast<int>(outcome), |
| 60 static_cast<int>( | 65 static_cast<int>( |
| 61 MediaRouterRouteCreationOutcome::TOTAL_COUNT)); | 66 MediaRouterRouteCreationOutcome::TOTAL_COUNT)); |
| 62 UMA_HISTOGRAM_ENUMERATION( | 67 UMA_HISTOGRAM_ENUMERATION( |
| 63 "MediaRouter.Route.CreationOutcome", static_cast<int>(outcome), | 68 "MediaRouter.Route.CreationOutcome", static_cast<int>(outcome), |
| 64 static_cast<int>(MediaRouterRouteCreationOutcome::TOTAL_COUNT)); | 69 static_cast<int>(MediaRouterRouteCreationOutcome::TOTAL_COUNT)); |
| 65 } | 70 } |
| 66 | 71 |
| 72 // static | |
| 73 void MediaRouterMetrics::RecordMediaRouteProviderVersion( | |
| 74 const extensions::Extension& extension) { | |
| 75 const base::Version* extension_version = extension.version(); | |
| 76 if (!extension_version) { | |
| 77 MediaRouterMetrics::RecordMediaRouteProviderVersion( | |
| 78 MediaRouteProviderVersion::UNKNOWN); | |
| 79 return; | |
| 80 } | |
| 81 | |
| 82 base::Version browser_version(version_info::GetVersionNumber()); | |
| 83 int version_difference = | |
| 84 GetVersionDifference(*extension_version, browser_version); | |
| 85 if (version_difference == std::numeric_limits<int>::min()) { | |
| 86 // Extension installed, version is invalid. | |
| 87 MediaRouterMetrics::RecordMediaRouteProviderVersion( | |
| 88 MediaRouteProviderVersion::UNKNOWN); | |
| 89 } else if (version_difference >= 0) { | |
| 90 MediaRouterMetrics::RecordMediaRouteProviderVersion( | |
| 91 MediaRouteProviderVersion::SAME_VERSION); | |
| 92 } else if (version_difference == -1) { | |
| 93 MediaRouterMetrics::RecordMediaRouteProviderVersion( | |
| 94 MediaRouteProviderVersion::PREVIOUS_VERSION); | |
| 95 } else { | |
| 96 MediaRouterMetrics::RecordMediaRouteProviderVersion( | |
| 97 MediaRouteProviderVersion::OUT_OF_DATE_VERSION); | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 // static | |
| 102 void MediaRouterMetrics::RecordMediaRouteProviderVersion( | |
| 103 MediaRouteProviderVersion version) { | |
| 104 DCHECK_NE(static_cast<int>(version), | |
|
Ilya Sherman
2016/03/16 22:23:05
Optional nit: Maybe DCHECK_LT? Ditto below.
| |
| 105 static_cast<int>(MediaRouteProviderVersion::TOTAL_COUNT)); | |
| 106 UMA_HISTOGRAM_ENUMERATION( | |
| 107 "MediaRouter.Provider.Version", static_cast<int>(version), | |
| 108 static_cast<int>(MediaRouteProviderVersion::TOTAL_COUNT)); | |
| 109 } | |
| 110 | |
| 111 // static | |
| 112 void MediaRouterMetrics::RecordMediaRouteProviderWakeup( | |
| 113 MediaRouteProviderWakeup wakeup) { | |
| 114 DCHECK_NE(static_cast<int>(wakeup), | |
| 115 static_cast<int>(MediaRouteProviderWakeup::TOTAL_COUNT)); | |
| 116 UMA_HISTOGRAM_ENUMERATION( | |
| 117 "MediaRouter.Provider.Wakeup", static_cast<int>(wakeup), | |
| 118 static_cast<int>(MediaRouteProviderWakeup::TOTAL_COUNT)); | |
| 119 } | |
| 120 | |
| 121 // static | |
| 122 int MediaRouterMetrics::GetVersionDifference(const base::Version& first, | |
| 123 const base::Version& second) { | |
| 124 if (!first.IsValid() || !first.components().size() || !second.IsValid() || | |
| 125 !second.components().size()) { | |
| 126 return std::numeric_limits<int>::min(); | |
| 127 } | |
| 128 | |
| 129 uint32_t first_major = first.components()[0]; | |
| 130 uint32_t second_major = second.components()[0]; | |
| 131 // Sanity check. | |
| 132 if (first_major < 1 || second_major < 1) | |
| 133 return std::numeric_limits<int>::min(); | |
| 134 | |
| 135 return first_major - second_major; | |
| 136 } | |
| 137 | |
| 67 } // namespace media_router | 138 } // namespace media_router |
| OLD | NEW |