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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/print_preview/printer_backend_proxy.h" 5 #include "chrome/browser/ui/webui/print_preview/printer_backend_proxy.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility>
8 9
9 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h"
10 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "chrome/browser/ui/webui/print_preview/printer_capabilities.h"
11 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
12 #include "printing/backend/print_backend.h" 15 #include "printing/backend/print_backend.h"
13 16
14 namespace printing { 17 namespace printing {
15 18
16 namespace { 19 namespace {
17 20
18 PrinterList EnumeratePrintersOnBlockingPoolThread() { 21 PrinterList EnumeratePrintersOnBlockingPoolThread() {
19 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 22 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
20 23
21 scoped_refptr<PrintBackend> print_backend( 24 scoped_refptr<PrintBackend> print_backend(
22 PrintBackend::CreateInstance(nullptr)); 25 PrintBackend::CreateInstance(nullptr));
23 26
24 PrinterList printer_list; 27 PrinterList printer_list;
25 print_backend->EnumeratePrinters(&printer_list); 28 print_backend->EnumeratePrinters(&printer_list);
26 29
27 return printer_list; 30 return printer_list;
28 } 31 }
29 32
33 std::unique_ptr<base::DictionaryValue> FetchCapabilitiesOnBlockingPool(
34 const std::string& device_name) {
35 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
36 scoped_refptr<printing::PrintBackend> print_backend(
37 printing::PrintBackend::CreateInstance(nullptr));
38
39 VLOG(1) << "Get printer capabilities start for " << device_name;
40
41 std::unique_ptr<base::DictionaryValue> printer_info;
42 if (!print_backend->IsValidPrinter(device_name)) {
43 LOG(WARNING) << "Invalid printer " << device_name;
44 return nullptr;
45 }
46
47 PrinterBasicInfo basic_info;
48 if (!print_backend->GetPrinterBasicInfo(device_name, &basic_info)) {
49 return nullptr;
50 }
51
52 return GetSettingsOnBlockingPool(device_name, basic_info);
53 }
54
30 } // namespace 55 } // namespace
31 56
32 std::string GetDefaultPrinterOnBlockingPoolThread() { 57 std::string GetDefaultPrinterOnBlockingPoolThread() {
33 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 58 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
34 59
35 scoped_refptr<printing::PrintBackend> print_backend( 60 scoped_refptr<printing::PrintBackend> print_backend(
36 PrintBackend::CreateInstance(nullptr)); 61 PrintBackend::CreateInstance(nullptr));
37 62
38 std::string default_printer = print_backend->GetDefaultPrinterName(); 63 std::string default_printer = print_backend->GetDefaultPrinterName();
39 VLOG(1) << "Default Printer: " << default_printer; 64 VLOG(1) << "Default Printer: " << default_printer;
40 return default_printer; 65 return default_printer;
41 } 66 }
42 67
43 void EnumeratePrinters(Profile* /* profile */, 68 void EnumeratePrinters(Profile* /* profile */,
44 const EnumeratePrintersCallback& cb) { 69 const EnumeratePrintersCallback& cb) {
45 base::PostTaskAndReplyWithResult( 70 base::PostTaskAndReplyWithResult(
46 content::BrowserThread::GetBlockingPool(), FROM_HERE, 71 content::BrowserThread::GetBlockingPool(), FROM_HERE,
47 base::Bind(&EnumeratePrintersOnBlockingPoolThread), cb); 72 base::Bind(&EnumeratePrintersOnBlockingPoolThread), cb);
48 } 73 }
49 74
75 void ConfigurePrinterAndFetchCapabilities(Profile* /* profile */,
76 const std::string& device_name,
77 const PrinterSetupCallback& cb) {
78 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
79
80 base::PostTaskAndReplyWithResult(
81 content::BrowserThread::GetBlockingPool(), FROM_HERE,
82 base::Bind(&FetchCapabilitiesOnBlockingPool, device_name), cb);
83 }
84
50 } // namespace printing 85 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698