diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-06 18:50:51 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-06 18:50:51 +0000 |
commit | c83dd9152c88cc9cb2dcdc6c68da651516dc9715 (patch) | |
tree | 22cf90855386d9946633963f943066f309820f47 | |
parent | ab9cd716eecd0153a111b19d3f60e4b1cc4e58ae (diff) | |
download | chromium_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
-rw-r--r-- | chrome/app/breakpad_linux.cc | 5 | ||||
-rw-r--r-- | chrome/app/breakpad_win.cc | 24 | ||||
-rw-r--r-- | chrome/browser/browser_main_win.cc | 18 | ||||
-rw-r--r-- | chrome/browser/child_process_host.cc | 5 | ||||
-rw-r--r-- | chrome/browser/crash_handler_host_linux.cc | 8 | ||||
-rw-r--r-- | chrome/browser/rlz/rlz.cc | 16 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/protocol_manager.cc | 7 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/protocol_manager.h | 4 | ||||
-rw-r--r-- | chrome/common/env_vars.cc | 16 | ||||
-rw-r--r-- | chrome/common/env_vars.h | 16 | ||||
-rw-r--r-- | chrome/common/logging_chrome.cc | 24 | ||||
-rw-r--r-- | chrome/common/logging_chrome_uitest.cc | 67 | ||||
-rw-r--r-- | chrome/common/process_watcher_win.cc | 7 | ||||
-rw-r--r-- | chrome/test/automated_ui_tests/automated_ui_tests.cc | 7 | ||||
-rw-r--r-- | chrome/test/tab_switching/tab_switching_test.cc | 6 | ||||
-rw-r--r-- | chrome/test/ui/ui_test_suite.cc | 9 |
16 files changed, 135 insertions, 104 deletions
diff --git a/chrome/app/breakpad_linux.cc b/chrome/app/breakpad_linux.cc index 970a12e..8c12143 100644 --- a/chrome/app/breakpad_linux.cc +++ b/chrome/app/breakpad_linux.cc @@ -1,4 +1,4 @@ -// Copyright (c) 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. @@ -731,8 +731,7 @@ void InitCrashReporter() { const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); const std::string process_type = parsed_command_line.GetSwitchValueASCII(switches::kProcessType); - const bool unattended = - (getenv(WideToASCII(env_vars::kHeadless).c_str()) != NULL); + const bool unattended = (getenv(env_vars::kHeadless) != NULL); if (process_type.empty()) { if (!(unattended || GoogleUpdateSettings::GetCollectStatsConsent())) return; diff --git a/chrome/app/breakpad_win.cc b/chrome/app/breakpad_win.cc index 27a2d80..ac8457a 100644 --- a/chrome/app/breakpad_win.cc +++ b/chrome/app/breakpad_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 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. @@ -184,9 +184,11 @@ bool DumpDoneCallback(const wchar_t*, const wchar_t*, void*, // We set CHROME_CRASHED env var. If the CHROME_RESTART is present. // This signals the child process to show the 'chrome has crashed' dialog. - if (!::GetEnvironmentVariableW(env_vars::kRestartInfo, NULL, 0)) + if (!::GetEnvironmentVariableW(ASCIIToWide(env_vars::kRestartInfo).c_str(), + NULL, 0)) { return true; - ::SetEnvironmentVariableW(env_vars::kShowRestart, L"1"); + } + ::SetEnvironmentVariableW(ASCIIToWide(env_vars::kShowRestart).c_str(), L"1"); // Now we just start chrome browser with the same command line. STARTUPINFOW si = {sizeof(si)}; PROCESS_INFORMATION pi; @@ -286,10 +288,13 @@ extern "C" void __declspec(dllexport) __cdecl SetExtensionID( // spawned and basically just shows the 'chrome has crashed' dialog if // the CHROME_CRASHED environment variable is present. bool ShowRestartDialogIfCrashed(bool* exit_now) { - if (!::GetEnvironmentVariableW(env_vars::kShowRestart, NULL, 0)) + if (!::GetEnvironmentVariableW(ASCIIToWide(env_vars::kShowRestart).c_str(), + NULL, 0)) { return false; + } - DWORD len = ::GetEnvironmentVariableW(env_vars::kRestartInfo, NULL, 0); + DWORD len = ::GetEnvironmentVariableW( + ASCIIToWide(env_vars::kRestartInfo).c_str(), NULL, 0); if (!len) return true; @@ -300,7 +305,8 @@ bool ShowRestartDialogIfCrashed(bool* exit_now) { #pragma warning(disable:4509) // warning: SEH used but dlg_strings has a dtor. __try { wchar_t* restart_data = new wchar_t[len + 1]; - ::GetEnvironmentVariableW(env_vars::kRestartInfo, restart_data, len); + ::GetEnvironmentVariableW(ASCIIToWide(env_vars::kRestartInfo).c_str(), + restart_data, len); restart_data[len] = 0; // The CHROME_RESTART var contains the dialog strings separated by '|'. // See PrepareRestartOnCrashEnviroment() function for details. @@ -313,7 +319,7 @@ bool ShowRestartDialogIfCrashed(bool* exit_now) { // If the UI layout is right-to-left, we need to pass the appropriate MB_XXX // flags so that an RTL message box is displayed. UINT flags = MB_OKCANCEL | MB_ICONWARNING; - if (dlg_strings[2] == env_vars::kRtlLocale) + if (dlg_strings[2] == ASCIIToWide(env_vars::kRtlLocale)) flags |= MB_RIGHT | MB_RTLREADING; // Show the dialog now. It is ok if another chrome is started by the @@ -345,7 +351,7 @@ static DWORD __stdcall InitCrashReporterThread(void* param) { const CommandLine& command = *CommandLine::ForCurrentProcess(); bool use_crash_service = command.HasSwitch(switches::kNoErrorDialogs) || - GetEnvironmentVariable(env_vars::kHeadless, NULL, 0); + GetEnvironmentVariable(ASCIIToWide(env_vars::kHeadless).c_str(), NULL, 0); bool is_per_user_install = InstallUtil::IsPerUserInstall(info->dll_path.c_str()); @@ -405,7 +411,7 @@ static DWORD __stdcall InitCrashReporterThread(void* param) { if (!g_breakpad->IsOutOfProcess()) { // The out-of-process handler is unavailable. - ::SetEnvironmentVariable(env_vars::kNoOOBreakpad, + ::SetEnvironmentVariable(ASCIIToWide(env_vars::kNoOOBreakpad).c_str(), info->process_type.c_str()); } else { // Tells breakpad to handle breakpoint and single step exceptions. diff --git a/chrome/browser/browser_main_win.cc b/chrome/browser/browser_main_win.cc index 8fba8c3..7b681e5 100644 --- a/chrome/browser/browser_main_win.cc +++ b/chrome/browser/browser_main_win.cc @@ -8,6 +8,8 @@ #include <windows.h> #include <shellapi.h> +#include <algorithm> + #include "app/l10n_util.h" #include "app/message_box_flags.h" #include "app/win_util.h" @@ -38,7 +40,8 @@ void DidEndMainMessageLoop() { } void RecordBreakpadStatusUMA(MetricsService* metrics) { - DWORD len = ::GetEnvironmentVariableW(env_vars::kNoOOBreakpad, NULL, 0); + DWORD len = ::GetEnvironmentVariableW( + ASCIIToWide(env_vars::kNoOOBreakpad).c_str() , NULL, 0); metrics->RecordBreakpadRegistration((len == 0)); metrics->RecordBreakpadHasDebugger(TRUE == ::IsDebuggerPresent()); } @@ -105,11 +108,13 @@ int DoUninstallTasks(bool chrome_still_running) { // chrome executable's lifetime. void PrepareRestartOnCrashEnviroment(const CommandLine &parsed_command_line) { // Clear this var so child processes don't show the dialog by default. - ::SetEnvironmentVariableW(env_vars::kShowRestart, NULL); + ::SetEnvironmentVariableW(ASCIIToWide(env_vars::kShowRestart).c_str(), NULL); // For non-interactive tests we don't restart on crash. - if (::GetEnvironmentVariableW(env_vars::kHeadless, NULL, 0)) + if (::GetEnvironmentVariableW(ASCIIToWide(env_vars::kHeadless).c_str(), + NULL, 0)) { return; + } // If the known command-line test options are used we don't create the // environment block which means we don't get the restart dialog. @@ -127,11 +132,12 @@ void PrepareRestartOnCrashEnviroment(const CommandLine &parsed_command_line) { dlg_strings.append(l10n_util::GetString(IDS_CRASH_RECOVERY_CONTENT)); dlg_strings.append(L"|"); if (base::i18n::IsRTL()) - dlg_strings.append(env_vars::kRtlLocale); + dlg_strings.append(ASCIIToWide(env_vars::kRtlLocale)); else - dlg_strings.append(env_vars::kLtrLocale); + dlg_strings.append(ASCIIToWide(env_vars::kLtrLocale)); - ::SetEnvironmentVariableW(env_vars::kRestartInfo, dlg_strings.c_str()); + ::SetEnvironmentVariableW(ASCIIToWide(env_vars::kRestartInfo).c_str(), + dlg_strings.c_str()); } // This method handles the --hide-icons and --show-icons command line options diff --git a/chrome/browser/child_process_host.cc b/chrome/browser/child_process_host.cc index a9dcbd7..727d57c 100644 --- a/chrome/browser/child_process_host.cc +++ b/chrome/browser/child_process_host.cc @@ -1,4 +1,4 @@ -// Copyright (c) 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. @@ -116,8 +116,7 @@ FilePath ChildProcessHost::GetChildPath(bool allow_self) { // static void ChildProcessHost::SetCrashReporterCommandLine(CommandLine* command_line) { #if defined(USE_LINUX_BREAKPAD) - const bool unattended = - (getenv(WideToASCII(env_vars::kHeadless).c_str()) != NULL); + const bool unattended = (getenv(env_vars::kHeadless) != NULL); if (unattended || GoogleUpdateSettings::GetCollectStatsConsent()) { command_line->AppendSwitchWithValue(switches::kEnableCrashReporter, ASCIIToWide(google_update::posix_guid + diff --git a/chrome/browser/crash_handler_host_linux.cc b/chrome/browser/crash_handler_host_linux.cc index 535542a..34166d6 100644 --- a/chrome/browser/crash_handler_host_linux.cc +++ b/chrome/browser/crash_handler_host_linux.cc @@ -1,4 +1,4 @@ -// Copyright (c) 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. @@ -45,11 +45,11 @@ CrashHandlerHostLinux::CrashHandlerHostLinux() // inherit some sockets. With PF_UNIX+SOCK_DGRAM, it can call sendmsg to send // a datagram to any (abstract) socket on the same system. With // SOCK_SEQPACKET, this is prevented. - CHECK(socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds) == 0); + CHECK_EQ(socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds), 0); static const int on = 1; // Enable passcred on the server end of the socket - CHECK(setsockopt(fds[1], SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)) == 0); + CHECK_EQ(setsockopt(fds[1], SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)), 0); process_socket_ = fds[0]; browser_socket_ = fds[1]; @@ -195,7 +195,7 @@ void CrashHandlerHostLinux::OnFileCanReadWithoutBlocking(int fd) { bool upload = true; FilePath dumps_path("/tmp"); - if (getenv(WideToASCII(env_vars::kHeadless).c_str())) { + if (getenv(env_vars::kHeadless)) { upload = false; PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path); } diff --git a/chrome/browser/rlz/rlz.cc b/chrome/browser/rlz/rlz.cc index e2c2a3c..73b9b3f 100644 --- a/chrome/browser/rlz/rlz.cc +++ b/chrome/browser/rlz/rlz.cc @@ -1,4 +1,4 @@ -// Copyright (c) 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. // @@ -8,12 +8,12 @@ #include "chrome/browser/rlz/rlz.h" -#include <algorithm> - #include <windows.h> #include <process.h> -#include "base/file_util.h" +#include <algorithm> + +#include "base/file_path.h" #include "base/message_loop.h" #include "base/path_service.h" #include "base/string_util.h" @@ -69,7 +69,6 @@ typedef bool (*SendFinancialPingNoDelayFn)(RLZTracker::Product product, const WCHAR* product_lang, bool exclude_id, void* reserved); - } // extern "C". RecordProductEventFn record_event = NULL; @@ -212,9 +211,8 @@ class DailyPingTask : public Task { // Organic brands all start with GG, such as GGCM. static bool is_organic(const std::wstring& brand) { - return (brand.size() < 2) ? false : (brand.substr(0,2) == L"GG"); + return (brand.size() < 2) ? false : (brand.substr(0, 2) == L"GG"); } - }; // Performs late RLZ initialization and RLZ event recording for chrome. @@ -229,8 +227,10 @@ class DelayedInitTask : public Task { virtual void Run() { // For non-interactive tests we don't do the rest of the initialization // because sometimes the very act of loading the dll causes QEMU to crash. - if (::GetEnvironmentVariableW(env_vars::kHeadless, NULL, 0)) + if (::GetEnvironmentVariableW(ASCIIToWide(env_vars::kHeadless).c_str(), + NULL, 0)) { return; + } // For organic brandcodes do not use rlz at all. Empty brandcode usually // means a chromium install. This is ok. std::wstring brand; diff --git a/chrome/browser/safe_browsing/protocol_manager.cc b/chrome/browser/safe_browsing/protocol_manager.cc index 31a093a..4fe02ce 100644 --- a/chrome/browser/safe_browsing/protocol_manager.cc +++ b/chrome/browser/safe_browsing/protocol_manager.cc @@ -1,17 +1,17 @@ -// 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/browser/safe_browsing/protocol_manager.h" #include "base/base64.h" +#include "base/env_var.h" #include "base/file_version_info.h" #include "base/histogram.h" #include "base/logging.h" #include "base/rand_util.h" #include "base/stl_util-inl.h" #include "base/string_util.h" -#include "base/sys_info.h" #include "base/task.h" #include "base/timer.h" #include "chrome/browser/chrome_thread.h" @@ -439,7 +439,8 @@ bool SafeBrowsingProtocolManager::HandleServiceResponse(const GURL& url, void SafeBrowsingProtocolManager::Initialize() { // Don't want to hit the safe browsing servers on build/chrome bots. - if (base::SysInfo::HasEnvVar(env_vars::kHeadless)) + scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); + if (env->HasEnv(env_vars::kHeadless)) return; ScheduleNextUpdate(false /* no back off */); diff --git a/chrome/browser/safe_browsing/protocol_manager.h b/chrome/browser/safe_browsing/protocol_manager.h index e16723c..dc6d703 100644 --- a/chrome/browser/safe_browsing/protocol_manager.h +++ b/chrome/browser/safe_browsing/protocol_manager.h @@ -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. @@ -12,6 +12,8 @@ #include <deque> #include <set> +#include <string> +#include <vector> #include "base/hash_tables.h" #include "base/scoped_ptr.h" 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) { diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.cc b/chrome/test/automated_ui_tests/automated_ui_tests.cc index fed3dba..85992bd 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.cc +++ b/chrome/test/automated_ui_tests/automated_ui_tests.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. @@ -7,13 +7,13 @@ #include <vector> #include "base/command_line.h" +#include "base/env_var.h" #include "base/file_util.h" #include "base/keyboard_codes.h" #include "base/logging.h" #include "base/path_service.h" #include "base/rand_util.h" #include "base/string_util.h" -#include "base/sys_info.h" #include "base/time.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/browser_process.h" @@ -130,7 +130,8 @@ AutomatedUITest::AutomatedUITest() post_action_delay_ = StringToInt(str); } } - if (base::SysInfo::HasEnvVar(env_vars::kHeadless)) + scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); + if (env->HasEnv(env_vars::kHeadless)) logging::SetLogReportHandler(SilentRuntimeReportHandler); } diff --git a/chrome/test/tab_switching/tab_switching_test.cc b/chrome/test/tab_switching/tab_switching_test.cc index 74c6f25..4f74c6e 100644 --- a/chrome/test/tab_switching/tab_switching_test.cc +++ b/chrome/test/tab_switching/tab_switching_test.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. @@ -44,10 +44,10 @@ class TabSwitchingUITest : public UITest { // Set the log file path for the browser test. #if defined(OS_WIN) - SetEnvironmentVariable(env_vars::kLogFileName, + SetEnvironmentVariable(UTF8ToWide(env_vars::kLogFileName).c_str(), log_file_name_.value().c_str()); #else - setenv(WideToASCII(env_vars::kLogFileName).c_str(), + setenv(env_vars::kLogFileName, log_file_name_.value().c_str(), 1); #endif diff --git a/chrome/test/ui/ui_test_suite.cc b/chrome/test/ui/ui_test_suite.cc index bbdf428b..7f1850c 100644 --- a/chrome/test/ui/ui_test_suite.cc +++ b/chrome/test/ui/ui_test_suite.cc @@ -1,12 +1,14 @@ -// 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/test/ui/ui_test_suite.h" +#include <string> + +#include "base/env_var.h" #include "base/path_service.h" #include "base/process_util.h" -#include "base/sys_info.h" #include "chrome/common/env_vars.h" // Force a test to use an already running browser instance. UI tests only. @@ -116,7 +118,8 @@ void UITestSuite::SuppressErrorDialogs() { #if defined(OS_WIN) void UITestSuite::LoadCrashService() { - if (base::SysInfo::HasEnvVar(env_vars::kHeadless)) + scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); + if (env->HasEnv(env_vars::kHeadless)) return; if (base::GetProcessCount(L"crash_service.exe", NULL)) |