Index: chromecast/base/metrics/cast_metrics_helper.cc |
diff --git a/chromecast/base/metrics/cast_metrics_helper.cc b/chromecast/base/metrics/cast_metrics_helper.cc |
index dda5f51ac82a5218ffe18a111427d1e8d0aa0383..d2d21ad67b29691830022aa009a71048d72236bc 100644 |
--- a/chromecast/base/metrics/cast_metrics_helper.cc |
+++ b/chromecast/base/metrics/cast_metrics_helper.cc |
@@ -10,6 +10,8 @@ |
#include "base/message_loop/message_loop_proxy.h" |
#include "base/metrics/histogram.h" |
#include "base/metrics/user_metrics.h" |
+#include "base/strings/string_split.h" |
+#include "base/strings/string_util.h" |
#include "chromecast/base/metrics/cast_histograms.h" |
#include "chromecast/base/metrics/grouped_histogram.h" |
@@ -38,11 +40,39 @@ const int kNominalVideoSamplePeriod = 5000000; |
} // namespace |
+// static |
+const char CastMetricsHelper::kMetricsNameAppInfoDelimiter = '#'; |
+ |
+// static |
+CastMetricsHelper::MetricsAppInfo CastMetricsHelper::GetAppInfoFromMetricsName( |
+ const std::string& metrics_name) { |
+ // TODO(gfhuang): This is a hacky way to encode/decode app infos into a |
gunsch
2014/12/10 22:43:58
Got a planned approach for the TODO, or is this ju
gfhuang
2014/12/11 02:59:39
Change to a NOTE.
|
+ // string. Mainly because it's hard to add another metrics serialization type |
+ // into components/metrics/serialization/. |
+ std::vector<std::string> tokens; |
+ base::SplitString(metrics_name, kMetricsNameAppInfoDelimiter, &tokens); |
+ DCHECK_EQ(tokens.size(), 4u); |
+ CastMetricsHelper::MetricsAppInfo metrics_app_info; |
+ // The order of tokens should match GetMetricsNameWithAppInfo(). |
+ metrics_app_info.action_name = tokens[0]; |
+ metrics_app_info.app_id = tokens[1]; |
+ metrics_app_info.session_id = tokens[2]; |
+ metrics_app_info.sdk_version = tokens[3]; |
+ return metrics_app_info; |
+} |
+ |
+// static |
CastMetricsHelper* CastMetricsHelper::GetInstance() { |
DCHECK(g_instance); |
return g_instance; |
} |
+CastMetricsHelper::MetricsAppInfo::MetricsAppInfo() { |
+} |
+ |
+CastMetricsHelper::MetricsAppInfo::~MetricsAppInfo() { |
+} |
+ |
CastMetricsHelper::CastMetricsHelper( |
scoped_refptr<base::MessageLoopProxy> message_loop_proxy) |
: message_loop_proxy_(message_loop_proxy), |
@@ -71,14 +101,24 @@ void CastMetricsHelper::TagAppStart(const std::string& arg_app_name) { |
new_startup_time_ = true; |
TagAppStartForGroupedHistograms(app_name_); |
+ // Clear app info |
+ UpdateCurrentAppInfo("", "", ""); |
} |
+void CastMetricsHelper::UpdateCurrentAppInfo(const std::string& app_id, |
+ const std::string& session_id, |
+ const std::string& sdk_version) { |
+ MAKE_SURE_THREAD(UpdateCurrentAppInfo, app_id, session_id, sdk_version); |
+ app_id_ = app_id; |
+ session_id_ = session_id; |
+ sdk_version_ = sdk_version; |
+} |
gunsch
2014/12/10 22:43:58
style nit: blank line between methods
gfhuang
2014/12/11 02:59:39
Done.
|
void CastMetricsHelper::LogMediaPlay() { |
- RecordSimpleAction(GetMetricsNameWithAppName("MediaPlay", "")); |
+ RecordSimpleAction(GetMetricsNameWithAppInfo("MediaPlay")); |
} |
void CastMetricsHelper::LogMediaPause() { |
- RecordSimpleAction(GetMetricsNameWithAppName("MediaPause", "")); |
+ RecordSimpleAction(GetMetricsNameWithAppInfo("MediaPause")); |
} |
void CastMetricsHelper::LogTimeToDisplayVideo() { |
@@ -189,6 +229,17 @@ std::string CastMetricsHelper::GetMetricsNameWithAppName( |
return metrics_name; |
} |
+std::string CastMetricsHelper::GetMetricsNameWithAppInfo( |
+ const std::string& action_name) const { |
+ DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
+ std::vector<std::string> parts; |
+ parts.push_back(action_name); |
+ parts.push_back(app_id_); |
+ parts.push_back(session_id_); |
+ parts.push_back(sdk_version_); |
+ return JoinString(parts, kMetricsNameAppInfoDelimiter); |
+} |
+ |
void CastMetricsHelper::SetMetricsSink(MetricsSink* delegate) { |
MAKE_SURE_THREAD(SetMetricsSink, delegate); |
metrics_sink_ = delegate; |