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

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

Issue 885443002: Roll Chrome into Mojo. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase to ToT mojo Created 5 years, 10 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/ssl/client_cert_store_chromeos.h ('k') | net/tools/crash_cache/crash_cache.cc » ('j') | 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 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 thread.Stop(); 71 thread.Stop();
72 // If the timeout kicked in, abort. 72 // If the timeout kicked in, abort.
73 if (unblocked) { 73 if (unblocked) {
74 LOG(ERROR) << "Timeout exceeded for ReadData"; 74 LOG(ERROR) << "Timeout exceeded for ReadData";
75 return false; 75 return false;
76 } 76 }
77 77
78 return true; 78 return true;
79 } 79 }
80 80
81 // Class that sets up a temporary path that includes the supplied path
82 // at the end.
83 //
84 // TODO(bratell): By making this more generic we can possibly reuse
85 // it at other places such as
86 // chrome/common/multi_process_lock_unittest.cc.
87 class ScopedPath {
88 public:
89 // Constructor which sets up the environment to include the path to
90 // |path_to_add|.
91 explicit ScopedPath(const base::FilePath& path_to_add);
92
93 // Destructor that restores the path that were active when the
94 // object was constructed.
95 ~ScopedPath();
96
97 private:
98 // The PATH environment variable before it was changed or an empty
99 // string if there was no PATH environment variable.
100 std::string old_path_;
101
102 // The helper object that allows us to read and set environment
103 // variables more easily.
104 scoped_ptr<base::Environment> environment_;
105
106 // A flag saying if we have actually modified the environment.
107 bool path_modified_;
108
109 DISALLOW_COPY_AND_ASSIGN(ScopedPath);
110 };
111
112 ScopedPath::ScopedPath(const base::FilePath& path_to_add)
113 : environment_(base::Environment::Create()),
114 path_modified_(false) {
115 environment_->GetVar("PATH", &old_path_);
116
117 std::string new_value = old_path_;
118 if (!new_value.empty())
119 new_value += ";";
120
121 new_value += base::WideToUTF8(path_to_add.value());
122
123 path_modified_ = environment_->SetVar("PATH", new_value);
124 }
125
126 ScopedPath::~ScopedPath() {
127 if (!path_modified_)
128 return;
129 if (old_path_.empty())
130 environment_->UnSetVar("PATH");
131 else
132 environment_->SetVar("PATH", old_path_);
133 }
134
135 } // namespace 81 } // namespace
136 82
137 namespace net { 83 namespace net {
138 84
139 bool LocalTestServer::LaunchPython(const base::FilePath& testserver_path) { 85 bool LocalTestServer::LaunchPython(const base::FilePath& testserver_path) {
140 base::CommandLine python_command(base::CommandLine::NO_PROGRAM); 86 base::CommandLine python_command(base::CommandLine::NO_PROGRAM);
141 if (!GetPythonCommand(&python_command)) 87 if (!GetPythonCommand(&python_command))
142 return false; 88 return false;
143 89
144 python_command.AppendArgPath(testserver_path); 90 python_command.AppendArgPath(testserver_path);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 if (!ParseServerData(server_data)) { 152 if (!ParseServerData(server_data)) {
207 LOG(ERROR) << "Could not parse server_data: " << server_data; 153 LOG(ERROR) << "Could not parse server_data: " << server_data;
208 return false; 154 return false;
209 } 155 }
210 156
211 return true; 157 return true;
212 } 158 }
213 159
214 } // namespace net 160 } // namespace net
215 161
OLDNEW
« no previous file with comments | « net/ssl/client_cert_store_chromeos.h ('k') | net/tools/crash_cache/crash_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698