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

Unified Diff: base/test/scoped_environment_variable.cc

Issue 11271024: Fix DeviceStatusCollectorTest.MaxStoredPeriods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698