diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-04 23:00:10 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-04 23:00:10 +0000 |
commit | 864b558217c75dbdebea9db3568056292d4cd274 (patch) | |
tree | 06bd9f240065ed47fab9ff415ae4cd49f21facf1 /base/time_win.cc | |
parent | 8c9e61a02aad4d8baa0f75ae7ac2f2f1963fffd6 (diff) | |
download | chromium_src-864b558217c75dbdebea9db3568056292d4cd274.zip chromium_src-864b558217c75dbdebea9db3568056292d4cd274.tar.gz chromium_src-864b558217c75dbdebea9db3568056292d4cd274.tar.bz2 |
This CL add a GetInstance() method to singleton classes instead of relying on the callers to use Singleton<T>.
In some cases I have used the LazyInstance<T> pattern as that was simpler.
This is a small step towards making all singleton classes use the Singleton<T> pattern within their code and not expect the callers to know about it.
I have selected all files under src/app and src/base which use Singleton<T> in this CL. Once this CL goes in I'll work on the rest of the files.
BUG=65298
TEST=all existing tests should continue to pass.
Review URL: http://codereview.chromium.org/5527004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68300 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/time_win.cc')
-rw-r--r-- | base/time_win.cc | 32 |
1 files changed, 18 insertions, 14 deletions
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 |