Commit a0a4f62c authored by Paul Dyson's avatar Paul Dyson Committed by Commit Bot

Log arc apps by hashed package name.

Bug: 841671
Change-Id: Ieb86ea9e6636651edd0655c2721c11ea430f96cd
Reviewed-on: https://chromium-review.googlesource.com/1148022Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Commit-Queue: Paul Dyson <pdyson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579986}
parent 91dfc8d8
......@@ -11,6 +11,7 @@ static_library("content") {
]
deps = [
"//base",
"//components/crx_file",
"//content/public/browser",
"//services/metrics/public/cpp:metrics_cpp",
"//services/metrics/public/cpp:ukm_builders",
......
include_rules = [
"+components/crx_file/id_util.h",
"+content/public/browser",
"+content/public/common",
"+content/public/test",
......
......@@ -5,6 +5,7 @@
#include "components/ukm/content/app_source_url_recorder.h"
#include "base/atomic_sequence_num.h"
#include "components/crx_file/id_util.h"
#include "services/metrics/public/cpp/delegating_ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
......@@ -17,16 +18,16 @@ SourceId AssignNewAppId() {
return ConvertToSourceId(seq.GetNext() + 1, SourceIdType::APP_ID);
}
SourceId AppSourceUrlRecorder::GetSourceIdForApp(AppType type,
const std::string& id) {
GURL url;
if (type == AppType::kArc)
url = GURL("app://play/" + id);
else if (type == AppType::kChromeExtension)
url = GURL("chrome-extension://" + id);
else
return kInvalidSourceId;
SourceId AppSourceUrlRecorder::GetSourceIdForChromeApp(const std::string& id) {
GURL url("chrome-extension://" + id);
return GetSourceIdForUrl(url);
}
SourceId AppSourceUrlRecorder::GetSourceIdForArc(
const std::string& package_name) {
const std::string package_name_hash =
crx_file::id_util::GenerateId(package_name);
GURL url("app://play/" + package_name_hash);
return GetSourceIdForUrl(url);
}
......
......@@ -18,17 +18,15 @@ namespace ukm {
const base::Feature kUkmAppLogging{"UkmAppLogging",
base::FEATURE_DISABLED_BY_DEFAULT};
enum class AppType { kArc, kChromeExtension };
class AppSourceUrlRecorder {
private:
friend class AppSourceUrlRecorderTest;
// Get a UKM SourceId for the app.
// Generates a url for the source depending upon AppType:
// kArc: app://play/id
// kChromeExtension: chrome-extension://id/
static SourceId GetSourceIdForApp(AppType type, const std::string& id);
// Get a UKM SourceId for a Chrome app.
static SourceId GetSourceIdForChromeApp(const std::string& id);
// Get a UKM SourceId for an Arc app.
static SourceId GetSourceIdForArc(const std::string& package_name);
// Get a UKM SourceId for a PWA.
static SourceId GetSourceIdForPWA(const GURL& url);
......
......@@ -21,8 +21,8 @@ class AppSourceUrlRecorderTest : public content::RenderViewHostTestHarness {
}
protected:
SourceId GetSourceIdForApp(AppType type, const std::string& id) {
return AppSourceUrlRecorder::GetSourceIdForApp(type, id);
SourceId GetSourceIdForArc(const std::string& package_name) {
return AppSourceUrlRecorder::GetSourceIdForArc(package_name);
}
SourceId GetSourceIdForPWA(const GURL& url) {
......@@ -33,19 +33,19 @@ class AppSourceUrlRecorderTest : public content::RenderViewHostTestHarness {
TestAutoSetUkmRecorder test_ukm_recorder_;
};
TEST_F(AppSourceUrlRecorderTest, CheckPlay) {
SourceId id_play =
GetSourceIdForApp(AppType::kArc, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
TEST_F(AppSourceUrlRecorderTest, CheckArc) {
SourceId id = GetSourceIdForArc("com.google.play");
GURL expected_url_play("app://play/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
std::string com_google_play_hash("pjhgmeephkiehhlkfcoginnkbphkdang");
GURL expected_url("app://play/" + com_google_play_hash);
const auto& sources = test_ukm_recorder_.GetSources();
EXPECT_EQ(1ul, sources.size());
ASSERT_EQ(1ul, sources.size());
ASSERT_NE(kInvalidSourceId, id_play);
auto it = sources.find(id_play);
ASSERT_NE(kInvalidSourceId, id);
auto it = sources.find(id);
ASSERT_NE(sources.end(), it);
EXPECT_EQ(expected_url_play, it->second->url());
EXPECT_EQ(expected_url, it->second->url());
EXPECT_TRUE(it->second->initial_url().is_empty());
}
......@@ -54,7 +54,7 @@ TEST_F(AppSourceUrlRecorderTest, CheckPWA) {
SourceId id = GetSourceIdForPWA(url);
const auto& sources = test_ukm_recorder_.GetSources();
EXPECT_EQ(1ul, sources.size());
ASSERT_EQ(1ul, sources.size());
ASSERT_NE(kInvalidSourceId, id);
auto it = sources.find(id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment