feedback_registration.cc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2020 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. #include "components/fuchsia_component_support/feedback_registration.h"
  5. #include <fuchsia/feedback/cpp/fidl.h>
  6. #include <lib/sys/cpp/component_context.h>
  7. #include "base/fuchsia/process_context.h"
  8. #include "base/strings/string_piece.h"
  9. #include "build/branding_buildflags.h"
  10. #include "components/version_info/version_info.h"
  11. namespace fuchsia_component_support {
  12. void RegisterProductDataForCrashReporting(
  13. base::StringPiece component_url,
  14. base::StringPiece crash_product_name) {
  15. fuchsia::feedback::CrashReportingProduct product_data;
  16. product_data.set_name(std::string(crash_product_name));
  17. product_data.set_version(version_info::GetVersionNumber());
  18. // TODO(https://crbug.com/1077428): Use the actual channel when appropriate.
  19. // For now, always set it to the empty string to avoid reporting "missing".
  20. product_data.set_channel("");
  21. auto crash_reporting_service =
  22. base::ComponentContextForProcess()
  23. ->svc()
  24. ->Connect<fuchsia::feedback::CrashReportingProductRegister>();
  25. // Only register the |crash_product_name| for official Chrome-branded builds.
  26. // Otherwise, the crashes will be handled as non-component-specific crashes.
  27. // Since Fuchsia handles crashes, it is possible that Fuchsia will upload a
  28. // crash for an unofficial and/or unbranded build of a Chromium-based
  29. // component if it is running on an official Fuchsia build. To avoid adding
  30. // noise from such crash reports, which are not received on other platforms,
  31. // do not set a product name for such builds.
  32. #if BUILDFLAG(GOOGLE_CHROME_BRANDING) && defined(OFFICIAL_BUILD)
  33. crash_reporting_service->Upsert(std::string(component_url),
  34. std::move(product_data));
  35. #endif
  36. }
  37. void RegisterProductDataForFeedback(base::StringPiece component_namespace) {
  38. fuchsia::feedback::ComponentData component_data;
  39. component_data.set_namespace_(std::string(component_namespace));
  40. // TODO(https://crbug.com/1077428): Add release channel to the annotations.
  41. component_data.mutable_annotations()->push_back(
  42. {"version", version_info::GetVersionNumber()});
  43. base::ComponentContextForProcess()
  44. ->svc()
  45. ->Connect<fuchsia::feedback::ComponentDataRegister>()
  46. ->Upsert(std::move(component_data), []() {});
  47. }
  48. } // namespace fuchsia_component_support