| 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 ukm::UkmService* ukm_service = g_browser_process->ukm_service(); |
| 57 if (ukm_service) |
| 58 ukm_service->OnAppEnterForeground(); |
| 56 } | 59 } |
| 57 ++active_session_count_; | 60 ++active_session_count_; |
| 58 } | 61 } |
| 59 | 62 |
| 60 void UmaSessionStats::UmaEndSession(JNIEnv* env, | 63 void UmaSessionStats::UmaEndSession(JNIEnv* env, |
| 61 const JavaParamRef<jobject>& obj) { | 64 const JavaParamRef<jobject>& obj) { |
| 62 --active_session_count_; | 65 --active_session_count_; |
| 63 DCHECK_GE(active_session_count_, 0); | 66 DCHECK_GE(active_session_count_, 0); |
| 64 | 67 |
| 65 if (active_session_count_ == 0) { | 68 if (active_session_count_ == 0) { |
| 66 base::TimeDelta duration = base::TimeTicks::Now() - session_start_time_; | 69 base::TimeDelta duration = base::TimeTicks::Now() - session_start_time_; |
| 67 | 70 |
| 68 // Note: This metric is recorded separately on desktop in | 71 // Note: This metric is recorded separately on desktop in |
| 69 // DesktopSessionDurationTracker::EndSession. | 72 // DesktopSessionDurationTracker::EndSession. |
| 70 UMA_HISTOGRAM_LONG_TIMES("Session.TotalDuration", duration); | 73 UMA_HISTOGRAM_LONG_TIMES("Session.TotalDuration", duration); |
| 71 | 74 |
| 72 DCHECK(g_browser_process); | 75 DCHECK(g_browser_process); |
| 73 // Tell the metrics service it was cleanly shutdown. | 76 // Tell the metrics services they were cleanly shutdown. |
| 74 metrics::MetricsService* metrics = g_browser_process->metrics_service(); | 77 metrics::MetricsService* metrics = g_browser_process->metrics_service(); |
| 75 if (metrics) { | 78 if (metrics) |
| 76 metrics->OnAppEnterBackground(); | 79 metrics->OnAppEnterBackground(); |
| 77 } | 80 ukm::UkmService* ukm_service = g_browser_process->ukm_service(); |
| 81 if (ukm_service) |
| 82 ukm_service->OnAppEnterBackground(); |
| 78 } | 83 } |
| 79 } | 84 } |
| 80 | 85 |
| 81 // static | 86 // static |
| 82 void UmaSessionStats::RegisterSyntheticFieldTrial( | 87 void UmaSessionStats::RegisterSyntheticFieldTrial( |
| 83 const std::string& trial_name, | 88 const std::string& trial_name, |
| 84 const std::string& group_name) { | 89 const std::string& group_name) { |
| 85 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(trial_name, | 90 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(trial_name, |
| 86 group_name); | 91 group_name); |
| 87 } | 92 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 // We should have only one UmaSessionStats instance. | 238 // We should have only one UmaSessionStats instance. |
| 234 DCHECK(!g_uma_session_stats); | 239 DCHECK(!g_uma_session_stats); |
| 235 g_uma_session_stats = new UmaSessionStats(); | 240 g_uma_session_stats = new UmaSessionStats(); |
| 236 return reinterpret_cast<intptr_t>(g_uma_session_stats); | 241 return reinterpret_cast<intptr_t>(g_uma_session_stats); |
| 237 } | 242 } |
| 238 | 243 |
| 239 // Register native methods | 244 // Register native methods |
| 240 bool RegisterUmaSessionStats(JNIEnv* env) { | 245 bool RegisterUmaSessionStats(JNIEnv* env) { |
| 241 return RegisterNativesImpl(env); | 246 return RegisterNativesImpl(env); |
| 242 } | 247 } |
| OLD | NEW |