Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2268)

Unified Diff: base/i18n/number_formatting.cc

Issue 5682008: Make members of Singleton<T> private and only visible to the singleton type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/lazy_instance.h » ('j') | base/lazy_instance.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/i18n/number_formatting.cc
diff --git a/base/i18n/number_formatting.cc b/base/i18n/number_formatting.cc
index 7a69294a76fc547b8f7ef0b7b93e1234fc27a589..df6af1462c2aeb09bf9f92ca7bd0ed0a95b76681 100644
--- a/base/i18n/number_formatting.cc
+++ b/base/i18n/number_formatting.cc
@@ -6,7 +6,8 @@
#include "base/format_macros.h"
#include "base/logging.h"
-#include "base/singleton.h"
+#include "base/lazy_instance.h"
+#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "unicode/numfmt.h"
@@ -16,25 +17,26 @@ namespace base {
namespace {
-struct NumberFormatSingletonTraits
- : public DefaultSingletonTraits<icu::NumberFormat> {
- static icu::NumberFormat* New() {
+struct NumberFormatWrapper {
+ NumberFormatWrapper() {
+ // There's no ICU call to destroy a NumberFormat object other than
+ // operator delete, so use the default Delete, which calls operator delete.
+ // This can cause problems if a different allocator is used by this file
+ // than by ICU.
UErrorCode status = U_ZERO_ERROR;
- icu::NumberFormat* formatter = icu::NumberFormat::createInstance(status);
+ number_format.reset(icu::NumberFormat::createInstance(status));
DCHECK(U_SUCCESS(status));
- return formatter;
}
- // There's no ICU call to destroy a NumberFormat object other than
- // operator delete, so use the default Delete, which calls operator delete.
- // This can cause problems if a different allocator is used by this file than
- // by ICU.
+
+ scoped_ptr<icu::NumberFormat> number_format;
};
} // namespace
+static LazyInstance<NumberFormatWrapper> g_number_format(LINKER_INITIALIZED);
Evan Martin 2010/12/13 17:38:30 *
+
string16 FormatNumber(int64 number) {
- icu::NumberFormat* number_format =
- Singleton<icu::NumberFormat, NumberFormatSingletonTraits>::get();
+ icu::NumberFormat* number_format = g_number_format.Get().number_format.get();
if (!number_format) {
// As a fallback, just return the raw number in a string.
« no previous file with comments | « no previous file | base/lazy_instance.h » ('j') | base/lazy_instance.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698