Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / printing / printer_manager_dialog_linux.cc
bloba568b99e76430849f3f74102ea37985e6bc5650f
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
3 // found in the LICENSE file.
5 #include "chrome/browser/printing/printer_manager_dialog.h"
7 #include "base/bind.h"
8 #include "base/environment.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/nix/xdg_util.h"
12 #include "base/process/kill.h"
13 #include "base/process/launch.h"
14 #include "content/public/browser/browser_thread.h"
16 using base::Environment;
17 using content::BrowserThread;
19 namespace {
21 // KDE printer config command ("system-config-printer-kde") causes the
22 // OptionWidget to crash (https://bugs.kde.org/show_bug.cgi?id=271957).
23 // Therefore, use GNOME printer config command for KDE.
24 const char kGNOMEPrinterConfigCommand[] = "system-config-printer";
26 // Detect the command based on the deskop environment and open the printer
27 // manager dialog.
28 void DetectAndOpenPrinterConfigDialog() {
29 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
30 scoped_ptr<Environment> env(Environment::Create());
32 const char* command = NULL;
33 switch (base::nix::GetDesktopEnvironment(env.get())) {
34 case base::nix::DESKTOP_ENVIRONMENT_GNOME:
35 case base::nix::DESKTOP_ENVIRONMENT_KDE3:
36 case base::nix::DESKTOP_ENVIRONMENT_KDE4:
37 case base::nix::DESKTOP_ENVIRONMENT_UNITY:
38 case base::nix::DESKTOP_ENVIRONMENT_XFCE:
39 command = kGNOMEPrinterConfigCommand;
40 break;
41 case base::nix::DESKTOP_ENVIRONMENT_OTHER:
42 break;
45 if (!command) {
46 LOG(ERROR) << "Failed to detect the command to open printer config dialog";
47 return;
50 std::vector<std::string> argv;
51 argv.push_back(command);
52 base::Process process = base::LaunchProcess(argv, base::LaunchOptions());
53 if (!process.IsValid()) {
54 LOG(ERROR) << "Failed to open printer manager dialog ";
55 return;
57 base::EnsureProcessGetsReaped(process.Pid());
60 } // anonymous namespace
62 namespace printing {
64 void PrinterManagerDialog::ShowPrinterManagerDialog() {
65 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
66 base::Bind(&DetectAndOpenPrinterConfigDialog));
69 } // namespace printing