Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 { | |
| 90 private: | |
| 91 std::string old_path_; | |
| 92 scoped_ptr<base::Environment> environment_; | |
| 93 bool path_modified_; | |
| 94 | |
| 95 DISALLOW_COPY_AND_ASSIGN(AddedPythonPath); | |
| 96 | |
| 97 public: | |
|
Paweł Hajdan Jr.
2013/08/19 19:16:56
nit: In Chromium style we usually put public: sect
| |
| 98 AddedPythonPath(); | |
| 99 ~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 (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
| |
| 109 | |
| 110 std::string new_value = old_path_; | |
| 111 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
| |
| 112 new_value += ";"; // Path seperator. | |
| 113 | |
| 114 // 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
| |
| 115 base::FilePath python_path; | |
| 116 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
| |
| 117 return; | |
| 118 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.
| |
| 119 .Append(FILE_PATH_LITERAL("python_26")); | |
| 120 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!
| |
| 121 | |
| 122 path_modified_ = environment_->SetVar("PATH", new_value); | |
| 123 } | |
| 124 | |
| 125 AddedPythonPath::~AddedPythonPath() { | |
| 126 if (path_modified_) { | |
| 127 if (old_path_.length() > 0) | |
| 128 (void)environment_->SetVar("PATH", old_path_); | |
| 129 else | |
| 130 (void)environment_->UnSetVar("PATH"); | |
| 131 } | |
| 132 } | |
| 133 | |
| 88 bool LocalTestServer::LaunchPython(const base::FilePath& testserver_path) { | 134 bool LocalTestServer::LaunchPython(const base::FilePath& testserver_path) { |
| 89 CommandLine python_command(CommandLine::NO_PROGRAM); | 135 CommandLine python_command(CommandLine::NO_PROGRAM); |
| 90 if (!GetPythonCommand(&python_command)) | 136 if (!GetPythonCommand(&python_command)) |
| 91 return false; | 137 return false; |
| 92 | 138 |
| 93 python_command.AppendArgPath(testserver_path); | 139 python_command.AppendArgPath(testserver_path); |
| 94 if (!AddCommandLineArguments(&python_command)) | 140 if (!AddCommandLineArguments(&python_command)) |
| 95 return false; | 141 return false; |
| 96 | 142 |
| 97 HANDLE child_read = NULL; | 143 HANDLE child_read = NULL; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 127 if (!job_handle_.IsValid()) { | 173 if (!job_handle_.IsValid()) { |
| 128 LOG(ERROR) << "Could not create JobObject."; | 174 LOG(ERROR) << "Could not create JobObject."; |
| 129 return false; | 175 return false; |
| 130 } | 176 } |
| 131 | 177 |
| 132 if (!base::SetJobObjectAsKillOnJobClose(job_handle_.Get())) { | 178 if (!base::SetJobObjectAsKillOnJobClose(job_handle_.Get())) { |
| 133 LOG(ERROR) << "Could not SetInformationJobObject."; | 179 LOG(ERROR) << "Could not SetInformationJobObject."; |
| 134 return false; | 180 return false; |
| 135 } | 181 } |
| 136 | 182 |
| 183 AddedPythonPath python_path; | |
| 137 base::LaunchOptions launch_options; | 184 base::LaunchOptions launch_options; |
| 138 launch_options.inherit_handles = true; | 185 launch_options.inherit_handles = true; |
| 139 launch_options.job_handle = job_handle_.Get(); | 186 launch_options.job_handle = job_handle_.Get(); |
| 140 if (!base::LaunchProcess(python_command, launch_options, &process_handle_)) { | 187 if (!base::LaunchProcess(python_command, launch_options, &process_handle_)) { |
| 141 LOG(ERROR) << "Failed to launch " << python_command.GetCommandLineString(); | 188 LOG(ERROR) << "Failed to launch " << python_command.GetCommandLineString(); |
| 142 return false; | 189 return false; |
| 143 } | 190 } |
| 144 | 191 |
| 145 return true; | 192 return true; |
| 146 } | 193 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 166 if (!ParseServerData(server_data)) { | 213 if (!ParseServerData(server_data)) { |
| 167 LOG(ERROR) << "Could not parse server_data: " << server_data; | 214 LOG(ERROR) << "Could not parse server_data: " << server_data; |
| 168 return false; | 215 return false; |
| 169 } | 216 } |
| 170 | 217 |
| 171 return true; | 218 return true; |
| 172 } | 219 } |
| 173 | 220 |
| 174 } // namespace net | 221 } // namespace net |
| 175 | 222 |
| OLD | NEW |