Index: base/test/scoped_environment_variable.cc |
diff --git a/base/test/scoped_environment_variable.cc b/base/test/scoped_environment_variable.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a044111e16cbe5d74528beb085ad5e054e655f95 |
--- /dev/null |
+++ b/base/test/scoped_environment_variable.cc |
@@ -0,0 +1,27 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/test/scoped_environment_variable.h" |
+ |
+#include "base/environment.h" |
+ |
+namespace base { |
+ |
+ScopedEnvironmentVariable::ScopedEnvironmentVariable( |
+ const std::string& name, |
+ const std::string& value) |
+ : name_(name), |
+ environment_(base::Environment::Create()) { |
+ prev_was_set_ = environment_->GetVar(name.c_str(), &prev_value_); |
+ environment_->SetVar(name_.c_str(), value); |
+} |
+ |
+ScopedEnvironmentVariable::~ScopedEnvironmentVariable() { |
+ if (prev_was_set_) |
+ environment_->SetVar(name_.c_str(), prev_value_); |
+ else |
+ environment_->UnSetVar(name_.c_str()); |
+} |
+ |
+} // namespace base |