Commit 2edcfe9a authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

scanning: Add file type to scan settings

Add a new FileType enum and include it in ScanSettings. The file type
will be used to save scanned images in the desired format.

Tbr: dcheng@chromium.org
Bug: 1059779
Change-Id: I114ee2e85582340c46b4ab2111411b0ba2c16813
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2460980
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817320}
parent 92f0925c
......@@ -64,7 +64,7 @@ void ScanService::Scan(const base::UnguessableToken& scanner_id,
lorgnette_scanner_manager_->Scan(
scanner_name, mojo::ConvertTo<lorgnette::ScanSettings>(settings),
base::BindRepeating(&ScanService::OnPageReceived,
weak_ptr_factory_.GetWeakPtr()),
weak_ptr_factory_.GetWeakPtr(), settings->file_type),
base::BindOnce(&ScanService::OnScanCompleted,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
......@@ -113,8 +113,17 @@ void ScanService::OnScannerCapabilitiesReceived(
mojo::ConvertTo<mojo_ipc::ScannerCapabilitiesPtr>(capabilities.value()));
}
void ScanService::OnPageReceived(std::string scanned_image,
void ScanService::OnPageReceived(const mojo_ipc::FileType file_type,
std::string scanned_image,
uint32_t page_number) {
// TODO(jschettler): Add support for converting the scanned image to other
// file types.
if (file_type != mojo_ipc::FileType::kPng) {
LOG(ERROR) << "Selected file type not supported.";
save_failed_ = true;
return;
}
// The |page_number| is 0-indexed.
const std::string filename = base::StringPrintf(
"scan_%02d%02d%02d-%02d%02d%02d_page_%d.png", start_time_.year,
......
......@@ -66,8 +66,11 @@ class ScanService : public scanning::mojom::ScanService, public KeyedService {
const base::Optional<lorgnette::ScannerCapabilities>& capabilities);
// Processes each |scanned_image| received after calling
// LorgnetteScannerManager::Scan().
void OnPageReceived(std::string scanned_image, uint32_t page_number);
// LorgnetteScannerManager::Scan(). |file_type| specifies the file type to use
// when saving scanned images.
void OnPageReceived(const scanning::mojom::FileType file_type,
std::string scanned_image,
uint32_t page_number);
// Processes the final result of calling LorgnetteScannerManager::Scan().
void OnScanCompleted(ScanCallback callback, bool success);
......
......@@ -198,7 +198,11 @@ TEST_F(ScanServiceTest, Scan) {
fake_lorgnette_scanner_manager_.SetScanResponse("TestData");
auto scanners = GetScanners();
ASSERT_EQ(scanners.size(), 1u);
EXPECT_TRUE(Scan(scanners[0]->id, mojo_ipc::ScanSettings::New()));
// Saving scanned images is currently only supported for the PNG file type.
mojo_ipc::ScanSettings settings;
settings.file_type = mojo_ipc::FileType::kPng;
EXPECT_TRUE(Scan(scanners[0]->id, settings.Clone()));
}
} // namespace chromeos
......@@ -14,6 +14,13 @@ enum ColorMode {
kColor,
};
// The file types that can be used when saving scanned images.
enum FileType {
kJpg,
kPdf,
kPng,
};
// The source types from which a scan can be obtained.
enum SourceType {
// An unknown source type.
......@@ -49,6 +56,8 @@ struct ScannerCapabilities {
struct ScanSettings {
// The SANE name of the ScanSource from which to scan.
string source_name;
// The file type to use when saving scanned images.
FileType file_type;
// The color mode with which to scan.
ColorMode color_mode;
// The resolution with which to scan in DPI.
......
......@@ -172,8 +172,11 @@ Polymer({
this.settingsDisabled_ = true;
this.scanButtonDisabled_ = true;
// TODO(jschettler): Set file type using the selected value when the
// corresponding dropdown is added.
const settings = {
'sourceName': this.selectedSource,
'fileType': chromeos.scanning.mojom.FileType.kPng,
'colorMode': this.selectedColorMode,
'resolutionDpi': this.selectedResolution,
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment