File: feedback.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (88 lines) | stat: -rw-r--r-- 3,073 bytes parent folder | download | duplicates (8)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos/ash/components/specialized_features/feedback.h"

#include <optional>
#include <string>
#include <utility>

#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/scoped_refptr.h"
#include "base/system/sys_info.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/version_info/version_string.h"
#include "chromeos/ash/components/channel/channel_info.h"
#include "components/feedback/feedback_data.h"
#include "components/feedback/redaction_tool/redaction_tool.h"

namespace specialized_features {

namespace {

// Gets the current Chrome version as a string.
// Equivalent to `chrome::GetVersionString()`, without needing to use //chrome
// dependencies.
std::string GetChromeVersion() {
  return version_info::GetVersionStringWithModifier(ash::GetChannelName());
}

// Gets `CHROMEOS_RELEASE_VERSION` as a string.
std::string GetOsVersion() {
  std::string version;
  base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_VERSION", &version);
  return version;
}

// Redacts the description of the provided feedback data and returns it.
scoped_refptr<feedback::FeedbackData> RedactFeedbackData(
    scoped_refptr<feedback::FeedbackData> feedback_data) {
  redaction::RedactionTool redactor(/*first_party_extension_ids=*/nullptr);
  redactor.EnableCreditCardRedaction(true);
  feedback_data->RedactDescription(redactor);
  return feedback_data;
}

// Queues a feedback report for the provided feedback data.
void SendFeedback(scoped_refptr<feedback::FeedbackData> feedback_data) {
  feedback_data->OnFeedbackPageDataComplete();
}

// Redacts the description, then sends the provided feedback data.
void RedactThenSendFeedback(
    scoped_refptr<feedback::FeedbackData> feedback_data) {
  base::ThreadPool::PostTaskAndReplyWithResult(
      FROM_HERE, {base::TaskPriority::BEST_EFFORT},
      base::BindOnce(&RedactFeedbackData, std::move(feedback_data)),
      base::BindOnce(&SendFeedback));
}

}  // namespace

void SendFeedback(feedback::FeedbackUploader& uploader,
                  int product_id,
                  std::string description,
                  std::optional<std::string> image,
                  std::optional<std::string> image_mime_type) {
  auto feedback_data = base::MakeRefCounted<feedback::FeedbackData>(
      uploader.AsWeakPtr(), /*tracing_manager=*/nullptr);

  feedback_data->set_product_id(product_id);
  feedback_data->set_include_chrome_platform(false);
  feedback_data->set_description(std::move(description));
  if (image.has_value()) {
    feedback_data->set_image(std::move(*image));
  }
  if (image_mime_type.has_value()) {
    feedback_data->set_image_mime_type(std::move(*image_mime_type));
  }
  feedback_data->AddLog("CHROME VERSION", GetChromeVersion());
  feedback_data->AddLog("CHROMEOS_RELEASE_VERSION", GetOsVersion());

  RedactThenSendFeedback(feedback_data);
}

}  // namespace specialized_features