| 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/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 16 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/installer/util/google_update_settings.h" | 19 #include "chrome/installer/util/google_update_settings.h" |
| 20 #include "components/metrics/metrics_pref_names.h" | 20 #include "components/metrics/metrics_pref_names.h" |
| 21 #include "components/metrics/metrics_service.h" | 21 #include "components/metrics/metrics_service.h" |
| 22 #include "components/metrics_services_manager/metrics_services_manager.h" | 22 #include "components/metrics_services_manager/metrics_services_manager.h" |
| 23 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
| 24 #include "components/ukm/ukm_service.h" | 24 #include "components/ukm/public/ukm_recorder.h" |
| 25 #include "components/variations/metrics_util.h" | 25 #include "components/variations/metrics_util.h" |
| 26 #include "components/variations/variations_associated_data.h" | 26 #include "components/variations/variations_associated_data.h" |
| 27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 28 #include "jni/UmaSessionStats_jni.h" | 28 #include "jni/UmaSessionStats_jni.h" |
| 29 | 29 |
| 30 using base::android::ConvertJavaStringToUTF8; | 30 using base::android::ConvertJavaStringToUTF8; |
| 31 using base::android::JavaParamRef; | 31 using base::android::JavaParamRef; |
| 32 using base::UserMetricsAction; | 32 using base::UserMetricsAction; |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 46 const JavaParamRef<jobject>& obj) { | 46 const JavaParamRef<jobject>& obj) { |
| 47 DCHECK(g_browser_process); | 47 DCHECK(g_browser_process); |
| 48 | 48 |
| 49 if (active_session_count_ == 0) { | 49 if (active_session_count_ == 0) { |
| 50 session_start_time_ = base::TimeTicks::Now(); | 50 session_start_time_ = base::TimeTicks::Now(); |
| 51 | 51 |
| 52 // Tell the metrics services that the application resumes. | 52 // Tell the metrics services that the application resumes. |
| 53 metrics::MetricsService* metrics = g_browser_process->metrics_service(); | 53 metrics::MetricsService* metrics = g_browser_process->metrics_service(); |
| 54 if (metrics) | 54 if (metrics) |
| 55 metrics->OnAppEnterForeground(); | 55 metrics->OnAppEnterForeground(); |
| 56 ukm::UkmService* ukm_service = g_browser_process->ukm_service(); | 56 ukm::UkmRecorder* ukm_recorder = g_browser_process->ukm_recorder(); |
| 57 if (ukm_service) | 57 if (ukm_recorder) |
| 58 ukm_service->OnAppEnterForeground(); | 58 ukm_recorder->OnAppEnterForeground(); |
| 59 } | 59 } |
| 60 ++active_session_count_; | 60 ++active_session_count_; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void UmaSessionStats::UmaEndSession(JNIEnv* env, | 63 void UmaSessionStats::UmaEndSession(JNIEnv* env, |
| 64 const JavaParamRef<jobject>& obj) { | 64 const JavaParamRef<jobject>& obj) { |
| 65 --active_session_count_; | 65 --active_session_count_; |
| 66 DCHECK_GE(active_session_count_, 0); | 66 DCHECK_GE(active_session_count_, 0); |
| 67 | 67 |
| 68 if (active_session_count_ == 0) { | 68 if (active_session_count_ == 0) { |
| 69 base::TimeDelta duration = base::TimeTicks::Now() - session_start_time_; | 69 base::TimeDelta duration = base::TimeTicks::Now() - session_start_time_; |
| 70 | 70 |
| 71 // Note: This metric is recorded separately on desktop in | 71 // Note: This metric is recorded separately on desktop in |
| 72 // DesktopSessionDurationTracker::EndSession. | 72 // DesktopSessionDurationTracker::EndSession. |
| 73 UMA_HISTOGRAM_LONG_TIMES("Session.TotalDuration", duration); | 73 UMA_HISTOGRAM_LONG_TIMES("Session.TotalDuration", duration); |
| 74 | 74 |
| 75 DCHECK(g_browser_process); | 75 DCHECK(g_browser_process); |
| 76 // Tell the metrics services they were cleanly shutdown. | 76 // Tell the metrics services they were cleanly shutdown. |
| 77 metrics::MetricsService* metrics = g_browser_process->metrics_service(); | 77 metrics::MetricsService* metrics = g_browser_process->metrics_service(); |
| 78 if (metrics) | 78 if (metrics) |
| 79 metrics->OnAppEnterBackground(); | 79 metrics->OnAppEnterBackground(); |
| 80 ukm::UkmService* ukm_service = g_browser_process->ukm_service(); | 80 ukm::UkmRecorder* ukm_recorder = g_browser_process->ukm_recorder(); |
| 81 if (ukm_service) | 81 if (ukm_recorder) |
| 82 ukm_service->OnAppEnterBackground(); | 82 ukm_recorder->OnAppEnterBackground(); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 // static | 86 // static |
| 87 void UmaSessionStats::RegisterSyntheticFieldTrial( | 87 void UmaSessionStats::RegisterSyntheticFieldTrial( |
| 88 const std::string& trial_name, | 88 const std::string& trial_name, |
| 89 const std::string& group_name) { | 89 const std::string& group_name) { |
| 90 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(trial_name, | 90 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(trial_name, |
| 91 group_name); | 91 group_name); |
| 92 } | 92 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 // We should have only one UmaSessionStats instance. | 237 // We should have only one UmaSessionStats instance. |
| 238 DCHECK(!g_uma_session_stats); | 238 DCHECK(!g_uma_session_stats); |
| 239 g_uma_session_stats = new UmaSessionStats(); | 239 g_uma_session_stats = new UmaSessionStats(); |
| 240 return reinterpret_cast<intptr_t>(g_uma_session_stats); | 240 return reinterpret_cast<intptr_t>(g_uma_session_stats); |
| 241 } | 241 } |
| 242 | 242 |
| 243 // Register native methods | 243 // Register native methods |
| 244 bool RegisterUmaSessionStats(JNIEnv* env) { | 244 bool RegisterUmaSessionStats(JNIEnv* env) { |
| 245 return RegisterNativesImpl(env); | 245 return RegisterNativesImpl(env); |
| 246 } | 246 } |
| OLD | NEW |