diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-16 00:12:42 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-16 00:12:42 +0000 |
commit | 054c80163856843954da96c1f05fec158a40c2c4 (patch) | |
tree | 2762b746fe7462db73d1e3910ea5da563b130840 | |
parent | b1719466a057a1f4bbab43934aeb9e8df5dc59a4 (diff) | |
download | chromium_src-054c80163856843954da96c1f05fec158a40c2c4.zip chromium_src-054c80163856843954da96c1f05fec158a40c2c4.tar.gz chromium_src-054c80163856843954da96c1f05fec158a40c2c4.tar.bz2 |
chrome: Remove 10 exit time destructors and 2 static initializers.
version_extension_ in MetricsLogBase was only used in the MetricsLog
subclass, so move it to there.
BUG=101600,94925
TEST=none
Review URL: http://codereview.chromium.org/8468018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110219 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/metrics/metrics_log.cc | 19 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_log.h | 5 | ||||
-rw-r--r-- | chrome/common/extensions/extension_file_util.cc | 5 | ||||
-rw-r--r-- | chrome/common/extensions/extension_l10n_util.cc | 12 | ||||
-rw-r--r-- | chrome/common/mac/objc_zombie.mm | 12 | ||||
-rw-r--r-- | chrome/common/metrics_helpers.cc | 3 | ||||
-rw-r--r-- | chrome/common/metrics_helpers.h | 10 | ||||
-rw-r--r-- | chrome/common/profiling.cc | 2 | ||||
-rw-r--r-- | chrome/common/time_format.cc | 4 | ||||
-rw-r--r-- | chrome/renderer/extensions/schema_generated_bindings.cc | 6 | ||||
-rw-r--r-- | chrome/renderer/searchbox_extension.cc | 4 |
11 files changed, 46 insertions, 36 deletions
diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc index 4526893..0f5f514 100644 --- a/chrome/browser/metrics/metrics_log.cc +++ b/chrome/browser/metrics/metrics_log.cc @@ -9,6 +9,7 @@ #include "base/basictypes.h" #include "base/file_util.h" +#include "base/lazy_instance.h" #include "base/memory/scoped_ptr.h" #include "base/perftimer.h" #include "base/string_util.h" @@ -37,6 +38,10 @@ extern "C" IMAGE_DOS_HEADER __ImageBase; #endif +static base::LazyInstance<std::string, + base::LeakyLazyInstanceTraits<std::string > > + g_version_extension = LAZY_INSTANCE_INITIALIZER; + MetricsLog::MetricsLog(const std::string& client_id, int session_id) : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {} @@ -81,8 +86,8 @@ std::string MetricsLog::GetVersionString() { } std::string version = version_info.Version(); - if (!version_extension_.empty()) - version += version_extension_; + if (!version_extension().empty()) + version += version_extension(); if (!version_info.IsOfficialBuild()) version.append("-devel"); return version; @@ -92,6 +97,16 @@ MetricsLog* MetricsLog::AsMetricsLog() { return this; } +// static +void MetricsLog::set_version_extension(const std::string& extension) { + g_version_extension.Get() = extension; +} + +// static +const std::string& MetricsLog::version_extension() { + return g_version_extension.Get(); +} + void MetricsLog::RecordIncrementalStabilityElements() { DCHECK(!locked_); diff --git a/chrome/browser/metrics/metrics_log.h b/chrome/browser/metrics/metrics_log.h index 95b1252..0903b14 100644 --- a/chrome/browser/metrics/metrics_log.h +++ b/chrome/browser/metrics/metrics_log.h @@ -65,6 +65,11 @@ class MetricsLog : public MetricsLogBase { virtual MetricsLog* AsMetricsLog(); + // Use |extension| in all uploaded appversions in addition to the standard + // version string. + static void set_version_extension(const std::string& extension); + static const std::string& version_extension(); + private: FRIEND_TEST_ALL_PREFIXES(MetricsLogTest, ChromeOSStabilityData); diff --git a/chrome/common/extensions/extension_file_util.cc b/chrome/common/extensions/extension_file_util.cc index f5cf9f4..b54bd62 100644 --- a/chrome/common/extensions/extension_file_util.cc +++ b/chrome/common/extensions/extension_file_util.cc @@ -514,8 +514,9 @@ bool CheckForIllegalFilenames(const FilePath& extension_path, Extension::kLocaleFolder, FILE_PATH_LITERAL("__MACOSX"), }; - static std::set<FilePath::StringType> reserved_underscore_names( - reserved_names, reserved_names + arraysize(reserved_names)); + CR_DEFINE_STATIC_LOCAL( + std::set<FilePath::StringType>, reserved_underscore_names, + (reserved_names, reserved_names + arraysize(reserved_names))); // Enumerate all files and directories in the extension root. // There is a problem when using pattern "_*" with FileEnumerator, so we have diff --git a/chrome/common/extensions/extension_l10n_util.cc b/chrome/common/extensions/extension_l10n_util.cc index b4e14b3..634c160 100644 --- a/chrome/common/extensions/extension_l10n_util.cc +++ b/chrome/common/extensions/extension_l10n_util.cc @@ -26,15 +26,15 @@ namespace errors = extension_manifest_errors; namespace keys = extension_manifest_keys; -static std::string* GetProcessLocale() { - static std::string locale; - return &locale; +static std::string& GetProcessLocale() { + CR_DEFINE_STATIC_LOCAL(std::string, locale, ()); + return locale; } namespace extension_l10n_util { void SetProcessLocale(const std::string& locale) { - *(GetProcessLocale()) = locale; + GetProcessLocale() = locale; } std::string GetDefaultLocaleFromManifest(const DictionaryValue& manifest, @@ -183,7 +183,7 @@ bool AddLocale(const std::set<std::string>& chrome_locales, } std::string CurrentLocaleOrDefault() { - std::string current_locale = l10n_util::NormalizeLocale(*GetProcessLocale()); + std::string current_locale = l10n_util::NormalizeLocale(GetProcessLocale()); if (current_locale.empty()) current_locale = "en"; @@ -205,7 +205,7 @@ void GetAllLocales(std::set<std::string>* all_locales) { bool GetValidLocales(const FilePath& locale_path, std::set<std::string>* valid_locales, std::string* error) { - static std::set<std::string> chrome_locales; + std::set<std::string> chrome_locales; GetAllLocales(&chrome_locales); // Enumerate all supplied locales in the extension. diff --git a/chrome/common/mac/objc_zombie.mm b/chrome/common/mac/objc_zombie.mm index 452aa6f..d065109 100644 --- a/chrome/common/mac/objc_zombie.mm +++ b/chrome/common/mac/objc_zombie.mm @@ -15,6 +15,7 @@ #include <iostream> #include "base/debug/stack_trace.h" +#include "base/lazy_instance.h" #include "base/logging.h" #include "base/mac/crash_logging.h" #include "base/mac/mac_util.h" @@ -75,7 +76,8 @@ size_t g_fatZombieSize = 0; BOOL g_zombieAllObjects = NO; // Protects |g_zombieCount|, |g_zombieIndex|, and |g_zombies|. -base::Lock lock_; +base::LazyInstance<base::Lock, base::LeakyLazyInstanceTraits<base::Lock> > + g_lock = LAZY_INSTANCE_INITIALIZER; // How many zombies to keep before freeing, and the current head of // the circular buffer. @@ -213,7 +215,7 @@ void ZombieDealloc(id self, SEL _cmd) { // Don't involve the lock when creating zombies without a treadmill. if (g_zombieCount > 0) { - base::AutoLock pin(lock_); + base::AutoLock pin(g_lock.Get()); // Check the count again in a thread-safe manner. if (g_zombieCount > 0) { @@ -236,7 +238,7 @@ void ZombieDealloc(id self, SEL _cmd) { BOOL GetZombieRecord(id object, ZombieRecord* record) { // Holding the lock is reasonable because this should be fast, and // the process is going to crash presently anyhow. - base::AutoLock pin(lock_); + base::AutoLock pin(g_lock.Get()); for (size_t i = 0; i < g_zombieCount; ++i) { if (g_zombies[i].object == object) { *record = g_zombies[i]; @@ -472,7 +474,7 @@ bool ZombieEnable(bool zombieAllObjects, ZombieRecord* oldZombies = g_zombies; { - base::AutoLock pin(lock_); + base::AutoLock pin(g_lock.Get()); // Save the old index in case zombies need to be transferred. size_t oldIndex = g_zombieIndex; @@ -543,7 +545,7 @@ void ZombieDisable() { ZombieRecord* oldZombies = g_zombies; { - base::AutoLock pin(lock_); // In case any |-dealloc| are in-progress. + base::AutoLock pin(g_lock.Get()); // In case any -dealloc are in progress. g_zombieCount = 0; g_zombies = NULL; } diff --git a/chrome/common/metrics_helpers.cc b/chrome/common/metrics_helpers.cc index 3a012fe..288e579 100644 --- a/chrome/common/metrics_helpers.cc +++ b/chrome/common/metrics_helpers.cc @@ -89,9 +89,6 @@ class MetricsLogBase::XmlWrapper { xmlTextWriterPtr writer_; }; -// static -std::string MetricsLogBase::version_extension_; - MetricsLogBase::MetricsLogBase(const std::string& client_id, int session_id, const std::string& version_string) : start_time_(Time::Now()), diff --git a/chrome/common/metrics_helpers.h b/chrome/common/metrics_helpers.h index 74196dd..65c111d 100644 --- a/chrome/common/metrics_helpers.h +++ b/chrome/common/metrics_helpers.h @@ -94,12 +94,6 @@ class MetricsLogBase { // reliability stats, from other builds, can be abandoned. static int64 GetBuildTime(); - // Use |extension| in all uploaded appversions in addition to the standard - // version string. - static void set_version_extension(const std::string& extension) { - version_extension_ = extension; - } - virtual MetricsLog* AsMetricsLog(); protected: @@ -150,9 +144,6 @@ class MetricsLogBase { // Write the attributes that are common to every metrics event type. void WriteCommonEventAttributes(); - // An extension that is appended to the appversion in each log. - static std::string version_extension_; - base::Time start_time_; base::Time end_time_; @@ -170,6 +161,7 @@ class MetricsLogBase { int num_events_; // the number of events recorded in this log + private: DISALLOW_COPY_AND_ASSIGN(MetricsLogBase); }; diff --git a/chrome/common/profiling.cc b/chrome/common/profiling.cc index 9422a90..946f54f 100644 --- a/chrome/common/profiling.cc +++ b/chrome/common/profiling.cc @@ -17,7 +17,7 @@ namespace { std::string GetProfileName() { static const char kDefaultProfileName[] = "chrome-profile-{type}-{pid}"; - static std::string profile_name; + CR_DEFINE_STATIC_LOCAL(std::string, profile_name, ()); if (profile_name.empty()) { const CommandLine& command_line = *CommandLine::ForCurrentProcess(); diff --git a/chrome/common/time_format.cc b/chrome/common/time_format.cc index d11b7ab..75407a9 100644 --- a/chrome/common/time_format.cc +++ b/chrome/common/time_format.cc @@ -186,7 +186,7 @@ static base::LazyInstance<TimeFormatter> g_time_formatter = void TimeFormatter::BuildFormats( FormatType format_type, std::vector<icu::PluralFormat*>* time_formats) { - static const icu::UnicodeString kKeywords[] = { + const icu::UnicodeString kKeywords[] = { UNICODE_STRING_SIMPLE("other"), UNICODE_STRING_SIMPLE("one"), UNICODE_STRING_SIMPLE("zero"), UNICODE_STRING_SIMPLE("two"), UNICODE_STRING_SIMPLE("few"), UNICODE_STRING_SIMPLE("many") @@ -237,7 +237,7 @@ void TimeFormatter::BuildFormats( // unless translators make a mistake. icu::PluralFormat* TimeFormatter::createFallbackFormat( const icu::PluralRules& rules, int index, FormatType format_type) { - static const icu::UnicodeString kUnits[4][2] = { + const icu::UnicodeString kUnits[4][2] = { { UNICODE_STRING_SIMPLE("sec"), UNICODE_STRING_SIMPLE("secs") }, { UNICODE_STRING_SIMPLE("min"), UNICODE_STRING_SIMPLE("mins") }, { UNICODE_STRING_SIMPLE("hour"), UNICODE_STRING_SIMPLE("hours") }, diff --git a/chrome/renderer/extensions/schema_generated_bindings.cc b/chrome/renderer/extensions/schema_generated_bindings.cc index 902b160..55d3220 100644 --- a/chrome/renderer/extensions/schema_generated_bindings.cc +++ b/chrome/renderer/extensions/schema_generated_bindings.cc @@ -324,16 +324,14 @@ class ExtensionImpl : public ChromeV8Extension { "fjcibdnjlbfnbfdjneajpipnlcppleek", "oflbaaikkabfdfkimeclgkackhdkpnip" // Testing extension. }; - static const std::vector<std::string> allowed_ids( - kAllowedIds, kAllowedIds + arraysize(kAllowedIds)); ExtensionImpl* v8_extension = GetFromArguments<ExtensionImpl>(args); const ::Extension* extension = v8_extension->GetExtensionForCurrentRenderView(); if (!extension) return v8::Undefined(); - if (allowed_ids.end() == std::find( - allowed_ids.begin(), allowed_ids.end(), extension->id())) { + if (kAllowedIds + arraysize(kAllowedIds) == std::find( + kAllowedIds, kAllowedIds + arraysize(kAllowedIds), extension->id())) { return v8::Undefined(); } diff --git a/chrome/renderer/searchbox_extension.cc b/chrome/renderer/searchbox_extension.cc index 1872cb1..1663c5a 100644 --- a/chrome/renderer/searchbox_extension.cc +++ b/chrome/renderer/searchbox_extension.cc @@ -420,8 +420,8 @@ bool SearchBoxExtension::PageSupportsInstant(WebFrame* frame) { // The deprecated API needs to notify the page of events it may have missed. // This isn't necessary in the SearchBox API, since the page can query the // API at any time. - static std::string init_script( - StringPrintf(kInitScript, kSetOmniboxBoundsScript, kUserInputScript)); + CR_DEFINE_STATIC_LOCAL(std::string, init_script, + (StringPrintf(kInitScript, kSetOmniboxBoundsScript, kUserInputScript))); if (supports_deprecated_api) { frame->executeScript(WebScriptSource(WebString::fromUTF8(init_script))); } |