Commit 19ac4cfb authored by Kalvin Lee's avatar Kalvin Lee Committed by Commit Bot

PpdProvider v3: complete ResolvePpdLicense()

This change implements PpdProvider::ResolvePpdLicense().

Bug: chromium:888189
Test: chromeos_unittests --gtest_filter='PpdProviderTest.ResolvePpdLicense'
Change-Id: I649397270fa45b809f8039fdee7808b55621a8a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2355008
Commit-Queue: Kalvin Lee <kdlee@chromium.org>
Reviewed-by: default avatarLuum Habtemariam <luum@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804126}
parent 3ef6ff3b
...@@ -266,7 +266,12 @@ class PpdProviderImpl : public PpdProvider { ...@@ -266,7 +266,12 @@ class PpdProviderImpl : public PpdProvider {
// locale-sensitive. // locale-sensitive.
void ResolvePpdLicense(base::StringPiece effective_make_and_model, void ResolvePpdLicense(base::StringPiece effective_make_and_model,
ResolvePpdLicenseCallback cb) override { ResolvePpdLicenseCallback cb) override {
// TODO(crbug.com/888189): implement this. auto callback = base::BindOnce(
&PpdProviderImpl::FindLicenseForEmm, weak_factory_.GetWeakPtr(),
std::string(effective_make_and_model), std::move(cb));
metadata_manager_->FindAllEmmsAvailableInIndex(
{std::string(effective_make_and_model)}, kMaxDataAge,
std::move(callback));
} }
protected: protected:
...@@ -566,6 +571,34 @@ class PpdProviderImpl : public PpdProvider { ...@@ -566,6 +571,34 @@ class PpdProviderImpl : public PpdProvider {
TryToResolvePpdReferenceFromUsbIndices(std::move(context)); TryToResolvePpdReferenceFromUsbIndices(std::move(context));
} }
// Continues a prior call to ResolvePpdLicense().
// This callback is fed to
// PpdMetadataManager::FindAllEmmsAvailableInIndexCallback().
void FindLicenseForEmm(const std::string& effective_make_and_model,
ResolvePpdLicenseCallback cb,
const base::flat_map<std::string, ParsedIndexValues>&
forward_index_results) {
const ParsedIndexLeaf* const index_leaf = FirstAllowableParsedIndexLeaf(
effective_make_and_model, forward_index_results);
if (!index_leaf) {
// This particular |effective_make_and_model| is invisible to the
// current |version_|; either it is restricted or it is missing
// entirely from the forward indices.
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(std::move(cb), CallbackResultCode::NOT_FOUND,
/*license_name=*/""));
return;
}
// Note that the license can also be empty; this denotes that
// no license is associated with this particular
// |effective_make_and_model| in this |version_|.
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(cb), CallbackResultCode::SUCCESS,
index_leaf->license));
}
// Locale of the browser, as returned by // Locale of the browser, as returned by
// BrowserContext::GetApplicationLocale(); // BrowserContext::GetApplicationLocale();
const std::string browser_locale_; const std::string browser_locale_;
......
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