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

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

Issue 2086103002: Add base::ExecutableExistsInPath (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rewrite unit test Created 4 years, 6 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"
(...skipping 12 matching lines...) Expand all
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 if (!base::ExecutableExistsInPath(base::Environment::Create(), *command))
mattm 2016/06/23 21:32:53 This will leak the Environment. (We should really
Lei Zhang 2016/06/23 21:35:32 Ditto in chrome/browser/ui/webui/settings_utils_li
Tom (Use chromium acct) 2016/06/23 21:55:12 I'm going to leave the unique_ptr change to Lei :)
Tom (Use chromium acct) 2016/06/23 21:55:12 Done.
55 return false; 37 return false;
56 std::vector<std::string> argv; 38 std::vector<std::string> argv;
57 while (*command) 39 while (*command)
58 argv.push_back(*command++); 40 argv.push_back(*command++);
59 base::Process process = base::LaunchProcess(argv, base::LaunchOptions()); 41 base::Process process = base::LaunchProcess(argv, base::LaunchOptions());
60 if (!process.IsValid()) 42 if (!process.IsValid())
61 return false; 43 return false;
62 base::EnsureProcessGetsReaped(process.Pid()); 44 base::EnsureProcessGetsReaped(process.Pid());
63 return true; 45 return true;
64 } 46 }
(...skipping 28 matching lines...) Expand all
93 } // anonymous namespace 75 } // anonymous namespace
94 76
95 namespace printing { 77 namespace printing {
96 78
97 void PrinterManagerDialog::ShowPrinterManagerDialog() { 79 void PrinterManagerDialog::ShowPrinterManagerDialog() {
98 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 80 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
99 base::Bind(&DetectAndOpenPrinterConfigDialog)); 81 base::Bind(&DetectAndOpenPrinterConfigDialog));
100 } 82 }
101 83
102 } // namespace printing 84 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698