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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_BROWSER_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_API_H_
#define EXTENSIONS_BROWSER_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_API_H_
#include <memory>
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "build/chromeos_buildflags.h"
#include "components/feedback/system_logs/system_logs_source.h"
#include "extensions/browser/api/feedback_private/feedback_service.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_function.h"
#include "extensions/common/api/feedback_private.h"
#include "ui/gfx/geometry/rect.h"
namespace extensions {
#if BUILDFLAG(IS_CHROMEOS)
class LogSourceAccessManager;
#endif // BUILDFLAG(IS_CHROMEOS)
class FeedbackPrivateAPI : public BrowserContextKeyedAPI {
public:
explicit FeedbackPrivateAPI(content::BrowserContext* context);
FeedbackPrivateAPI(const FeedbackPrivateAPI&) = delete;
FeedbackPrivateAPI& operator=(const FeedbackPrivateAPI&) = delete;
~FeedbackPrivateAPI() override;
scoped_refptr<FeedbackService> GetService() const;
#if BUILDFLAG(IS_CHROMEOS)
LogSourceAccessManager* GetLogSourceAccessManager() const;
#endif // BUILDFLAG(IS_CHROMEOS)
// Create a FeedbackInfo to be passed to UI/JS
std::unique_ptr<api::feedback_private::FeedbackInfo> CreateFeedbackInfo(
const std::string& description_template,
const std::string& description_placeholder_text,
const std::string& category_tag,
const std::string& extra_diagnostics,
const GURL& page_url,
api::feedback_private::FeedbackFlow flow,
bool from_assistant,
bool include_bluetooth_logs,
bool show_questionnaire,
bool from_chrome_labs_or_kaleidoscope,
bool from_autofill,
const base::Value::Dict& autofill_metadata,
const base::Value::Dict& ai_metadata);
// BrowserContextKeyedAPI implementation.
static BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>*
GetFactoryInstance();
// Use a custom FeedbackService implementation for tests.
void SetFeedbackServiceForTesting(scoped_refptr<FeedbackService> service) {
service_ = service;
}
private:
friend class BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>;
// BrowserContextKeyedAPI implementation.
static const char* service_name() { return "FeedbackPrivateAPI"; }
static const bool kServiceHasOwnInstanceInIncognito = true;
const raw_ptr<content::BrowserContext> browser_context_;
scoped_refptr<FeedbackService> service_;
#if BUILDFLAG(IS_CHROMEOS)
std::unique_ptr<LogSourceAccessManager> log_source_access_manager_;
#endif // BUILDFLAG(IS_CHROMEOS)
};
class FeedbackPrivateGetUserEmailFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("feedbackPrivate.getUserEmail",
FEEDBACKPRIVATE_GETUSEREMAIL)
protected:
~FeedbackPrivateGetUserEmailFunction() override {}
ResponseAction Run() override;
};
class FeedbackPrivateGetSystemInformationFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("feedbackPrivate.getSystemInformation",
FEEDBACKPRIVATE_GETSYSTEMINFORMATION)
protected:
~FeedbackPrivateGetSystemInformationFunction() override {}
ResponseAction Run() override;
private:
void OnCompleted(std::unique_ptr<system_logs::SystemLogsResponse> sys_info);
bool send_all_crash_report_ids_;
};
// This function only reads from actual log sources on Chrome OS. On other
// platforms, it just returns EmptyResponse().
class FeedbackPrivateReadLogSourceFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("feedbackPrivate.readLogSource",
FEEDBACKPRIVATE_READLOGSOURCE)
protected:
~FeedbackPrivateReadLogSourceFunction() override {}
ResponseAction Run() override;
#if BUILDFLAG(IS_CHROMEOS)
private:
void OnCompleted(
std::unique_ptr<api::feedback_private::ReadLogSourceResult> result);
#endif // BUILDFLAG(IS_CHROMEOS)
};
class FeedbackPrivateSendFeedbackFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("feedbackPrivate.sendFeedback",
FEEDBACKPRIVATE_SENDFEEDBACK)
protected:
~FeedbackPrivateSendFeedbackFunction() override {}
ResponseAction Run() override;
void OnCompleted(api::feedback_private::LandingPageType type, bool success);
};
class FeedbackPrivateOpenFeedbackFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("feedbackPrivate.openFeedback",
FEEDBACKPRIVATE_OPENFEEDBACK)
protected:
~FeedbackPrivateOpenFeedbackFunction() override = default;
ResponseAction Run() override;
};
} // namespace extensions
#endif // EXTENSIONS_BROWSER_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_API_H_
|