1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/ukm/app_source_url_recorder.h"
7 #include "base/atomic_sequence_num.h"
8 #include "components/crx_file/id_util.h"
9 #include "services/metrics/public/cpp/delegating_ukm_recorder.h"
10 #include "services/metrics/public/cpp/ukm_recorder.h"
11 #include "services/metrics/public/cpp/ukm_source_id.h"
16 SourceId AssignNewAppId() {
17 static base::AtomicSequenceNumber seq;
18 return ConvertToSourceId(seq.GetNext() + 1, SourceIdType::APP_ID);
21 SourceId AppSourceUrlRecorder::GetSourceIdForChromeApp(const std::string& id) {
22 GURL url("chrome-extension://" + id);
23 return GetSourceIdForUrl(url);
26 SourceId AppSourceUrlRecorder::GetSourceIdForArc(
27 const std::string& package_name) {
28 const std::string package_name_hash =
29 crx_file::id_util::GenerateId(package_name);
30 GURL url("app://play/" + package_name_hash);
31 return GetSourceIdForUrl(url);
34 SourceId AppSourceUrlRecorder::GetSourceIdForPWA(const GURL& url) {
35 return GetSourceIdForUrl(url);
38 SourceId AppSourceUrlRecorder::GetSourceIdForUrl(const GURL& url) {
39 ukm::DelegatingUkmRecorder* const recorder =
40 ukm::DelegatingUkmRecorder::Get();
42 return kInvalidSourceId;
44 const SourceId source_id = AssignNewAppId();
45 if (base::FeatureList::IsEnabled(kUkmAppLogging)) {
46 recorder->UpdateAppURL(source_id, url);