printer_manager_dialog_linux.cc revision 9ab5563a3196760eb381d102cbb2bc0f7abc6a50
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. 4 5#include "chrome/browser/printing/printer_manager_dialog.h" 6 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_util.h" 13#include "content/public/browser/browser_thread.h" 14 15using base::Environment; 16using content::BrowserThread; 17 18namespace { 19 20// KDE printer config command ("system-config-printer-kde") causes the 21// OptionWidget to crash (https://bugs.kde.org/show_bug.cgi?id=271957). 22// Therefore, use GNOME printer config command for KDE. 23const char kGNOMEPrinterConfigCommand[] = "system-config-printer"; 24 25// Detect the command based on the deskop environment and open the printer 26// manager dialog. 27void DetectAndOpenPrinterConfigDialog() { 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 29 scoped_ptr<Environment> env(Environment::Create()); 30 31 const char* command = NULL; 32 switch (base::nix::GetDesktopEnvironment(env.get())) { 33 case base::nix::DESKTOP_ENVIRONMENT_GNOME: 34 case base::nix::DESKTOP_ENVIRONMENT_KDE3: 35 case base::nix::DESKTOP_ENVIRONMENT_KDE4: 36 case base::nix::DESKTOP_ENVIRONMENT_UNITY: 37 command = kGNOMEPrinterConfigCommand; 38 break; 39 case base::nix::DESKTOP_ENVIRONMENT_XFCE: 40 case base::nix::DESKTOP_ENVIRONMENT_OTHER: 41 break; 42 } 43 44 if (!command) { 45 LOG(ERROR) << "Failed to detect the command to open printer config dialog"; 46 return; 47 } 48 49 std::vector<std::string> argv; 50 argv.push_back(command); 51 base::ProcessHandle handle; 52 if (!base::LaunchProcess(argv, base::LaunchOptions(), &handle)) { 53 LOG(ERROR) << "Failed to open printer manager dialog "; 54 return; 55 } 56 base::EnsureProcessGetsReaped(handle); 57} 58 59} // anonymous namespace 60 61namespace printing { 62 63void PrinterManagerDialog::ShowPrinterManagerDialog() { 64 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 65 base::Bind(&DetectAndOpenPrinterConfigDialog)); 66} 67 68} // namespace printing 69