Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/android/vr_shell/vr_usage_monitor.h" | 5 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "components/rappor/public/rappor_utils.h" | 10 #include "components/rappor/public/rappor_utils.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 | 116 |
| 117 void SendAccumulatedSessionTime() override { | 117 void SendAccumulatedSessionTime() override { |
| 118 if (!accumulated_time_.is_zero()) { | 118 if (!accumulated_time_.is_zero()) { |
| 119 UMA_HISTOGRAM_CUSTOM_TIMES(HistogramNameFromSessionType(sessionType), | 119 UMA_HISTOGRAM_CUSTOM_TIMES(HistogramNameFromSessionType(sessionType), |
| 120 accumulated_time_, base::TimeDelta(), | 120 accumulated_time_, base::TimeDelta(), |
| 121 base::TimeDelta::FromHours(5), 100); | 121 base::TimeDelta::FromHours(5), 100); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 bool VrMetricsHelper::logged_gvr_version_ = false; | |
| 127 | |
| 126 void SessionTimer::StartSession(base::Time start_time) { | 128 void SessionTimer::StartSession(base::Time start_time) { |
| 127 // If the new start time is within the minimum session gap time from the last | 129 // If the new start time is within the minimum session gap time from the last |
| 128 // stop, continue the previous session. | 130 // stop, continue the previous session. |
| 129 // Otherwise, start a new session, sending the event for the last session. | 131 // Otherwise, start a new session, sending the event for the last session. |
| 130 if (!stop_time_.is_null() && | 132 if (!stop_time_.is_null() && |
| 131 start_time - stop_time_ <= maximum_session_gap_time_) { | 133 start_time - stop_time_ <= maximum_session_gap_time_) { |
| 132 // Mark the previous segment as non-continuable, sending data and clearing | 134 // Mark the previous segment as non-continuable, sending data and clearing |
| 133 // state. | 135 // state. |
| 134 StopSession(false, stop_time_); | 136 StopSession(false, stop_time_); |
| 135 } | 137 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 } else if (is_webvr_) { | 171 } else if (is_webvr_) { |
| 170 mode = VRMode::WEBVR; | 172 mode = VRMode::WEBVR; |
| 171 } else { | 173 } else { |
| 172 mode = is_fullscreen_ ? VRMode::VR_FULLSCREEN : VRMode::VR_BROWSER; | 174 mode = is_fullscreen_ ? VRMode::VR_FULLSCREEN : VRMode::VR_BROWSER; |
| 173 } | 175 } |
| 174 | 176 |
| 175 if (mode != mode_) | 177 if (mode != mode_) |
| 176 SetVrMode(mode); | 178 SetVrMode(mode); |
| 177 } | 179 } |
| 178 | 180 |
| 181 ViewerType VrMetricsHelper::GetVrViewerType(gvr_context* context) { | |
| 182 auto gvr_api = gvr::GvrApi::WrapNonOwned(context); | |
| 183 switch (gvr_api->GetViewerType()) { | |
| 184 case gvr::ViewerType::GVR_VIEWER_TYPE_DAYDREAM: | |
| 185 return ViewerType::DAYDREAM; | |
| 186 case gvr::ViewerType::GVR_VIEWER_TYPE_CARDBOARD: | |
| 187 return ViewerType::CARDBOARD; | |
| 188 default: | |
| 189 NOTREACHED(); | |
| 190 return ViewerType::UNKNOWN_TYPE; | |
| 191 } | |
| 192 } | |
| 193 | |
| 179 void VrMetricsHelper::SetWebVREnabled(bool is_webvr_presenting) { | 194 void VrMetricsHelper::SetWebVREnabled(bool is_webvr_presenting) { |
| 180 is_webvr_ = is_webvr_presenting; | 195 is_webvr_ = is_webvr_presenting; |
| 181 UpdateMode(); | 196 UpdateMode(); |
| 182 } | 197 } |
| 183 | 198 |
| 184 void VrMetricsHelper::SetVRActive(bool is_vr_enabled) { | 199 void VrMetricsHelper::SetVRActive(bool is_vr_enabled) { |
| 185 is_vr_enabled_ = is_vr_enabled; | 200 is_vr_enabled_ = is_vr_enabled; |
| 186 UpdateMode(); | 201 UpdateMode(); |
| 187 } | 202 } |
| 188 | 203 |
| 204 void VrMetricsHelper::LogGvrVersionAndVrViewerType(gvr_context* context, | |
| 205 gvr_version version) { | |
| 206 if (!logged_gvr_version_) { | |
| 207 // Resolves to GVR_OTHER. Should not happen. | |
| 208 int gvr_version_numeric = static_cast<int>( | |
| 209 GVRVersionCrossedVRViewerType::GVR_OTHER_AND_UNKNOWN_TYPE); | |
| 210 if (version.major < 0) { | |
| 211 gvr_version_numeric = | |
| 212 static_cast<int>(GVRVersionCrossedVRViewerType::GVR_NONE); | |
| 213 } else if (version.major < 1) { | |
| 214 gvr_version_numeric = 0; | |
| 215 } else if (version.major == 1 && version.major <= 40) { | |
| 216 switch (version.minor) { | |
| 217 case 10: | |
| 218 gvr_version_numeric = static_cast<int>( | |
| 219 GVRVersionCrossedVRViewerType::GVR_1_10_AND_UNKNOWN_TYPE); | |
| 220 break; | |
| 221 case 20: | |
| 222 gvr_version_numeric = static_cast<int>( | |
| 223 GVRVersionCrossedVRViewerType::GVR_1_20_AND_UNKNOWN_TYPE); | |
| 224 break; | |
| 225 case 30: | |
| 226 gvr_version_numeric = static_cast<int>( | |
| 227 GVRVersionCrossedVRViewerType::GVR_1_30_AND_UNKNOWN_TYPE); | |
| 228 break; | |
| 229 case 40: | |
| 230 gvr_version_numeric = static_cast<int>( | |
| 231 GVRVersionCrossedVRViewerType::GVR_1_40_AND_UNKNOWN_TYPE); | |
| 232 break; | |
| 233 } | |
| 234 } else { | |
| 235 gvr_version_numeric = static_cast<int>( | |
| 236 GVRVersionCrossedVRViewerType::GVR_NEWER_AND_UNKNOWN_TYPE); | |
| 237 } | |
| 238 ViewerType vr_viewer_type = | |
| 239 context ? GetVrViewerType(context) : ViewerType::UNKNOWN_TYPE; | |
| 240 | |
| 241 int datum = static_cast<int>(vr_viewer_type) * 7 + gvr_version_numeric; | |
|
ddorwin
2017/05/05 20:29:59
Magic number. Also, this doesn't seem maintainable
tiborg
2017/05/10 20:39:52
It's gone in favor of the UMA_HISTOGRAM_SPARSE_SLO
| |
| 242 UMA_HISTOGRAM_ENUMERATION( | |
| 243 "GVRVersionCrossedVRViewerType", datum, | |
| 244 static_cast<int>(GVRVersionCrossedVRViewerType:: | |
| 245 GVR_VERSION_CROSSED_VR_VIEWER_TYPE_MAX)); | |
| 246 logged_gvr_version_ = true; | |
| 247 } | |
| 248 } | |
| 249 | |
| 250 void VrMetricsHelper::LogVrViewerType(gvr_context* context) { | |
| 251 UMA_HISTOGRAM_ENUMERATION("VRViewerType", | |
| 252 static_cast<int>(GetVrViewerType(context)), | |
| 253 static_cast<int>(ViewerType::VIEWER_TYPE_MAX)); | |
| 254 } | |
| 255 | |
| 189 void VrMetricsHelper::SetVrMode(VRMode mode) { | 256 void VrMetricsHelper::SetVrMode(VRMode mode) { |
| 190 DCHECK(mode != mode_); | 257 DCHECK(mode != mode_); |
| 191 | 258 |
| 192 base::Time switchTime = base::Time::Now(); | 259 base::Time switchTime = base::Time::Now(); |
| 193 | 260 |
| 194 // stop the previous modes | 261 // stop the previous modes |
| 195 if (mode_ != VRMode::NO_VR) { | 262 if (mode_ != VRMode::NO_VR) { |
| 196 if (num_videos_playing_ > 0) | 263 if (num_videos_playing_ > 0) |
| 197 mode_video_timer_->StopSession(false, switchTime); | 264 mode_video_timer_->StopSession(false, switchTime); |
| 198 | 265 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 } | 396 } |
| 330 } | 397 } |
| 331 | 398 |
| 332 void VrMetricsHelper::DidToggleFullscreenModeForTab(bool entered_fullscreen, | 399 void VrMetricsHelper::DidToggleFullscreenModeForTab(bool entered_fullscreen, |
| 333 bool will_cause_resize) { | 400 bool will_cause_resize) { |
| 334 is_fullscreen_ = entered_fullscreen; | 401 is_fullscreen_ = entered_fullscreen; |
| 335 UpdateMode(); | 402 UpdateMode(); |
| 336 } | 403 } |
| 337 | 404 |
| 338 } // namespace vr_shell | 405 } // namespace vr_shell |
| OLD | NEW |