summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/surface/io_surface_support_mac.cc4
-rw-r--r--base/crypto/cssm_init.cc22
-rw-r--r--base/debug/trace_event.cc14
-rw-r--r--base/debug/trace_event.h8
-rw-r--r--base/debug/trace_event_win.cc6
-rw-r--r--base/debug/trace_event_win.h2
-rw-r--r--base/debug/trace_event_win_unittest.cc4
-rw-r--r--base/i18n/file_util_icu.cc46
-rw-r--r--base/logging_win.cc19
-rw-r--r--base/logging_win.h8
-rw-r--r--base/mime_util_xdg.cc27
-rw-r--r--base/string_util.cc10
-rw-r--r--base/time_win.cc32
-rw-r--r--chrome/browser/printing/print_dialog_cloud_uitest.cc46
-rw-r--r--chrome/common/extensions/extension_message_bundle.cc20
-rw-r--r--chrome/common/extensions/extension_message_bundle.h9
-rw-r--r--chrome/renderer/extensions/event_bindings.cc7
-rw-r--r--chrome/renderer/extensions/extension_process_bindings.cc14
-rw-r--r--gfx/window_impl.cc6
-rw-r--r--ipc/ipc_channel_posix.cc18
-rw-r--r--net/base/net_util.cc9
21 files changed, 200 insertions, 131 deletions
diff --git a/app/surface/io_surface_support_mac.cc b/app/surface/io_surface_support_mac.cc
index 154f895..b27a544 100644
--- a/app/surface/io_surface_support_mac.cc
+++ b/app/surface/io_surface_support_mac.cc
@@ -80,10 +80,8 @@ class IOSurfaceSupportImpl : public IOSurfaceSupport {
DISALLOW_COPY_AND_ASSIGN(IOSurfaceSupportImpl);
};
-static Singleton<IOSurfaceSupportImpl> sole_instance_;
-
IOSurfaceSupportImpl* IOSurfaceSupportImpl::Initialize() {
- IOSurfaceSupportImpl* impl = sole_instance_.get();
+ IOSurfaceSupportImpl* impl = Singleton<IOSurfaceSupportImpl>::get();
if (impl->InitializedSuccessfully())
return impl;
return NULL;
diff --git a/base/crypto/cssm_init.cc b/base/crypto/cssm_init.cc
index b04cbe7..46a6ffe 100644
--- a/base/crypto/cssm_init.cc
+++ b/base/crypto/cssm_init.cc
@@ -22,6 +22,13 @@ namespace {
class CSSMInitSingleton {
public:
+ static CSSMInitSingleton* GetInstance() {
+ return Singleton<CSSMInitSingleton>::get();
+ }
+
+ CSSM_CSP_HANDLE csp_handle() const {return csp_handle_;}
+
+ private:
CSSMInitSingleton() : inited_(false), loaded_(false), csp_handle_(NULL) {
static CSSM_VERSION version = {2, 0};
// TODO(wtc): what should our caller GUID be?
@@ -68,18 +75,21 @@ class CSSMInitSingleton {
}
}
- CSSM_CSP_HANDLE csp_handle() const {return csp_handle_;}
-
- private:
bool inited_; // True if CSSM_Init has been called successfully.
bool loaded_; // True if CSSM_ModuleLoad has been called successfully.
CSSM_CSP_HANDLE csp_handle_;
+
+ friend struct DefaultSingletonTraits<CSSMInitSingleton>;
};
// This singleton is separate as it pertains to Apple's wrappers over
// their own CSSM handles, as opposed to our own CSSM_CSP_HANDLE.
class SecurityServicesSingleton {
public:
+ static SecurityServicesSingleton* GetInstance() {
+ return Singleton<SecurityServicesSingleton>::get();
+ }
+
~SecurityServicesSingleton() {}
Lock& lock() { return lock_; }
@@ -100,11 +110,11 @@ class SecurityServicesSingleton {
namespace base {
void EnsureCSSMInit() {
- Singleton<CSSMInitSingleton>::get();
+ CSSMInitSingleton::GetInstance();
}
CSSM_CSP_HANDLE GetSharedCSPHandle() {
- return Singleton<CSSMInitSingleton>::get()->csp_handle();
+ return CSSMInitSingleton::GetInstance()->csp_handle();
}
void* CSSMMalloc(CSSM_SIZE size, void *alloc_ref) {
@@ -145,7 +155,7 @@ void LogCSSMError(const char *fn_name, CSSM_RETURN err) {
}
Lock& GetMacSecurityServicesLock() {
- return Singleton<SecurityServicesSingleton>::get()->lock();
+ return SecurityServicesSingleton::GetInstance()->lock();
}
} // namespace base
diff --git a/base/debug/trace_event.cc b/base/debug/trace_event.cc
index 4d1d315..f50422c 100644
--- a/base/debug/trace_event.cc
+++ b/base/debug/trace_event.cc
@@ -45,15 +45,18 @@ TraceLog::~TraceLog() {
}
// static
+TraceLog* TraceLog::GetInstance() {
+ return Singleton<TraceLog, DefaultSingletonTraits<TraceLog> >::get();
+}
+
+// static
bool TraceLog::IsTracing() {
- TraceLog* trace = Singleton<TraceLog>::get();
- return trace->enabled_;
+ return TraceLog::GetInstance()->enabled_;
}
// static
bool TraceLog::StartTracing() {
- TraceLog* trace = Singleton<TraceLog>::get();
- return trace->Start();
+ return TraceLog::GetInstance()->Start();
}
bool TraceLog::Start() {
@@ -70,8 +73,7 @@ bool TraceLog::Start() {
// static
void TraceLog::StopTracing() {
- TraceLog* trace = Singleton<TraceLog>::get();
- return trace->Stop();
+ return TraceLog::GetInstance()->Stop();
}
void TraceLog::Stop() {
diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h
index 49ba4bd..160bbc8 100644
--- a/base/debug/trace_event.h
+++ b/base/debug/trace_event.h
@@ -52,7 +52,7 @@
// Record that an event (of name, id) has begun. All BEGIN events should have
// corresponding END events with a matching (name, id).
#define TRACE_EVENT_BEGIN(name, id, extra) \
- Singleton<base::debug::TraceLog>::get()->Trace( \
+ base::debug::TraceLog::GetInstance()->Trace( \
name, \
base::debug::TraceLog::EVENT_BEGIN, \
reinterpret_cast<const void*>(id), \
@@ -63,7 +63,7 @@
// Record that an event (of name, id) has ended. All END events should have
// corresponding BEGIN events with a matching (name, id).
#define TRACE_EVENT_END(name, id, extra) \
- Singleton<base::debug::TraceLog>::get()->Trace( \
+ base::debug::TraceLog::GetInstance()->Trace( \
name, \
base::debug::TraceLog::EVENT_END, \
reinterpret_cast<const void*>(id), \
@@ -73,7 +73,7 @@
// Record that an event (of name, id) with no duration has happened.
#define TRACE_EVENT_INSTANT(name, id, extra) \
- Singleton<base::debug::TraceLog>::get()->Trace( \
+ base::debug::TraceLog::GetInstance()->Trace( \
name, \
base::debug::TraceLog::EVENT_INSTANT, \
reinterpret_cast<const void*>(id), \
@@ -96,6 +96,8 @@ class TraceLog {
EVENT_INSTANT
};
+ static TraceLog* GetInstance();
+
// Is tracing currently enabled.
static bool IsTracing();
// Start logging trace events.
diff --git a/base/debug/trace_event_win.cc b/base/debug/trace_event_win.cc
index 8405699..005ff62 100644
--- a/base/debug/trace_event_win.cc
+++ b/base/debug/trace_event_win.cc
@@ -31,8 +31,8 @@ TraceLog::TraceLog() : EtwTraceProvider(kChromeTraceProviderName) {
Register();
}
-TraceLog* TraceLog::Get() {
- return Singleton<TraceLog, StaticMemorySingletonTraits<TraceLog>>::get();
+TraceLog* TraceLog::GetInstance() {
+ return Singleton<TraceLog, StaticMemorySingletonTraits<TraceLog> >::get();
}
bool TraceLog::StartTracing() {
@@ -99,7 +99,7 @@ void TraceLog::Trace(const char* name,
const void* id,
const char* extra,
size_t extra_len) {
- TraceLog* provider = TraceLog::Get();
+ TraceLog* provider = TraceLog::GetInstance();
if (provider && provider->IsTracing()) {
// Compute the name & extra lengths if not supplied already.
if (name_len == -1)
diff --git a/base/debug/trace_event_win.h b/base/debug/trace_event_win.h
index dd3f512..a1c79ba 100644
--- a/base/debug/trace_event_win.h
+++ b/base/debug/trace_event_win.h
@@ -85,7 +85,7 @@ class TraceLog : public base::win::EtwTraceProvider {
// Retrieves the singleton.
// Note that this may return NULL post-AtExit processing.
- static TraceLog* Get();
+ static TraceLog* GetInstance();
// Returns true iff tracing is turned on.
bool IsTracing() {
diff --git a/base/debug/trace_event_win_unittest.cc b/base/debug/trace_event_win_unittest.cc
index 8544bc7..4c5ed45 100644
--- a/base/debug/trace_event_win_unittest.cc
+++ b/base/debug/trace_event_win_unittest.cc
@@ -106,7 +106,7 @@ class TraceEventTest: public testing::Test {
TraceLog* tracelog = NULL;
if (!is_xp) {
TraceLog::Resurrect();
- tracelog = TraceLog::Get();
+ tracelog = TraceLog::GetInstance();
ASSERT_TRUE(tracelog != NULL);
ASSERT_FALSE(tracelog->IsTracing());
}
@@ -142,7 +142,7 @@ class TraceEventTest: public testing::Test {
if (is_xp) {
TraceLog::Resurrect();
- tracelog = TraceLog::Get();
+ tracelog = TraceLog::GetInstance();
}
ASSERT_TRUE(tracelog != NULL);
EXPECT_TRUE(tracelog->IsTracing());
diff --git a/base/i18n/file_util_icu.cc b/base/i18n/file_util_icu.cc
index 0e9c2cd..34eefac 100644
--- a/base/i18n/file_util_icu.cc
+++ b/base/i18n/file_util_icu.cc
@@ -21,6 +21,10 @@ namespace {
class IllegalCharacters {
public:
+ static IllegalCharacters* GetInstance() {
+ return Singleton<IllegalCharacters>::get();
+ }
+
bool contains(UChar32 ucs4) {
return !!set->contains(ucs4);
}
@@ -76,19 +80,8 @@ IllegalCharacters::IllegalCharacters() {
class LocaleAwareComparator {
public:
- LocaleAwareComparator() {
- UErrorCode error_code = U_ZERO_ERROR;
- // Use the default collator. The default locale should have been properly
- // set by the time this constructor is called.
- collator_.reset(icu::Collator::createInstance(error_code));
- DCHECK(U_SUCCESS(error_code));
- // Make it case-sensitive.
- collator_->setStrength(icu::Collator::TERTIARY);
- // Note: We do not set UCOL_NORMALIZATION_MODE attribute. In other words, we
- // do not pay performance penalty to guarantee sort order correctness for
- // non-FCD (http://unicode.org/notes/tn5/#FCD) file names. This should be a
- // reasonable tradeoff because such file names should be rare and the sort
- // order doesn't change much anyway.
+ static LocaleAwareComparator* GetInstance() {
+ return Singleton<LocaleAwareComparator>::get();
}
// Note: A similar function is available in l10n_util.
@@ -111,6 +104,21 @@ class LocaleAwareComparator {
}
private:
+ LocaleAwareComparator() {
+ UErrorCode error_code = U_ZERO_ERROR;
+ // Use the default collator. The default locale should have been properly
+ // set by the time this constructor is called.
+ collator_.reset(icu::Collator::createInstance(error_code));
+ DCHECK(U_SUCCESS(error_code));
+ // Make it case-sensitive.
+ collator_->setStrength(icu::Collator::TERTIARY);
+ // Note: We do not set UCOL_NORMALIZATION_MODE attribute. In other words, we
+ // do not pay performance penalty to guarantee sort order correctness for
+ // non-FCD (http://unicode.org/notes/tn5/#FCD) file names. This should be a
+ // reasonable tradeoff because such file names should be rare and the sort
+ // order doesn't change much anyway.
+ }
+
scoped_ptr<icu::Collator> collator_;
Lock lock_;
friend struct DefaultSingletonTraits<LocaleAwareComparator>;
@@ -123,19 +131,19 @@ class LocaleAwareComparator {
namespace file_util {
bool IsFilenameLegal(const string16& file_name) {
- return Singleton<IllegalCharacters>()->containsNone(file_name);
+ return IllegalCharacters::GetInstance()->containsNone(file_name);
}
void ReplaceIllegalCharactersInPath(FilePath::StringType* file_name,
char replace_char) {
DCHECK(file_name);
- DCHECK(!(Singleton<IllegalCharacters>()->contains(replace_char)));
+ DCHECK(!(IllegalCharacters::GetInstance()->contains(replace_char)));
// Remove leading and trailing whitespace.
TrimWhitespace(*file_name, TRIM_ALL, file_name);
- IllegalCharacters* illegal = Singleton<IllegalCharacters>::get();
+ IllegalCharacters* illegal = IllegalCharacters::GetInstance();
int cursor = 0; // The ICU macros expect an int.
while (cursor < static_cast<int>(file_name->size())) {
int char_begin = cursor;
@@ -171,8 +179,8 @@ void ReplaceIllegalCharactersInPath(FilePath::StringType* file_name,
bool LocaleAwareCompareFilenames(const FilePath& a, const FilePath& b) {
#if defined(OS_WIN)
- return Singleton<LocaleAwareComparator>()->Compare(a.value().c_str(),
- b.value().c_str()) < 0;
+ return LocaleAwareComparator::GetInstance()->Compare(a.value().c_str(),
+ b.value().c_str()) < 0;
#elif defined(OS_POSIX)
// On linux, the file system encoding is not defined. We assume
@@ -181,7 +189,7 @@ bool LocaleAwareCompareFilenames(const FilePath& a, const FilePath& b) {
// ICU's collator can take strings in OS native encoding. But we convert the
// strings to UTF-16 ourselves to ensure conversion consistency.
// TODO(yuzo): Perhaps we should define SysNativeMBToUTF16?
- return Singleton<LocaleAwareComparator>()->Compare(
+ return LocaleAwareComparator::GetInstance()->Compare(
WideToUTF16(base::SysNativeMBToWide(a.value().c_str())),
WideToUTF16(base::SysNativeMBToWide(b.value().c_str()))) < 0;
#else
diff --git a/base/logging_win.cc b/base/logging_win.cc
index 42610b5..f780b5e 100644
--- a/base/logging_win.cc
+++ b/base/logging_win.cc
@@ -6,14 +6,6 @@
#include "base/singleton.h"
#include <initguid.h> // NOLINT
-namespace {
-
-typedef StaticMemorySingletonTraits<logging::LogEventProvider>
- LogEventSingletonTraits;
-Singleton<logging::LogEventProvider, LogEventSingletonTraits> log_provider;
-
-} // namespace
-
namespace logging {
using base::win::EtwEventLevel;
@@ -25,6 +17,11 @@ DEFINE_GUID(kLogEventId,
LogEventProvider::LogEventProvider() : old_log_level_(LOG_NONE) {
}
+LogEventProvider* LogEventProvider::GetInstance() {
+ return Singleton<LogEventProvider,
+ StaticMemorySingletonTraits<LogEventProvider> >::get();
+}
+
bool LogEventProvider::LogMessage(logging::LogSeverity severity,
const char* file, int line, size_t message_start,
const std::string& message) {
@@ -53,7 +50,7 @@ bool LogEventProvider::LogMessage(logging::LogSeverity severity,
// Bail if we're not logging, not at that level,
// or if we're post-atexit handling.
- LogEventProvider* provider = log_provider.get();
+ LogEventProvider* provider = LogEventProvider::GetInstance();
if (provider == NULL || level > provider->enable_level())
return false;
@@ -100,7 +97,7 @@ bool LogEventProvider::LogMessage(logging::LogSeverity severity,
}
void LogEventProvider::Initialize(const GUID& provider_name) {
- LogEventProvider* provider = log_provider.get();
+ LogEventProvider* provider = LogEventProvider::GetInstance();
provider->set_provider_name(provider_name);
provider->Register();
@@ -110,7 +107,7 @@ void LogEventProvider::Initialize(const GUID& provider_name) {
}
void LogEventProvider::Uninitialize() {
- log_provider.get()->Unregister();
+ LogEventProvider::GetInstance()->Unregister();
}
void LogEventProvider::OnEventsEnabled() {
diff --git a/base/logging_win.h b/base/logging_win.h
index 695c7f2..9058c84 100644
--- a/base/logging_win.h
+++ b/base/logging_win.h
@@ -11,6 +11,9 @@
#include "base/win/event_trace_provider.h"
#include "base/logging.h"
+template <typename Type>
+struct StaticMemorySingletonTraits;
+
namespace logging {
// Event ID for the log messages we generate.
@@ -47,7 +50,7 @@ enum LogMessageTypes {
// with Event Tracing for Windows.
class LogEventProvider : public base::win::EtwTraceProvider {
public:
- LogEventProvider();
+ static LogEventProvider* GetInstance();
static bool LogMessage(logging::LogSeverity severity, const char* file,
int line, size_t message_start, const std::string& str);
@@ -61,10 +64,13 @@ class LogEventProvider : public base::win::EtwTraceProvider {
virtual void OnEventsDisabled();
private:
+ LogEventProvider();
+
// The log severity prior to OnEventsEnabled,
// restored in OnEventsDisabled.
logging::LogSeverity old_log_level_;
+ friend struct StaticMemorySingletonTraits<LogEventProvider>;
DISALLOW_COPY_AND_ASSIGN(LogEventProvider);
};
diff --git a/base/mime_util_xdg.cc b/base/mime_util_xdg.cc
index 5dc4960..8be1d0d 100644
--- a/base/mime_util_xdg.cc
+++ b/base/mime_util_xdg.cc
@@ -28,6 +28,9 @@ class IconTheme;
class MimeUtilConstants {
public:
+ static MimeUtilConstants* GetInstance() {
+ return Singleton<MimeUtilConstants>::get();
+ }
// In seconds, specified by icon theme specs.
const int kUpdateInterval;
@@ -157,7 +160,7 @@ IconTheme::IconTheme(const std::string& name)
std::map<FilePath, int>::iterator iter;
FilePath theme_path;
std::map<FilePath, int>* icon_dirs =
- Singleton<MimeUtilConstants>::get()->icon_dirs_;
+ MimeUtilConstants::GetInstance()->icon_dirs_;
for (iter = icon_dirs->begin(); iter != icon_dirs->end(); ++iter) {
theme_path = iter->first.Append(name);
if (!file_util::DirectoryExists(theme_path))
@@ -218,7 +221,7 @@ FilePath IconTheme::GetIconPath(const std::string& icon_name, int size,
IconTheme* IconTheme::LoadTheme(const std::string& theme_name) {
scoped_ptr<IconTheme> theme;
std::map<std::string, IconTheme*>* icon_themes =
- Singleton<MimeUtilConstants>::get()->icon_themes_;
+ MimeUtilConstants::GetInstance()->icon_themes_;
if (icon_themes->find(theme_name) != icon_themes->end()) {
theme.reset((*icon_themes)[theme_name]);
} else {
@@ -235,7 +238,7 @@ FilePath IconTheme::GetIconPathUnderSubdir(const std::string& icon_name,
FilePath icon_path;
std::list<FilePath>::iterator dir_iter;
std::vector<std::string>* icon_formats =
- &Singleton<MimeUtilConstants>::get()->icon_formats_;
+ &MimeUtilConstants::GetInstance()->icon_formats_;
for (dir_iter = dirs_.begin(); dir_iter != dirs_.end(); ++dir_iter) {
for (size_t i = 0; i < icon_formats->size(); ++i) {
icon_path = dir_iter->Append(subdir);
@@ -383,7 +386,7 @@ bool IconTheme::SetDirectories(const std::string& dirs) {
void TryAddIconDir(const FilePath& dir) {
if (!file_util::DirectoryExists(dir))
return;
- (*Singleton<MimeUtilConstants>::get()->icon_dirs_)[dir] = 0;
+ (*MimeUtilConstants::GetInstance()->icon_dirs_)[dir] = 0;
}
// For a xdg directory |dir|, add the appropriate icon sub-directories.
@@ -396,7 +399,7 @@ void AddXDGDataDir(const FilePath& dir) {
// Add all the xdg icon directories.
void InitIconDir() {
- Singleton<MimeUtilConstants>::get()->icon_dirs_->clear();
+ MimeUtilConstants::GetInstance()->icon_dirs_->clear();
FilePath home = file_util::GetHomeDir();
if (!home.empty()) {
FilePath legacy_data_dir(home);
@@ -435,7 +438,7 @@ void EnsureUpdated() {
struct timeval t;
gettimeofday(&t, NULL);
time_t now = t.tv_sec;
- MimeUtilConstants* constants = Singleton<MimeUtilConstants>::get();
+ MimeUtilConstants* constants = MimeUtilConstants::GetInstance();
if (constants->last_check_time_ == 0) {
constants->icon_dirs_ = new std::map<FilePath, int>;
@@ -453,7 +456,7 @@ void EnsureUpdated() {
// Find a fallback icon if we cannot find it in the default theme.
FilePath LookupFallbackIcon(const std::string& icon_name) {
FilePath icon;
- MimeUtilConstants* constants = Singleton<MimeUtilConstants>::get();
+ MimeUtilConstants* constants = MimeUtilConstants::GetInstance();
std::map<FilePath, int>::iterator iter;
std::map<FilePath, int>* icon_dirs = constants->icon_dirs_;
std::vector<std::string>* icon_formats = &constants->icon_formats_;
@@ -470,7 +473,7 @@ FilePath LookupFallbackIcon(const std::string& icon_name) {
// Initialize the list of default themes.
void InitDefaultThemes() {
IconTheme** default_themes =
- Singleton<MimeUtilConstants>::get()->default_themes_;
+ MimeUtilConstants::GetInstance()->default_themes_;
char* env = getenv("KDE_FULL_SESSION");
if (env) {
@@ -498,7 +501,7 @@ void InitDefaultThemes() {
} else {
// Assume it's Gnome and use GTK to figure out the theme.
default_themes[1] = IconTheme::LoadTheme(
- Singleton<MimeUtilConstants>::get()->gtk_theme_name_);
+ MimeUtilConstants::GetInstance()->gtk_theme_name_);
default_themes[2] = IconTheme::LoadTheme("gnome");
}
// hicolor needs to be last per icon theme spec.
@@ -518,7 +521,7 @@ void InitDefaultThemes() {
// Try to find an icon with the name |icon_name| that's |size| pixels.
FilePath LookupIconInDefaultTheme(const std::string& icon_name, int size) {
EnsureUpdated();
- MimeUtilConstants* constants = Singleton<MimeUtilConstants>::get();
+ MimeUtilConstants* constants = MimeUtilConstants::GetInstance();
std::map<std::string, IconTheme*>* icon_themes = constants->icon_themes_;
if (icon_themes->size() == 0)
InitDefaultThemes();
@@ -558,7 +561,7 @@ void DetectGtkTheme() {
// If the theme name is already loaded, do nothing. Chrome doesn't respond
// to changes in the system theme, so we never need to set this more than
// once.
- if (!Singleton<MimeUtilConstants>::get()->gtk_theme_name_.empty())
+ if (!MimeUtilConstants::GetInstance()->gtk_theme_name_.empty())
return;
// We should only be called on the UI thread.
@@ -568,7 +571,7 @@ void DetectGtkTheme() {
g_object_get(gtk_settings_get_default(),
"gtk-icon-theme-name",
&gtk_theme_name, NULL);
- Singleton<MimeUtilConstants>::get()->gtk_theme_name_.assign(gtk_theme_name);
+ MimeUtilConstants::GetInstance()->gtk_theme_name_.assign(gtk_theme_name);
g_free(gtk_theme_name);
}
diff --git a/base/string_util.cc b/base/string_util.cc
index d7b6729..fc1372b 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -38,6 +38,10 @@ struct EmptyStrings {
const std::string s;
const std::wstring ws;
const string16 s16;
+
+ static EmptyStrings* GetInstance() {
+ return Singleton<EmptyStrings>::get();
+ }
};
// Used by ReplaceStringPlaceholders to track the position in the string of
@@ -102,15 +106,15 @@ bool IsWprintfFormatPortable(const wchar_t* format) {
const std::string& EmptyString() {
- return Singleton<EmptyStrings>::get()->s;
+ return EmptyStrings::GetInstance()->s;
}
const std::wstring& EmptyWString() {
- return Singleton<EmptyStrings>::get()->ws;
+ return EmptyStrings::GetInstance()->ws;
}
const string16& EmptyString16() {
- return Singleton<EmptyStrings>::get()->s16;
+ return EmptyStrings::GetInstance()->s16;
}
#define WHITESPACE_UNICODE \
diff --git a/base/time_win.cc b/base/time_win.cc
index 5d3ecd6..ca3aef1 100644
--- a/base/time_win.cc
+++ b/base/time_win.cc
@@ -310,16 +310,8 @@ TimeDelta RolloverProtectedNow() {
// retrieve and more reliable.
class HighResNowSingleton {
public:
- HighResNowSingleton()
- : ticks_per_microsecond_(0.0),
- skew_(0) {
- InitializeClock();
-
- // On Athlon X2 CPUs (e.g. model 15) QueryPerformanceCounter is
- // unreliable. Fallback to low-res clock.
- base::CPU cpu;
- if (cpu.vendor_name() == "AuthenticAMD" && cpu.family() == 15)
- DisableHighResClock();
+ static HighResNowSingleton* GetInstance() {
+ return Singleton<HighResNowSingleton>::get();
}
bool IsUsingHighResClock() {
@@ -346,6 +338,18 @@ class HighResNowSingleton {
}
private:
+ HighResNowSingleton()
+ : ticks_per_microsecond_(0.0),
+ skew_(0) {
+ InitializeClock();
+
+ // On Athlon X2 CPUs (e.g. model 15) QueryPerformanceCounter is
+ // unreliable. Fallback to low-res clock.
+ base::CPU cpu;
+ if (cpu.vendor_name() == "AuthenticAMD" && cpu.family() == 15)
+ DisableHighResClock();
+ }
+
// Synchronize the QPC clock with GetSystemTimeAsFileTime.
void InitializeClock() {
LARGE_INTEGER ticks_per_sec = {0};
@@ -374,7 +378,7 @@ class HighResNowSingleton {
float ticks_per_microsecond_; // 0 indicates QPF failed and we're broken.
int64 skew_; // Skew between lo-res and hi-res clocks (for debugging).
- DISALLOW_COPY_AND_ASSIGN(HighResNowSingleton);
+ friend struct DefaultSingletonTraits<HighResNowSingleton>;
};
} // namespace
@@ -394,15 +398,15 @@ TimeTicks TimeTicks::Now() {
// static
TimeTicks TimeTicks::HighResNow() {
- return TimeTicks() + Singleton<HighResNowSingleton>::get()->Now();
+ return TimeTicks() + HighResNowSingleton::GetInstance()->Now();
}
// static
int64 TimeTicks::GetQPCDriftMicroseconds() {
- return Singleton<HighResNowSingleton>::get()->GetQPCDriftMicroseconds();
+ return HighResNowSingleton::GetInstance()->GetQPCDriftMicroseconds();
}
// static
bool TimeTicks::IsHighResClockWorking() {
- return Singleton<HighResNowSingleton>::get()->IsUsingHighResClock();
+ return HighResNowSingleton::GetInstance()->IsUsingHighResClock();
} \ No newline at end of file
diff --git a/chrome/browser/printing/print_dialog_cloud_uitest.cc b/chrome/browser/printing/print_dialog_cloud_uitest.cc
index e13c792..e4c8804 100644
--- a/chrome/browser/printing/print_dialog_cloud_uitest.cc
+++ b/chrome/browser/printing/print_dialog_cloud_uitest.cc
@@ -31,7 +31,9 @@ namespace {
class TestData {
public:
- TestData() {}
+ static TestData* GetInstance() {
+ return Singleton<TestData>::get();
+ }
const char* GetTestData() {
// Fetching this data blocks the IO thread, but we don't really care because
@@ -48,7 +50,11 @@ class TestData {
return test_data_.c_str();
}
private:
+ TestData() {}
+
std::string test_data_;
+
+ friend struct DefaultSingletonTraits<TestData>;
};
// A simple test URLRequestJob. We don't care what it does, only that
@@ -57,7 +63,7 @@ class SimpleTestJob : public URLRequestTestJob {
public:
explicit SimpleTestJob(net::URLRequest* request)
: URLRequestTestJob(request, test_headers(),
- Singleton<TestData>()->GetTestData(), true) {}
+ TestData::GetInstance()->GetTestData(), true) {}
virtual void GetResponseInfo(net::HttpResponseInfo* info) {
URLRequestTestJob::GetResponseInfo(info);
@@ -84,10 +90,9 @@ class SimpleTestJob : public URLRequestTestJob {
class TestController {
public:
- TestController()
- : result_(false),
- use_delegate_(false),
- delegate_(NULL) {}
+ static TestController* GetInstance() {
+ return Singleton<TestController>::get();
+ }
void set_result(bool value) {
result_ = value;
}
@@ -113,10 +118,17 @@ class TestController {
return use_delegate_;
}
private:
+ TestController()
+ : result_(false),
+ use_delegate_(false),
+ delegate_(NULL) {}
+
bool result_;
bool use_delegate_;
GURL expected_url_;
TestDelegate* delegate_;
+
+ friend struct DefaultSingletonTraits<TestController>;
};
} // namespace
@@ -141,7 +153,7 @@ class PrintDialogCloudTest : public InProcessBrowserTest {
};
virtual void SetUp() {
- Singleton<TestController>()->set_result(false);
+ TestController::GetInstance()->set_result(false);
InProcessBrowserTest::SetUp();
}
@@ -150,7 +162,7 @@ class PrintDialogCloudTest : public InProcessBrowserTest {
URLRequestFilter* filter = URLRequestFilter::GetInstance();
filter->RemoveHostnameHandler(scheme_, host_name_);
handler_added_ = false;
- Singleton<TestController>()->set_delegate(NULL);
+ TestController::GetInstance()->set_delegate(NULL);
}
InProcessBrowserTest::TearDown();
}
@@ -174,8 +186,8 @@ class PrintDialogCloudTest : public InProcessBrowserTest {
GURL cloud_print_dialog_url =
CloudPrintURL(browser()->profile()).
GetCloudPrintServiceDialogURL();
- Singleton<TestController>()->set_expected_url(cloud_print_dialog_url);
- Singleton<TestController>()->set_delegate(&delegate_);
+ TestController::GetInstance()->set_expected_url(cloud_print_dialog_url);
+ TestController::GetInstance()->set_delegate(&delegate_);
}
CreateDialogForTest();
@@ -198,11 +210,11 @@ class PrintDialogCloudTest : public InProcessBrowserTest {
URLRequestJob* PrintDialogCloudTest::Factory(net::URLRequest* request,
const std::string& scheme) {
- if (Singleton<TestController>()->use_delegate())
- request->set_delegate(Singleton<TestController>()->delegate());
+ if (TestController::GetInstance()->use_delegate())
+ request->set_delegate(TestController::GetInstance()->delegate());
if (request &&
- (request->url() == Singleton<TestController>()->expected_url())) {
- Singleton<TestController>()->set_result(true);
+ (request->url() == TestController::GetInstance()->expected_url())) {
+ TestController::GetInstance()->set_result(true);
}
return new SimpleTestJob(request);
}
@@ -213,11 +225,11 @@ IN_PROC_BROWSER_TEST_F(PrintDialogCloudTest, HandlersRegistered) {
AddTestHandlers();
- Singleton<TestController>()->set_use_delegate(true);
+ TestController::GetInstance()->set_use_delegate(true);
ui_test_utils::RunMessageLoop();
- ASSERT_TRUE(Singleton<TestController>()->result());
+ ASSERT_TRUE(TestController::GetInstance()->result());
}
#if defined(OS_CHROMEOS)
@@ -240,6 +252,6 @@ IN_PROC_BROWSER_TEST_F(PrintDialogCloudTest, DISABLED_DialogGrabbed) {
ui_test_utils::RunMessageLoop();
- ASSERT_TRUE(Singleton<TestController>()->result());
+ ASSERT_TRUE(TestController::GetInstance()->result());
}
#endif
diff --git a/chrome/common/extensions/extension_message_bundle.cc b/chrome/common/extensions/extension_message_bundle.cc
index 3f7c152..ea28c83 100644
--- a/chrome/common/extensions/extension_message_bundle.cc
+++ b/chrome/common/extensions/extension_message_bundle.cc
@@ -10,9 +10,9 @@
#include "app/l10n_util.h"
#include "base/hash_tables.h"
#include "base/i18n/rtl.h"
+#include "base/lazy_instance.h"
#include "base/linked_ptr.h"
#include "base/scoped_ptr.h"
-#include "base/singleton.h"
#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
@@ -316,18 +316,30 @@ std::string ExtensionMessageBundle::GetL10nMessage(
//
///////////////////////////////////////////////////////////////////////////////
+// Unique class for Singleton.
+struct ExtensionToMessagesMap {
+ ExtensionToMessagesMap();
+ ~ExtensionToMessagesMap();
+
+ // Maps extension ID to message map.
+ ExtensionToL10nMessagesMap messages_map;
+};
+
+static base::LazyInstance<ExtensionToMessagesMap> g_extension_to_messages_map(
+ base::LINKER_INITIALIZED);
+
ExtensionToMessagesMap::ExtensionToMessagesMap() {}
ExtensionToMessagesMap::~ExtensionToMessagesMap() {}
ExtensionToL10nMessagesMap* GetExtensionToL10nMessagesMap() {
- return &Singleton<ExtensionToMessagesMap>()->messages_map;
+ return &g_extension_to_messages_map.Get().messages_map;
}
L10nMessagesMap* GetL10nMessagesMap(const std::string extension_id) {
ExtensionToL10nMessagesMap::iterator it =
- Singleton<ExtensionToMessagesMap>()->messages_map.find(extension_id);
- if (it != Singleton<ExtensionToMessagesMap>()->messages_map.end())
+ g_extension_to_messages_map.Get().messages_map.find(extension_id);
+ if (it != g_extension_to_messages_map.Get().messages_map.end())
return &(it->second);
return NULL;
diff --git a/chrome/common/extensions/extension_message_bundle.h b/chrome/common/extensions/extension_message_bundle.h
index 6370559..df3bf35 100644
--- a/chrome/common/extensions/extension_message_bundle.h
+++ b/chrome/common/extensions/extension_message_bundle.h
@@ -155,15 +155,6 @@ typedef std::map<std::string, std::string> L10nMessagesMap;
// A map of extension ID to l10n message map.
typedef std::map<std::string, L10nMessagesMap > ExtensionToL10nMessagesMap;
-// Unique class for Singleton.
-struct ExtensionToMessagesMap {
- ExtensionToMessagesMap();
- ~ExtensionToMessagesMap();
-
- // Maps extension ID to message map.
- ExtensionToL10nMessagesMap messages_map;
-};
-
// Returns the extension_id to messages map.
ExtensionToL10nMessagesMap* GetExtensionToL10nMessagesMap();
diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc
index 423c370..60c5c0d 100644
--- a/chrome/renderer/extensions/event_bindings.cc
+++ b/chrome/renderer/extensions/event_bindings.cc
@@ -5,7 +5,7 @@
#include "chrome/renderer/extensions/event_bindings.h"
#include "base/basictypes.h"
-#include "base/singleton.h"
+#include "base/lazy_instance.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
#include "chrome/renderer/extensions/bindings_utils.h"
@@ -61,8 +61,11 @@ struct SingletonData {
std::map<std::string, EventListenerCounts> listener_counts_;
};
+static base::LazyInstance<SingletonData> g_singleton_data(
+ base::LINKER_INITIALIZED);
+
static EventListenerCounts& GetListenerCounts(const std::string& extension_id) {
- return Singleton<SingletonData>()->listener_counts_[extension_id];
+ return g_singleton_data.Get().listener_counts_[extension_id];
}
class ExtensionImpl : public ExtensionBase {
diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc
index bdbb9aa..6631587 100644
--- a/chrome/renderer/extensions/extension_process_bindings.cc
+++ b/chrome/renderer/extensions/extension_process_bindings.cc
@@ -11,8 +11,8 @@
#include "base/command_line.h"
#include "base/json/json_reader.h"
+#include "base/lazy_instance.h"
#include "base/scoped_ptr.h"
-#include "base/singleton.h"
#include "base/string_util.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h"
@@ -78,21 +78,23 @@ struct SingletonData {
ExtensionPermissionsList permissions_;
};
+static base::LazyInstance<SingletonData> g_singleton_data(
+ base::LINKER_INITIALIZED);
+
static std::set<std::string>* GetFunctionNameSet() {
- return &Singleton<SingletonData>()->function_names_;
+ return &g_singleton_data.Get().function_names_;
}
static PageActionIdMap* GetPageActionMap() {
- return &Singleton<SingletonData>()->page_action_ids_;
+ return &g_singleton_data.Get().page_action_ids_;
}
static PermissionsList* GetPermissionsList(const std::string& extension_id) {
- return &Singleton<SingletonData>()->permissions_[extension_id];
+ return &g_singleton_data.Get().permissions_[extension_id];
}
static void GetActiveExtensionIDs(std::set<std::string>* extension_ids) {
- ExtensionPermissionsList& permissions =
- Singleton<SingletonData>()->permissions_;
+ ExtensionPermissionsList& permissions = g_singleton_data.Get().permissions_;
for (ExtensionPermissionsList::iterator iter = permissions.begin();
iter != permissions.end(); ++iter) {
diff --git a/gfx/window_impl.cc b/gfx/window_impl.cc
index 74e0e20..95561ff 100644
--- a/gfx/window_impl.cc
+++ b/gfx/window_impl.cc
@@ -42,6 +42,10 @@ struct ClassInfo {
class ClassRegistrar {
public:
+ static ClassRegistrar* GetInstance() {
+ return Singleton<ClassRegistrar>::get();
+ }
+
~ClassRegistrar() {
for (RegisteredClasses::iterator i = registered_classes_.begin();
i != registered_classes_.end(); ++i) {
@@ -198,7 +202,7 @@ LRESULT CALLBACK WindowImpl::WndProc(HWND hwnd,
std::wstring WindowImpl::GetWindowClassName() {
ClassInfo class_info(initial_class_style());
std::wstring name;
- if (Singleton<ClassRegistrar>()->RetrieveClassName(class_info, &name))
+ if (ClassRegistrar::GetInstance()->RetrieveClassName(class_info, &name))
return name;
// No class found, need to register one.
diff --git a/ipc/ipc_channel_posix.cc b/ipc/ipc_channel_posix.cc
index 65a04e1..bbf13743 100644
--- a/ipc/ipc_channel_posix.cc
+++ b/ipc/ipc_channel_posix.cc
@@ -75,6 +75,10 @@ namespace {
class PipeMap {
public:
+ static PipeMap* GetInstance() {
+ return Singleton<PipeMap>::get();
+ }
+
// Lookup a given channel id. Return -1 if not found.
int Lookup(const std::string& channel_id) {
AutoLock locked(lock_);
@@ -115,13 +119,15 @@ class PipeMap {
Lock lock_;
typedef std::map<std::string, int> ChannelToFDMap;
ChannelToFDMap map_;
+
+ friend struct DefaultSingletonTraits<PipeMap>;
};
// Used to map a channel name to the equivalent FD # in the current process.
// Returns -1 if the channel is unknown.
int ChannelNameToFD(const std::string& channel_id) {
// See the large block comment above PipeMap for the reasoning here.
- const int fd = Singleton<PipeMap>()->Lookup(channel_id);
+ const int fd = PipeMap::GetInstance()->Lookup(channel_id);
if (fd != -1) {
int dup_fd = dup(fd);
@@ -305,17 +311,17 @@ Channel::ChannelImpl::~ChannelImpl() {
// static
void AddChannelSocket(const std::string& name, int socket) {
- Singleton<PipeMap>()->Insert(name, socket);
+ PipeMap::GetInstance()->Insert(name, socket);
}
// static
void RemoveAndCloseChannelSocket(const std::string& name) {
- Singleton<PipeMap>()->RemoveAndClose(name);
+ PipeMap::GetInstance()->RemoveAndClose(name);
}
// static
bool ChannelSocketExists(const std::string& name) {
- return Singleton<PipeMap>()->Lookup(name) != -1;
+ return PipeMap::GetInstance()->Lookup(name) != -1;
}
// static
@@ -512,7 +518,7 @@ bool Channel::ChannelImpl::ProcessIncomingMessages() {
DCHECK(bytes_read);
if (client_pipe_ != -1) {
- Singleton<PipeMap>()->RemoveAndClose(pipe_name_);
+ PipeMap::GetInstance()->RemoveAndClose(pipe_name_);
client_pipe_ = -1;
}
@@ -1021,7 +1027,7 @@ void Channel::ChannelImpl::Close() {
pipe_ = -1;
}
if (client_pipe_ != -1) {
- Singleton<PipeMap>()->RemoveAndClose(pipe_name_);
+ PipeMap::GetInstance()->RemoveAndClose(pipe_name_);
client_pipe_ = -1;
}
#if !defined(OS_MACOSX)
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index d032d8a..5426b68 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -513,6 +513,11 @@ bool IsCompatibleWithASCIILetters(const std::string& lang) {
typedef std::map<std::string, icu::UnicodeSet*> LangToExemplarSetMap;
class LangToExemplarSet {
+ public:
+ static LangToExemplarSet* GetInstance() {
+ return Singleton<LangToExemplarSet>::get();
+ }
+
private:
LangToExemplarSetMap map;
LangToExemplarSet() { }
@@ -530,7 +535,7 @@ class LangToExemplarSet {
bool GetExemplarSetForLang(const std::string& lang,
icu::UnicodeSet** lang_set) {
- const LangToExemplarSetMap& map = Singleton<LangToExemplarSet>()->map;
+ const LangToExemplarSetMap& map = LangToExemplarSet::GetInstance()->map;
LangToExemplarSetMap::const_iterator pos = map.find(lang);
if (pos != map.end()) {
*lang_set = pos->second;
@@ -541,7 +546,7 @@ bool GetExemplarSetForLang(const std::string& lang,
void SetExemplarSetForLang(const std::string& lang,
icu::UnicodeSet* lang_set) {
- LangToExemplarSetMap& map = Singleton<LangToExemplarSet>()->map;
+ LangToExemplarSetMap& map = LangToExemplarSet::GetInstance()->map;
map.insert(std::make_pair(lang, lang_set));
}