File: feedback_registration.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (69 lines) | stat: -rw-r--r-- 2,752 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/fuchsia_component_support/feedback_registration.h"

#include <fuchsia/feedback/cpp/fidl.h>
#include <lib/sys/cpp/component_context.h>

#include <string_view>

#include "base/check.h"
#include "base/fuchsia/process_context.h"
#include "base/strings/string_util.h"
#include "build/branding_buildflags.h"
#include "components/version_info/version_info.h"

namespace fuchsia_component_support {

namespace {

constexpr char kAbsoluteComponentUrlSchemPrefix[] = "fuchsia-pkg://";

}  // namespace

void RegisterProductDataForCrashReporting(
    std::string_view absolute_component_url,
    std::string_view crash_product_name) {
  DCHECK(base::StartsWith(absolute_component_url,
                          kAbsoluteComponentUrlSchemPrefix));

  fuchsia::feedback::CrashReportingProduct product_data;
  product_data.set_name(std::string(crash_product_name));
  product_data.set_version(std::string(version_info::GetVersionNumber()));
  // TODO(crbug.com/42050100): Use the actual channel when appropriate.
  // For now, always set it to the empty string to avoid reporting "missing".
  product_data.set_channel("");

  auto crash_reporting_service =
      base::ComponentContextForProcess()
          ->svc()
          ->Connect<fuchsia::feedback::CrashReportingProductRegister>();

  // Only register the |crash_product_name| for official Chrome-branded builds.
  // Otherwise, the crashes will be handled as non-component-specific crashes.
  // Since Fuchsia handles crashes, it is possible that Fuchsia will upload a
  // crash for an unofficial and/or unbranded build of a Chromium-based
  // component if it is running on an official Fuchsia build. To avoid adding
  // noise from such crash reports, which are not received on other platforms,
  // do not set a product name for such builds.
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) && defined(OFFICIAL_BUILD)
  crash_reporting_service->Upsert(std::string(absolute_component_url),
                                  std::move(product_data));
#endif
}

void RegisterProductDataForFeedback(std::string_view component_namespace) {
  fuchsia::feedback::ComponentData component_data;
  component_data.set_namespace_(std::string(component_namespace));
  // TODO(crbug.com/42050100): Add release channel to the annotations.
  component_data.mutable_annotations()->push_back(
      {"version", std::string(version_info::GetVersionNumber())});
  base::ComponentContextForProcess()
      ->svc()
      ->Connect<fuchsia::feedback::ComponentDataRegister>()
      ->Upsert(std::move(component_data), []() {});
}

}  // namespace fuchsia_component_support