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

Side by Side Diff: net/test/spawned_test_server/local_test_server_win.cc

Issue 21537002: Remove hard dependency on bundled python_26 in tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@glyphcache_20130604
Patch Set: Addressed some review issues. Created 7 years, 4 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
« no previous file with comments | « net/test/python_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "net/test/spawned_test_server/local_test_server.h" 5 #include "net/test/spawned_test_server/local_test_server.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <wincrypt.h> 8 #include <wincrypt.h>
9 9
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/environment.h"
13 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
14 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
15 #include "base/path_service.h" 16 #include "base/path_service.h"
16 #include "base/process/launch.h" 17 #include "base/process/launch.h"
17 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
19 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
20 #include "base/test/test_timeouts.h" 21 #include "base/test/test_timeouts.h"
21 #include "base/threading/thread.h" 22 #include "base/threading/thread.h"
22 #include "base/win/scoped_handle.h" 23 #include "base/win/scoped_handle.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 return false; 79 return false;
79 } 80 }
80 81
81 return true; 82 return true;
82 } 83 }
83 84
84 } // namespace 85 } // namespace
85 86
86 namespace net { 87 namespace net {
87 88
89 class AddedPythonPath {
Paweł Hajdan Jr. 2013/08/22 18:11:53 nit: Rename to ScopedPath, and move to anonymous n
Daniel Bratell 2013/08/23 17:42:30 Won't ScopedPath feel like a strange name for some
Daniel Bratell 2013/08/23 17:43:35 Ignore this. I wrote this comment before reading y
90 public:
Paweł Hajdan Jr. 2013/08/22 18:11:53 nit: Indent +1.
91 AddedPythonPath();
92 ~AddedPythonPath();
93
94 private:
Paweł Hajdan Jr. 2013/08/22 18:11:53 nit: Indent +1.
95 std::string old_path_;
Paweł Hajdan Jr. 2013/08/22 18:11:53 nit: Please comment all the members.
96 scoped_ptr<base::Environment> environment_;
97 bool path_modified_;
98
99 DISALLOW_COPY_AND_ASSIGN(AddedPythonPath);
100 };
101
102 AddedPythonPath::AddedPythonPath()
103 : environment_(base::Environment::Create()),
104 path_modified_(false) {
105 // Retrieves the old path, adds third_party/python26 to the end of it and
106 // then restores the original path in the destructor.
107
108 ignore_result(environment_->GetVar("PATH", &old_path_));
109
110 std::string new_value = old_path_;
111 if (!new_value.empty())
112 new_value += ";"; // Path seperator.
Paweł Hajdan Jr. 2013/08/22 18:11:53 nit: No need for the comment (by the way, we'd use
113
114 // Add new path to the end so that the system python is used if available.
115 base::FilePath python_path;
116 if (!PathService::Get(base::DIR_SOURCE_ROOT, &python_path))
Paweł Hajdan Jr. 2013/08/22 18:11:53 Please propagate this error as said before...
117 return;
118 python_path = python_path.AppendASCII("third_party")
Paweł Hajdan Jr. 2013/08/22 18:11:53 Actually it'd be better to pass this as a paramete
119 .AppendASCII("python_26");
Paweł Hajdan Jr. 2013/08/22 18:11:53 nit: This is a bit weird wrapping - if it doesn't
Daniel Bratell 2013/08/23 17:42:30 It was the way the code looked before so I just as
120 new_value += WideToUTF8(python_path.value());
121
122 path_modified_ = environment_->SetVar("PATH", new_value);
123 }
124
125 AddedPythonPath::~AddedPythonPath() {
126 if (path_modified_) {
127 // Ignoring return values since there is nothing we can do to fix
128 // any problem and leaving a test python at the end of the path is
129 // unlikely to do any harm.
130 if (old_path_.empty())
131 ignore_result(environment_->UnSetVar("PATH"));
132 else
133 ignore_result(environment_->SetVar("PATH", old_path_));
134 }
135 }
136
88 bool LocalTestServer::LaunchPython(const base::FilePath& testserver_path) { 137 bool LocalTestServer::LaunchPython(const base::FilePath& testserver_path) {
89 CommandLine python_command(CommandLine::NO_PROGRAM); 138 CommandLine python_command(CommandLine::NO_PROGRAM);
90 if (!GetPythonCommand(&python_command)) 139 if (!GetPythonCommand(&python_command))
91 return false; 140 return false;
92 141
93 python_command.AppendArgPath(testserver_path); 142 python_command.AppendArgPath(testserver_path);
94 if (!AddCommandLineArguments(&python_command)) 143 if (!AddCommandLineArguments(&python_command))
95 return false; 144 return false;
96 145
97 HANDLE child_read = NULL; 146 HANDLE child_read = NULL;
(...skipping 29 matching lines...) Expand all
127 if (!job_handle_.IsValid()) { 176 if (!job_handle_.IsValid()) {
128 LOG(ERROR) << "Could not create JobObject."; 177 LOG(ERROR) << "Could not create JobObject.";
129 return false; 178 return false;
130 } 179 }
131 180
132 if (!base::SetJobObjectAsKillOnJobClose(job_handle_.Get())) { 181 if (!base::SetJobObjectAsKillOnJobClose(job_handle_.Get())) {
133 LOG(ERROR) << "Could not SetInformationJobObject."; 182 LOG(ERROR) << "Could not SetInformationJobObject.";
134 return false; 183 return false;
135 } 184 }
136 185
186 AddedPythonPath python_path;
137 base::LaunchOptions launch_options; 187 base::LaunchOptions launch_options;
138 launch_options.inherit_handles = true; 188 launch_options.inherit_handles = true;
139 launch_options.job_handle = job_handle_.Get(); 189 launch_options.job_handle = job_handle_.Get();
140 if (!base::LaunchProcess(python_command, launch_options, &process_handle_)) { 190 if (!base::LaunchProcess(python_command, launch_options, &process_handle_)) {
141 LOG(ERROR) << "Failed to launch " << python_command.GetCommandLineString(); 191 LOG(ERROR) << "Failed to launch " << python_command.GetCommandLineString();
142 return false; 192 return false;
143 } 193 }
144 194
145 return true; 195 return true;
146 } 196 }
(...skipping 19 matching lines...) Expand all
166 if (!ParseServerData(server_data)) { 216 if (!ParseServerData(server_data)) {
167 LOG(ERROR) << "Could not parse server_data: " << server_data; 217 LOG(ERROR) << "Could not parse server_data: " << server_data;
168 return false; 218 return false;
169 } 219 }
170 220
171 return true; 221 return true;
172 } 222 }
173 223
174 } // namespace net 224 } // namespace net
175 225
OLDNEW
« no previous file with comments | « net/test/python_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698