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