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

Side by Side Diff: chrome/browser/ui/webui/print_preview/printer_backend_proxy_chromeos.cc

Issue 2463473002: Present the printer list from preferences for Chrome OS. (Closed)
Patch Set: done 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/print_preview/printer_backend_proxy.h"
6
7 #include <memory>
8 #include <vector>
9
10 #include "base/command_line.h"
11 #include "base/values.h"
12 #include "chrome/browser/chromeos/printing/printer_pref_manager.h"
13 #include "chrome/browser/chromeos/printing/printer_pref_manager_factory.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chromeos/printing/printer_configuration.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "printing/backend/print_backend.h"
19 #include "printing/backend/print_backend_consts.h"
20
21 namespace printing {
22
23 namespace {
24
25 // Store the name used in CUPS, Printer#id in |printer_name|, the description
26 // as the system_driverinfo option value, and the Printer#display_name in
27 // the |printer_description| field. This will match how Mac OS X presents
28 // printer information.
29 printing::PrinterBasicInfo ToBasicInfo(const chromeos::Printer& printer) {
30 PrinterBasicInfo basic_info;
31
32 // TODO(skau): Unify Mac with the other platforms for display name
33 // presentation so I can remove this strange code.
34 basic_info.options[kDriverInfoTagName] = printer.description();
35 basic_info.printer_name = printer.id();
36 basic_info.printer_description = printer.display_name();
37 return basic_info;
38 }
39
40 } // namespace
41
42 std::string GetDefaultPrinterOnBlockingPoolThread() {
43 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
44 // TODO(crbug.com/660898): Add default printers to ChromeOS.
45 return "";
46 }
47
48 void EnumeratePrinters(Profile* profile, const EnumeratePrintersCallback& cb) {
49 // PrinterPrefManager is not thread safe and must be called from the UI
50 // thread.
51 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
52
53 PrinterList printer_list;
54
55 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
56 switches::kEnableNativeCups)) {
57 chromeos::PrinterPrefManager* prefs =
58 chromeos::PrinterPrefManagerFactory::GetForBrowserContext(profile);
59 std::vector<std::unique_ptr<chromeos::Printer>> printers =
60 prefs->GetPrinters();
61 for (const std::unique_ptr<chromeos::Printer>& printer : printers) {
62 printer_list.push_back(ToBasicInfo(*printer));
63 }
64 }
65
66 cb.Run(printer_list);
67 }
68
69 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/print_preview/printer_backend_proxy.cc ('k') | printing/backend/print_backend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698