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

ash / webui / os_feedback_ui / backend / feedback_service_provider.h [blame]

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_WEBUI_OS_FEEDBACK_UI_BACKEND_FEEDBACK_SERVICE_PROVIDER_H_
#define ASH_WEBUI_OS_FEEDBACK_UI_BACKEND_FEEDBACK_SERVICE_PROVIDER_H_

#include <memory>

#include "ash/webui/os_feedback_ui/mojom/os_feedback_ui.mojom.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"

namespace ash {

class OsFeedbackDelegate;

namespace feedback {

class FeedbackServiceProvider
    : public os_feedback_ui::mojom::FeedbackServiceProvider {
 public:
  explicit FeedbackServiceProvider(
      std::unique_ptr<OsFeedbackDelegate> feedback_delegate);
  FeedbackServiceProvider(const FeedbackServiceProvider&) = delete;
  FeedbackServiceProvider& operator=(const FeedbackServiceProvider&) = delete;
  ~FeedbackServiceProvider() override;

  // os_feedback_ui::mojom::FeedbackServiceProvider:
  void GetFeedbackContext(GetFeedbackContextCallback callback) override;
  void GetScreenshotPng(GetScreenshotPngCallback callback) override;
  void SendReport(os_feedback_ui::mojom::ReportPtr report,
                  SendReportCallback callback) override;
  void OpenDiagnosticsApp() override;
  void OpenExploreApp() override;
  void OpenMetricsDialog() override;
  void OpenSystemInfoDialog() override;
  void OpenAutofillDialog(const std::string& autofill_metadata) override;
  void RecordPostSubmitAction(
      os_feedback_ui::mojom::FeedbackAppPostSubmitAction action) override;
  void RecordPreSubmitAction(
      os_feedback_ui::mojom::FeedbackAppPreSubmitAction action) override;
  void RecordExitPath(
      os_feedback_ui::mojom::FeedbackAppExitPath exit_path) override;
  void RecordHelpContentOutcome(
      os_feedback_ui::mojom::FeedbackAppHelpContentOutcome outcome) override;
  void RecordHelpContentSearchResultCount(int count) override;

  void BindInterface(
      mojo::PendingReceiver<os_feedback_ui::mojom::FeedbackServiceProvider>
          receiver);

 private:
  std::unique_ptr<OsFeedbackDelegate> feedback_delegate_;
  mojo::Receiver<os_feedback_ui::mojom::FeedbackServiceProvider> receiver_{
      this};
  // Timestamp of when the app was opened. Used to calculate a duration for
  // metrics.
  base::Time app_open_timestamp_;
  base::Time share_data_page_open_timestamp_;
  base::Time share_data_page_close_timestamp_;
  bool feedback_sent;
  base::WeakPtrFactory<FeedbackServiceProvider> weak_ptr_factory_{this};
};

}  // namespace feedback
}  // namespace ash

#endif  // ASH_WEBUI_OS_FEEDBACK_UI_BACKEND_FEEDBACK_SERVICE_PROVIDER_H_