diff options
59 files changed, 325 insertions, 149 deletions
diff --git a/chrome/browser/accessibility/browser_accessibility_state.cc b/chrome/browser/accessibility/browser_accessibility_state.cc index 83f81f9..a6967c8 100644 --- a/chrome/browser/accessibility/browser_accessibility_state.cc +++ b/chrome/browser/accessibility/browser_accessibility_state.cc @@ -3,6 +3,8 @@ // found in the LICENSE file. #include "chrome/browser/accessibility/browser_accessibility_state.h" + +#include "base/singleton.h" #include "chrome/browser/profiles/profile.h" BrowserAccessibilityState::BrowserAccessibilityState() @@ -12,6 +14,11 @@ BrowserAccessibilityState::BrowserAccessibilityState() BrowserAccessibilityState::~BrowserAccessibilityState() { } +// static +BrowserAccessibilityState* BrowserAccessibilityState::GetInstance() { + return Singleton<BrowserAccessibilityState>::get(); +} + void BrowserAccessibilityState::OnScreenReaderDetected() { screen_reader_active_ = true; } diff --git a/chrome/browser/accessibility/browser_accessibility_state.h b/chrome/browser/accessibility/browser_accessibility_state.h index efcd2dd..bdd7bcc 100644 --- a/chrome/browser/accessibility/browser_accessibility_state.h +++ b/chrome/browser/accessibility/browser_accessibility_state.h @@ -7,7 +7,8 @@ #pragma once #include "base/basictypes.h" -#include "base/singleton.h" + +template <typename T> struct DefaultSingletonTraits; // The BrowserAccessibilityState class is used to determine if Chrome should be // customized for users with assistive technology, such as screen readers. We @@ -25,6 +26,9 @@ // file for Universal Access with the key "voiceOverOnOffKey". class BrowserAccessibilityState { public: + // Returns the singleton instance. + static BrowserAccessibilityState* GetInstance(); + ~BrowserAccessibilityState(); // Called when screen reader client is detected. diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac.mm b/chrome/browser/autofill/autofill_dialog_controller_mac.mm index 990ba58..ac17b07 100644 --- a/chrome/browser/autofill/autofill_dialog_controller_mac.mm +++ b/chrome/browser/autofill/autofill_dialog_controller_mac.mm @@ -5,8 +5,8 @@ #import "chrome/browser/autofill/autofill_dialog_controller_mac.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "base/lazy_instance.h" #include "base/mac_util.h" -#include "base/singleton.h" #include "base/sys_string_conversions.h" #import "chrome/browser/autofill/autofill_address_model_mac.h" #import "chrome/browser/autofill/autofill_address_sheet_controller_mac.h" @@ -32,6 +32,9 @@ namespace { // dialog. typedef std::map<Profile*, AutoFillDialogController*> ProfileControllerMap; +static base::LazyInstance<ProfileControllerMap> g_profile_controller_map( + base::LINKER_INITIALIZED); + } // namespace // Delegate protocol that needs to be in place for the AutoFillTableView's @@ -268,7 +271,7 @@ class PreferenceObserver : public NotificationObserver { [self autorelease]; // Remove ourself from the map. - ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); + ProfileControllerMap* map = g_profile_controller_map.Pointer(); ProfileControllerMap::iterator it = map->find(profile_); if (it != map->end()) { map->erase(it); @@ -633,7 +636,7 @@ class PreferenceObserver : public NotificationObserver { profile:(Profile*)profile { profile = profile->GetOriginalProfile(); - ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); + ProfileControllerMap* map = g_profile_controller_map.Pointer(); DCHECK(map != NULL); ProfileControllerMap::iterator it = map->find(profile); if (it == map->end()) { diff --git a/chrome/browser/chromeos/audio_handler.cc b/chrome/browser/chromeos/audio_handler.cc index a463e29..2f6638f 100644 --- a/chrome/browser/chromeos/audio_handler.cc +++ b/chrome/browser/chromeos/audio_handler.cc @@ -7,6 +7,7 @@ #include <math.h> #include "base/logging.h" +#include "base/singleton.h" #include "chrome/browser/chromeos/pulse_audio_mixer.h" namespace chromeos { @@ -168,4 +169,9 @@ double AudioHandler::PercentToVolumeDb(double volume_percent) { (kMaxVolumeDb - kMinVolumeDb) + kMinVolumeDb; } +// static +AudioHandler* AudioHandler::instance() { + return Singleton<AudioHandler>::get(); +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/audio_handler.h b/chrome/browser/chromeos/audio_handler.h index 67addcb..ca1a83b 100644 --- a/chrome/browser/chromeos/audio_handler.h +++ b/chrome/browser/chromeos/audio_handler.h @@ -6,8 +6,10 @@ #define CHROME_BROWSER_CHROMEOS_AUDIO_HANDLER_H_ #pragma once +#include "base/basictypes.h" #include "base/scoped_ptr.h" -#include "base/singleton.h" + +template <typename T> struct DefaultSingletonTraits; namespace chromeos { @@ -15,9 +17,7 @@ class PulseAudioMixer; class AudioHandler { public: - static AudioHandler* instance() { - return Singleton<AudioHandler>::get(); - } + static AudioHandler* instance(); // Get volume level in our internal 0-100% range, 0 being pure silence. // Volume may go above 100% if another process changes PulseAudio's volume. diff --git a/chrome/browser/chromeos/dom_ui/imageburner_ui.cc b/chrome/browser/chromeos/dom_ui/imageburner_ui.cc index c285163..75d8b40 100644 --- a/chrome/browser/chromeos/dom_ui/imageburner_ui.cc +++ b/chrome/browser/chromeos/dom_ui/imageburner_ui.cc @@ -105,7 +105,7 @@ ImageBurnHandler::ImageBurnHandler(TabContents* contents) chromeos::CrosLibrary::Get()->GetBurnLibrary(); burn_lib->AddObserver(this); local_image_file_path_.clear(); - burn_resource_manager_ = Singleton<ImageBurnResourceManager>::get(); + burn_resource_manager_ = ImageBurnResourceManager::GetInstance(); } ImageBurnHandler::~ImageBurnHandler() { @@ -398,7 +398,7 @@ void ImageBurnHandler::CreateLocalImagePath() { ImageBurnTaskProxy::ImageBurnTaskProxy( const base::WeakPtr<ImageBurnHandler>& handler) : handler_(handler) { - resource_manager_ = Singleton<ImageBurnResourceManager>::get(); + resource_manager_ = ImageBurnResourceManager::GetInstance(); } bool ImageBurnTaskProxy::ReportDownloadInitialized() { @@ -464,6 +464,11 @@ ImageBurnResourceManager::~ImageBurnResourceManager() { download_manager_->RemoveObserver(this); } +// static +ImageBurnResourceManager* ImageBurnResourceManager::GetInstance() { + return Singleton<ImageBurnResourceManager>::get(); +} + void ImageBurnResourceManager::OnDownloadUpdated(DownloadItem* download) { if (download->state() == DownloadItem::CANCELLED) { image_url_.reset(); diff --git a/chrome/browser/chromeos/dom_ui/imageburner_ui.h b/chrome/browser/chromeos/dom_ui/imageburner_ui.h index 0f2560a..5803762 100644 --- a/chrome/browser/chromeos/dom_ui/imageburner_ui.h +++ b/chrome/browser/chromeos/dom_ui/imageburner_ui.h @@ -26,6 +26,8 @@ #include "googleurl/src/gurl.h" #include "net/base/file_stream.h" +template <typename T> struct DefaultSingletonTraits; + static const std::string kPropertyPath = "path"; static const std::string kPropertyTitle = "title"; static const std::string kPropertyDirectory = "isDirectory"; @@ -158,8 +160,8 @@ class ImageBurnTaskProxy class ImageBurnResourceManager : public DownloadManager::Observer, public DownloadItem::Observer { public: - ImageBurnResourceManager(); - ~ImageBurnResourceManager(); + // Returns the singleton instance. + static ImageBurnResourceManager* GetInstance(); // DownloadItem::Observer interface virtual void OnDownloadUpdated(DownloadItem* download); @@ -190,6 +192,11 @@ class ImageBurnResourceManager : public DownloadManager::Observer, net::FileStream* CreateFileStream(FilePath* file_path); private: + friend struct DefaultSingletonTraits<ImageBurnResourceManager>; + + ImageBurnResourceManager(); + ~ImageBurnResourceManager(); + FilePath local_image_dir_file_path_; FilePath image_fecher_local_path_; bool image_download_started_; diff --git a/chrome/browser/chromeos/gview_request_interceptor.h b/chrome/browser/chromeos/gview_request_interceptor.h index 7642d1d..cd8dfde 100644 --- a/chrome/browser/chromeos/gview_request_interceptor.h +++ b/chrome/browser/chromeos/gview_request_interceptor.h @@ -10,6 +10,8 @@ #include "base/hash_tables.h" #include "net/url_request/url_request.h" +template <typename T> struct DefaultSingletonTraits; + namespace chromeos { // This class integrates the Google Document Viewer into ChromeOS, @@ -20,9 +22,6 @@ namespace chromeos { // parameter. class GViewRequestInterceptor : public net::URLRequest::Interceptor { public: - GViewRequestInterceptor(); - virtual ~GViewRequestInterceptor(); - // Always returns NULL because we don't want to attempt a redirect // before seeing the detected mime type of the request. virtual net::URLRequestJob* MaybeIntercept(net::URLRequest* request); @@ -36,6 +35,11 @@ class GViewRequestInterceptor : public net::URLRequest::Interceptor { static net::URLRequest::Interceptor* GetGViewRequestInterceptor(); private: + friend struct DefaultSingletonTraits<GViewRequestInterceptor>; + + GViewRequestInterceptor(); + virtual ~GViewRequestInterceptor(); + // The list of supported mime types. base::hash_set<std::string> supported_mime_types_; }; diff --git a/chrome/browser/chromeos/input_method/input_method_util.cc b/chrome/browser/chromeos/input_method/input_method_util.cc index 9f8811d..fbc904b 100644 --- a/chrome/browser/chromeos/input_method/input_method_util.cc +++ b/chrome/browser/chromeos/input_method/input_method_util.cc @@ -109,6 +109,11 @@ struct IdMaps { scoped_ptr<std::map<std::string, std::string> > id_to_display_name; scoped_ptr<std::map<std::string, std::string> > id_to_keyboard_overlay_id; + // Returns the singleton instance. + static IdMaps* GetInstance() { + return Singleton<IdMaps>::get(); + } + void ReloadMaps() { chromeos::InputMethodLibrary* library = chromeos::CrosLibrary::Get()->GetInputMethodLibrary(); @@ -536,8 +541,8 @@ std::string GetLanguageCodeFromInputMethodId( // defined in app/l10_util.cc. const char kDefaultLanguageCode[] = "en-US"; std::map<std::string, std::string>::const_iterator iter - = Singleton<IdMaps>::get()->id_to_language_code->find(input_method_id); - return (iter == Singleton<IdMaps>::get()->id_to_language_code->end()) ? + = IdMaps::GetInstance()->id_to_language_code->find(input_method_id); + return (iter == IdMaps::GetInstance()->id_to_language_code->end()) ? // Returning |kDefaultLanguageCode| here is not for Chrome OS but for // Ubuntu where the ibus-xkb-layouts engine could be missing. kDefaultLanguageCode : iter->second; @@ -555,7 +560,7 @@ std::string GetKeyboardLayoutName(const std::string& input_method_id) { std::string GetKeyboardOverlayId(const std::string& input_method_id) { const std::map<std::string, std::string>& id_map = - *(Singleton<IdMaps>::get()->id_to_keyboard_overlay_id); + *(IdMaps::GetInstance()->id_to_keyboard_overlay_id); std::map<std::string, std::string>::const_iterator iter = id_map.find(input_method_id); return (iter == id_map.end() ? "" : iter->second); @@ -565,8 +570,8 @@ std::string GetInputMethodDisplayNameFromId( const std::string& input_method_id) { static const char kDefaultDisplayName[] = "USA"; std::map<std::string, std::string>::const_iterator iter - = Singleton<IdMaps>::get()->id_to_display_name->find(input_method_id); - return (iter == Singleton<IdMaps>::get()->id_to_display_name->end()) ? + = IdMaps::GetInstance()->id_to_display_name->find(input_method_id); + return (iter == IdMaps::GetInstance()->id_to_display_name->end()) ? kDefaultDisplayName : iter->second; } @@ -603,7 +608,7 @@ void SortLanguageCodesByNames(std::vector<std::string>* language_codes) { void SortInputMethodIdsByNames(std::vector<std::string>* input_method_ids) { SortInputMethodIdsByNamesInternal( - *(Singleton<IdMaps>::get()->id_to_language_code), input_method_ids); + *(IdMaps::GetInstance()->id_to_language_code), input_method_ids); } void SortInputMethodIdsByNamesInternal( @@ -629,7 +634,7 @@ bool GetInputMethodIdsFromLanguageCode( InputMethodType type, std::vector<std::string>* out_input_method_ids) { return GetInputMethodIdsFromLanguageCodeInternal( - *Singleton<IdMaps>::get()->language_code_to_ids, + *IdMaps::GetInstance()->language_code_to_ids, normalized_language_code, type, out_input_method_ids); } @@ -687,7 +692,7 @@ void EnableInputMethods(const std::string& language_code, InputMethodType type, } void OnLocaleChanged() { - Singleton<IdMaps>::get()->ReloadMaps(); + IdMaps::GetInstance()->ReloadMaps(); } } // namespace input_method diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc index ad8da19..11df756 100644 --- a/chrome/browser/chromeos/login/login_utils.cc +++ b/chrome/browser/chromeos/login/login_utils.cc @@ -143,7 +143,9 @@ class LoginUtilsImpl : public LoginUtils { class LoginUtilsWrapper { public: - LoginUtilsWrapper() {} + static LoginUtilsWrapper* GetInstance() { + return Singleton<LoginUtilsWrapper>::get(); + } LoginUtils* get() { AutoLock create(create_lock_); @@ -157,6 +159,10 @@ class LoginUtilsWrapper { } private: + friend struct DefaultSingletonTraits<LoginUtilsWrapper>; + + LoginUtilsWrapper() {} + Lock create_lock_; scoped_ptr<LoginUtils> ptr_; @@ -454,11 +460,11 @@ void LoginUtilsImpl::PrewarmAuthentication() { } LoginUtils* LoginUtils::Get() { - return Singleton<LoginUtilsWrapper>::get()->get(); + return LoginUtilsWrapper::GetInstance()->get(); } void LoginUtils::Set(LoginUtils* mock) { - Singleton<LoginUtilsWrapper>::get()->reset(mock); + LoginUtilsWrapper::GetInstance()->reset(mock); } void LoginUtils::DoBrowserLaunch(Profile* profile) { diff --git a/chrome/browser/chromeos/login/signed_settings_temp_storage.cc b/chrome/browser/chromeos/login/signed_settings_temp_storage.cc index 2e731a5..24a0b38 100644 --- a/chrome/browser/chromeos/login/signed_settings_temp_storage.cc +++ b/chrome/browser/chromeos/login/signed_settings_temp_storage.cc @@ -4,12 +4,16 @@ #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" +#include "base/lazy_instance.h" #include "base/values.h" #include "chrome/browser/chromeos/login/ownership_service.h" #include "chrome/browser/chromeos/login/signed_settings.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/common/pref_names.h" +static base::LazyInstance<chromeos::SignedSettings::Delegate<bool> > + g_signed_settings_delegate(base::LINKER_INITIALIZED); + namespace chromeos { // static @@ -66,7 +70,7 @@ void SignedSettingsTempStorage::Finalize(PrefService* local_state) { temp_storage->GetStringWithoutPathExpansion(*it, &value); SignedSettings::CreateStorePropertyOp( *it, value, - Singleton< SignedSettings::Delegate<bool> >::get())->Execute(); + g_signed_settings_delegate.Pointer())->Execute(); } local_state->ClearPref(prefs::kSignedSettingsTempStorage); } diff --git a/chrome/browser/chromeos/usb_mount_observer.cc b/chrome/browser/chromeos/usb_mount_observer.cc index 2f1e7a4..e63718f 100644 --- a/chrome/browser/chromeos/usb_mount_observer.cc +++ b/chrome/browser/chromeos/usb_mount_observer.cc @@ -5,6 +5,7 @@ #include "chrome/browser/chromeos/usb_mount_observer.h" #include "base/command_line.h" +#include "base/singleton.h" #include "chrome/browser/dom_ui/filebrowse_ui.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" @@ -23,6 +24,11 @@ const int kPopupTop = 0; const int kPopupWidth = 250; const int kPopupHeight = 300; +// static +USBMountObserver* USBMountObserver::Get() { + return Singleton<USBMountObserver>::get(); +} + void USBMountObserver::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { diff --git a/chrome/browser/chromeos/usb_mount_observer.h b/chrome/browser/chromeos/usb_mount_observer.h index 5f30b31..66ab2bf 100644 --- a/chrome/browser/chromeos/usb_mount_observer.h +++ b/chrome/browser/chromeos/usb_mount_observer.h @@ -16,6 +16,7 @@ #include "chrome/common/notification_type.h" class Browser; +template <typename T> struct DefaultSingletonTraits; class Profile; namespace chromeos { // NOLINT @@ -31,12 +32,8 @@ class USBMountObserver : public chromeos::MountLibrary::Observer, std::string mount_path; }; - USBMountObserver() {} - ~USBMountObserver() {} + static USBMountObserver* Get(); - static USBMountObserver* Get() { - return Singleton<USBMountObserver>::get(); - } void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details); @@ -48,9 +45,13 @@ class USBMountObserver : public chromeos::MountLibrary::Observer, void ScanForDevices(chromeos::MountLibrary* obj); private: + friend struct DefaultSingletonTraits<USBMountObserver>; typedef std::vector<BrowserWithPath>::iterator BrowserIterator; BrowserIterator FindBrowserForPath(const std::string& path); + USBMountObserver() {} + ~USBMountObserver() {} + void RemoveBrowserFromVector(const std::string& path); // Used to create a window of a standard size, and add it to a list diff --git a/chrome/browser/chromeos/volume_bubble.cc b/chrome/browser/chromeos/volume_bubble.cc index f1850be..0846885 100644 --- a/chrome/browser/chromeos/volume_bubble.cc +++ b/chrome/browser/chromeos/volume_bubble.cc @@ -5,6 +5,7 @@ #include "chrome/browser/chromeos/volume_bubble.h" #include "app/resource_bundle.h" +#include "base/singleton.h" #include "grit/theme_resources.h" namespace chromeos { @@ -19,4 +20,9 @@ VolumeBubble::VolumeBubble() IDR_VOLUME_BUBBLE_MUTE_ICON)) { } +// static +VolumeBubble* VolumeBubble::instance() { + return Singleton<VolumeBubble>::get(); +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/volume_bubble.h b/chrome/browser/chromeos/volume_bubble.h index 9d0ee57..a99ae2c 100644 --- a/chrome/browser/chromeos/volume_bubble.h +++ b/chrome/browser/chromeos/volume_bubble.h @@ -6,17 +6,16 @@ #define CHROME_BROWSER_CHROMEOS_VOLUME_BUBBLE_H_ #pragma once -#include "base/singleton.h" #include "chrome/browser/chromeos/setting_level_bubble.h" +template <typename T> struct DefaultSingletonTraits; + namespace chromeos { // Singleton class controlling volume bubble. class VolumeBubble : public SettingLevelBubble { public: - static VolumeBubble* instance() { - return Singleton<VolumeBubble>::get(); - } + static VolumeBubble* instance(); private: friend struct DefaultSingletonTraits<VolumeBubble>; diff --git a/chrome/browser/dom_ui/constrained_html_ui.cc b/chrome/browser/dom_ui/constrained_html_ui.cc index d15644c..3d90faf 100644 --- a/chrome/browser/dom_ui/constrained_html_ui.cc +++ b/chrome/browser/dom_ui/constrained_html_ui.cc @@ -4,12 +4,15 @@ #include "chrome/browser/dom_ui/constrained_html_ui.h" -#include "base/singleton.h" +#include "base/lazy_instance.h" #include "chrome/browser/dom_ui/dom_ui_util.h" #include "chrome/browser/dom_ui/html_dialog_ui.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/common/bindings_policy.h" +static base::LazyInstance<PropertyAccessor<ConstrainedHtmlUIDelegate*> > + g_constrained_html_ui_property_accessor(base::LINKER_INITIALIZED); + ConstrainedHtmlUI::ConstrainedHtmlUI(TabContents* contents) : DOMUI(contents) { } @@ -50,5 +53,5 @@ ConstrainedHtmlUIDelegate* // static PropertyAccessor<ConstrainedHtmlUIDelegate*>& ConstrainedHtmlUI::GetPropertyAccessor() { - return *Singleton<PropertyAccessor<ConstrainedHtmlUIDelegate*> >::get(); + return g_constrained_html_ui_property_accessor.Get(); } diff --git a/chrome/browser/dom_ui/html_dialog_ui.cc b/chrome/browser/dom_ui/html_dialog_ui.cc index ee9ce34..fbea1f6 100644 --- a/chrome/browser/dom_ui/html_dialog_ui.cc +++ b/chrome/browser/dom_ui/html_dialog_ui.cc @@ -5,13 +5,16 @@ #include "chrome/browser/dom_ui/html_dialog_ui.h" #include "base/callback.h" -#include "base/singleton.h" +#include "base/lazy_instance.h" #include "base/values.h" #include "chrome/browser/dom_ui/dom_ui_util.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/common/bindings_policy.h" +static base::LazyInstance<PropertyAccessor<HtmlDialogUIDelegate*> > + g_html_dialog_ui_property_accessor(base::LINKER_INITIALIZED); + HtmlDialogUI::HtmlDialogUI(TabContents* tab_contents) : DOMUI(tab_contents) { } @@ -28,7 +31,7 @@ HtmlDialogUI::~HtmlDialogUI() { // static PropertyAccessor<HtmlDialogUIDelegate*>& HtmlDialogUI::GetPropertyAccessor() { - return *Singleton< PropertyAccessor<HtmlDialogUIDelegate*> >::get(); + return g_html_dialog_ui_property_accessor.Get(); } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/dom_ui/mediaplayer_ui.cc b/chrome/browser/dom_ui/mediaplayer_ui.cc index 2fb141c..3119e534 100644 --- a/chrome/browser/dom_ui/mediaplayer_ui.cc +++ b/chrome/browser/dom_ui/mediaplayer_ui.cc @@ -355,6 +355,11 @@ DISABLE_RUNNABLE_METHOD_REFCOUNT(MediaPlayer); MediaPlayer::~MediaPlayer() { } +// static +MediaPlayer* MediaPlayer::Get() { + return Singleton<MediaPlayer>::get(); +} + void MediaPlayer::EnqueueMediaURL(const GURL& url, Browser* creator) { if (!Enabled()) { return; diff --git a/chrome/browser/dom_ui/mediaplayer_ui.h b/chrome/browser/dom_ui/mediaplayer_ui.h index 8a34d7c..ec198b2 100644 --- a/chrome/browser/dom_ui/mediaplayer_ui.h +++ b/chrome/browser/dom_ui/mediaplayer_ui.h @@ -9,7 +9,6 @@ #include <set> #include <vector> -#include "base/singleton.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" #include "chrome/browser/dom_ui/dom_ui.h" #include "chrome/common/notification_observer.h" @@ -19,6 +18,7 @@ #include "net/base/directory_lister.h" #include "net/url_request/url_request.h" +template <typename T> struct DefaultSingletonTraits; class GURL; class MediaplayerHandler; class Browser; @@ -89,11 +89,11 @@ class MediaPlayer : public NotificationObserver, const NotificationDetails& details); // Getter for the singleton. - static MediaPlayer* Get() { - return Singleton<MediaPlayer>::get(); - } + static MediaPlayer* Get(); private: + friend struct DefaultSingletonTraits<MediaPlayer>; + MediaPlayer(); // Popup the mediaplayer, this shows the browser, and sets up its @@ -147,7 +147,6 @@ class MediaPlayer : public NotificationObserver, // List of mimetypes that the mediaplayer should listen to. Used for // interceptions of url GETs. std::set<std::string> supported_mime_types_; - friend struct DefaultSingletonTraits<MediaPlayer>; DISALLOW_COPY_AND_ASSIGN(MediaPlayer); }; diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index dbed4db..57a61a4 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -16,8 +16,8 @@ #include "base/file_util.h" #include "base/i18n/rtl.h" #include "base/i18n/time_formatting.h" +#include "base/lazy_instance.h" #include "base/path_service.h" -#include "base/singleton.h" #include "base/string16.h" #include "base/string_number_conversions.h" #include "base/stringprintf.h" @@ -108,12 +108,15 @@ class DefaultDownloadDirectory { } } } - friend struct DefaultSingletonTraits<DefaultDownloadDirectory>; + friend struct base::DefaultLazyInstanceTraits<DefaultDownloadDirectory>; FilePath path_; }; +static base::LazyInstance<DefaultDownloadDirectory> + g_default_download_directory(base::LINKER_INITIALIZED); + const FilePath& GetDefaultDownloadDirectory() { - return Singleton<DefaultDownloadDirectory>::get()->path(); + return g_default_download_directory.Get().path(); } bool CreateTemporaryFileForDownload(FilePath* temp_file) { diff --git a/chrome/browser/extensions/crx_installer.cc b/chrome/browser/extensions/crx_installer.cc index 294bdcb..6d937a6 100644 --- a/chrome/browser/extensions/crx_installer.cc +++ b/chrome/browser/extensions/crx_installer.cc @@ -9,9 +9,9 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/file_util.h" +#include "base/lazy_instance.h" #include "base/path_service.h" #include "base/scoped_temp_dir.h" -#include "base/singleton.h" #include "base/stl_util-inl.h" #include "base/stringprintf.h" #include "base/time.h" @@ -51,25 +51,28 @@ struct WhitelistedInstallData { std::set<std::string> ids; }; +static base::LazyInstance<WhitelistedInstallData> + g_whitelisted_install_data(base::LINKER_INITIALIZED); + } // namespace // static void CrxInstaller::SetWhitelistedInstallId(const std::string& id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - Singleton<WhitelistedInstallData>::get()->ids.insert(id); + g_whitelisted_install_data.Get().ids.insert(id); } // static bool CrxInstaller::IsIdWhitelisted(const std::string& id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - std::set<std::string>& ids = Singleton<WhitelistedInstallData>::get()->ids; + std::set<std::string>& ids = g_whitelisted_install_data.Get().ids; return ContainsKey(ids, id); } // static bool CrxInstaller::ClearWhitelistedInstallId(const std::string& id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - std::set<std::string>& ids = Singleton<WhitelistedInstallData>::get()->ids; + std::set<std::string>& ids = g_whitelisted_install_data.Get().ids; if (ContainsKey(ids, id)) { ids.erase(id); return true; diff --git a/chrome/browser/extensions/extension_omnibox_api.cc b/chrome/browser/extensions/extension_omnibox_api.cc index 8492788..760e459 100644 --- a/chrome/browser/extensions/extension_omnibox_api.cc +++ b/chrome/browser/extensions/extension_omnibox_api.cc @@ -5,7 +5,7 @@ #include "chrome/browser/extensions/extension_omnibox_api.h" #include "base/json/json_writer.h" -#include "base/singleton.h" +#include "base/lazy_instance.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "base/values.h" @@ -36,8 +36,11 @@ const char kDescriptionStylesType[] = "type"; const char kDescriptionStylesOffset[] = "offset"; const char kDescriptionStylesLength[] = "length"; +static base::LazyInstance<PropertyAccessor<ExtensionOmniboxSuggestion> > + g_extension_omnibox_suggestion_property_accessor(base::LINKER_INITIALIZED); + PropertyAccessor<ExtensionOmniboxSuggestion>& GetPropertyAccessor() { - return *Singleton< PropertyAccessor<ExtensionOmniboxSuggestion> >::get(); + return g_extension_omnibox_suggestion_property_accessor.Get(); } // Returns the suggestion object set by the extension via the diff --git a/chrome/browser/extensions/extension_test_api.cc b/chrome/browser/extensions/extension_test_api.cc index 7afd5eb..104e51b 100644 --- a/chrome/browser/extensions/extension_test_api.cc +++ b/chrome/browser/extensions/extension_test_api.cc @@ -6,6 +6,7 @@ #include <string> +#include "base/singleton.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/extensions/extensions_quota_service.h" #include "chrome/browser/profiles/profile.h" @@ -93,17 +94,23 @@ void ExtensionTestSendMessageFunction::Reply(const std::string& message) { // static void ExtensionTestGetConfigFunction::set_test_config_state( DictionaryValue* value) { - TestConfigState* test_config_state = Singleton<TestConfigState>::get(); + TestConfigState* test_config_state = TestConfigState::GetInstance(); test_config_state->set_config_state(value); } ExtensionTestGetConfigFunction::TestConfigState::TestConfigState() : config_state_(NULL) {} +// static +ExtensionTestGetConfigFunction::TestConfigState* +ExtensionTestGetConfigFunction::TestConfigState::GetInstance() { + return Singleton<TestConfigState>::get(); +} + ExtensionTestGetConfigFunction::~ExtensionTestGetConfigFunction() {} bool ExtensionTestGetConfigFunction::RunImpl() { - TestConfigState* test_config_state = Singleton<TestConfigState>::get(); + TestConfigState* test_config_state = TestConfigState::GetInstance(); if (!test_config_state->config_state()) { error_ = kNoTestConfigDataError; diff --git a/chrome/browser/extensions/extension_test_api.h b/chrome/browser/extensions/extension_test_api.h index 27b55dc..1a0baa0 100644 --- a/chrome/browser/extensions/extension_test_api.h +++ b/chrome/browser/extensions/extension_test_api.h @@ -6,10 +6,11 @@ #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_API_H_ #pragma once -#include "base/singleton.h" #include "base/values.h" #include "chrome/browser/extensions/extension_function.h" +template <typename T> struct DefaultSingletonTraits; + class ExtensionTestPassFunction : public SyncExtensionFunction { ~ExtensionTestPassFunction(); virtual bool RunImpl(); @@ -65,6 +66,8 @@ class ExtensionTestGetConfigFunction : public SyncExtensionFunction { // state, owned by the test code. class TestConfigState { public: + static TestConfigState* GetInstance(); + void set_config_state(DictionaryValue* config_state) { config_state_ = config_state; } diff --git a/chrome/browser/file_path_watcher/file_path_watcher_inotify.cc b/chrome/browser/file_path_watcher/file_path_watcher_inotify.cc index 1ce4b8c..c65b22d 100644 --- a/chrome/browser/file_path_watcher/file_path_watcher_inotify.cc +++ b/chrome/browser/file_path_watcher/file_path_watcher_inotify.cc @@ -20,11 +20,11 @@ #include "base/file_path.h" #include "base/file_util.h" #include "base/hash_tables.h" +#include "base/lazy_instance.h" #include "base/lock.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/scoped_ptr.h" -#include "base/singleton.h" #include "base/task.h" #include "base/thread.h" @@ -51,7 +51,7 @@ class InotifyReader { void OnInotifyEvent(const inotify_event* event); private: - friend struct DefaultSingletonTraits<InotifyReader>; + friend struct ::base::DefaultLazyInstanceTraits<InotifyReader>; typedef std::set<FilePathWatcherImpl*> WatcherSet; @@ -199,6 +199,9 @@ class InotifyReaderTask : public Task { DISALLOW_COPY_AND_ASSIGN(InotifyReaderTask); }; +static base::LazyInstance<InotifyReader> g_inotify_reader( + base::LINKER_INITIALIZED); + InotifyReader::InotifyReader() : thread_("inotify_reader"), inotify_fd_(inotify_init()), @@ -366,7 +369,7 @@ void FilePathWatcherImpl::Cancel() { for (WatchVector::iterator watch_entry(watches_.begin()); watch_entry != watches_.end(); ++watch_entry) { if (watch_entry->watch_ != InotifyReader::kInvalidWatch) - Singleton<InotifyReader>::get()->RemoveWatch(watch_entry->watch_, this); + g_inotify_reader.Get().RemoveWatch(watch_entry->watch_, this); } watches_.clear(); delegate_ = NULL; @@ -385,8 +388,7 @@ bool FilePathWatcherImpl::UpdateWatches() { watch_entry != watches_.end(); ++watch_entry) { InotifyReader::Watch old_watch = watch_entry->watch_; if (path_valid) { - watch_entry->watch_ = - Singleton<InotifyReader>::get()->AddWatch(path, this); + watch_entry->watch_ = g_inotify_reader.Get().AddWatch(path, this); if (watch_entry->watch_ == InotifyReader::kInvalidWatch) { path_valid = false; } @@ -395,7 +397,7 @@ bool FilePathWatcherImpl::UpdateWatches() { } if (old_watch != InotifyReader::kInvalidWatch && old_watch != watch_entry->watch_) { - Singleton<InotifyReader>::get()->RemoveWatch(old_watch, this); + g_inotify_reader.Get().RemoveWatch(old_watch, this); } path = path.Append(watch_entry->subdir_); } diff --git a/chrome/browser/gtk/accelerators_gtk.cc b/chrome/browser/gtk/accelerators_gtk.cc index c0a2f73..5456b0d 100644 --- a/chrome/browser/gtk/accelerators_gtk.cc +++ b/chrome/browser/gtk/accelerators_gtk.cc @@ -8,6 +8,7 @@ #include <gdk/gdkkeysyms.h> #include <X11/XF86keysym.h> +#include "base/singleton.h" #include "chrome/app/chrome_command_ids.h" namespace { @@ -190,6 +191,11 @@ AcceleratorsGtk::AcceleratorsGtk() { AcceleratorsGtk::~AcceleratorsGtk() {} +// static +AcceleratorsGtk* AcceleratorsGtk::GetInstance() { + return Singleton<AcceleratorsGtk>::get(); +} + const menus::AcceleratorGtk* AcceleratorsGtk::GetPrimaryAcceleratorForCommand( int command_id) { base::hash_map<int, menus::AcceleratorGtk>::const_iterator iter = diff --git a/chrome/browser/gtk/accelerators_gtk.h b/chrome/browser/gtk/accelerators_gtk.h index 1ea7ce4..2e45700 100644 --- a/chrome/browser/gtk/accelerators_gtk.h +++ b/chrome/browser/gtk/accelerators_gtk.h @@ -9,15 +9,17 @@ #include "app/menus/accelerator_gtk.h" #include "base/hash_tables.h" +template <typename T> struct DefaultSingletonTraits; + class AcceleratorsGtk { public: - AcceleratorsGtk(); - ~AcceleratorsGtk(); - typedef std::vector<std::pair<int, menus::AcceleratorGtk> > AcceleratorGtkList; typedef AcceleratorGtkList::const_iterator const_iterator; + // Returns the singleton instance. + static AcceleratorsGtk* GetInstance(); + const_iterator const begin() { return all_accelerators_.begin(); } @@ -30,6 +32,11 @@ class AcceleratorsGtk { const menus::AcceleratorGtk* GetPrimaryAcceleratorForCommand(int command_id); private: + friend struct DefaultSingletonTraits<AcceleratorsGtk>; + + AcceleratorsGtk(); + ~AcceleratorsGtk(); + base::hash_map<int, menus::AcceleratorGtk> primary_accelerators_; AcceleratorGtkList all_accelerators_; diff --git a/chrome/browser/gtk/browser_titlebar.cc b/chrome/browser/gtk/browser_titlebar.cc index 0e7e290a2..7af5a5e 100644 --- a/chrome/browser/gtk/browser_titlebar.cc +++ b/chrome/browser/gtk/browser_titlebar.cc @@ -307,7 +307,7 @@ void BrowserTitlebar::Init() { #if defined(USE_GCONF) // Either read the gconf database and register for updates (on GNOME), or use // the default value (anywhere else). - Singleton<GConfTitlebarListener>()->SetTitlebarButtons(this); + GConfTitlebarListener::GetInstance()->SetTitlebarButtons(this); #else BuildButtons(kDefaultButtonString); #endif @@ -373,7 +373,7 @@ void BrowserTitlebar::Init() { BrowserTitlebar::~BrowserTitlebar() { ActiveWindowWatcherX::RemoveObserver(this); #if defined(USE_GCONF) - Singleton<GConfTitlebarListener>()->RemoveObserver(this); + GConfTitlebarListener::GetInstance()->RemoveObserver(this); #endif } @@ -849,7 +849,7 @@ void BrowserTitlebar::ExecuteCommand(int command_id) { bool BrowserTitlebar::GetAcceleratorForCommandId( int command_id, menus::Accelerator* accelerator) { const menus::AcceleratorGtk* accelerator_gtk = - Singleton<AcceleratorsGtk>()->GetPrimaryAcceleratorForCommand( + AcceleratorsGtk::GetInstance()->GetPrimaryAcceleratorForCommand( command_id); if (accelerator_gtk) *accelerator = *accelerator_gtk; diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index a50a372..ad10e51 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -329,7 +329,7 @@ bool BrowserToolbarGtk::GetAcceleratorForCommandId( int id, menus::Accelerator* accelerator) { const menus::AcceleratorGtk* accelerator_gtk = - Singleton<AcceleratorsGtk>()->GetPrimaryAcceleratorForCommand(id); + AcceleratorsGtk::GetInstance()->GetPrimaryAcceleratorForCommand(id); if (accelerator_gtk) *accelerator = *accelerator_gtk; return !!accelerator_gtk; diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index f0462e5..25c8f12 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -663,7 +663,7 @@ void BrowserWindowGtk::Close() { if (accel_group_) { // Disconnecting the keys we connected to our accelerator group frees the // closures allocated in ConnectAccelerators. - AcceleratorsGtk* accelerators = Singleton<AcceleratorsGtk>().get(); + AcceleratorsGtk* accelerators = AcceleratorsGtk::GetInstance(); for (AcceleratorsGtk::const_iterator iter = accelerators->begin(); iter != accelerators->end(); ++iter) { gtk_accel_group_disconnect_key(accel_group_, @@ -1721,7 +1721,7 @@ void BrowserWindowGtk::ConnectAccelerators() { accel_group_ = gtk_accel_group_new(); gtk_window_add_accel_group(window_, accel_group_); - AcceleratorsGtk* accelerators = Singleton<AcceleratorsGtk>().get(); + AcceleratorsGtk* accelerators = AcceleratorsGtk::GetInstance(); for (AcceleratorsGtk::const_iterator iter = accelerators->begin(); iter != accelerators->end(); ++iter) { gtk_accel_group_connect( diff --git a/chrome/browser/gtk/gconf_titlebar_listener.cc b/chrome/browser/gtk/gconf_titlebar_listener.cc index 237332f..ae89f1a 100644 --- a/chrome/browser/gtk/gconf_titlebar_listener.cc +++ b/chrome/browser/gtk/gconf_titlebar_listener.cc @@ -7,6 +7,7 @@ #include <gtk/gtk.h> #include "base/scoped_ptr.h" +#include "base/singleton.h" #include "base/environment.h" #include "base/nix/xdg_util.h" #include "chrome/browser/gtk/browser_titlebar.h" @@ -25,6 +26,11 @@ const char* kMetacityGeneral = "/apps/metacity/general"; // Public interface: +// static +GConfTitlebarListener* GConfTitlebarListener::GetInstance() { + return Singleton<GConfTitlebarListener>::get(); +} + void GConfTitlebarListener::SetTitlebarButtons(BrowserTitlebar* titlebar) { if (client_) { titlebar->BuildButtons(current_value_); diff --git a/chrome/browser/gtk/gconf_titlebar_listener.h b/chrome/browser/gtk/gconf_titlebar_listener.h index 19318eb..b96b759 100644 --- a/chrome/browser/gtk/gconf_titlebar_listener.h +++ b/chrome/browser/gtk/gconf_titlebar_listener.h @@ -13,9 +13,10 @@ #include <string> #include "app/gtk_signal.h" -#include "base/singleton.h" +#include "base/basictypes.h" class BrowserTitlebar; +template <typename T> struct DefaultSingletonTraits; // On GNOME desktops, subscribes to the gconf key which controlls button order. // Everywhere else, SetTiltebarButtons() just calls back into BrowserTitlebar @@ -24,6 +25,9 @@ class BrowserTitlebar; // Meant to be used as a Singleton through base/singleton.h's interface. class GConfTitlebarListener { public: + // Returns the singleton instance. + static GConfTitlebarListener* GetInstance(); + // Sets the current titlebar button order. On GNOME desktops, also subscribes // to further notifications when this changes. void SetTitlebarButtons(BrowserTitlebar* titlebar); diff --git a/chrome/browser/gtk/tabs/tab_gtk.cc b/chrome/browser/gtk/tabs/tab_gtk.cc index 958498d..4172569 100644 --- a/chrome/browser/gtk/tabs/tab_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_gtk.cc @@ -69,7 +69,7 @@ class TabGtk::ContextMenuController : public menus::SimpleMenuModel::Delegate, &browser_command)) return false; const menus::AcceleratorGtk* accelerator_gtk = - Singleton<AcceleratorsGtk>()->GetPrimaryAcceleratorForCommand( + AcceleratorsGtk::GetInstance()->GetPrimaryAcceleratorForCommand( browser_command); if (accelerator_gtk) *accelerator = *accelerator_gtk; diff --git a/chrome/browser/net/predictor_api.cc b/chrome/browser/net/predictor_api.cc index 33bf25d..6898dfa 100644 --- a/chrome/browser/net/predictor_api.cc +++ b/chrome/browser/net/predictor_api.cc @@ -8,7 +8,7 @@ #include <string> #include "base/metrics/field_trial.h" -#include "base/singleton.h" +#include "base/lazy_instance.h" #include "base/stl_util-inl.h" #include "base/string_number_conversions.h" #include "base/thread.h" @@ -330,7 +330,8 @@ class OffTheRecordObserver : public NotificationObserver { } private: - friend struct DefaultSingletonTraits<OffTheRecordObserver>; + friend struct base::DefaultLazyInstanceTraits<OffTheRecordObserver>; + OffTheRecordObserver() : count_off_the_record_windows_(0) {} ~OffTheRecordObserver() {} @@ -340,6 +341,9 @@ class OffTheRecordObserver : public NotificationObserver { DISALLOW_COPY_AND_ASSIGN(OffTheRecordObserver); }; +static base::LazyInstance<OffTheRecordObserver> g_off_the_record_observer( + base::LINKER_INITIALIZED); + //------------------------------------------------------------------------------ // This section supports the about:dns page. //------------------------------------------------------------------------------ @@ -576,7 +580,7 @@ PredictorInit::PredictorInit(PrefService* user_prefs, // We will register the incognito observer regardless of whether prefetching // is enabled, as it is also used to clear the host cache. - Singleton<OffTheRecordObserver>::get()->Register(); + g_off_the_record_observer.Get().Register(); if (trial_->group() != disabled_prefetch) { // Initialize the DNS prefetch system. diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc index 25df2d5..0259ed4 100644 --- a/chrome/browser/policy/configuration_policy_pref_store.cc +++ b/chrome/browser/policy/configuration_policy_pref_store.cc @@ -5,9 +5,9 @@ #include "chrome/browser/policy/configuration_policy_pref_store.h" #include "base/command_line.h" +#include "base/lazy_instance.h" #include "base/logging.h" #include "base/path_service.h" -#include "base/singleton.h" #include "base/string16.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" @@ -68,6 +68,9 @@ class ConfigurationPolicyProviderKeeper { DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderKeeper); }; +static base::LazyInstance<ConfigurationPolicyProviderKeeper> + g_configuration_policy_provider_keeper(base::LINKER_INITIALIZED); + ConfigurationPolicyProvider* ConfigurationPolicyProviderKeeper::CreateManagedPlatformProvider() { const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = @@ -372,9 +375,8 @@ void ConfigurationPolicyPrefStore::Apply(ConfigurationPolicyType policy, // static ConfigurationPolicyPrefStore* ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore() { - ConfigurationPolicyProviderKeeper* keeper = - Singleton<ConfigurationPolicyProviderKeeper>::get(); - return new ConfigurationPolicyPrefStore(keeper->managed_platform_provider()); + return new ConfigurationPolicyPrefStore( + g_configuration_policy_provider_keeper.Get().managed_platform_provider()); } // static @@ -382,7 +384,7 @@ ConfigurationPolicyPrefStore* ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore( Profile* profile) { ConfigurationPolicyProviderKeeper* keeper = - Singleton<ConfigurationPolicyProviderKeeper>::get(); + g_configuration_policy_provider_keeper.Pointer(); ConfigurationPolicyProvider* provider = NULL; if (profile) provider = profile->GetPolicyContext()->GetDeviceManagementPolicyProvider(); @@ -394,9 +396,8 @@ ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore( // static ConfigurationPolicyPrefStore* ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore() { - ConfigurationPolicyProviderKeeper* keeper = - Singleton<ConfigurationPolicyProviderKeeper>::get(); - return new ConfigurationPolicyPrefStore(keeper->recommended_provider()); + return new ConfigurationPolicyPrefStore( + g_configuration_policy_provider_keeper.Get().recommended_provider()); } // static diff --git a/chrome/browser/renderer_host/render_widget_host.cc b/chrome/browser/renderer_host/render_widget_host.cc index eb04155..ae142eb 100644 --- a/chrome/browser/renderer_host/render_widget_host.cc +++ b/chrome/browser/renderer_host/render_widget_host.cc @@ -101,7 +101,7 @@ RenderWidgetHost::RenderWidgetHost(RenderProcessHost* process, if (CommandLine::ForCurrentProcess()->HasSwitch( switches::kForceRendererAccessibility) || - Singleton<BrowserAccessibilityState>()->IsAccessibleBrowser()) { + BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) { EnableRendererAccessibility(); } } diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm index 8cb6fc3..bd4a722 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -524,7 +524,7 @@ RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) // Turn on accessibility only if VoiceOver is running. if (IsVoiceOverRunning()) { - Singleton<BrowserAccessibilityState>()->OnScreenReaderDetected(); + BrowserAccessibilityState::GetInstance()->OnScreenReaderDetected(); render_widget_host_->EnableRendererAccessibility(); } } diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.cc b/chrome/browser/renderer_host/render_widget_host_view_win.cc index f41badf..022d027 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_win.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_win.cc @@ -1646,7 +1646,7 @@ LRESULT RenderWidgetHostViewWin::OnGetObject(UINT message, WPARAM wparam, if (kIdCustom == lparam) { // An MSAA client requestes our custom id. Assume that we have detected an // active windows screen reader. - Singleton<BrowserAccessibilityState>()->OnScreenReaderDetected(); + BrowserAccessibilityState::GetInstance()->OnScreenReaderDetected(); render_widget_host_->EnableRendererAccessibility(); // Return with failure. diff --git a/chrome/browser/renderer_host/resource_message_filter_gtk.cc b/chrome/browser/renderer_host/resource_message_filter_gtk.cc index e2bf641..f10931e 100644 --- a/chrome/browser/renderer_host/resource_message_filter_gtk.cc +++ b/chrome/browser/renderer_host/resource_message_filter_gtk.cc @@ -10,8 +10,8 @@ #include "app/clipboard/clipboard.h" #include "app/x11_util.h" #include "base/file_util.h" +#include "base/lazy_instance.h" #include "base/path_service.h" -#include "base/singleton.h" #include "chrome/browser/browser_thread.h" #if defined(TOOLKIT_GTK) #include "chrome/browser/printing/print_dialog_gtk.h" @@ -37,6 +37,9 @@ struct PrintingFileDescriptorMap { FdMap map; }; +static base::LazyInstance<PrintingFileDescriptorMap> + g_printing_file_descriptor_map(base::LINKER_INITIALIZED); + } // namespace // We get null window_ids passed into the two functions below; please see @@ -234,7 +237,7 @@ void ResourceMessageFilter::DoOnAllocateTempFileForPrinting( file_util::CreateTemporaryFile(&path)) { int fd = open(path.value().c_str(), O_WRONLY); if (fd >= 0) { - FdMap* map = &Singleton<PrintingFileDescriptorMap>::get()->map; + FdMap* map = &g_printing_file_descriptor_map.Get().map; FdMap::iterator it = map->find(fd); if (it != map->end()) { NOTREACHED() << "The file descriptor is in use. fd=" << fd; @@ -366,7 +369,7 @@ void ResourceMessageFilter::OnAllocateTempFileForPrinting( // Called on the IO thread. void ResourceMessageFilter::OnTempFileForPrintingWritten(int fd_in_browser) { - FdMap* map = &Singleton<PrintingFileDescriptorMap>::get()->map; + FdMap* map = &g_printing_file_descriptor_map.Get().map; FdMap::iterator it = map->find(fd_in_browser); if (it == map->end()) { NOTREACHED() << "Got a file descriptor that we didn't pass to the " diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc index 9bc9f7d..bc72883 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc @@ -11,7 +11,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/i18n/rtl.h" -#include "base/singleton.h" +#include "base/lazy_instance.h" #include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "base/values.h" @@ -86,13 +86,17 @@ class SafeBrowsingBlockingPageFactoryImpl } private: - friend struct DefaultSingletonTraits<SafeBrowsingBlockingPageFactoryImpl>; + friend struct base::DefaultLazyInstanceTraits< + SafeBrowsingBlockingPageFactoryImpl>; SafeBrowsingBlockingPageFactoryImpl() { } DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageFactoryImpl); }; +static base::LazyInstance<SafeBrowsingBlockingPageFactoryImpl> + g_safe_browsing_blocking_page_factory_impl(base::LINKER_INITIALIZED); + SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( SafeBrowsingService* sb_service, TabContents* tab_contents, @@ -541,7 +545,7 @@ void SafeBrowsingBlockingPage::ShowBlockingPage( // Set up the factory if this has not been done already (tests do that // before this method is called). if (!factory_) - factory_ = Singleton<SafeBrowsingBlockingPageFactoryImpl>::get(); + factory_ = g_safe_browsing_blocking_page_factory_impl.Pointer(); SafeBrowsingBlockingPage* blocking_page = factory_->CreateSafeBrowsingPage(sb_service, tab_contents, resources); blocking_page->Show(); diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc index c8e3c09..6248624 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.cc +++ b/chrome/browser/safe_browsing/safe_browsing_service.cc @@ -6,8 +6,8 @@ #include "base/callback.h" #include "base/command_line.h" +#include "base/lazy_instance.h" #include "base/path_service.h" -#include "base/singleton.h" #include "base/string_util.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_thread.h" @@ -62,13 +62,16 @@ class SafeBrowsingServiceFactoryImpl : public SafeBrowsingServiceFactory { } private: - friend struct DefaultSingletonTraits<SafeBrowsingServiceFactoryImpl>; + friend struct base::DefaultLazyInstanceTraits<SafeBrowsingServiceFactoryImpl>; SafeBrowsingServiceFactoryImpl() { } DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactoryImpl); }; +static base::LazyInstance<SafeBrowsingServiceFactoryImpl> + g_safe_browsing_service_factory_impl(base::LINKER_INITIALIZED); + struct SafeBrowsingService::WhiteListedEntry { int render_process_host_id; int render_view_id; @@ -97,7 +100,7 @@ SafeBrowsingService::SafeBrowsingCheck::~SafeBrowsingCheck() {} /* static */ SafeBrowsingService* SafeBrowsingService::CreateSafeBrowsingService() { if (!factory_) - factory_ = Singleton<SafeBrowsingServiceFactoryImpl>::get(); + factory_ = g_safe_browsing_service_factory_impl.Pointer(); return factory_->CreateSafeBrowsingService(); } diff --git a/chrome/browser/service/service_process_control.cc b/chrome/browser/service/service_process_control.cc index fdeea6d..bd98319 100644 --- a/chrome/browser/service/service_process_control.cc +++ b/chrome/browser/service/service_process_control.cc @@ -129,7 +129,7 @@ void ServiceProcessControl::ConnectInternal() { // We just established a channel with the service process. Notify it if an // upgrade is available. - if (Singleton<UpgradeDetector>::get()->notify_upgrade()) { + if (UpgradeDetector::GetInstance()->notify_upgrade()) { Send(new ServiceMsg_UpdateAvailable); } else { if (registrar_.IsEmpty()) diff --git a/chrome/browser/speech/speech_input_dispatcher_host.cc b/chrome/browser/speech/speech_input_dispatcher_host.cc index 1563af3..add39af 100644 --- a/chrome/browser/speech/speech_input_dispatcher_host.cc +++ b/chrome/browser/speech/speech_input_dispatcher_host.cc @@ -4,7 +4,7 @@ #include "chrome/browser/speech/speech_input_dispatcher_host.h" -#include "base/singleton.h" +#include "base/lazy_instance.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_view_host_notification_task.h" @@ -40,7 +40,7 @@ class SpeechInputDispatcherHost::SpeechInputCallers { int render_view_id; int request_id; }; - friend struct DefaultSingletonTraits<SpeechInputCallers>; + friend struct base::DefaultLazyInstanceTraits<SpeechInputCallers>; SpeechInputCallers(); @@ -48,6 +48,9 @@ class SpeechInputDispatcherHost::SpeechInputCallers { int next_id_; }; +static base::LazyInstance<SpeechInputDispatcherHost::SpeechInputCallers> + g_speech_input_callers(base::LINKER_INITIALIZED); + SpeechInputDispatcherHost::SpeechInputCallers::SpeechInputCallers() : next_id_(1) { } @@ -107,8 +110,7 @@ SpeechInputManager::AccessorMethod* SpeechInputDispatcherHost::SpeechInputDispatcherHost( int resource_message_filter_process_id) - : resource_message_filter_process_id_(resource_message_filter_process_id), - callers_(Singleton<SpeechInputCallers>::get()) { + : resource_message_filter_process_id_(resource_message_filter_process_id) { // This is initialized by ResourceMessageFilter. Do not add any non-trivial // initialization here, instead do it lazily when required (e.g. see the // method |manager()|) or add an Init() method. @@ -143,8 +145,8 @@ void SpeechInputDispatcherHost::OnStartRecognition( const gfx::Rect& element_rect, const std::string& language, const std::string& grammar) { - int caller_id = callers_->CreateId(resource_message_filter_process_id_, - render_view_id, request_id); + int caller_id = g_speech_input_callers.Get().CreateId( + resource_message_filter_process_id_, render_view_id, request_id); manager()->StartRecognition(this, caller_id, resource_message_filter_process_id_, render_view_id, element_rect, @@ -153,18 +155,19 @@ void SpeechInputDispatcherHost::OnStartRecognition( void SpeechInputDispatcherHost::OnCancelRecognition(int render_view_id, int request_id) { - int caller_id = callers_->GetId(resource_message_filter_process_id_, - render_view_id, request_id); + int caller_id = g_speech_input_callers.Get().GetId( + resource_message_filter_process_id_, render_view_id, request_id); if (caller_id) { manager()->CancelRecognition(caller_id); - callers_->RemoveId(caller_id); // Request sequence ended so remove mapping. + // Request sequence ended so remove mapping. + g_speech_input_callers.Get().RemoveId(caller_id); } } void SpeechInputDispatcherHost::OnStopRecording(int render_view_id, int request_id) { - int caller_id = callers_->GetId(resource_message_filter_process_id_, - render_view_id, request_id); + int caller_id = g_speech_input_callers.Get().GetId( + resource_message_filter_process_id_, render_view_id, request_id); if (caller_id) manager()->StopRecording(caller_id); } @@ -180,8 +183,9 @@ void SpeechInputDispatcherHost::SetRecognitionResult( int caller_id, const SpeechInputResultArray& result) { VLOG(1) << "SpeechInputDispatcherHost::SetRecognitionResult enter"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - int caller_render_view_id = callers_->render_view_id(caller_id); - int caller_request_id = callers_->request_id(caller_id); + int caller_render_view_id = + g_speech_input_callers.Get().render_view_id(caller_id); + int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); SendMessageToRenderView( new ViewMsg_SpeechInput_SetRecognitionResult(caller_render_view_id, caller_request_id, @@ -193,8 +197,9 @@ void SpeechInputDispatcherHost::SetRecognitionResult( void SpeechInputDispatcherHost::DidCompleteRecording(int caller_id) { VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecording enter"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - int caller_render_view_id = callers_->render_view_id(caller_id); - int caller_request_id = callers_->request_id(caller_id); + int caller_render_view_id = + g_speech_input_callers.Get().render_view_id(caller_id); + int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); SendMessageToRenderView( new ViewMsg_SpeechInput_RecordingComplete(caller_render_view_id, caller_request_id), @@ -205,13 +210,15 @@ void SpeechInputDispatcherHost::DidCompleteRecording(int caller_id) { void SpeechInputDispatcherHost::DidCompleteRecognition(int caller_id) { VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition enter"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - int caller_render_view_id = callers_->render_view_id(caller_id); - int caller_request_id = callers_->request_id(caller_id); + int caller_render_view_id = + g_speech_input_callers.Get().render_view_id(caller_id); + int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); SendMessageToRenderView( new ViewMsg_SpeechInput_RecognitionComplete(caller_render_view_id, caller_request_id), caller_render_view_id); - callers_->RemoveId(caller_id); // Request sequence ended, so remove mapping. + // Request sequence ended, so remove mapping. + g_speech_input_callers.Get().RemoveId(caller_id); VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; } diff --git a/chrome/browser/speech/speech_input_dispatcher_host.h b/chrome/browser/speech/speech_input_dispatcher_host.h index 987bd57..38de835 100644 --- a/chrome/browser/speech/speech_input_dispatcher_host.h +++ b/chrome/browser/speech/speech_input_dispatcher_host.h @@ -20,6 +20,8 @@ class SpeechInputDispatcherHost : public base::RefCountedThreadSafe<SpeechInputDispatcherHost>, public SpeechInputManager::Delegate { public: + class SpeechInputCallers; + explicit SpeechInputDispatcherHost(int resource_message_filter_process_id); // SpeechInputManager::Delegate methods. @@ -38,7 +40,6 @@ class SpeechInputDispatcherHost } private: - class SpeechInputCallers; friend class base::RefCountedThreadSafe<SpeechInputDispatcherHost>; virtual ~SpeechInputDispatcherHost(); @@ -56,7 +57,6 @@ class SpeechInputDispatcherHost SpeechInputManager* manager(); int resource_message_filter_process_id_; - SpeechInputCallers* callers_; // weak reference to a singleton. static SpeechInputManager::AccessorMethod* manager_accessor_; diff --git a/chrome/browser/speech/speech_input_manager.cc b/chrome/browser/speech/speech_input_manager.cc index 6ea8d19..181786b 100644 --- a/chrome/browser/speech/speech_input_manager.cc +++ b/chrome/browser/speech/speech_input_manager.cc @@ -10,7 +10,7 @@ #include "app/l10n_util.h" #include "base/lock.h" #include "base/ref_counted.h" -#include "base/singleton.h" +#include "base/lazy_instance.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/prefs/pref_service.h" @@ -124,7 +124,7 @@ class SpeechInputManagerImpl : public SpeechInputManager, }; // Private constructor to enforce singleton. - friend struct DefaultSingletonTraits<SpeechInputManagerImpl>; + friend struct base::DefaultLazyInstanceTraits<SpeechInputManagerImpl>; SpeechInputManagerImpl(); virtual ~SpeechInputManagerImpl(); @@ -144,8 +144,11 @@ class SpeechInputManagerImpl : public SpeechInputManager, scoped_refptr<HardwareInfo> hardware_info_; }; +static ::base::LazyInstance<SpeechInputManagerImpl> g_speech_input_manager_impl( + base::LINKER_INITIALIZED); + SpeechInputManager* SpeechInputManager::Get() { - return Singleton<SpeechInputManagerImpl>::get(); + return g_speech_input_manager_impl.Pointer(); } SpeechInputManagerImpl::SpeechInputManagerImpl() diff --git a/chrome/browser/ui/cocoa/accelerators_cocoa.h b/chrome/browser/ui/cocoa/accelerators_cocoa.h index b2d2269..9b0a555 100644 --- a/chrome/browser/ui/cocoa/accelerators_cocoa.h +++ b/chrome/browser/ui/cocoa/accelerators_cocoa.h @@ -10,6 +10,8 @@ #include "app/menus/accelerator_cocoa.h" +template <typename T> struct DefaultSingletonTraits; + // This class maintains a map of command_ids to AcceleratorCocoa objects (see // chrome/app/chrome_command_ids.h). Currently, this only lists the commands // that are used in the Wrench menu. @@ -19,20 +21,25 @@ // // #import "base/singleton.h" // ... -// AcceleratorsCocoa* keymap = Singleton<AcceleratorsCocoa>::get(); +// AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance(); // return keymap->GetAcceleratorForCommand(IDC_COPY); // class AcceleratorsCocoa { public: - AcceleratorsCocoa(); - ~AcceleratorsCocoa() {} - typedef std::map<int, menus::AcceleratorCocoa> AcceleratorCocoaMap; // Returns NULL if there is no accelerator for the command. const menus::AcceleratorCocoa* GetAcceleratorForCommand(int command_id); + // Returns the singleton instance. + static AcceleratorsCocoa* GetInstance(); + private: + friend struct DefaultSingletonTraits<AcceleratorsCocoa>; + + AcceleratorsCocoa(); + ~AcceleratorsCocoa() {} + AcceleratorCocoaMap accelerators_; DISALLOW_COPY_AND_ASSIGN(AcceleratorsCocoa); diff --git a/chrome/browser/ui/cocoa/accelerators_cocoa.mm b/chrome/browser/ui/cocoa/accelerators_cocoa.mm index eba1888..6f28a0f 100644 --- a/chrome/browser/ui/cocoa/accelerators_cocoa.mm +++ b/chrome/browser/ui/cocoa/accelerators_cocoa.mm @@ -6,6 +6,7 @@ #import <Cocoa/Cocoa.h> +#include "base/singleton.h" #include "chrome/app/chrome_command_ids.h" namespace { @@ -48,6 +49,11 @@ AcceleratorsCocoa::AcceleratorsCocoa() { } } +// static +AcceleratorsCocoa* AcceleratorsCocoa::GetInstance() { + return Singleton<AcceleratorsCocoa>::get(); +} + const menus::AcceleratorCocoa* AcceleratorsCocoa::GetAcceleratorForCommand( int command_id) { AcceleratorCocoaMap::iterator it = accelerators_.find(command_id); diff --git a/chrome/browser/ui/cocoa/accelerators_cocoa_unittest.mm b/chrome/browser/ui/cocoa/accelerators_cocoa_unittest.mm index e2b27f0..ef1436d 100644 --- a/chrome/browser/ui/cocoa/accelerators_cocoa_unittest.mm +++ b/chrome/browser/ui/cocoa/accelerators_cocoa_unittest.mm @@ -12,7 +12,7 @@ #include "testing/gtest_mac.h" TEST(AcceleratorsCocoaTest, GetAccelerator) { - AcceleratorsCocoa* keymap = Singleton<AcceleratorsCocoa>::get(); + AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance(); const menus::AcceleratorCocoa* accelerator = keymap->GetAcceleratorForCommand(IDC_COPY); ASSERT_TRUE(accelerator); @@ -21,7 +21,7 @@ TEST(AcceleratorsCocoaTest, GetAccelerator) { } TEST(AcceleratorsCocoaTest, GetNullAccelerator) { - AcceleratorsCocoa* keymap = Singleton<AcceleratorsCocoa>::get(); + AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance(); const menus::AcceleratorCocoa* accelerator = keymap->GetAcceleratorForCommand(314159265); EXPECT_FALSE(accelerator); diff --git a/chrome/browser/ui/cocoa/clear_browsing_data_controller.mm b/chrome/browser/ui/cocoa/clear_browsing_data_controller.mm index d59e89e..c0c927e 100644 --- a/chrome/browser/ui/cocoa/clear_browsing_data_controller.mm +++ b/chrome/browser/ui/cocoa/clear_browsing_data_controller.mm @@ -5,9 +5,9 @@ #import "chrome/browser/ui/cocoa/clear_browsing_data_controller.h" #include "app/l10n_util.h" +#include "base/lazy_instance.h" #include "base/mac_util.h" #include "base/scoped_nsobject.h" -#include "base/singleton.h" #include "chrome/browser/browsing_data_remover.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" @@ -41,6 +41,9 @@ namespace { typedef std::map<Profile*, ClearBrowsingDataController*> ProfileControllerMap; +static base::LazyInstance<ProfileControllerMap> g_profile_controller_map( + base::LINKER_INITIALIZED); + } // namespace @implementation ClearBrowsingDataController @@ -74,7 +77,7 @@ typedef std::map<Profile*, ClearBrowsingDataController*> ProfileControllerMap; // profile. profile = profile->GetOriginalProfile(); - ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); + ProfileControllerMap* map = g_profile_controller_map.Pointer(); DCHECK(map != NULL); ProfileControllerMap::iterator it = map->find(profile); if (it == map->end()) { @@ -205,7 +208,7 @@ typedef std::map<Profile*, ClearBrowsingDataController*> ProfileControllerMap; } - (void)closeDialog { - ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); + ProfileControllerMap* map = g_profile_controller_map.Pointer(); ProfileControllerMap::iterator it = map->find(profile_); if (it != map->end()) { map->erase(it); diff --git a/chrome/browser/ui/cocoa/keyword_editor_cocoa_controller.mm b/chrome/browser/ui/cocoa/keyword_editor_cocoa_controller.mm index 0f2271e..1a0819f 100644 --- a/chrome/browser/ui/cocoa/keyword_editor_cocoa_controller.mm +++ b/chrome/browser/ui/cocoa/keyword_editor_cocoa_controller.mm @@ -7,7 +7,7 @@ #import "chrome/browser/ui/cocoa/keyword_editor_cocoa_controller.h" #import "base/mac_util.h" -#include "base/singleton.h" +#include "base/lazy_instance.h" #include "base/sys_string_conversions.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/prefs/pref_service.h" @@ -101,12 +101,15 @@ namespace { typedef std::map<Profile*,KeywordEditorCocoaController*> ProfileControllerMap; +static base::LazyInstance<ProfileControllerMap> g_profile_controller_map( + base::LINKER_INITIALIZED); + } // namespace @implementation KeywordEditorCocoaController + (KeywordEditorCocoaController*)sharedInstanceForProfile:(Profile*)profile { - ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); + ProfileControllerMap* map = g_profile_controller_map.Pointer(); DCHECK(map != NULL); ProfileControllerMap::iterator it = map->find(profile); if (it != map->end()) { @@ -125,7 +128,7 @@ typedef std::map<Profile*,KeywordEditorCocoaController*> ProfileControllerMap; // either way, arrange to use the original profile instead. profile = profile->GetOriginalProfile(); - ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); + ProfileControllerMap* map = g_profile_controller_map.Pointer(); DCHECK(map != NULL); ProfileControllerMap::iterator it = map->find(profile); if (it == map->end()) { @@ -194,7 +197,7 @@ typedef std::map<Profile*,KeywordEditorCocoaController*> ProfileControllerMap; - (void)windowWillClose:(NSNotification*)notif { [self autorelease]; - ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); + ProfileControllerMap* map = g_profile_controller_map.Pointer(); ProfileControllerMap::iterator it = map->find(profile_); // It should not be possible for this to be missing. // TODO(shess): Except that the unit test reaches in directly. diff --git a/chrome/browser/ui/cocoa/tab_view.mm b/chrome/browser/ui/cocoa/tab_view.mm index 58659ca..aa043db 100644 --- a/chrome/browser/ui/cocoa/tab_view.mm +++ b/chrome/browser/ui/cocoa/tab_view.mm @@ -80,7 +80,7 @@ const CGFloat kRapidCloseDist = 2.5; // TODO(dtseng): crbug.com/59978. // Retain in case we remove it from its superview. closeButtonRetainer_.reset([closeButton_ retain]); - if (Singleton<BrowserAccessibilityState>::get()->IsAccessibleBrowser()) { + if (BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) { // The superview gives up ownership of the closeButton here. [closeButton_ removeFromSuperview]; } diff --git a/chrome/browser/ui/cocoa/toolbar_controller.mm b/chrome/browser/ui/cocoa/toolbar_controller.mm index 669657b..bb6f433 100644 --- a/chrome/browser/ui/cocoa/toolbar_controller.mm +++ b/chrome/browser/ui/cocoa/toolbar_controller.mm @@ -104,7 +104,7 @@ class WrenchAcceleratorDelegate : public menus::AcceleratorProvider { // string gets copied, too. menus::AcceleratorCocoa* out_accelerator = static_cast<menus::AcceleratorCocoa*>(accelerator_generic); - AcceleratorsCocoa* keymap = Singleton<AcceleratorsCocoa>::get(); + AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance(); const menus::AcceleratorCocoa* accelerator = keymap->GetAcceleratorForCommand(command_id); if (accelerator) { @@ -226,7 +226,7 @@ class NotificationBridge : public NotificationObserver { [homeButton_ setImage:nsimage_cache::ImageNamed(kHomeButtonImageName)]; [wrenchButton_ setImage:nsimage_cache::ImageNamed(kWrenchButtonImageName)]; - if (Singleton<UpgradeDetector>::get()->notify_upgrade()) + if (UpgradeDetector::GetInstance()->notify_upgrade()) [self badgeWrenchMenu]; [backButton_ setShowsBorderOnlyWhileMouseInside:YES]; diff --git a/chrome/browser/ui/cocoa/view_id_util.mm b/chrome/browser/ui/cocoa/view_id_util.mm index df8f079..ea0e859 100644 --- a/chrome/browser/ui/cocoa/view_id_util.mm +++ b/chrome/browser/ui/cocoa/view_id_util.mm @@ -9,8 +9,8 @@ #include <map> #include <utility> +#include "base/lazy_instance.h" #include "base/logging.h" -#include "base/singleton.h" #import "chrome/browser/ui/cocoa/browser_window_controller.h" #import "chrome/browser/ui/cocoa/tab_strip_controller.h" @@ -21,6 +21,8 @@ namespace { // rather than using a separated map. typedef std::map<NSView*, ViewID> ViewIDMap; +static base::LazyInstance<ViewIDMap> g_view_id_map(base::LINKER_INITIALIZED); + // Returns the view's nearest descendant (including itself) with a specific // ViewID, or nil if no subview has that ViewID. NSView* FindViewWithID(NSView* view, ViewID viewID) { @@ -44,12 +46,12 @@ void SetID(NSView* view, ViewID viewID) { DCHECK(viewID != VIEW_ID_NONE); // We handle VIEW_ID_TAB_0 to VIEW_ID_TAB_LAST in GetView() function directly. DCHECK(!((viewID >= VIEW_ID_TAB_0) && (viewID <= VIEW_ID_TAB_LAST))); - (*Singleton<ViewIDMap>::get())[view] = viewID; + g_view_id_map.Get()[view] = viewID; } void UnsetID(NSView* view) { DCHECK(view); - Singleton<ViewIDMap>::get()->erase(view); + g_view_id_map.Get().erase(view); } NSView* GetView(NSWindow* window, ViewID viewID) { @@ -79,7 +81,7 @@ NSView* GetView(NSWindow* window, ViewID viewID) { @implementation NSView (ViewID) - (ViewID)viewID { - ViewIDMap* map = Singleton<ViewIDMap>::get(); + ViewIDMap* map = g_view_id_map.Pointer(); ViewIDMap::const_iterator iter = map->find(self); return iter != map->end() ? iter->second : VIEW_ID_NONE; } diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc index 0adec32..b44c346 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc @@ -4,11 +4,14 @@ #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "base/singleton.h" +#include "base/lazy_instance.h" #include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/password_manager_delegate_impl.h" #include "chrome/browser/tab_contents/tab_contents.h" +static base::LazyInstance<PropertyAccessor<TabContentsWrapper*> > + g_tab_contents_wrapper_property_accessor(base::LINKER_INITIALIZED); + //////////////////////////////////////////////////////////////////////////////// // TabContentsWrapper, public: @@ -29,7 +32,7 @@ TabContentsWrapper::~TabContentsWrapper() { } PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() { - return Singleton< PropertyAccessor<TabContentsWrapper*> >::get(); + return g_tab_contents_wrapper_property_accessor.Pointer(); } TabContentsWrapper* TabContentsWrapper::Clone() { diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.cc b/chrome/browser/ui/toolbar/wrench_menu_model.cc index 50b6c49..7eb2309 100644 --- a/chrome/browser/ui/toolbar/wrench_menu_model.cc +++ b/chrome/browser/ui/toolbar/wrench_menu_model.cc @@ -301,7 +301,7 @@ bool WrenchMenuModel::IsCommandIdVisible(int command_id) const { return (chromeos::CrosLibrary::Get()->GetUpdateLibrary()->status().status == chromeos::UPDATE_STATUS_UPDATED_NEED_REBOOT); #else - return Singleton<UpgradeDetector>::get()->notify_upgrade(); + return UpgradeDetector::GetInstance()->notify_upgrade(); #endif } else if (command_id == IDC_VIEW_INCOMPATIBILITIES) { #if defined(OS_WIN) diff --git a/chrome/browser/ui/views/frame/browser_frame_win.cc b/chrome/browser/ui/views/frame/browser_frame_win.cc index 2fc188d..716e4fc 100644 --- a/chrome/browser/ui/views/frame/browser_frame_win.cc +++ b/chrome/browser/ui/views/frame/browser_frame_win.cc @@ -240,7 +240,7 @@ ThemeProvider* BrowserFrameWin::GetDefaultThemeProvider() const { } void BrowserFrameWin::OnScreenReaderDetected() { - Singleton<BrowserAccessibilityState>()->OnScreenReaderDetected(); + BrowserAccessibilityState::GetInstance()->OnScreenReaderDetected(); WindowWin::OnScreenReaderDetected(); } diff --git a/chrome/browser/ui/views/toolbar_view.cc b/chrome/browser/ui/views/toolbar_view.cc index 5163c9d..73a4be3 100644 --- a/chrome/browser/ui/views/toolbar_view.cc +++ b/chrome/browser/ui/views/toolbar_view.cc @@ -233,7 +233,7 @@ void ToolbarView::Init(Profile* profile) { SetProfile(profile); // Accessibility specific tooltip text. - if (Singleton<BrowserAccessibilityState>()->IsAccessibleBrowser()) { + if (BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) { back_->SetTooltipText(l10n_util::GetString(IDS_ACCNAME_TOOLTIP_BACK)); forward_->SetTooltipText(l10n_util::GetString(IDS_ACCNAME_TOOLTIP_FORWARD)); } @@ -628,7 +628,7 @@ bool ToolbarView::IsUpgradeRecommended() { return (chromeos::CrosLibrary::Get()->GetUpdateLibrary()->status().status == chromeos::UPDATE_STATUS_UPDATED_NEED_REBOOT); #else - return (Singleton<UpgradeDetector>::get()->notify_upgrade()); + return (UpgradeDetector::GetInstance()->notify_upgrade()); #endif } diff --git a/chrome/browser/upgrade_detector.cc b/chrome/browser/upgrade_detector.cc index 539c20a..a8928f1 100644 --- a/chrome/browser/upgrade_detector.cc +++ b/chrome/browser/upgrade_detector.cc @@ -7,6 +7,7 @@ #include <string> #include "base/command_line.h" +#include "base/singleton.h" #include "base/scoped_ptr.h" #include "base/time.h" #include "base/task.h" @@ -167,6 +168,11 @@ UpgradeDetector::UpgradeDetector() UpgradeDetector::~UpgradeDetector() { } +// static +UpgradeDetector* UpgradeDetector::GetInstance() { + return Singleton<UpgradeDetector>::get(); +} + void UpgradeDetector::CheckForUpgrade() { method_factory_.RevokeAll(); Task* callback_task = diff --git a/chrome/browser/upgrade_detector.h b/chrome/browser/upgrade_detector.h index 7c15128..e6aa6a6 100644 --- a/chrome/browser/upgrade_detector.h +++ b/chrome/browser/upgrade_detector.h @@ -6,9 +6,9 @@ #define CHROME_BROWSER_UPGRADE_DETECTOR_H_ #pragma once -#include "base/singleton.h" #include "base/timer.h" +template <typename T> struct DefaultSingletonTraits; class PrefService; /////////////////////////////////////////////////////////////////////////////// @@ -23,6 +23,9 @@ class PrefService; // class UpgradeDetector { public: + // Returns the singleton instance. + static UpgradeDetector* GetInstance(); + ~UpgradeDetector(); static void RegisterPrefs(PrefService* prefs); @@ -30,9 +33,10 @@ class UpgradeDetector { bool notify_upgrade() { return notify_upgrade_; } private: - UpgradeDetector(); friend struct DefaultSingletonTraits<UpgradeDetector>; + UpgradeDetector(); + // Launches a task on the file thread to check if we have the latest version. void CheckForUpgrade(); |