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

Unified Diff: chrome/browser/ui/webui/print_preview/printer_backend_proxy.cc

Issue 2457933004: Register and select printer on click. (Closed)
Patch Set: rebase 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
Index: chrome/browser/ui/webui/print_preview/printer_backend_proxy.cc
diff --git a/chrome/browser/ui/webui/print_preview/printer_backend_proxy.cc b/chrome/browser/ui/webui/print_preview/printer_backend_proxy.cc
index 9b316d5698c4ec05f98c5c4fbe30606e53698cc2..6e9d897c3e6f21e243deadf844e8471f216516d7 100644
--- a/chrome/browser/ui/webui/print_preview/printer_backend_proxy.cc
+++ b/chrome/browser/ui/webui/print_preview/printer_backend_proxy.cc
@@ -5,14 +5,28 @@
#include "chrome/browser/ui/webui/print_preview/printer_backend_proxy.h"
#include <string>
+#include <utility>
#include "base/logging.h"
+#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
+#include "chrome/browser/ui/webui/print_preview/printer_capabilities.h"
#include "content/public/browser/browser_thread.h"
#include "printing/backend/print_backend.h"
namespace printing {
+namespace {
+
+void PostCallbackOnUIThread(const PrinterSetupCallback& cb,
+ std::unique_ptr<base::DictionaryValue> result) {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(cb, base::Passed(std::move(result))));
Lei Zhang 2016/11/03 23:41:46 Also less verbose if std::move(result) is removed
skau 2016/11/04 19:28:59 Switched to PostTaskAndReply. Code has been remov
+}
+
+} // namespace
+
std::string GetDefaultPrinterOnBlockingPoolThread() {
DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
@@ -36,4 +50,30 @@ PrinterList EnumeratePrintersOnBlockingPoolThread(Profile* /* profile */) {
return printer_list;
}
+void ConfigurePrinterAndFetchCapabilities(Profile* /* profile */,
+ const std::string& device_name,
+ const PrinterSetupCallback& cb) {
+ DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
+
+ scoped_refptr<printing::PrintBackend> print_backend(
+ printing::PrintBackend::CreateInstance(nullptr));
+
+ VLOG(1) << "Get printer capabilities start for " << device_name;
+
+ std::unique_ptr<base::DictionaryValue> printer_info;
+ if (!print_backend->IsValidPrinter(device_name)) {
+ LOG(WARNING) << "Invalid printer " << device_name;
+ PostCallbackOnUIThread(cb, nullptr);
Lei Zhang 2016/11/03 23:41:46 An alternative to having PostCallbackOnUIThread()
skau 2016/11/04 19:28:59 Thanks. I've done that and it is simpler now.
+ return;
+ }
+
+ PrinterBasicInfo basic_info;
+ if (!print_backend->GetPrinterBasicInfo(device_name, &basic_info)) {
+ PostCallbackOnUIThread(cb, nullptr);
+ return;
+ }
+
+ PostCallbackOnUIThread(cb, GetSettingsDictionary(device_name, basic_info));
+}
+
} // namespace printing

Powered by Google App Engine
This is Rietveld 408576698