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

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: Add 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 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"
13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
15 #include "base/nix/xdg_util.h" 13 #include "base/nix/xdg_util.h"
16 #include "base/process/launch.h" 14 #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" 15 #include "build/build_config.h"
20 #include "chrome/browser/tab_contents/tab_util.h" 16 #include "chrome/browser/tab_contents/tab_util.h"
21 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
23 #include "content/public/browser/render_view_host.h" 19 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
25 21
26 using content::BrowserThread; 22 using content::BrowserThread;
27 using content::OpenURLParams; 23 using content::OpenURLParams;
28 using content::Referrer; 24 using content::Referrer;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 61 }
66 62
67 // Start the given proxy configuration utility. 63 // Start the given proxy configuration utility.
68 bool StartProxyConfigUtil(const char* command[]) { 64 bool StartProxyConfigUtil(const char* command[]) {
69 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 65 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
70 // base::LaunchProcess() returns true ("success") if the fork() 66 // base::LaunchProcess() returns true ("success") if the fork()
71 // succeeds, but not necessarily the exec(). We'd like to be able to 67 // succeeds, but not necessarily the exec(). We'd like to be able to
72 // use StartProxyConfigUtil() to search possible options and stop on 68 // use StartProxyConfigUtil() to search possible options and stop on
73 // success, so we search $PATH first to predict whether the exec is 69 // success, so we search $PATH first to predict whether the exec is
74 // expected to succeed. 70 // expected to succeed.
75 // TODO(mdm): this is a useful check, and is very similar to some 71 if (!base::ExecutableExistsInPath(command[0]))
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());
79 std::string path;
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; 72 return false;
97 73
98 std::vector<std::string> argv; 74 std::vector<std::string> argv;
99 for (size_t i = 0; command[i]; ++i) 75 for (size_t i = 0; command[i]; ++i)
100 argv.push_back(command[i]); 76 argv.push_back(command[i]);
101 base::Process process = base::LaunchProcess(argv, base::LaunchOptions()); 77 base::Process process = base::LaunchProcess(argv, base::LaunchOptions());
102 if (!process.IsValid()) { 78 if (!process.IsValid()) {
103 LOG(ERROR) << "StartProxyConfigUtil failed to start " << command[0]; 79 LOG(ERROR) << "StartProxyConfigUtil failed to start " << command[0];
104 return false; 80 return false;
105 } 81 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 void ShowNetworkProxySettings(content::WebContents* web_contents) { 135 void ShowNetworkProxySettings(content::WebContents* web_contents) {
160 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 136 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
161 base::Bind(&DetectAndStartProxyConfigUtil, 137 base::Bind(&DetectAndStartProxyConfigUtil,
162 web_contents->GetRenderProcessHost()->GetID(), 138 web_contents->GetRenderProcessHost()->GetID(),
163 web_contents->GetRenderViewHost()->GetRoutingID())); 139 web_contents->GetRenderViewHost()->GetRoutingID()));
164 } 140 }
165 141
166 } // namespace settings_utils 142 } // namespace settings_utils
167 143
168 #endif // !defined(OS_CHROMEOS) 144 #endif // !defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698