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

ash / scanner / scanner_action_view_model.h [blame]

// 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.

#ifndef ASH_SCANNER_SCANNER_ACTION_VIEW_MODEL_H_
#define ASH_SCANNER_SCANNER_ACTION_VIEW_MODEL_H_

#include <string>

#include "ash/ash_export.h"
#include "ash/scanner/scanner_action_handler.h"
#include "ash/scanner/scanner_unpopulated_action.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/weak_ptr.h"
#include "components/manta/proto/scanner.pb.h"

namespace gfx {
struct VectorIcon;
}

namespace ash {

class ScannerCommandDelegate;

// A view model wrapper around a `ScannerUnpopulatedAction`, which handles the
// conversion to a user-facing text string, icon, and a callback.
class ASH_EXPORT ScannerActionViewModel {
 public:
  explicit ScannerActionViewModel(
      ScannerUnpopulatedAction unpopulated_action,
      base::WeakPtr<ScannerCommandDelegate> delegate);
  ScannerActionViewModel(const ScannerActionViewModel&);
  ScannerActionViewModel& operator=(const ScannerActionViewModel&);
  ScannerActionViewModel(ScannerActionViewModel&&);
  ScannerActionViewModel& operator=(ScannerActionViewModel&&);
  ~ScannerActionViewModel();

  // Gets the UI facing text for this action.
  // This may crash if this action has been previously moved.
  std::u16string GetText() const;
  const gfx::VectorIcon& GetIcon() const;
  manta::proto::ScannerAction::ActionCase GetActionCase() const;

  // Executes this action, running the provided callback with a success value
  // when the execution finishes.
  void ExecuteAction(ScannerCommandCallback action_finished_callback) const;

 private:
  ScannerUnpopulatedAction unpopulated_action_;
  base::WeakPtr<ScannerCommandDelegate> delegate_;
};

}  // namespace ash

#endif  // ASH_SCANNER_SCANNER_ACTION_VIEW_MODEL_H_