diff options
author | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-29 22:18:01 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-29 22:18:01 +0000 |
commit | 05f9b688e319fcb092be0e06f7b72d39dd3113b3 (patch) | |
tree | 6d24be7f9b788bbebbff6b2349e51dec49034ce6 /chrome/browser | |
parent | 86ec30d6710923cf1c193eb88b1e6251f831e0ef (diff) | |
download | chromium_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/browser')
-rw-r--r-- | chrome/browser/browser_main.cc | 1 | ||||
-rw-r--r-- | chrome/browser/cache_manager_host.cc | 1 | ||||
-rw-r--r-- | chrome/browser/importer/importer_unittest.cc | 5 | ||||
-rw-r--r-- | chrome/browser/metrics_log.cc | 11 | ||||
-rw-r--r-- | chrome/browser/render_process_host.cc | 4 | ||||
-rw-r--r-- | chrome/browser/render_process_host.h | 5 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/bloom_filter_unittest.cc | 6 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/protocol_manager.cc | 14 | ||||
-rw-r--r-- | chrome/browser/views/bug_report_view.cc | 2 |
9 files changed, 22 insertions, 27 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index fbb216a9..3cb98f1 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -41,7 +41,6 @@ #include "chrome/common/chrome_constants.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" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/l10n_util.h" diff --git a/chrome/browser/cache_manager_host.cc b/chrome/browser/cache_manager_host.cc index 13fc171..be6faf3 100644 --- a/chrome/browser/cache_manager_host.cc +++ b/chrome/browser/cache_manager_host.cc @@ -11,7 +11,6 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/render_process_host.h" #include "chrome/common/chrome_constants.h" -#include "chrome/common/env_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/notification_service.h" diff --git a/chrome/browser/importer/importer_unittest.cc b/chrome/browser/importer/importer_unittest.cc index 3d39db1..4a0a8df 100644 --- a/chrome/browser/importer/importer_unittest.cc +++ b/chrome/browser/importer/importer_unittest.cc @@ -19,7 +19,6 @@ #include "chrome/browser/importer/importer.h" #include "chrome/browser/profile.h" #include "chrome/common/chrome_paths.h" -#include "chrome/common/env_util.h" #include "chrome/common/win_util.h" class ImporterTest : public testing::Test { @@ -274,10 +273,6 @@ void WritePStore(IPStore* pstore, const GUID* type, const GUID* subtype) { } TEST_F(ImporterTest, IEImporter) { - // Skips in Win2000 for the running environment can not be set up. - if (env_util::GetOperatingSystemVersion() == "5.0") - return; - // Sets up a favorites folder. win_util::ScopedCOMInitializer com_init; std::wstring path = test_path_; diff --git a/chrome/browser/metrics_log.cc b/chrome/browser/metrics_log.cc index bb2c2bb..a1d8f67 100644 --- a/chrome/browser/metrics_log.cc +++ b/chrome/browser/metrics_log.cc @@ -12,7 +12,6 @@ #include "base/sys_info.h" #include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/browser_process.h" -#include "chrome/common/env_util.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" @@ -447,7 +446,7 @@ void MetricsLog::RecordEnvironment( { OPEN_ELEMENT_FOR_SCOPE("cpu"); - WriteAttribute("arch", env_util::GetCPUArchitecture()); + WriteAttribute("arch", base::SysInfo::CPUArchitecture()); } { @@ -469,19 +468,19 @@ void MetricsLog::RecordEnvironment( { OPEN_ELEMENT_FOR_SCOPE("os"); WriteAttribute("name", - env_util::GetOperatingSystemName()); + base::SysInfo::OperatingSystemName()); WriteAttribute("version", - env_util::GetOperatingSystemVersion()); + base::SysInfo::OperatingSystemVersion()); } { OPEN_ELEMENT_FOR_SCOPE("display"); int width = 0; int height = 0; - env_util::GetPrimaryDisplayDimensions(&width, &height); + base::SysInfo::GetPrimaryDisplayDimensions(&width, &height); WriteIntAttribute("xsize", width); WriteIntAttribute("ysize", height); - WriteIntAttribute("screens", env_util::GetDisplayCount()); + WriteIntAttribute("screens", base::SysInfo::DisplayCount()); } { diff --git a/chrome/browser/render_process_host.cc b/chrome/browser/render_process_host.cc index a1244ed..ed969a6 100644 --- a/chrome/browser/render_process_host.cc +++ b/chrome/browser/render_process_host.cc @@ -19,6 +19,7 @@ #include "base/logging.h" #include "base/path_service.h" #include "base/process_util.h" +#include "base/rand_util.h" #include "base/shared_event.h" #include "base/shared_memory.h" #include "base/string_util.h" @@ -43,7 +44,6 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/debug_flags.h" -#include "chrome/common/env_util.h" #include "chrome/common/l10n_util.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/pref_names.h" @@ -675,7 +675,7 @@ RenderProcessHost* RenderProcessHost::GetExistingProcessHost(Profile* profile) { // Now pick a random suitable renderer, if we have any if (!suitable_renderers.empty()) { int suitable_count = static_cast<int>(suitable_renderers.size()); - int random_index = rand_util::RandInt(0, suitable_count - 1); + int random_index = base::RandInt(0, suitable_count - 1); return suitable_renderers[random_index]; } diff --git a/chrome/browser/render_process_host.h b/chrome/browser/render_process_host.h index fd76ad7..0e6a2cc 100644 --- a/chrome/browser/render_process_host.h +++ b/chrome/browser/render_process_host.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_RENDER_PROCESS_HOST_H_ #define CHROME_BROWSER_RENDER_PROCESS_HOST_H_ +#include <limits> #include <set> #include <vector> #include <windows.h> @@ -12,12 +13,12 @@ #include "base/id_map.h" #include "base/object_watcher.h" #include "base/process.h" +#include "base/rand_util.h" #include "base/ref_counted.h" #include "base/scoped_handle.h" #include "base/scoped_ptr.h" #include "chrome/common/ipc_sync_channel.h" #include "chrome/common/notification_service.h" -#include "chrome/common/rand_util.h" #include "chrome/common/render_messages.h" class PrefService; @@ -271,7 +272,7 @@ inline std::wstring GenerateRandomChannelID(void* instance) { // to fail. return StringPrintf(L"%d.%x.%d", GetCurrentProcessId(), instance, - rand_util::RandIntSecure(0, kint32max)); + base::RandInt(0, std::numeric_limits<int>::max())); } diff --git a/chrome/browser/safe_browsing/bloom_filter_unittest.cc b/chrome/browser/safe_browsing/bloom_filter_unittest.cc index 1612084..c0ac6cb 100644 --- a/chrome/browser/safe_browsing/bloom_filter_unittest.cc +++ b/chrome/browser/safe_browsing/bloom_filter_unittest.cc @@ -5,18 +5,20 @@ #include "chrome/browser/safe_browsing/bloom_filter.h" +#include <limits.h> + #include <set> #include "base/logging.h" +#include "base/rand_util.h" #include "base/string_util.h" #include "base/win_util.h" -#include "chrome/common/rand_util.h" #include "testing/gtest/include/gtest/gtest.h" namespace { uint32 GenHash() { - return static_cast<uint32>(rand_util::RandIntSecure(0, kint32max)); + return static_cast<uint32>(base::RandInt(INT_MIN, INT_MAX)); } } diff --git a/chrome/browser/safe_browsing/protocol_manager.cc b/chrome/browser/safe_browsing/protocol_manager.cc index 3e3c12b..e3a91ad 100644 --- a/chrome/browser/safe_browsing/protocol_manager.cc +++ b/chrome/browser/safe_browsing/protocol_manager.cc @@ -7,22 +7,22 @@ #include "base/histogram.h" #include "base/logging.h" #include "base/message_loop.h" +#include "base/rand_util.h" #include "base/string_util.h" +#include "base/sys_info.h" #include "base/task.h" #include "base/timer.h" #include "chrome/browser/profile.h" #include "chrome/browser/safe_browsing/protocol_parser.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h" -#include "chrome/common/env_util.h" #include "chrome/common/env_vars.h" -#include "chrome/common/rand_util.h" #include "chrome/common/stl_util-inl.h" #include "net/base/base64.h" #include "net/base/load_flags.h" // Maximum time, in seconds, from start up before we must issue an update query. -static const int kSbTimerStartIntervalSec = 300; +static const int kSbTimerStartIntervalSec = 5 * 60; // Update URL for querying about the latest set of chunk updates. static const char* const kSbUpdateUrl = @@ -69,10 +69,10 @@ SafeBrowsingProtocolManager::SafeBrowsingProtocolManager( client_key_(client_key), wrapped_key_(wrapped_key) { // Set the backoff multiplier fuzz to a random value between 0 and 1. - back_off_fuzz_ = static_cast<float>(rand_util::RandInt(1, INT_MAX)) / INT_MAX; + back_off_fuzz_ = static_cast<float>(base::RandDouble()); // The first update must happen between 0-5 minutes of start up. - next_update_sec_ = rand_util::RandInt(60, kSbTimerStartIntervalSec); + next_update_sec_ = base::RandInt(60, kSbTimerStartIntervalSec); } SafeBrowsingProtocolManager::~SafeBrowsingProtocolManager() { @@ -276,7 +276,7 @@ bool SafeBrowsingProtocolManager::HandleServiceResponse(const GURL& url, if (next_update_sec > 0) { next_update_sec_ = next_update_sec; } else if (update_state_ == SECOND_REQUEST) { - next_update_sec_ = rand_util::RandInt(15, 45) * 60; + next_update_sec_ = base::RandInt(15 * 60, 45 * 60); } // We need to request a new set of keys for MAC. @@ -372,7 +372,7 @@ bool SafeBrowsingProtocolManager::HandleServiceResponse(const GURL& url, void SafeBrowsingProtocolManager::Initialize() { // Don't want to hit the safe browsing servers on build/chrome bots. - if (env_util::HasEnvironmentVariable(env_vars::kHeadless)) + if (base::SysInfo::HasEnvVar(env_vars::kHeadless)) return; ScheduleNextUpdate(false /* no back off */); diff --git a/chrome/browser/views/bug_report_view.cc b/chrome/browser/views/bug_report_view.cc index b1dfacb..77a0d31 100644 --- a/chrome/browser/views/bug_report_view.cc +++ b/chrome/browser/views/bug_report_view.cc @@ -330,7 +330,7 @@ void BugReportView::SetUrl(const GURL& url) { // win_util::GetWinVersion returns WinVersion, which is just // an enum of 2000, XP, 2003, or VISTA. Not enough detail for // bug reports -// env_util::GetOperatingSystemVersion returns an std::string +// base::SysInfo::OperatingSystemVersion returns an std::string // but doesn't include the build or service pack. That function // is probably the right one to extend, but will require changing // all the call sites or making it a wrapper around another util. |