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..42b665c4e3f7b5b836c0c62fd07f8631f0b8a2c8 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" |
@@ -36,8 +38,51 @@ const int kDisplayedFramesPerSecondPeriod = 1000000; |
// Sample every 5 seconds, represented in microseconds. |
const int kNominalVideoSamplePeriod = 5000000; |
+const char kMetricsNameAppInfoDelimiter = '#'; |
+ |
} // namespace |
+// static |
+ |
+// NOTE(gfhuang): This is a hacky way to encode/decode app infos into a |
+// string. Mainly because it's hard to add another metrics serialization type |
+// into components/metrics/serialization/. |
+// static |
+bool CastMetricsHelper::DecodeAppInfoFromMetricsName( |
+ const std::string& metrics_name, |
+ std::string* action_name, |
+ std::string* app_id, |
+ std::string* session_id, |
+ std::string* sdk_version) { |
byungchul
2014/12/11 18:35:49
DCHECK()'s for pointers.
gfhuang
2014/12/11 19:20:26
Done.
|
+ if (metrics_name.find(kMetricsNameAppInfoDelimiter) == std::string::npos) { |
+ return false; |
+ } |
byungchul
2014/12/11 18:35:49
remove {}
gfhuang
2014/12/11 19:20:26
Done.
|
+ std::vector<std::string> tokens; |
+ base::SplitString(metrics_name, kMetricsNameAppInfoDelimiter, &tokens); |
+ DCHECK_EQ(tokens.size(), 4u); |
lcwu1
2014/12/11 18:41:57
If the number of the tokens is not 4, which means
gfhuang
2014/12/11 19:20:26
If the metrics name has magic char '#', but tokens
|
+ // The order of tokens should match EncodeAppInfoIntoMetricsName(). |
+ *action_name = tokens[0]; |
+ *app_id = tokens[1]; |
+ *session_id = tokens[2]; |
+ *sdk_version = tokens[3]; |
+ return true; |
+} |
+ |
+// static |
+std::string CastMetricsHelper::EncodeAppInfoIntoMetricsName( |
+ const std::string& action_name, |
+ const std::string& app_id, |
+ const std::string& session_id, |
+ const std::string& sdk_version) { |
+ 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); |
+} |
+ |
+// static |
CastMetricsHelper* CastMetricsHelper::GetInstance() { |
DCHECK(g_instance); |
return g_instance; |
@@ -71,14 +116,29 @@ 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; |
} |
void CastMetricsHelper::LogMediaPlay() { |
- RecordSimpleAction(GetMetricsNameWithAppName("MediaPlay", "")); |
+ MAKE_SURE_THREAD(LogMediaPlay); |
+ RecordSimpleAction(EncodeAppInfoIntoMetricsName( |
+ "MediaPlay", app_id_, session_id_, sdk_version_)); |
} |
void CastMetricsHelper::LogMediaPause() { |
- RecordSimpleAction(GetMetricsNameWithAppName("MediaPause", "")); |
+ MAKE_SURE_THREAD(LogMediaPause); |
+ RecordSimpleAction(EncodeAppInfoIntoMetricsName( |
+ "MediaPause", app_id_, session_id_, sdk_version_)); |
} |
void CastMetricsHelper::LogTimeToDisplayVideo() { |