| OLD | NEW |
| 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 // KDE printer config command ("system-config-printer-kde") causes the | 24 // KDE printer config command ("system-config-printer-kde") causes the |
| 25 // OptionWidget to crash (https://bugs.kde.org/show_bug.cgi?id=271957). | 25 // OptionWidget to crash (https://bugs.kde.org/show_bug.cgi?id=271957). |
| 26 // Therefore, use GNOME printer config command for KDE. | 26 // Therefore, use GNOME printer config command for KDE. |
| 27 const char* const kSystemConfigPrinterCommand[] = {"system-config-printer", | 27 const char* const kSystemConfigPrinterCommand[] = {"system-config-printer", |
| 28 nullptr}; | 28 nullptr}; |
| 29 | 29 |
| 30 const char* const kGnomeControlCenterPrintersCommand[] = { | 30 const char* const kGnomeControlCenterPrintersCommand[] = { |
| 31 "gnome-control-center", "printers", nullptr}; | 31 "gnome-control-center", "printers", nullptr}; |
| 32 | 32 |
| 33 bool CommandExists(const char* command) { | |
| 34 std::unique_ptr<base::Environment> env(base::Environment::Create()); | |
| 35 std::string path; | |
| 36 if (!env->GetVar("PATH", &path)) { | |
| 37 LOG(ERROR) << "No $PATH variable. Assuming no " << command << "."; | |
| 38 return false; | |
| 39 } | |
| 40 | |
| 41 for (const base::StringPiece& cur_path : | |
| 42 base::SplitStringPiece(path, ":", base::KEEP_WHITESPACE, | |
| 43 base::SPLIT_WANT_NONEMPTY)) { | |
| 44 base::FilePath file(cur_path); | |
| 45 if (base::PathExists(file.Append(command))) | |
| 46 return true; | |
| 47 } | |
| 48 return false; | |
| 49 } | |
| 50 | |
| 51 // Returns true if the dialog was opened successfully. | 33 // Returns true if the dialog was opened successfully. |
| 52 bool OpenPrinterConfigDialog(const char* const* command) { | 34 bool OpenPrinterConfigDialog(const char* const* command) { |
| 53 DCHECK(command); | 35 DCHECK(command); |
| 54 if (!CommandExists(*command)) | 36 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| 37 if (!base::ExecutableExistsInPath(env.get(), *command)) |
| 55 return false; | 38 return false; |
| 56 std::vector<std::string> argv; | 39 std::vector<std::string> argv; |
| 57 while (*command) | 40 while (*command) |
| 58 argv.push_back(*command++); | 41 argv.push_back(*command++); |
| 59 base::Process process = base::LaunchProcess(argv, base::LaunchOptions()); | 42 base::Process process = base::LaunchProcess(argv, base::LaunchOptions()); |
| 60 if (!process.IsValid()) | 43 if (!process.IsValid()) |
| 61 return false; | 44 return false; |
| 62 base::EnsureProcessGetsReaped(process.Pid()); | 45 base::EnsureProcessGetsReaped(process.Pid()); |
| 63 return true; | 46 return true; |
| 64 } | 47 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 93 } // anonymous namespace | 76 } // anonymous namespace |
| 94 | 77 |
| 95 namespace printing { | 78 namespace printing { |
| 96 | 79 |
| 97 void PrinterManagerDialog::ShowPrinterManagerDialog() { | 80 void PrinterManagerDialog::ShowPrinterManagerDialog() { |
| 98 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 81 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 99 base::Bind(&DetectAndOpenPrinterConfigDialog)); | 82 base::Bind(&DetectAndOpenPrinterConfigDialog)); |
| 100 } | 83 } |
| 101 | 84 |
| 102 } // namespace printing | 85 } // namespace printing |
| OLD | NEW |