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/android/metrics/uma_session_stats.h" | 5 #include "chrome/browser/android/metrics/uma_session_stats.h" |
| 6 | 6 |
| 7 #include "base/android/jni_array.h" | 7 #include "base/android/jni_array.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 15 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/installer/util/google_update_settings.h" | 18 #include "chrome/installer/util/google_update_settings.h" |
| 19 #include "components/metrics/metrics_pref_names.h" | 19 #include "components/metrics/metrics_pref_names.h" |
| 20 #include "components/metrics/metrics_service.h" | 20 #include "components/metrics/metrics_service.h" |
| 21 #include "components/metrics_services_manager/metrics_services_manager.h" | 21 #include "components/metrics_services_manager/metrics_services_manager.h" |
| 22 #include "components/prefs/pref_service.h" | 22 #include "components/prefs/pref_service.h" |
| 23 #include "components/ukm/ukm_service.h" | |
| 23 #include "components/variations/metrics_util.h" | 24 #include "components/variations/metrics_util.h" |
| 24 #include "components/variations/variations_associated_data.h" | 25 #include "components/variations/variations_associated_data.h" |
| 25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/user_metrics.h" | 27 #include "content/public/browser/user_metrics.h" |
| 27 #include "jni/UmaSessionStats_jni.h" | 28 #include "jni/UmaSessionStats_jni.h" |
| 28 | 29 |
| 29 using base::android::ConvertJavaStringToUTF8; | 30 using base::android::ConvertJavaStringToUTF8; |
| 30 using base::android::JavaParamRef; | 31 using base::android::JavaParamRef; |
| 31 using base::UserMetricsAction; | 32 using base::UserMetricsAction; |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 UmaSessionStats* g_uma_session_stats = NULL; | 35 UmaSessionStats* g_uma_session_stats = NULL; |
| 35 } // namespace | 36 } // namespace |
| 36 | 37 |
| 37 UmaSessionStats::UmaSessionStats() | 38 UmaSessionStats::UmaSessionStats() |
| 38 : active_session_count_(0) { | 39 : active_session_count_(0) { |
| 39 } | 40 } |
| 40 | 41 |
| 41 UmaSessionStats::~UmaSessionStats() { | 42 UmaSessionStats::~UmaSessionStats() { |
| 42 } | 43 } |
| 43 | 44 |
| 44 void UmaSessionStats::UmaResumeSession(JNIEnv* env, | 45 void UmaSessionStats::UmaResumeSession(JNIEnv* env, |
| 45 const JavaParamRef<jobject>& obj) { | 46 const JavaParamRef<jobject>& obj) { |
| 46 DCHECK(g_browser_process); | 47 DCHECK(g_browser_process); |
| 47 | 48 |
| 48 if (active_session_count_ == 0) { | 49 if (active_session_count_ == 0) { |
| 49 session_start_time_ = base::TimeTicks::Now(); | 50 session_start_time_ = base::TimeTicks::Now(); |
| 50 | 51 |
| 51 // Tell the metrics service that the application resumes. | 52 // Tell the metrics services that the application resumes. |
| 52 metrics::MetricsService* metrics = g_browser_process->metrics_service(); | 53 metrics::MetricsService* metrics = g_browser_process->metrics_service(); |
| 53 if (metrics) { | 54 if (metrics) { |
| 54 metrics->OnAppEnterForeground(); | 55 metrics->OnAppEnterForeground(); |
| 55 } | 56 } |
| 57 ukm::UkmService* ukm_service = g_browser_process->ukm_service(); | |
| 58 if (ukm_service) { | |
|
Alexei Svitkine (slow)
2017/03/01 22:56:13
Nit: No {}s
Remove them from metrics service case
Bryan McQuade
2017/03/01 23:06:50
Done
| |
| 59 ukm_service->OnAppEnterForeground(); | |
| 60 } | |
| 56 } | 61 } |
| 57 ++active_session_count_; | 62 ++active_session_count_; |
| 58 } | 63 } |
| 59 | 64 |
| 60 void UmaSessionStats::UmaEndSession(JNIEnv* env, | 65 void UmaSessionStats::UmaEndSession(JNIEnv* env, |
| 61 const JavaParamRef<jobject>& obj) { | 66 const JavaParamRef<jobject>& obj) { |
| 62 --active_session_count_; | 67 --active_session_count_; |
| 63 DCHECK_GE(active_session_count_, 0); | 68 DCHECK_GE(active_session_count_, 0); |
| 64 | 69 |
| 65 if (active_session_count_ == 0) { | 70 if (active_session_count_ == 0) { |
| 66 base::TimeDelta duration = base::TimeTicks::Now() - session_start_time_; | 71 base::TimeDelta duration = base::TimeTicks::Now() - session_start_time_; |
| 67 | 72 |
| 68 // Note: This metric is recorded separately on desktop in | 73 // Note: This metric is recorded separately on desktop in |
| 69 // DesktopSessionDurationTracker::EndSession. | 74 // DesktopSessionDurationTracker::EndSession. |
| 70 UMA_HISTOGRAM_LONG_TIMES("Session.TotalDuration", duration); | 75 UMA_HISTOGRAM_LONG_TIMES("Session.TotalDuration", duration); |
| 71 | 76 |
| 72 DCHECK(g_browser_process); | 77 DCHECK(g_browser_process); |
| 73 // Tell the metrics service it was cleanly shutdown. | 78 // Tell the metrics services they were cleanly shutdown. |
| 74 metrics::MetricsService* metrics = g_browser_process->metrics_service(); | 79 metrics::MetricsService* metrics = g_browser_process->metrics_service(); |
| 75 if (metrics) { | 80 if (metrics) { |
| 76 metrics->OnAppEnterBackground(); | 81 metrics->OnAppEnterBackground(); |
| 77 } | 82 } |
| 83 ukm::UkmService* ukm_service = g_browser_process->ukm_service(); | |
| 84 if (ukm_service) { | |
| 85 ukm_service->OnAppEnterBackground(); | |
| 86 } | |
| 78 } | 87 } |
| 79 } | 88 } |
| 80 | 89 |
| 81 // static | 90 // static |
| 82 void UmaSessionStats::RegisterSyntheticFieldTrial( | 91 void UmaSessionStats::RegisterSyntheticFieldTrial( |
| 83 const std::string& trial_name, | 92 const std::string& trial_name, |
| 84 const std::string& group_name) { | 93 const std::string& group_name) { |
| 85 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(trial_name, | 94 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(trial_name, |
| 86 group_name); | 95 group_name); |
| 87 } | 96 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 // We should have only one UmaSessionStats instance. | 242 // We should have only one UmaSessionStats instance. |
| 234 DCHECK(!g_uma_session_stats); | 243 DCHECK(!g_uma_session_stats); |
| 235 g_uma_session_stats = new UmaSessionStats(); | 244 g_uma_session_stats = new UmaSessionStats(); |
| 236 return reinterpret_cast<intptr_t>(g_uma_session_stats); | 245 return reinterpret_cast<intptr_t>(g_uma_session_stats); |
| 237 } | 246 } |
| 238 | 247 |
| 239 // Register native methods | 248 // Register native methods |
| 240 bool RegisterUmaSessionStats(JNIEnv* env) { | 249 bool RegisterUmaSessionStats(JNIEnv* env) { |
| 241 return RegisterNativesImpl(env); | 250 return RegisterNativesImpl(env); |
| 242 } | 251 } |
| OLD | NEW |