Introduce ProfilerMetricsProvider
[chromium-blink-merge.git] / chrome / browser / printing / printer_manager_dialog_linux.cc
blobcc36c3c3a2c6932505d56792bf130130f215b9ae
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 command = kGNOMEPrinterConfigCommand;
39 break;
40 case base::nix::DESKTOP_ENVIRONMENT_XFCE:
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::ProcessHandle handle;
53 if (!base::LaunchProcess(argv, base::LaunchOptions(), &handle)) {
54 LOG(ERROR) << "Failed to open printer manager dialog ";
55 return;
57 base::EnsureProcessGetsReaped(handle);
60 } // anonymous namespace
62 namespace printing {
64 void PrinterManagerDialog::ShowPrinterManagerDialog() {
65 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
66 base::Bind(&DetectAndOpenPrinterConfigDialog));
69 } // namespace printing