[M73 Dev][EFL] Disable VizDisplayCompositor for EFL port
[platform/framework/web/chromium-efl.git] / components / ukm / app_source_url_recorder.cc
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.
4
5 #include "components/ukm/app_source_url_recorder.h"
6
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"
12 #include "url/gurl.h"
13
14 namespace ukm {
15
16 SourceId AssignNewAppId() {
17   static base::AtomicSequenceNumber seq;
18   return ConvertToSourceId(seq.GetNext() + 1, SourceIdType::APP_ID);
19 }
20
21 SourceId AppSourceUrlRecorder::GetSourceIdForChromeApp(const std::string& id) {
22   GURL url("chrome-extension://" + id);
23   return GetSourceIdForUrl(url);
24 }
25
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);
32 }
33
34 SourceId AppSourceUrlRecorder::GetSourceIdForPWA(const GURL& url) {
35   return GetSourceIdForUrl(url);
36 }
37
38 SourceId AppSourceUrlRecorder::GetSourceIdForUrl(const GURL& url) {
39   ukm::DelegatingUkmRecorder* const recorder =
40       ukm::DelegatingUkmRecorder::Get();
41   if (!recorder)
42     return kInvalidSourceId;
43
44   const SourceId source_id = AssignNewAppId();
45   if (base::FeatureList::IsEnabled(kUkmAppLogging)) {
46     recorder->UpdateAppURL(source_id, url);
47   }
48   return source_id;
49 }
50
51 }  // namespace ukm