#ifndef ASH_SCANNER_SCANNER_SESSION_H_
#define ASH_SCANNER_SCANNER_SESSION_H_
#include <memory>
#include <string>
#include <vector>
#include "ash/ash_export.h"
#include "ash/scanner/scanner_action_view_model.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "base/types/expected.h"
#include "components/manta/manta_status.h"
#include "components/manta/proto/scanner.pb.h"
namespace ash {
class ScannerProfileScopedDelegate;
class ASH_EXPORT ScannerSession {
public:
struct FetchError {
std::u16string error_message;
bool can_try_again = false;
};
using FetchActionsResponse =
base::expected<std::vector<ScannerActionViewModel>, FetchError>;
using FetchActionsCallback =
base::OnceCallback<void(FetchActionsResponse response)>;
using PopulateActionCallback =
base::OnceCallback<void(manta::proto::ScannerAction action)>;
explicit ScannerSession(ScannerProfileScopedDelegate* delegate);
ScannerSession(const ScannerSession&) = delete;
ScannerSession& operator=(const ScannerSession&) = delete;
~ScannerSession();
void FetchActionsForImage(scoped_refptr<base::RefCountedMemory> jpeg_bytes,
FetchActionsCallback callback);
void PopulateAction(
scoped_refptr<base::RefCountedMemory> downscaled_jpeg_bytes,
manta::proto::ScannerAction unpopulated_action,
PopulateActionCallback callback);
void SetMockScannerOutput(
std::unique_ptr<manta::proto::ScannerOutput> mock_output);
private:
void OnActionsReturned(
scoped_refptr<base::RefCountedMemory> downscaled_jpeg_bytes,
base::TimeTicks request_start_time,
FetchActionsCallback callback,
std::unique_ptr<manta::proto::ScannerOutput> output,
manta::MantaStatus status);
const raw_ptr<ScannerProfileScopedDelegate> delegate_;
std::unique_ptr<manta::proto::ScannerOutput> mock_scanner_output_;
base::WeakPtrFactory<ScannerSession> weak_ptr_factory_{this};
};
}
#endif