app_source_url_recorder.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #ifndef COMPONENTS_UKM_APP_SOURCE_URL_RECORDER_H_
  5. #define COMPONENTS_UKM_APP_SOURCE_URL_RECORDER_H_
  6. #include "services/metrics/public/cpp/ukm_recorder.h"
  7. #include "services/metrics/public/cpp/ukm_source_id.h"
  8. #include "base/feature_list.h"
  9. #include <string>
  10. class GURL;
  11. namespace apps {
  12. class AppPlatformMetrics;
  13. }
  14. namespace app_list {
  15. class AppLaunchEventLogger;
  16. } // namespace app_list
  17. namespace badging {
  18. class BadgeManager;
  19. } // namespace badging
  20. namespace ukm {
  21. const base::Feature kUkmAppLogging{"UkmAppLogging",
  22. base::FEATURE_ENABLED_BY_DEFAULT};
  23. class AppSourceUrlRecorder {
  24. private:
  25. friend class apps::AppPlatformMetrics;
  26. friend class AppSourceUrlRecorderTest;
  27. friend class app_list::AppLaunchEventLogger;
  28. friend class badging::BadgeManager;
  29. // Get a UKM SourceId with the prefix "app://" for a Chrome app with `app_id`,
  30. // a unique hash string to identify the app. For example,
  31. // "mgndgikekgjfcpckkfioiadnlibdjbkf" is the `app_id` for Chrome browser, and
  32. // the output SourceId is "app://mgndgikekgjfcpckkfioiadnlibdjbkf".
  33. static SourceId GetSourceIdForChromeApp(const std::string& app_id);
  34. // Get a UKM SourceId with the prefix "chrome-extension://" for a Chrome
  35. // extension. For example, for `id`, "mhjfbmdgcfjbbpaeojofohoefgiehjai", the
  36. // output SourceId is "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai".
  37. static SourceId GetSourceIdForChromeExtension(const std::string& id);
  38. // Get a UKM SourceId with the prefix "app://" for an Arc app with
  39. // `package_name`. For example, for `package_name`, "com.google.play", the
  40. // output SourceId is "app://com.google.play".
  41. static SourceId GetSourceIdForArcPackageName(const std::string& package_name);
  42. // Get a UKM SourceId with the prefix "app://" for an Arc app with a hash
  43. // string for `package_name`. For example, for `package_name`,
  44. // "com.google.play", the output SourceId is
  45. // "app://play/pjhgmeephkiehhlkfcoginnkbphkdang".
  46. static SourceId GetSourceIdForArc(const std::string& package_name);
  47. // Get a UKM SourceId for a PWA.
  48. static SourceId GetSourceIdForPWA(const GURL& url);
  49. // Get a UKM SourceId with the prefix "app://borealis/" for a Borealis app.
  50. // `app` could be a numeric Borealis App ID, or a string identifying a
  51. // special case such as the main client app or an unregistered app.
  52. static SourceId GetSourceIdForBorealis(const std::string& app);
  53. // Get a UKM SourceId with the prefix "app://" for a Crostini app with an XDG
  54. // desktop id of `desktop_id` and app name of `app_name`.
  55. static SourceId GetSourceIdForCrostini(const std::string& desktop_id,
  56. const std::string& app_name);
  57. // For internal use only.
  58. static SourceId GetSourceIdForUrl(const GURL& url, const AppType);
  59. // Informs UKM service that the source_id is no longer needed nor used by the
  60. // end of the current reporting cycle, and thus can be deleted later.
  61. static void MarkSourceForDeletion(SourceId source_id);
  62. };
  63. } // namespace ukm
  64. #endif // COMPONENTS_UKM_APP_SOURCE_URL_RECORDER_H_