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

Side by Side Diff: chrome/browser/printing/printer_manager_dialog_linux.cc

Issue 2965803002: Move more printing code off of the FILE thread. (Closed)
Patch Set: tweak Created 3 years, 5 months 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/printing/printer_manager_dialog.h" 5 #include "chrome/browser/printing/printer_manager_dialog.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/nix/xdg_util.h" 12 #include "base/nix/xdg_util.h"
14 #include "base/process/kill.h" 13 #include "base/process/kill.h"
15 #include "base/process/launch.h" 14 #include "base/process/launch.h"
16 #include "base/strings/string_split.h" 15 #include "base/task_scheduler/post_task.h"
17 #include "content/public/browser/browser_thread.h" 16 #include "base/threading/thread_restrictions.h"
18
19 using base::Environment;
20 using content::BrowserThread;
21 17
22 namespace { 18 namespace {
23 19
24 // KDE printer config command ("system-config-printer-kde") causes the 20 // KDE printer config command ("system-config-printer-kde") causes the
25 // OptionWidget to crash (https://bugs.kde.org/show_bug.cgi?id=271957). 21 // OptionWidget to crash (https://bugs.kde.org/show_bug.cgi?id=271957).
26 // Therefore, use GNOME printer config command for KDE. 22 // Therefore, use GNOME printer config command for KDE.
27 const char* const kSystemConfigPrinterCommand[] = {"system-config-printer", 23 const char* const kSystemConfigPrinterCommand[] = {"system-config-printer",
28 nullptr}; 24 nullptr};
29 25
30 const char* const kGnomeControlCenterPrintersCommand[] = { 26 const char* const kGnomeControlCenterPrintersCommand[] = {
(...skipping 11 matching lines...) Expand all
42 base::Process process = base::LaunchProcess(argv, base::LaunchOptions()); 38 base::Process process = base::LaunchProcess(argv, base::LaunchOptions());
43 if (!process.IsValid()) 39 if (!process.IsValid())
44 return false; 40 return false;
45 base::EnsureProcessGetsReaped(process.Pid()); 41 base::EnsureProcessGetsReaped(process.Pid());
46 return true; 42 return true;
47 } 43 }
48 44
49 // Detect the command based on the deskop environment and open the printer 45 // Detect the command based on the deskop environment and open the printer
50 // manager dialog. 46 // manager dialog.
51 void DetectAndOpenPrinterConfigDialog() { 47 void DetectAndOpenPrinterConfigDialog() {
52 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 48 base::ThreadRestrictions::AssertIOAllowed();
53 std::unique_ptr<Environment> env(Environment::Create()); 49 std::unique_ptr<base::Environment> env(base::Environment::Create());
54 50
55 bool opened = false; 51 bool opened = false;
56 switch (base::nix::GetDesktopEnvironment(env.get())) { 52 switch (base::nix::GetDesktopEnvironment(env.get())) {
57 case base::nix::DESKTOP_ENVIRONMENT_GNOME: 53 case base::nix::DESKTOP_ENVIRONMENT_GNOME:
58 opened = OpenPrinterConfigDialog(kSystemConfigPrinterCommand) || 54 opened = OpenPrinterConfigDialog(kSystemConfigPrinterCommand) ||
59 OpenPrinterConfigDialog(kGnomeControlCenterPrintersCommand); 55 OpenPrinterConfigDialog(kGnomeControlCenterPrintersCommand);
60 break; 56 break;
61 case base::nix::DESKTOP_ENVIRONMENT_KDE3: 57 case base::nix::DESKTOP_ENVIRONMENT_KDE3:
62 case base::nix::DESKTOP_ENVIRONMENT_KDE4: 58 case base::nix::DESKTOP_ENVIRONMENT_KDE4:
63 case base::nix::DESKTOP_ENVIRONMENT_KDE5: 59 case base::nix::DESKTOP_ENVIRONMENT_KDE5:
64 case base::nix::DESKTOP_ENVIRONMENT_UNITY: 60 case base::nix::DESKTOP_ENVIRONMENT_UNITY:
65 case base::nix::DESKTOP_ENVIRONMENT_XFCE: 61 case base::nix::DESKTOP_ENVIRONMENT_XFCE:
66 opened = OpenPrinterConfigDialog(kSystemConfigPrinterCommand); 62 opened = OpenPrinterConfigDialog(kSystemConfigPrinterCommand);
67 break; 63 break;
68 case base::nix::DESKTOP_ENVIRONMENT_OTHER: 64 case base::nix::DESKTOP_ENVIRONMENT_OTHER:
69 LOG(ERROR) 65 LOG(ERROR)
70 << "Failed to detect the command to open printer config dialog"; 66 << "Failed to detect the command to open printer config dialog";
71 return; 67 return;
72 } 68 }
73 LOG_IF(ERROR, !opened) << "Failed to open printer manager dialog "; 69 LOG_IF(ERROR, !opened) << "Failed to open printer manager dialog ";
74 } 70 }
75 71
76 } // anonymous namespace 72 } // namespace
77 73
78 namespace printing { 74 namespace printing {
79 75
80 void PrinterManagerDialog::ShowPrinterManagerDialog() { 76 void PrinterManagerDialog::ShowPrinterManagerDialog() {
81 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 77 base::PostTaskWithTraits(
82 base::BindOnce(&DetectAndOpenPrinterConfigDialog)); 78 FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_BLOCKING},
79 base::BindOnce(&DetectAndOpenPrinterConfigDialog));
83 } 80 }
84 81
85 } // namespace printing 82 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_dialog_cloud_win.cc ('k') | chrome/browser/printing/printer_manager_dialog_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698