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

Side by Side Diff: chrome/browser/ui/webui/settings_utils_linux.cc

Issue 2086103002: Add base::ExecutableExistsInPath (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't leak base::Environment 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #if !defined(OS_CHROMEOS) 5 #if !defined(OS_CHROMEOS)
6 6
7 #include "chrome/browser/ui/webui/settings_utils.h" 7 #include "chrome/browser/ui/webui/settings_utils.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/environment.h" 12 #include "base/environment.h"
13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
15 #include "base/nix/xdg_util.h" 14 #include "base/nix/xdg_util.h"
16 #include "base/process/launch.h" 15 #include "base/process/launch.h"
17 #include "base/strings/string_split.h"
18 #include "base/strings/string_util.h"
19 #include "build/build_config.h" 16 #include "build/build_config.h"
20 #include "chrome/browser/tab_contents/tab_util.h" 17 #include "chrome/browser/tab_contents/tab_util.h"
21 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
23 #include "content/public/browser/render_view_host.h" 20 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
25 22
26 using content::BrowserThread; 23 using content::BrowserThread;
27 using content::OpenURLParams; 24 using content::OpenURLParams;
28 using content::Referrer; 25 using content::Referrer;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 62 }
66 63
67 // Start the given proxy configuration utility. 64 // Start the given proxy configuration utility.
68 bool StartProxyConfigUtil(const char* command[]) { 65 bool StartProxyConfigUtil(const char* command[]) {
69 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 66 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
70 // base::LaunchProcess() returns true ("success") if the fork() 67 // base::LaunchProcess() returns true ("success") if the fork()
71 // succeeds, but not necessarily the exec(). We'd like to be able to 68 // succeeds, but not necessarily the exec(). We'd like to be able to
72 // use StartProxyConfigUtil() to search possible options and stop on 69 // use StartProxyConfigUtil() to search possible options and stop on
73 // success, so we search $PATH first to predict whether the exec is 70 // success, so we search $PATH first to predict whether the exec is
74 // expected to succeed. 71 // expected to succeed.
75 // TODO(mdm): this is a useful check, and is very similar to some
76 // code in proxy_config_service_linux.cc. It should probably be in
77 // base:: somewhere.
78 std::unique_ptr<base::Environment> env(base::Environment::Create()); 72 std::unique_ptr<base::Environment> env(base::Environment::Create());
79 std::string path; 73 if (!base::ExecutableExistsInPath(env.get(), command[0]))
80 if (!env->GetVar("PATH", &path)) {
81 LOG(ERROR) << "No $PATH variable. Assuming no " << command[0] << ".";
82 return false;
83 }
84
85 bool found = false;
86 for (const base::StringPiece& cur_path :
87 base::SplitStringPiece(path, ":", base::KEEP_WHITESPACE,
88 base::SPLIT_WANT_NONEMPTY)) {
89 base::FilePath file(cur_path);
90 if (base::PathExists(file.Append(command[0]))) {
91 found = true;
92 break;
93 }
94 }
95 if (!found)
96 return false; 74 return false;
97 75
98 std::vector<std::string> argv; 76 std::vector<std::string> argv;
99 for (size_t i = 0; command[i]; ++i) 77 for (size_t i = 0; command[i]; ++i)
100 argv.push_back(command[i]); 78 argv.push_back(command[i]);
101 base::Process process = base::LaunchProcess(argv, base::LaunchOptions()); 79 base::Process process = base::LaunchProcess(argv, base::LaunchOptions());
102 if (!process.IsValid()) { 80 if (!process.IsValid()) {
103 LOG(ERROR) << "StartProxyConfigUtil failed to start " << command[0]; 81 LOG(ERROR) << "StartProxyConfigUtil failed to start " << command[0];
104 return false; 82 return false;
105 } 83 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 void ShowNetworkProxySettings(content::WebContents* web_contents) { 137 void ShowNetworkProxySettings(content::WebContents* web_contents) {
160 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 138 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
161 base::Bind(&DetectAndStartProxyConfigUtil, 139 base::Bind(&DetectAndStartProxyConfigUtil,
162 web_contents->GetRenderProcessHost()->GetID(), 140 web_contents->GetRenderProcessHost()->GetID(),
163 web_contents->GetRenderViewHost()->GetRoutingID())); 141 web_contents->GetRenderViewHost()->GetRoutingID()));
164 } 142 }
165 143
166 } // namespace settings_utils 144 } // namespace settings_utils
167 145
168 #endif // !defined(OS_CHROMEOS) 146 #endif // !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « chrome/browser/printing/printer_manager_dialog_linux.cc ('k') | net/proxy/proxy_config_service_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698