summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-17 06:06:15 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-17 06:06:15 +0000
commite4de6b5d0a654164e312f6213d81c41df7ca5eed (patch)
tree04e72943e8b22305d6aeee85c288987ebd3dce33 /chrome
parent383a0ca55d444ac67c9be491f74e591b7c1ccea7 (diff)
downloadchromium_src-e4de6b5d0a654164e312f6213d81c41df7ca5eed.zip
chromium_src-e4de6b5d0a654164e312f6213d81c41df7ca5eed.tar.gz
chromium_src-e4de6b5d0a654164e312f6213d81c41df7ca5eed.tar.bz2
chrome: Remove 11 exit time destructors and 4 static initializers.
BUG=101600,94925 TEST=none TBR=erg,willchan Review URL: http://codereview.chromium.org/8590003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110447 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/memory_details_mac.cc2
-rw-r--r--chrome/browser/net/network_stats.cc2
-rw-r--r--chrome/browser/profiles/profile_manager.cc2
-rw-r--r--chrome/browser/spellchecker/spellcheck_host_impl.cc2
-rw-r--r--chrome/browser/themes/theme_service.cc4
-rw-r--r--chrome/browser/ui/browser_list.cc106
-rw-r--r--chrome/browser/ui/browser_list.h23
-rw-r--r--chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm2
-rw-r--r--chrome/browser/ui/gtk/gtk_theme_service.cc2
-rw-r--r--chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc2
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_views.cc2
-rw-r--r--chrome/browser/ui/webui/chrome_url_data_manager.cc12
-rw-r--r--chrome/browser/ui/webui/chrome_url_data_manager.h4
13 files changed, 98 insertions, 67 deletions
diff --git a/chrome/browser/memory_details_mac.cc b/chrome/browser/memory_details_mac.cc
index 46b19c8..0b1fb12 100644
--- a/chrome/browser/memory_details_mac.cc
+++ b/chrome/browser/memory_details_mac.cc
@@ -53,7 +53,7 @@ enum BrowserType {
MemoryDetails::MemoryDetails() {
- static const std::string google_browser_name =
+ const std::string google_browser_name =
l10n_util::GetStringUTF8(IDS_PRODUCT_NAME);
// (Human and process) names of browsers; should match the ordering for
// |BrowserProcess| (i.e., |BrowserType|).
diff --git a/chrome/browser/net/network_stats.cc b/chrome/browser/net/network_stats.cc
index 1892a4e..570e6d4 100644
--- a/chrome/browser/net/network_stats.cc
+++ b/chrome/browser/net/network_stats.cc
@@ -539,7 +539,7 @@ void CollectNetworkStats(const std::string& network_stats_server,
// to the server has succeeded.
DCHECK(!net::NetworkChangeNotifier::IsOffline());
- static scoped_refptr<base::FieldTrial> trial = NULL;
+ CR_DEFINE_STATIC_LOCAL(scoped_refptr<base::FieldTrial>, trial, ());
static bool collect_stats = false;
if (!trial.get()) {
diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc
index ae4fb09..9c058de 100644
--- a/chrome/browser/profiles/profile_manager.cc
+++ b/chrome/browser/profiles/profile_manager.cc
@@ -53,7 +53,7 @@ namespace {
// Profiles that should be deleted on shutdown.
std::vector<FilePath>& ProfilesToDelete() {
- static std::vector<FilePath> profiles_to_delete;
+ CR_DEFINE_STATIC_LOCAL(std::vector<FilePath>, profiles_to_delete, ());
return profiles_to_delete;
}
diff --git a/chrome/browser/spellchecker/spellcheck_host_impl.cc b/chrome/browser/spellchecker/spellcheck_host_impl.cc
index b0d9627..c0cd19b 100644
--- a/chrome/browser/spellchecker/spellcheck_host_impl.cc
+++ b/chrome/browser/spellchecker/spellcheck_host_impl.cc
@@ -52,7 +52,7 @@ FilePath GetFirstChoiceFilePath(const std::string& language) {
// spellchecker.
void RecordSpellCheckStats(bool native_spellchecker_used,
const std::string& language) {
- static std::set<std::string> languages_seen;
+ CR_DEFINE_STATIC_LOCAL(std::set<std::string>, languages_seen, ());
// Only count a language code once for each session..
if (languages_seen.find(language) != languages_seen.end()) {
diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc
index 049bd27..8b96356 100644
--- a/chrome/browser/themes/theme_service.cc
+++ b/chrome/browser/themes/theme_service.cc
@@ -153,7 +153,7 @@ const int kThemeableImages[] = {
};
bool HasThemeableImage(int themeable_image_id) {
- static std::set<int> themeable_images;
+ CR_DEFINE_STATIC_LOCAL(std::set<int>, themeable_images, ());
if (themeable_images.empty()) {
themeable_images.insert(
kThemeableImages, kThemeableImages + arraysize(kThemeableImages));
@@ -537,7 +537,7 @@ bool ThemeService::GetDefaultDisplayProperty(int id, int* result) {
// static
const std::set<int>& ThemeService::GetTintableToolbarButtons() {
- static std::set<int> button_set;
+ CR_DEFINE_STATIC_LOCAL(std::set<int>, button_set, ());
if (button_set.empty()) {
button_set = std::set<int>(
kToolbarButtonIDs,
diff --git a/chrome/browser/ui/browser_list.cc b/chrome/browser/ui/browser_list.cc
index 18fea4e..4a922af 100644
--- a/chrome/browser/ui/browser_list.cc
+++ b/chrome/browser/ui/browser_list.cc
@@ -117,6 +117,22 @@ const int kMatchOriginalProfile = 1 << 0;
const int kMatchCanSupportWindowFeature = 1 << 1;
const int kMatchTabbed = 1 << 2;
+static BrowserList::BrowserVector& browsers() {
+ CR_DEFINE_STATIC_LOCAL(BrowserList::BrowserVector, browser_vector, ());
+ return browser_vector;
+}
+
+static BrowserList::BrowserVector& last_active_browsers() {
+ CR_DEFINE_STATIC_LOCAL(BrowserList::BrowserVector, last_active_vector, ());
+ return last_active_vector;
+}
+
+static ObserverList<BrowserList::Observer>& observers() {
+ CR_DEFINE_STATIC_LOCAL(
+ ObserverList<BrowserList::Observer>, observer_vector, ());
+ return observer_vector;
+}
+
// Returns true if the specified |browser| matches the specified arguments.
// |match_types| is a bitmask dictating what parameters to match:
// . If it contains kMatchOriginalProfile then the original profile of the
@@ -251,13 +267,10 @@ void NotifyWindowManagerAboutSignout() {
} // namespace
-BrowserList::BrowserVector BrowserList::browsers_;
-ObserverList<BrowserList::Observer> BrowserList::observers_;
-
// static
void BrowserList::AddBrowser(Browser* browser) {
DCHECK(browser);
- browsers_.push_back(browser);
+ browsers().push_back(browser);
g_browser_process->AddRefModule();
@@ -271,9 +284,9 @@ void BrowserList::AddBrowser(Browser* browser) {
// Send out notifications after add has occurred. Do some basic checking to
// try to catch evil observers that change the list from under us.
- size_t original_count = observers_.size();
- FOR_EACH_OBSERVER(Observer, observers_, OnBrowserAdded(browser));
- DCHECK_EQ(original_count, observers_.size())
+ size_t original_count = observers().size();
+ FOR_EACH_OBSERVER(Observer, observers(), OnBrowserAdded(browser));
+ DCHECK_EQ(original_count, observers().size())
<< "observer list modified during notification";
}
@@ -337,30 +350,30 @@ void BrowserList::NotifyAndTerminate(bool fast_path) {
// static
void BrowserList::RemoveBrowser(Browser* browser) {
- RemoveBrowserFrom(browser, &last_active_browsers_);
+ RemoveBrowserFrom(browser, &last_active_browsers());
// Closing all windows does not indicate quitting the application on the Mac,
// however, many UI tests rely on this behavior so leave it be for now and
// simply ignore the behavior on the Mac outside of unit tests.
// TODO(andybons): Fix the UI tests to Do The Right Thing.
- bool closing_last_browser = (browsers_.size() == 1);
+ bool closing_last_browser = (browsers().size() == 1);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_BROWSER_CLOSED,
content::Source<Browser>(browser),
content::Details<bool>(&closing_last_browser));
- RemoveBrowserFrom(browser, &browsers_);
+ RemoveBrowserFrom(browser, &browsers());
// Do some basic checking to try to catch evil observers
// that change the list from under us.
- size_t original_count = observers_.size();
- FOR_EACH_OBSERVER(Observer, observers_, OnBrowserRemoved(browser));
- DCHECK_EQ(original_count, observers_.size())
+ size_t original_count = observers().size();
+ FOR_EACH_OBSERVER(Observer, observers(), OnBrowserRemoved(browser));
+ DCHECK_EQ(original_count, observers().size())
<< "observer list modified during notification";
// If the last Browser object was destroyed, make sure we try to close any
// remaining dependent windows too.
- if (browsers_.empty()) {
+ if (browsers().empty()) {
delete activity_observer;
activity_observer = NULL;
}
@@ -369,7 +382,7 @@ void BrowserList::RemoveBrowser(Browser* browser) {
// If we're exiting, send out the APP_TERMINATING notification to allow other
// modules to shut themselves down.
- if (browsers_.empty() &&
+ if (browsers().empty() &&
(browser_shutdown::IsTryingToQuit() ||
g_browser_process->IsShuttingDown())) {
// Last browser has just closed, and this is a user-initiated quit or there
@@ -384,12 +397,12 @@ void BrowserList::RemoveBrowser(Browser* browser) {
// static
void BrowserList::AddObserver(BrowserList::Observer* observer) {
- observers_.AddObserver(observer);
+ observers().AddObserver(observer);
}
// static
void BrowserList::RemoveObserver(BrowserList::Observer* observer) {
- observers_.RemoveObserver(observer);
+ observers().RemoveObserver(observer);
}
// static
@@ -406,7 +419,7 @@ void BrowserList::CloseAllBrowsers() {
// If there are no browsers, send the APP_TERMINATING action here. Otherwise,
// it will be sent by RemoveBrowser() when the last browser has closed.
if (browser_shutdown::ShuttingDownWithoutClosingBrowsers() ||
- browsers_.empty()) {
+ browsers().empty()) {
NotifyAndTerminate(true);
return;
}
@@ -623,7 +636,7 @@ void BrowserList::EndKeepAlive() {
// If there are no browsers open and we aren't already shutting down,
// initiate a shutdown. Also skips shutdown if this is a unit test
// (MessageLoop::current() == null).
- if (browsers_.empty() && !browser_shutdown::IsTryingToQuit() &&
+ if (browsers().empty() && !browser_shutdown::IsTryingToQuit() &&
MessageLoop::current())
CloseAllBrowsers();
}
@@ -635,7 +648,24 @@ bool BrowserList::WillKeepAlive() {
}
// static
-BrowserList::BrowserVector BrowserList::last_active_browsers_;
+BrowserList::const_iterator BrowserList::begin() {
+ return browsers().begin();
+}
+
+// static
+BrowserList::const_iterator BrowserList::end() {
+ return browsers().end();
+}
+
+// static
+bool BrowserList::empty() {
+ return browsers().empty();
+}
+
+// static
+size_t BrowserList::size() {
+ return browsers().size();
+}
// static
void BrowserList::SetLastActive(Browser* browser) {
@@ -644,16 +674,16 @@ void BrowserList::SetLastActive(Browser* browser) {
// intended depending on the order in which the windows close.
if (browser_shutdown::IsTryingToQuit())
return;
- RemoveBrowserFrom(browser, &last_active_browsers_);
- last_active_browsers_.push_back(browser);
+ RemoveBrowserFrom(browser, &last_active_browsers());
+ last_active_browsers().push_back(browser);
- FOR_EACH_OBSERVER(Observer, observers_, OnBrowserSetLastActive(browser));
+ FOR_EACH_OBSERVER(Observer, observers(), OnBrowserSetLastActive(browser));
}
// static
Browser* BrowserList::GetLastActive() {
- if (!last_active_browsers_.empty())
- return *(last_active_browsers_.rbegin());
+ if (!last_active_browsers().empty())
+ return *(last_active_browsers().rbegin());
return NULL;
}
@@ -728,26 +758,36 @@ Browser* BrowserList::FindBrowserWithTabContents(TabContents* tab_contents) {
}
// static
-size_t BrowserList::GetBrowserCountForType(Profile* profile,
- bool match_tabbed) {
+BrowserList::const_reverse_iterator BrowserList::begin_last_active() {
+ return last_active_browsers().rbegin();
+}
+
+// static
+BrowserList::const_reverse_iterator BrowserList::end_last_active() {
+ return last_active_browsers().rend();
+}
+
+// static
+size_t BrowserList::GetBrowserCount(Profile* profile) {
size_t result = 0;
for (BrowserList::const_iterator i = BrowserList::begin();
i != BrowserList::end(); ++i) {
- if (BrowserMatches(*i, profile, Browser::FEATURE_NONE,
- match_tabbed ? kMatchTabbed : kMatchAny))
+ if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, kMatchAny)) {
++result;
+ }
}
return result;
}
// static
-size_t BrowserList::GetBrowserCount(Profile* profile) {
+size_t BrowserList::GetBrowserCountForType(Profile* profile,
+ bool match_tabbed) {
size_t result = 0;
for (BrowserList::const_iterator i = BrowserList::begin();
i != BrowserList::end(); ++i) {
- if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, kMatchAny)) {
- result++;
- }
+ if (BrowserMatches(*i, profile, Browser::FEATURE_NONE,
+ match_tabbed ? kMatchTabbed : kMatchAny))
+ ++result;
}
return result;
}
diff --git a/chrome/browser/ui/browser_list.h b/chrome/browser/ui/browser_list.h
index 447f6cb..700c51a 100644
--- a/chrome/browser/ui/browser_list.h
+++ b/chrome/browser/ui/browser_list.h
@@ -170,25 +170,20 @@ class BrowserList {
// closes.
static bool WillKeepAlive();
- // Browsers are added to |browsers_| before they have constructed windows,
+ // Browsers are added to the list before they have constructed windows,
// so the |window()| member function may return NULL.
- static const_iterator begin() { return browsers_.begin(); }
- static const_iterator end() { return browsers_.end(); }
+ static const_iterator begin();
+ static const_iterator end();
- static bool empty() { return browsers_.empty(); }
- static size_t size() { return browsers_.size(); }
+ static bool empty();
+ static size_t size();
// Returns iterated access to list of open browsers ordered by when
// they were last active. The underlying data structure is a vector
// and we push_back on recent access so a reverse iterator gives the
// latest accessed browser first.
- static const_reverse_iterator begin_last_active() {
- return last_active_browsers_.rbegin();
- }
-
- static const_reverse_iterator end_last_active() {
- return last_active_browsers_.rend();
- }
+ static const_reverse_iterator begin_last_active();
+ static const_reverse_iterator end_last_active();
// Return the number of browsers with the following profile which are
// currently open.
@@ -217,10 +212,6 @@ class BrowserList {
static void MarkAsCleanShutdown();
static void AttemptExitInternal();
- static BrowserVector browsers_;
- static BrowserVector last_active_browsers_;
- static ObserverList<Observer> observers_;
-
// Counter of calls to StartKeepAlive(). If non-zero, the application will
// continue running after the last browser has exited.
static int keep_alive_count_;
diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
index 46051c6..230fedd 100644
--- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
+++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
@@ -104,7 +104,7 @@ struct OmniboxViewMacState {
// globally-unique id used to index into the per-tab PropertyBag used
// to store the state data.
PropertyAccessor<OmniboxViewMacState>* GetStateAccessor() {
- static PropertyAccessor<OmniboxViewMacState> accessor;
+ CR_DEFINE_STATIC_LOCAL(PropertyAccessor<OmniboxViewMacState>, accessor, ());
return &accessor;
}
diff --git a/chrome/browser/ui/gtk/gtk_theme_service.cc b/chrome/browser/ui/gtk/gtk_theme_service.cc
index d92d610..567e48f 100644
--- a/chrome/browser/ui/gtk/gtk_theme_service.cc
+++ b/chrome/browser/ui/gtk/gtk_theme_service.cc
@@ -122,7 +122,7 @@ const int kAutocompleteImages[] = {
};
bool IsOverridableImage(int id) {
- static std::set<int> images;
+ CR_DEFINE_STATIC_LOCAL(std::set<int>, images, ());
if (images.empty()) {
images.insert(kThemeImages, kThemeImages + arraysize(kThemeImages));
images.insert(kAutocompleteImages,
diff --git a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc
index 1c91d44..a1e6c4a 100644
--- a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc
+++ b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc
@@ -105,7 +105,7 @@ struct AutocompleteEditState {
// Returns a lazily initialized property bag accessor for saving our state in a
// TabContents.
PropertyAccessor<AutocompleteEditState>* GetStateAccessor() {
- static PropertyAccessor<AutocompleteEditState> state;
+ CR_DEFINE_STATIC_LOCAL(PropertyAccessor<AutocompleteEditState>, state, ());
return &state;
}
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index ffa3d2d0..f7e1da3 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -114,7 +114,7 @@ struct AutocompleteEditState {
// Returns a lazily initialized property bag accessor for saving our state in a
// TabContents.
PropertyAccessor<AutocompleteEditState>* GetStateAccessor() {
- static PropertyAccessor<AutocompleteEditState> state;
+ CR_DEFINE_STATIC_LOCAL(PropertyAccessor<AutocompleteEditState>, state, ());
return &state;
}
diff --git a/chrome/browser/ui/webui/chrome_url_data_manager.cc b/chrome/browser/ui/webui/chrome_url_data_manager.cc
index 23b61e7..f9eabae 100644
--- a/chrome/browser/ui/webui/chrome_url_data_manager.cc
+++ b/chrome/browser/ui/webui/chrome_url_data_manager.cc
@@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/i18n/rtl.h"
+#include "base/lazy_instance.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
@@ -27,8 +28,9 @@
using content::BrowserThread;
-// static
-base::Lock ChromeURLDataManager::delete_lock_;
+static base::LazyInstance<base::Lock,
+ base::LeakyLazyInstanceTraits<base::Lock> >
+ g_delete_lock = LAZY_INSTANCE_INITIALIZER;
// static
ChromeURLDataManager::DataSources* ChromeURLDataManager::data_sources_ = NULL;
@@ -62,7 +64,7 @@ void ChromeURLDataManager::DeleteDataSources() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DataSources sources;
{
- base::AutoLock lock(delete_lock_);
+ base::AutoLock lock(g_delete_lock.Get());
if (!data_sources_)
return;
data_sources_->swap(sources);
@@ -84,7 +86,7 @@ void ChromeURLDataManager::DeleteDataSource(const DataSource* data_source) {
// to delete.
bool schedule_delete = false;
{
- base::AutoLock lock(delete_lock_);
+ base::AutoLock lock(g_delete_lock.Get());
if (!data_sources_)
data_sources_ = new DataSources();
schedule_delete = data_sources_->empty();
@@ -101,7 +103,7 @@ void ChromeURLDataManager::DeleteDataSource(const DataSource* data_source) {
// static
bool ChromeURLDataManager::IsScheduledForDeletion(
const DataSource* data_source) {
- base::AutoLock lock(delete_lock_);
+ base::AutoLock lock(g_delete_lock.Get());
if (!data_sources_)
return false;
return std::find(data_sources_->begin(), data_sources_->end(), data_source) !=
diff --git a/chrome/browser/ui/webui/chrome_url_data_manager.h b/chrome/browser/ui/webui/chrome_url_data_manager.h
index e5dc1e5..c81b662 100644
--- a/chrome/browser/ui/webui/chrome_url_data_manager.h
+++ b/chrome/browser/ui/webui/chrome_url_data_manager.h
@@ -177,10 +177,8 @@ class ChromeURLDataManager {
// the UI thread, but ChromeURLDataManagerBackend lives on the IO thread.
const base::Callback<ChromeURLDataManagerBackend*(void)> backend_;
- // Lock used when accessing |data_sources_|.
- static base::Lock delete_lock_;
-
// |data_sources_| that are no longer referenced and scheduled for deletion.
+ // Protected by g_delete_lock in the .cc file.
static DataSources* data_sources_;
DISALLOW_COPY_AND_ASSIGN(ChromeURLDataManager);