summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-29 22:18:01 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-29 22:18:01 +0000
commit05f9b688e319fcb092be0e06f7b72d39dd3113b3 (patch)
tree6d24be7f9b788bbebbff6b2349e51dec49034ce6 /chrome/common
parent86ec30d6710923cf1c193eb88b1e6251f831e0ef (diff)
downloadchromium_src-05f9b688e319fcb092be0e06f7b72d39dd3113b3.zip
chromium_src-05f9b688e319fcb092be0e06f7b72d39dd3113b3.tar.gz
chromium_src-05f9b688e319fcb092be0e06f7b72d39dd3113b3.tar.bz2
Refactoring for portability:
- Move chrome/common/env_util to base/sys_info - Move chrome/common/rand_util to base/rand_util (new), simplify its public interface, and fix its implementation Patch by Paweł Hajdan, Jr. <phajdan.jr@gmail.com> http://codereview.chromium.org/4079 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2697 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/SConscript2
-rw-r--r--chrome/common/common.vcproj16
-rw-r--r--chrome/common/env_util.cc46
-rw-r--r--chrome/common/env_util.h40
-rw-r--r--chrome/common/logging_chrome.cc4
-rw-r--r--chrome/common/process_watcher.cc8
-rw-r--r--chrome/common/rand_util.cc29
-rw-r--r--chrome/common/rand_util.h24
8 files changed, 6 insertions, 163 deletions
diff --git a/chrome/common/SConscript b/chrome/common/SConscript
index 7cc8c4d..24bf254 100644
--- a/chrome/common/SConscript
+++ b/chrome/common/SConscript
@@ -87,7 +87,6 @@ if env['PLATFORM'] == 'win32':
'clipboard_service.cc',
'common_glue.cc',
'drag_drop_types.cc',
- 'env_util.cc',
'gfx/chrome_canvas.cc',
'gfx/chrome_font.cc',
'gfx/emf.cc',
@@ -110,7 +109,6 @@ if env['PLATFORM'] == 'win32':
'plugin_messages.cc',
'pref_service.cc',
'process_watcher.cc',
- 'rand_util.cc',
'render_messages.cc',
'resource_bundle.cc',
'resource_dispatcher.cc',
diff --git a/chrome/common/common.vcproj b/chrome/common/common.vcproj
index 203aa3f..771ff8c 100644
--- a/chrome/common/common.vcproj
+++ b/chrome/common/common.vcproj
@@ -422,14 +422,6 @@
>
</File>
<File
- RelativePath=".\env_util.cc"
- >
- </File>
- <File
- RelativePath=".\env_util.h"
- >
- </File>
- <File
RelativePath=".\env_vars.cc"
>
</File>
@@ -598,14 +590,6 @@
>
</File>
<File
- RelativePath=".\rand_util.cc"
- >
- </File>
- <File
- RelativePath=".\rand_util.h"
- >
- </File>
- <File
RelativePath=".\ref_counted_util.h"
>
</File>
diff --git a/chrome/common/env_util.cc b/chrome/common/env_util.cc
deleted file mode 100644
index 3af22a6..0000000
--- a/chrome/common/env_util.cc
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (c) 2006-2008 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/env_util.h"
-
-#include "base/basictypes.h"
-#include "base/logging.h"
-
-namespace env_util {
-
-std::string GetOperatingSystemName() {
- return "Windows";
-}
-
-std::string GetOperatingSystemVersion() {
- OSVERSIONINFO info = {0};
- info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionEx(&info);
-
- char result[20];
- memset(result, 0, arraysize(result));
- _snprintf_s(result, arraysize(result),
- "%lu.%lu", info.dwMajorVersion, info.dwMinorVersion);
- return std::string(result);
-}
-
-std::string GetCPUArchitecture() {
- // TODO: Make this vary when we support any other architectures.
- return "x86";
-}
-
-void GetPrimaryDisplayDimensions(int* width, int* height) {
- if (width)
- *width = GetSystemMetrics(SM_CXSCREEN);
-
- if (height)
- *height = GetSystemMetrics(SM_CYSCREEN);
-}
-
-int GetDisplayCount() {
- return GetSystemMetrics(SM_CMONITORS);
-}
-
-} // namespace env_util
-
diff --git a/chrome/common/env_util.h b/chrome/common/env_util.h
deleted file mode 100644
index bb37935..0000000
--- a/chrome/common/env_util.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright (c) 2006-2008 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.
-
-// This file defines utility functions that can report details about the
-// host operating environment.
-
-#ifndef CHROME_COMMON_ENV_UTIL_H__
-#define CHROME_COMMON_ENV_UTIL_H__
-
-#include <windows.h>
-#include <string>
-
-namespace env_util {
-
-// Test if the given environment variable is defined.
-inline bool HasEnvironmentVariable(const wchar_t* var) {
- return GetEnvironmentVariable(var, NULL, 0) != 0;
-}
-
-// Returns the name of the host operating system.
-std::string GetOperatingSystemName();
-
-// Returns the version of the host operating system.
-std::string GetOperatingSystemVersion();
-
-// Returns the CPU architecture of the system.
-std::string GetCPUArchitecture();
-
-// Returns the pixel dimensions of the primary display via the
-// width and height parameters.
-void GetPrimaryDisplayDimensions(int* width, int* height);
-
-// Return the number of displays.
-int GetDisplayCount();
-
-} // namespace env_util
-
-#endif // CHROME_COMMON_ENV_UTIL_H__
-
diff --git a/chrome/common/logging_chrome.cc b/chrome/common/logging_chrome.cc
index 232e500..af6b647 100644
--- a/chrome/common/logging_chrome.cc
+++ b/chrome/common/logging_chrome.cc
@@ -14,9 +14,9 @@
#include "base/logging.h"
#include "base/path_service.h"
#include "base/string_util.h"
+#include "base/sys_info.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/common/env_util.h"
#include "chrome/common/env_vars.h"
// When true, this means that error dialogs should not be shown.
@@ -96,7 +96,7 @@ 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 (env_util::HasEnvironmentVariable(env_vars::kHeadless) ||
+ if (base::SysInfo::HasEnvVar(env_vars::kHeadless) ||
command_line.HasSwitch(switches::kNoErrorDialogs))
SuppressDialogs();
diff --git a/chrome/common/process_watcher.cc b/chrome/common/process_watcher.cc
index b8d78bd2..c189c2d 100644
--- a/chrome/common/process_watcher.cc
+++ b/chrome/common/process_watcher.cc
@@ -6,8 +6,8 @@
#include "base/message_loop.h"
#include "base/object_watcher.h"
+#include "base/sys_info.h"
#include "chrome/app/result_codes.h"
-#include "chrome/common/env_util.h"
#include "chrome/common/env_vars.h"
// Maximum amount of time (in milliseconds) to wait for the process to exit.
@@ -48,9 +48,9 @@ class TimerExpiredTask : public Task, public base::ObjectWatcher::Delegate {
private:
void KillProcess() {
- if (env_util::HasEnvironmentVariable(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 (base::SysInfo::HasEnvVar(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) {
OnObjectSignaled(process_);
return;
diff --git a/chrome/common/rand_util.cc b/chrome/common/rand_util.cc
deleted file mode 100644
index 52492a0..0000000
--- a/chrome/common/rand_util.cc
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (c) 2006-2008 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/rand_util.h"
-
-#include <stdlib.h>
-
-#include "base/logging.h"
-
-namespace rand_util {
-
-int RandInt(int min, int max) {
- return RandIntSecure(min, max);
-}
-
-int RandIntSecure(int min, int max) {
- unsigned int number;
- // This code will not work on win2k, which we do not support.
- errno_t rv = rand_s(&number);
- DCHECK(rv == 0) << "rand_s failed with error " << rv;
-
- // From the rand man page, use this instead of just rand() % max, so that the
- // higher bits are used.
- return min + static_cast<int>(static_cast<double>(max - min + 1.0) *
- (number / (UINT_MAX + 1.0)));
-}
-
-} // namespace rand_util
diff --git a/chrome/common/rand_util.h b/chrome/common/rand_util.h
deleted file mode 100644
index 08e735f..0000000
--- a/chrome/common/rand_util.h
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (c) 2006-2008 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_COMMON_RAND_UTIL_H__
-#define CHROME_COMMON_RAND_UTIL_H__
-
-#include "base/basictypes.h"
-
-namespace rand_util {
-
-// Returns a random number between min and max (inclusive). This is a
-// non-cryptographic random number generator, using rand() from the CRT.
-int RandInt(int min, int max);
-
-// Returns a random number between min and max (inclusive). This is a (slower)
-// cryptographic random number generator using rand_s() from the CRT. Note
-// that it does not work in Win2K, so it degrades to RandInt.
-int RandIntSecure(int min, int max);
-
-} // namespace rand_util
-
-#endif // CHROME_COMMON_RAND_UTIL_H__
-