Index: net/test/spawned_test_server/local_test_server_win.cc |
diff --git a/net/test/spawned_test_server/local_test_server_win.cc b/net/test/spawned_test_server/local_test_server_win.cc |
index fd26483ed477b37698538f1f2b609e7d79b343f2..91b902f7e60e144af675b7f1ab8331896d7623ae 100644 |
--- a/net/test/spawned_test_server/local_test_server_win.cc |
+++ b/net/test/spawned_test_server/local_test_server_win.cc |
@@ -10,6 +10,7 @@ |
#include "base/base_paths.h" |
#include "base/bind.h" |
#include "base/command_line.h" |
+#include "base/environment.h" |
#include "base/files/file_path.h" |
#include "base/message_loop/message_loop.h" |
#include "base/path_service.h" |
@@ -85,6 +86,51 @@ bool ReadData(HANDLE read_fd, HANDLE write_fd, |
namespace net { |
+class AddedPythonPath { |
+private: |
+ std::string old_path_; |
+ scoped_ptr<base::Environment> environment_; |
+ bool path_modified_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AddedPythonPath); |
+ |
+public: |
Paweł Hajdan Jr.
2013/08/19 19:16:56
nit: In Chromium style we usually put public: sect
|
+ AddedPythonPath(); |
+ ~AddedPythonPath(); |
+}; |
+ |
+AddedPythonPath::AddedPythonPath() |
+ : environment_(base::Environment::Create()), |
+ path_modified_(false) { |
+ // Retrieves the old path, adds third_party/python26 to the end of it and |
+ // then restores the original path in the destructor. |
+ |
+ (void)environment_->GetVar("PATH", &old_path_); |
Paweł Hajdan Jr.
2013/08/19 19:16:56
nit: Are these (void) casts needed? Generally we d
Daniel Bratell
2013/08/20 14:33:09
Not needed. Just an old convention to silence stat
Paweł Hajdan Jr.
2013/08/22 18:11:53
If these ignore_results are not needed to get it t
|
+ |
+ std::string new_value = old_path_; |
+ if (new_value.length() > 0) |
Paweł Hajdan Jr.
2013/08/19 19:16:56
nit: Why not do an .empty() check instead? The int
Daniel Bratell
2013/08/20 14:33:09
Thanks! Just my string class confusion made me thi
|
+ new_value += ";"; // Path seperator. |
+ |
+ // Add new path to the end so system pythons are used if available. |
Paweł Hajdan Jr.
2013/08/19 19:16:56
nit: system pythons -> system python (plural -> si
|
+ base::FilePath python_path; |
+ if (!PathService::Get(base::DIR_SOURCE_ROOT, &python_path)) |
Paweł Hajdan Jr.
2013/08/19 19:16:56
This is a silent failure, and the function that ca
Daniel Bratell
2013/08/20 14:33:09
This is the constructor so you mean adding/using a
Paweł Hajdan Jr.
2013/08/22 18:11:53
We disable exceptions in Chrome. This means you'd
|
+ return; |
+ python_path = python_path.Append(FILE_PATH_LITERAL("third_party")) |
Paweł Hajdan Jr.
2013/08/19 19:16:56
nit: You can just use AppendASCII.
|
+ .Append(FILE_PATH_LITERAL("python_26")); |
+ new_value += python_path.AsUTF8Unsafe(); |
Paweł Hajdan Jr.
2013/08/19 19:16:56
Why the Unsafe method? :-/
Note that it may be ne
Daniel Bratell
2013/08/20 14:33:09
The Environment class uses UTF-8 strings in the AP
Paweł Hajdan Jr.
2013/08/22 18:11:53
Sounds good!
|
+ |
+ path_modified_ = environment_->SetVar("PATH", new_value); |
+} |
+ |
+AddedPythonPath::~AddedPythonPath() { |
+ if (path_modified_) { |
+ if (old_path_.length() > 0) |
+ (void)environment_->SetVar("PATH", old_path_); |
+ else |
+ (void)environment_->UnSetVar("PATH"); |
+ } |
+} |
+ |
bool LocalTestServer::LaunchPython(const base::FilePath& testserver_path) { |
CommandLine python_command(CommandLine::NO_PROGRAM); |
if (!GetPythonCommand(&python_command)) |
@@ -134,6 +180,7 @@ bool LocalTestServer::LaunchPython(const base::FilePath& testserver_path) { |
return false; |
} |
+ AddedPythonPath python_path; |
base::LaunchOptions launch_options; |
launch_options.inherit_handles = true; |
launch_options.job_handle = job_handle_.Get(); |