Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(824)

Unified Diff: chromeos/printing/ppd_provider.cc

Issue 2487343006: Add in-memory caching to PpdCache available printers. (Closed)
Patch Set: Address thestig@ comment Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/printing/ppd_cache_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/printing/ppd_provider.cc
diff --git a/chromeos/printing/ppd_provider.cc b/chromeos/printing/ppd_provider.cc
index fcae71105236f94f1b8b861539916d6c54a39cad..c35e213e9221be95de36fefe34b0dac3bf282b26 100644
--- a/chromeos/printing/ppd_provider.cc
+++ b/chromeos/printing/ppd_provider.cc
@@ -127,12 +127,12 @@ class PpdProviderImpl : public PpdProvider {
CHECK(query_fetcher_ == nullptr)
<< "Can't have concurrent PpdProvider QueryAvailable() calls";
- base::Optional<PpdProvider::AvailablePrintersMap> result =
+ const PpdProvider::AvailablePrintersMap* result =
cache_->FindAvailablePrinters();
- if (result) {
+ if (result != nullptr) {
// Satisfy from cache.
base::SequencedTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(cb, PpdProvider::SUCCESS, result.value()));
+ FROM_HERE, base::Bind(cb, PpdProvider::SUCCESS, *result));
return;
}
// Not in the cache, ask QuirksServer.
@@ -258,7 +258,7 @@ class PpdProviderImpl : public PpdProvider {
return;
}
- PpdProvider::AvailablePrintersMap result;
+ auto result = base::MakeUnique<PpdProvider::AvailablePrintersMap>();
for (const std::unique_ptr<base::Value>& entry : *top_list) {
base::DictionaryValue* dict;
std::string manufacturer;
@@ -272,7 +272,7 @@ class PpdProviderImpl : public PpdProvider {
continue;
}
- std::vector<std::string>& dest = result[manufacturer];
+ std::vector<std::string>& dest = (*result)[manufacturer];
for (const std::unique_ptr<base::Value>& model_value : *model_list) {
if (model_value->GetAsString(&model)) {
dest.push_back(model);
@@ -282,8 +282,9 @@ class PpdProviderImpl : public PpdProvider {
}
}
}
- if (!result.empty()) {
- cache_->StoreAvailablePrinters(result);
+ query_done_callback_.Run(PpdProvider::SUCCESS, *result);
+ if (!result->empty()) {
+ cache_->StoreAvailablePrinters(std::move(result));
} else {
// An empty map means something is probably wrong; if we cache this map,
// we'll have an empty map until the cache expires. So complain and
@@ -291,7 +292,6 @@ class PpdProviderImpl : public PpdProvider {
LOG(ERROR) << "Available printers map is unexpectedly empty. Refusing "
"to cache this.";
}
- query_done_callback_.Run(PpdProvider::SUCCESS, result);
}
// Generate a url to look up a manufacturer/model from the quirks server
« no previous file with comments | « chromeos/printing/ppd_cache_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698