summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-09 22:26:04 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-09 22:26:04 +0000
commit44281e0f80ec95ac224bdafff41eee8902804760 (patch)
treee4c320122bca95899720f36f0e15e962d8573cbd /net
parent8be5bd63f15549b1fb009c69bfaacbfa0e36c359 (diff)
downloadchromium_src-44281e0f80ec95ac224bdafff41eee8902804760.zip
chromium_src-44281e0f80ec95ac224bdafff41eee8902804760.tar.gz
chromium_src-44281e0f80ec95ac224bdafff41eee8902804760.tar.bz2
net: Remove 3 exit time destructors and 3 static initializers.
BUG=101600,94925 TEST=none Review URL: http://codereview.chromium.org/8467037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109317 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/net_util.cc31
-rw-r--r--net/base/net_util.h4
-rw-r--r--net/base/net_util_unittest.cc4
-rw-r--r--net/url_request/url_request_test_job.cc35
4 files changed, 45 insertions, 29 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 2ae1e79..53206dc 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -33,6 +33,7 @@
#include "base/i18n/icu_string_conversions.h"
#include "base/i18n/time_formatting.h"
#include "base/json/string_escape.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/message_loop.h"
@@ -490,7 +491,9 @@ void SetExemplarSetForLang(const std::string& lang,
map.insert(std::make_pair(lang, lang_set));
}
-static base::Lock lang_set_lock;
+static base::LazyInstance<base::Lock,
+ base::LeakyLazyInstanceTraits<base::Lock> >
+ g_lang_set_lock(base::LINKER_INITIALIZED);
// Returns true if all the characters in component_characters are used by
// the language |lang|.
@@ -501,7 +504,7 @@ bool IsComponentCoveredByLang(const icu::UnicodeSet& component_characters,
icu::UnicodeSet* lang_set;
// We're called from both the UI thread and the history thread.
{
- base::AutoLock lock(lang_set_lock);
+ base::AutoLock lock(g_lang_set_lock.Get());
if (!GetExemplarSetForLang(lang, &lang_set)) {
UErrorCode status = U_ZERO_ERROR;
ULocaleData* uld = ulocdata_open(lang.c_str(), &status);
@@ -1114,8 +1117,13 @@ const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2;
const FormatUrlType kFormatUrlOmitAll = kFormatUrlOmitUsernamePassword |
kFormatUrlOmitHTTP | kFormatUrlOmitTrailingSlashOnBareHostname;
-// TODO(viettrungluu): We don't want non-POD globals; change this.
-std::multiset<int> explicitly_allowed_ports;
+static base::LazyInstance<std::multiset<int>,
+ base::LeakyLazyInstanceTraits<std::multiset<int> > >
+ g_explicitly_allowed_ports(base::LINKER_INITIALIZED);
+
+size_t GetCountOfExplicitlyAllowedPorts() {
+ return g_explicitly_allowed_ports.Get().size();
+}
GURL FilePathToFileURL(const FilePath& path) {
// Produce a URL like "file:///C:/foo" for a regular file, or
@@ -1575,10 +1583,10 @@ bool IsPortAllowedByFtp(int port) {
}
bool IsPortAllowedByOverride(int port) {
- if (explicitly_allowed_ports.empty())
+ if (g_explicitly_allowed_ports.Get().empty())
return false;
- return explicitly_allowed_ports.count(port) > 0;
+ return g_explicitly_allowed_ports.Get().count(port) > 0;
}
int SetNonBlocking(int fd) {
@@ -1992,17 +2000,18 @@ void SetExplicitlyAllowedPorts(const std::string& allowed_ports) {
last = i + 1;
}
}
- explicitly_allowed_ports = ports;
+ g_explicitly_allowed_ports.Get() = ports;
}
ScopedPortException::ScopedPortException(int port) : port_(port) {
- explicitly_allowed_ports.insert(port);
+ g_explicitly_allowed_ports.Get().insert(port);
}
ScopedPortException::~ScopedPortException() {
- std::multiset<int>::iterator it = explicitly_allowed_ports.find(port_);
- if (it != explicitly_allowed_ports.end())
- explicitly_allowed_ports.erase(it);
+ std::multiset<int>::iterator it =
+ g_explicitly_allowed_ports.Get().find(port_);
+ if (it != g_explicitly_allowed_ports.Get().end())
+ g_explicitly_allowed_ports.Get().erase(it);
else
NOTREACHED();
}
diff --git a/net/base/net_util.h b/net/base/net_util.h
index 08cb02f..c51ca3d 100644
--- a/net/base/net_util.h
+++ b/net/base/net_util.h
@@ -76,8 +76,8 @@ NET_EXPORT extern const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname;
// Convenience for omitting all unecessary types.
NET_EXPORT extern const FormatUrlType kFormatUrlOmitAll;
-// Holds a list of ports that should be accepted despite bans.
-NET_EXPORT_PRIVATE extern std::multiset<int> explicitly_allowed_ports;
+// Returns the number of explicitly allowed ports; for testing.
+NET_EXPORT_PRIVATE extern size_t GetCountOfExplicitlyAllowedPorts();
// Given the full path to a file name, creates a file: URL. The returned URL
// may not be valid if the input is malformed.
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index 88c987e..9138f83 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -3209,12 +3209,12 @@ TEST(NetUtilTest, SetExplicitlyAllowedPortsTest) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(invalid); ++i) {
SetExplicitlyAllowedPorts(invalid[i]);
- EXPECT_EQ(0, static_cast<int>(explicitly_allowed_ports.size()));
+ EXPECT_EQ(0, static_cast<int>(GetCountOfExplicitlyAllowedPorts()));
}
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid); ++i) {
SetExplicitlyAllowedPorts(valid[i]);
- EXPECT_EQ(i, explicitly_allowed_ports.size());
+ EXPECT_EQ(i, GetCountOfExplicitlyAllowedPorts());
}
}
diff --git a/net/url_request/url_request_test_job.cc b/net/url_request/url_request_test_job.cc
index 3f471b7..1df6f63 100644
--- a/net/url_request/url_request_test_job.cc
+++ b/net/url_request/url_request_test_job.cc
@@ -8,6 +8,7 @@
#include <list>
#include "base/compiler_specific.h"
+#include "base/lazy_instance.h"
#include "base/message_loop.h"
#include "base/string_util.h"
#include "net/base/io_buffer.h"
@@ -17,10 +18,14 @@
namespace net {
-// This emulates the global message loop for the test URL request class, since
-// this is only test code, it's probably not too dangerous to have this static
-// object.
-static std::list<URLRequestTestJob*> g_pending_jobs;
+namespace {
+
+typedef std::list<URLRequestTestJob*> URLRequestJobList;
+base::LazyInstance<URLRequestJobList,
+ base::LeakyLazyInstanceTraits<URLRequestJobList> >
+ g_pending_jobs(base::LINKER_INITIALIZED);
+
+} // namespace
// static getters for known URLs
GURL URLRequestTestJob::test_url_1() {
@@ -116,9 +121,10 @@ URLRequestTestJob::URLRequestTestJob(URLRequest* request,
}
URLRequestTestJob::~URLRequestTestJob() {
- g_pending_jobs.erase(
- std::remove(g_pending_jobs.begin(), g_pending_jobs.end(), this),
- g_pending_jobs.end());
+ g_pending_jobs.Get().erase(
+ std::remove(
+ g_pending_jobs.Get().begin(), g_pending_jobs.Get().end(), this),
+ g_pending_jobs.Get().end());
}
bool URLRequestTestJob::GetMimeType(std::string* mime_type) const {
@@ -222,9 +228,10 @@ void URLRequestTestJob::Kill() {
stage_ = DONE;
URLRequestJob::Kill();
method_factory_.RevokeAll();
- g_pending_jobs.erase(
- std::remove(g_pending_jobs.begin(), g_pending_jobs.end(), this),
- g_pending_jobs.end());
+ g_pending_jobs.Get().erase(
+ std::remove(
+ g_pending_jobs.Get().begin(), g_pending_jobs.Get().end(), this),
+ g_pending_jobs.Get().end());
}
void URLRequestTestJob::ProcessNextOperation() {
@@ -265,16 +272,16 @@ void URLRequestTestJob::AdvanceJob() {
&URLRequestTestJob::ProcessNextOperation));
return;
}
- g_pending_jobs.push_back(this);
+ g_pending_jobs.Get().push_back(this);
}
// static
bool URLRequestTestJob::ProcessOnePendingMessage() {
- if (g_pending_jobs.empty())
+ if (g_pending_jobs.Get().empty())
return false;
- URLRequestTestJob* next_job(g_pending_jobs.front());
- g_pending_jobs.pop_front();
+ URLRequestTestJob* next_job(g_pending_jobs.Get().front());
+ g_pending_jobs.Get().pop_front();
DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q
next_job->ProcessNextOperation();