summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/app/breakpad_win.cc12
-rw-r--r--chrome/app/client_util.cc14
-rw-r--r--chrome/browser/browser_main_win.cc12
-rw-r--r--chrome/browser/first_run/first_run_win.cc8
-rw-r--r--chrome/test/tab_switching/tab_switching_test.cc9
-rw-r--r--chrome_frame/crash_reporting/crash_dll.cc12
-rw-r--r--chrome_frame/crash_reporting/crash_dll.h14
-rw-r--r--chrome_frame/crash_reporting/nt_loader_unittest.cc19
-rw-r--r--chrome_frame/crash_reporting/vectored_handler_unittest.cc12
9 files changed, 67 insertions, 45 deletions
diff --git a/chrome/app/breakpad_win.cc b/chrome/app/breakpad_win.cc
index a21f5b5..183887d 100644
--- a/chrome/app/breakpad_win.cc
+++ b/chrome/app/breakpad_win.cc
@@ -13,9 +13,11 @@
#include "base/base_switches.h"
#include "base/command_line.h"
+#include "base/environment.h"
#include "base/file_util.h"
#include "base/file_version_info.h"
#include "base/registry.h"
+#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/win_util.h"
@@ -203,11 +205,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(ASCIIToWide(env_vars::kRestartInfo).c_str(),
- NULL, 0)) {
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ if (!env->HasVar(env_vars::kRestartInfo)) {
return true;
}
- ::SetEnvironmentVariableW(ASCIIToWide(env_vars::kShowRestart).c_str(), L"1");
+ env->SetVar(env_vars::kShowRestart, "1");
// Now we just start chrome browser with the same command line.
STARTUPINFOW si = {sizeof(si)};
PROCESS_INFORMATION pi;
@@ -501,8 +503,8 @@ static DWORD __stdcall InitCrashReporterThread(void* param) {
if (!g_breakpad->IsOutOfProcess()) {
// The out-of-process handler is unavailable.
- ::SetEnvironmentVariable(ASCIIToWide(env_vars::kNoOOBreakpad).c_str(),
- info->process_type.c_str());
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ env->SetVar(env_vars::kNoOOBreakpad, WideToUTF8(info->process_type));
} else {
// Tells breakpad to handle breakpoint and single step exceptions.
// This might break JIT debuggers, but at least it will always
diff --git a/chrome/app/client_util.cc b/chrome/app/client_util.cc
index a360d51..61d8c40 100644
--- a/chrome/app/client_util.cc
+++ b/chrome/app/client_util.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.
@@ -6,9 +6,12 @@
#include <shlwapi.h>
#include "base/command_line.h"
-#include "base/logging.h"
+#include "base/environment.h"
#include "base/file_util.h"
#include "base/trace_event.h"
+#include "base/logging.h"
+#include "base/scoped_ptr.h"
+#include "base/utf_string_conversions.h"
#include "chrome/app/breakpad_win.h"
#include "chrome/app/client_util.h"
#include "chrome/common/chrome_switches.h"
@@ -228,9 +231,10 @@ int MainDllLoader::Launch(HINSTANCE instance,
if (!dll_)
return ResultCodes::MISSING_DATA;
- ::SetEnvironmentVariableW(
- BrowserDistribution::GetDistribution()->GetEnvVersionKey().c_str(),
- version.c_str());
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ env->SetVar(WideToUTF8(
+ BrowserDistribution::GetDistribution()->GetEnvVersionKey()).c_str(),
+ WideToUTF8(version));
InitCrashReporterWithDllPath(file);
OnBeforeLaunch(version);
diff --git a/chrome/browser/browser_main_win.cc b/chrome/browser/browser_main_win.cc
index 553b912..32a7bb4 100644
--- a/chrome/browser/browser_main_win.cc
+++ b/chrome/browser/browser_main_win.cc
@@ -13,9 +13,11 @@
#include "app/l10n_util.h"
#include "app/win_util.h"
#include "base/command_line.h"
+#include "base/environment.h"
#include "base/i18n/rtl.h"
#include "base/nss_util.h"
#include "base/path_service.h"
+#include "base/scoped_ptr.h"
#include "base/utf_string_conversions.h"
#include "base/win_util.h"
#include "chrome/browser/browser_list.h"
@@ -109,13 +111,12 @@ 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(ASCIIToWide(env_vars::kShowRestart).c_str(), NULL);
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ env->UnSetVar(env_vars::kShowRestart);
// For non-interactive tests we don't restart on crash.
- if (::GetEnvironmentVariableW(ASCIIToWide(env_vars::kHeadless).c_str(),
- NULL, 0)) {
+ if (env->HasVar(env_vars::kHeadless))
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.
@@ -137,8 +138,7 @@ void PrepareRestartOnCrashEnviroment(const CommandLine &parsed_command_line) {
else
dlg_strings.append(ASCIIToWide(env_vars::kLtrLocale));
- ::SetEnvironmentVariableW(ASCIIToWide(env_vars::kRestartInfo).c_str(),
- dlg_strings.c_str());
+ env->SetVar(env_vars::kRestartInfo, WideToUTF8(dlg_strings));
}
// This method handles the --hide-icons and --show-icons command line options
diff --git a/chrome/browser/first_run/first_run_win.cc b/chrome/browser/first_run/first_run_win.cc
index 06d4a3c..6cfc233 100644
--- a/chrome/browser/first_run/first_run_win.cc
+++ b/chrome/browser/first_run/first_run_win.cc
@@ -16,6 +16,7 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/command_line.h"
+#include "base/environment.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/object_watcher.h"
@@ -24,6 +25,7 @@
#include "base/process_util.h"
#include "base/registry.h"
#include "base/scoped_comptr_win.h"
+#include "base/scoped_ptr.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
@@ -423,9 +425,9 @@ bool Upgrade::IsBrowserAlreadyRunning() {
}
bool Upgrade::RelaunchChromeBrowser(const CommandLine& command_line) {
- ::SetEnvironmentVariable(
- BrowserDistribution::GetDistribution()->GetEnvVersionKey().c_str(),
- NULL);
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ env->UnSetVar(WideToUTF8(
+ BrowserDistribution::GetDistribution()->GetEnvVersionKey()).c_str());
return base::LaunchApp(command_line.command_line_string(),
false, false, NULL);
}
diff --git a/chrome/test/tab_switching/tab_switching_test.cc b/chrome/test/tab_switching/tab_switching_test.cc
index ffbc659..1c5b7f2 100644
--- a/chrome/test/tab_switching/tab_switching_test.cc
+++ b/chrome/test/tab_switching/tab_switching_test.cc
@@ -3,10 +3,12 @@
// found in the LICENSE file.
#include "base/command_line.h"
+#include "base/environment.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/platform_thread.h"
+#include "base/scoped_ptr.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_dll_resource.h"
@@ -44,12 +46,11 @@ class TabSwitchingUITest : public UITest {
log_file_name_ = browser_directory_.AppendASCII("chrome_debug.log");
// Set the log file path for the browser test.
+ scoped_ptr<base::Environment> env(base::Environment::Create());
#if defined(OS_WIN)
- SetEnvironmentVariable(UTF8ToWide(env_vars::kLogFileName).c_str(),
- log_file_name_.value().c_str());
+ env->SetVar(env_vars::kLogFileName, WideToUTF8(log_file_name_.value()));
#else
- setenv(env_vars::kLogFileName,
- log_file_name_.value().c_str(), 1);
+ env->SetVar(env_vars::kLogFileName, log_file_name_.value());
#endif
// Add the necessary arguments to Chrome's launch command for these tests.
diff --git a/chrome_frame/crash_reporting/crash_dll.cc b/chrome_frame/crash_reporting/crash_dll.cc
index 97f41c9..0fc1048 100644
--- a/chrome_frame/crash_reporting/crash_dll.cc
+++ b/chrome_frame/crash_reporting/crash_dll.cc
@@ -1,7 +1,7 @@
// 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.
-//
+
// Main entry point for a DLL that can be instructed to crash on
// load or unload by setting an environment variable appropriately.
//
@@ -10,7 +10,9 @@
// during DLL_PROCESS_ATTACH. This in turn causes the loading process to
// crash on exit. To work around this, this DLL has its entrypoint set
// to the DllMain routine and does not link with the CRT.
+
#include <windows.h>
+
#include "crash_dll.h"
void Crash() {
@@ -26,14 +28,12 @@ void CrashConditionally(const wchar_t* name) {
Crash();
}
-extern "C" BOOL WINAPI DllMain(HINSTANCE instance,
- DWORD reason,
+extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason,
LPVOID reserved) {
- if (reason == DLL_PROCESS_ATTACH) {
+ if (reason == DLL_PROCESS_ATTACH)
CrashConditionally(kCrashOnLoadMode);
- } else if (reason == DLL_PROCESS_DETACH) {
+ else if (reason == DLL_PROCESS_DETACH)
CrashConditionally(kCrashOnUnloadMode);
- }
return 1;
}
diff --git a/chrome_frame/crash_reporting/crash_dll.h b/chrome_frame/crash_reporting/crash_dll.h
index ca38e15..f87766f 100644
--- a/chrome_frame/crash_reporting/crash_dll.h
+++ b/chrome_frame/crash_reporting/crash_dll.h
@@ -1,14 +1,16 @@
// 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.
-#ifndef CHROME_FRAME_CRASH_REPORT_CRASH_DLL_H_
-#define CHROME_FRAME_CRASH_REPORT_CRASH_DLL_H_
+
+#ifndef CHROME_FRAME_CRASH_REPORTING_CRASH_DLL_H_
+#define CHROME_FRAME_CRASH_REPORTING_CRASH_DLL_H_
+#pragma once
// Set either of these environment variables to
// crash at load or unload time, respectively.
-static const wchar_t* kCrashDllName = L"crash_dll.dll";
-static const wchar_t* kCrashOnLoadMode = L"CRASH_DLL_CRASH_ON_LOAD";
-static const wchar_t* kCrashOnUnloadMode = L"CRASH_DLL_CRASH_ON_UNLOAD";
+static const wchar_t kCrashDllName[] = L"crash_dll.dll";
+static const wchar_t kCrashOnLoadMode[] = L"CRASH_DLL_CRASH_ON_LOAD";
+static const wchar_t kCrashOnUnloadMode[] = L"CRASH_DLL_CRASH_ON_UNLOAD";
static const DWORD kCrashAddress = 0x42;
-#endif // CHROME_FRAME_CRASH_REPORT_CRASH_DLL_H_
+#endif // CHROME_FRAME_CRASH_REPORTING_CRASH_DLL_H_
diff --git a/chrome_frame/crash_reporting/nt_loader_unittest.cc b/chrome_frame/crash_reporting/nt_loader_unittest.cc
index a73fb9f..2c46eab 100644
--- a/chrome_frame/crash_reporting/nt_loader_unittest.cc
+++ b/chrome_frame/crash_reporting/nt_loader_unittest.cc
@@ -6,11 +6,14 @@
#include <tlhelp32.h>
#include <winnt.h>
#include <base/at_exit.h>
+#include <base/environment.h>
#include <base/message_loop.h>
#include <base/scoped_handle.h>
+#include <base/scoped_ptr.h>
#include <base/string_util.h>
#include <base/sys_info.h>
#include <base/thread.h>
+#include <base/utf_string_conversions.h>
#include "chrome_frame/crash_reporting/crash_dll.h"
#include "gtest/gtest.h"
@@ -191,8 +194,9 @@ class NtLoaderTest: public testing::Test {
EXPECT_TRUE(veh_id_ != NULL);
// Clear the crash DLL environment.
- ::SetEnvironmentVariable(kCrashOnLoadMode, NULL);
- ::SetEnvironmentVariable(kCrashOnUnloadMode, NULL);
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ env->UnSetVar(WideToASCII(kCrashOnLoadMode).c_str());
+ env->UnSetVar(WideToASCII(kCrashOnUnloadMode).c_str());
}
void TearDown() {
@@ -200,8 +204,9 @@ class NtLoaderTest: public testing::Test {
EXPECT_NE(0, ::RemoveVectoredExceptionHandler(veh_id_));
// Clear the crash DLL environment.
- ::SetEnvironmentVariable(kCrashOnLoadMode, NULL);
- ::SetEnvironmentVariable(kCrashOnUnloadMode, NULL);
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ env->UnSetVar(WideToASCII(kCrashOnLoadMode).c_str());
+ env->UnSetVar(WideToASCII(kCrashOnUnloadMode).c_str());
}
void set_exception_function(ExceptionFunction func) {
@@ -259,7 +264,8 @@ TEST_F(NtLoaderTest, CrashOnLoadLibrary) {
set_exception_function(OnCrashDuringLoadLibrary);
// Setup to crash on load.
- ::SetEnvironmentVariable(kCrashOnLoadMode, L"1");
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ env->SetVar(WideToASCII(kCrashOnLoadMode).c_str(), "1");
// And load it.
HMODULE module = ::LoadLibrary(kCrashDllName);
@@ -294,7 +300,8 @@ static void OnCrashDuringUnloadLibrary(EXCEPTION_POINTERS* ex_ptrs) {
TEST_F(NtLoaderTest, CrashOnUnloadLibrary) {
// Setup to crash on unload.
- ::SetEnvironmentVariable(kCrashOnUnloadMode, L"1");
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ env->SetVar(WideToASCII(kCrashOnUnloadMode).c_str(), "1");
// And load it.
HMODULE module = ::LoadLibrary(kCrashDllName);
diff --git a/chrome_frame/crash_reporting/vectored_handler_unittest.cc b/chrome_frame/crash_reporting/vectored_handler_unittest.cc
index d17847b..4153646 100644
--- a/chrome_frame/crash_reporting/vectored_handler_unittest.cc
+++ b/chrome_frame/crash_reporting/vectored_handler_unittest.cc
@@ -1,10 +1,13 @@
-// 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.
#include <atlbase.h>
+#include "base/environment.h"
#include "base/logging.h"
+#include "base/scoped_ptr.h"
+#include "base/utf_string_conversions.h"
#include "chrome_frame/crash_reporting/crash_dll.h"
#include "chrome_frame/crash_reporting/nt_loader.h"
#include "chrome_frame/crash_reporting/vectored_handler-impl.h"
@@ -138,18 +141,19 @@ TEST(ChromeFrame, ExceptionReport) {
g_mock_veh = &veh;
void* id = ::AddVectoredExceptionHandler(FALSE, VEH);
- EXPECT_TRUE(::SetEnvironmentVariable(kCrashOnLoadMode, L"1"));
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ EXPECT_TRUE(env->SetVar(WideToUTF8(kCrashOnLoadMode).c_str(), "1"));
long exceptions_seen = veh.get_exceptions_seen();
HMODULE module = ::LoadLibrary(kCrashDllName);
EXPECT_EQ(NULL, module);
testing::Mock::VerifyAndClearExpectations(&api);
EXPECT_EQ(exceptions_seen + 1, veh.get_exceptions_seen());
- EXPECT_TRUE(::SetEnvironmentVariable(kCrashOnLoadMode, NULL));
+ EXPECT_TRUE(env->UnSetVar(WideToUTF8(kCrashOnLoadMode).c_str()));
// Exception in an unloading module, we are on the stack/
// Make sure we report it.
- EXPECT_TRUE(::SetEnvironmentVariable(kCrashOnUnloadMode, L"1"));
+ EXPECT_TRUE(env->SetVar(WideToUTF8(kCrashOnUnloadMode).c_str(), "1"));
module = ::LoadLibrary(kCrashDllName);