summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-06 18:50:51 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-06 18:50:51 +0000
commitc83dd9152c88cc9cb2dcdc6c68da651516dc9715 (patch)
tree22cf90855386d9946633963f943066f309820f47 /chrome/common
parentab9cd716eecd0153a111b19d3f60e4b1cc4e58ae (diff)
downloadchromium_src-c83dd9152c88cc9cb2dcdc6c68da651516dc9715.zip
chromium_src-c83dd9152c88cc9cb2dcdc6c68da651516dc9715.tar.gz
chromium_src-c83dd9152c88cc9cb2dcdc6c68da651516dc9715.tar.bz2
Convert variables in chrome/common/env_vars.cc from wchar_t to char. Enable ChromeLoggingTest along the way.
BUG=none TEST=none Review URL: http://codereview.chromium.org/1559016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43738 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/env_vars.cc16
-rw-r--r--chrome/common/env_vars.h16
-rw-r--r--chrome/common/logging_chrome.cc24
-rw-r--r--chrome/common/logging_chrome_uitest.cc67
-rw-r--r--chrome/common/process_watcher_win.cc7
5 files changed, 72 insertions, 58 deletions
diff --git a/chrome/common/env_vars.cc b/chrome/common/env_vars.cc
index c838ca4..9a0457f 100644
--- a/chrome/common/env_vars.cc
+++ b/chrome/common/env_vars.cc
@@ -9,29 +9,29 @@ namespace env_vars {
// We call running in unattended mode (for automated testing) "headless".
// This mode can be enabled using this variable or by the kNoErrorDialogs
// switch.
-const wchar_t kHeadless[] = L"CHROME_HEADLESS";
+const char kHeadless[] = "CHROME_HEADLESS";
// The name of the log file.
-const wchar_t kLogFileName[] = L"CHROME_LOG_FILE";
+const char kLogFileName[] = "CHROME_LOG_FILE";
// If this environment variable is set, Chrome on Windows will log
// to Event Tracing for Windows.
-const wchar_t kEtwLogging[] = L"CHROME_ETW_LOGGING";
+const char kEtwLogging[] = "CHROME_ETW_LOGGING";
// CHROME_CRASHED exists if a previous instance of chrome has crashed. This
// triggers the 'restart chrome' dialog. CHROME_RESTART contains the strings
// that are needed to show the dialog.
-const wchar_t kShowRestart[] = L"CHROME_CRASHED";
-const wchar_t kRestartInfo[] = L"CHROME_RESTART";
+const char kShowRestart[] = "CHROME_CRASHED";
+const char kRestartInfo[] = "CHROME_RESTART";
// The strings RIGHT_TO_LEFT and LEFT_TO_RIGHT indicate the locale direction.
// For example, for Hebrew and Arabic locales, we use RIGHT_TO_LEFT so that the
// dialog is displayed using the right orientation.
-const wchar_t kRtlLocale[] = L"RIGHT_TO_LEFT";
-const wchar_t kLtrLocale[] = L"LEFT_TO_RIGHT";
+const char kRtlLocale[] = "RIGHT_TO_LEFT";
+const char kLtrLocale[] = "LEFT_TO_RIGHT";
// If the out-of-process breakpad could not be installed, we set this variable
// according to the process.
-const wchar_t kNoOOBreakpad[] = L"NO_OO_BREAKPAD";
+const char kNoOOBreakpad[] = "NO_OO_BREAKPAD";
} // namespace env_vars
diff --git a/chrome/common/env_vars.h b/chrome/common/env_vars.h
index 21dde5e..ed83d1e 100644
--- a/chrome/common/env_vars.h
+++ b/chrome/common/env_vars.h
@@ -9,14 +9,14 @@
namespace env_vars {
-extern const wchar_t kHeadless[];
-extern const wchar_t kLogFileName[];
-extern const wchar_t kEtwLogging[];
-extern const wchar_t kShowRestart[];
-extern const wchar_t kRestartInfo[];
-extern const wchar_t kRtlLocale[];
-extern const wchar_t kLtrLocale[];
-extern const wchar_t kNoOOBreakpad[];
+extern const char kHeadless[];
+extern const char kLogFileName[];
+extern const char kEtwLogging[];
+extern const char kShowRestart[];
+extern const char kRestartInfo[];
+extern const char kRtlLocale[];
+extern const char kLtrLocale[];
+extern const char kNoOOBreakpad[];
} // namespace env_vars
diff --git a/chrome/common/logging_chrome.cc b/chrome/common/logging_chrome.cc
index 2747447..4120aa1 100644
--- a/chrome/common/logging_chrome.cc
+++ b/chrome/common/logging_chrome.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -34,17 +34,16 @@
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/debug_util.h"
+#include "base/env_var.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
-#include "base/sys_info.h"
#include "base/utf_string_conversions.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/env_vars.h"
#include "ipc/ipc_logging.h"
-#include "ipc/ipc_message.h"
#if defined(OS_WIN)
#include "base/logging_win.h"
#include <initguid.h>
@@ -147,7 +146,8 @@ void InitChromeLogging(const CommandLine& command_line,
// headless mode to be configured either by the Environment
// Variable or by the Command Line Switch. This is for
// automated test purposes.
- if (base::SysInfo::HasEnvVar(env_vars::kHeadless) ||
+ scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
+ if (env->HasEnv(env_vars::kHeadless) ||
command_line.HasSwitch(switches::kNoErrorDialogs))
SuppressDialogs();
@@ -169,7 +169,7 @@ void InitChromeLogging(const CommandLine& command_line,
#if defined(OS_WIN)
// Enable trace control and transport through event tracing for Windows.
- if (base::SysInfo::HasEnvVar(env_vars::kEtwLogging))
+ if (env->HasEnv(env_vars::kEtwLogging))
logging::LogEventProvider::Initialize(kChromeTraceProviderName);
#endif
@@ -188,9 +188,15 @@ void CleanupChromeLogging() {
}
FilePath GetLogFileName() {
- std::wstring filename = base::SysInfo::GetEnvVar(env_vars::kLogFileName);
- if (!filename.empty())
- return FilePath::FromWStringHack(filename);
+ std::string filename;
+ scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
+ if (env->GetEnv(env_vars::kLogFileName, &filename) && !filename.empty()) {
+#if defined(OS_WIN)
+ return FilePath(UTF8ToWide(filename).c_str());
+#elif defined(OS_POSIX)
+ return FilePath(filename.c_str());
+#endif
+ }
const FilePath log_filename(FILE_PATH_LITERAL("chrome_debug.log"));
FilePath log_path;
@@ -236,4 +242,4 @@ size_t GetFatalAssertions(AssertionList* assertions) {
return assertion_count;
}
-} // namespace logging
+} // namespace logging
diff --git a/chrome/common/logging_chrome_uitest.cc b/chrome/common/logging_chrome_uitest.cc
index 394a54a..8f3670b 100644
--- a/chrome/common/logging_chrome_uitest.cc
+++ b/chrome/common/logging_chrome_uitest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -12,6 +12,7 @@
#include "base/basictypes.h"
#include "base/command_line.h"
+#include "base/env_var.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/env_vars.h"
#include "chrome/common/logging_chrome.h"
@@ -19,38 +20,45 @@
#include "chrome/test/ui/ui_test.h"
#include "testing/gtest/include/gtest/gtest.h"
-#if defined(OS_WIN)
-// TODO(port)
namespace {
- class ChromeLoggingTest : public testing::Test {
- public:
- // Stores the current value of the log file name environment
- // variable and sets the variable to new_value.
- void SaveEnvironmentVariable(std::wstring new_value) {
- unsigned status = GetEnvironmentVariable(env_vars::kLogFileName,
- environment_filename_,
- MAX_PATH);
- if (!status) {
- wcscpy_s(environment_filename_, L"");
- }
-
- SetEnvironmentVariable(env_vars::kLogFileName, new_value.c_str());
- }
-
- // Restores the value of the log file nave environment variable
- // previously saved by SaveEnvironmentVariable().
- void RestoreEnvironmentVariable() {
- SetEnvironmentVariable(env_vars::kLogFileName, environment_filename_);
- }
-
- private:
- wchar_t environment_filename_[MAX_PATH]; // Saves real environment value.
- };
+
+class ChromeLoggingTest : public testing::Test {
+ public:
+ // Stores the current value of the log file name environment
+ // variable and sets the variable to new_value.
+ void SaveEnvironmentVariable(std::string new_value) {
+ scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
+ if (!env->GetEnv(env_vars::kLogFileName, &environment_filename_))
+ environment_filename_ = "";
+
+ // TODO(port) Add base::SetEnv() and get rid of the ifdefs.
+#if defined(OS_WIN)
+ SetEnvironmentVariable(ASCIIToWide(env_vars::kLogFileName).c_str(),
+ ASCIIToWide(new_value).c_str());
+#else
+ setenv(env_vars::kLogFileName, new_value.c_str(), 1);
+#endif
+ }
+
+ // Restores the value of the log file nave environment variable
+ // previously saved by SaveEnvironmentVariable().
+ void RestoreEnvironmentVariable() {
+#if defined(OS_WIN)
+ SetEnvironmentVariable(ASCIIToWide(env_vars::kLogFileName).c_str(),
+ ASCIIToWide(environment_filename_).c_str());
+#else
+ setenv(env_vars::kLogFileName, environment_filename_.c_str(), 1);
+#endif
+ }
+
+ private:
+ std::string environment_filename_; // Saves real environment value.
+};
};
// Tests the log file name getter without an environment variable.
TEST_F(ChromeLoggingTest, LogFileName) {
- SaveEnvironmentVariable(std::wstring());
+ SaveEnvironmentVariable("");
FilePath filename = logging::GetLogFileName();
ASSERT_NE(FilePath::StringType::npos,
@@ -61,7 +69,7 @@ TEST_F(ChromeLoggingTest, LogFileName) {
// Tests the log file name getter with an environment variable.
TEST_F(ChromeLoggingTest, EnvironmentLogFileName) {
- SaveEnvironmentVariable(std::wstring(L"test value"));
+ SaveEnvironmentVariable("test value");
FilePath filename = logging::GetLogFileName();
ASSERT_EQ(FilePath(FILE_PATH_LITERAL("test value")).value(),
@@ -69,7 +77,6 @@ TEST_F(ChromeLoggingTest, EnvironmentLogFileName) {
RestoreEnvironmentVariable();
}
-#endif // defined(OS_WIN)
#if defined(OS_LINUX) && (!defined(NDEBUG) || !defined(USE_LINUX_BREAKPAD))
// On Linux in Debug mode, Chrome generates a SIGTRAP.
diff --git a/chrome/common/process_watcher_win.cc b/chrome/common/process_watcher_win.cc
index 93c681d..59f7899 100644
--- a/chrome/common/process_watcher_win.cc
+++ b/chrome/common/process_watcher_win.cc
@@ -1,12 +1,12 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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 "chrome/common/process_watcher.h"
+#include "base/env_var.h"
#include "base/message_loop.h"
#include "base/object_watcher.h"
-#include "base/sys_info.h"
#include "chrome/common/env_vars.h"
#include "chrome/common/result_codes.h"
@@ -48,7 +48,8 @@ class TimerExpiredTask : public Task, public base::ObjectWatcher::Delegate {
private:
void KillProcess() {
- if (base::SysInfo::HasEnvVar(env_vars::kHeadless)) {
+ scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
+ if (env->HasEnv(env_vars::kHeadless)) {
// If running the distributed tests, give the renderer a little time
// to figure out that the channel is shutdown and unwind.
if (WaitForSingleObject(process_, kWaitInterval) == WAIT_OBJECT_0) {