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/mime_util_xdg.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/mime_util_xdg.cc')
-rw-r--r-- | base/mime_util_xdg.cc | 27 |
1 files changed, 15 insertions, 12 deletions
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", >k_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); } |