diff options
author | mmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-21 16:20:02 +0000 |
---|---|---|
committer | mmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-21 16:20:02 +0000 |
commit | 7fad3d83abe5281e6be62f5a809da4015ad6b222 (patch) | |
tree | ab84b802185c39e77f8334e18459b86b32416a32 /net/base/registry_controlled_domain.cc | |
parent | f25387b62a3cccde48622d0b7fca57cd6fb16ab7 (diff) | |
download | chromium_src-7fad3d83abe5281e6be62f5a809da4015ad6b222.zip chromium_src-7fad3d83abe5281e6be62f5a809da4015ad6b222.tar.gz chromium_src-7fad3d83abe5281e6be62f5a809da4015ad6b222.tar.bz2 |
Port cookie_monster, net_util, and registry_controlled_domain to POSIXish platforms
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1154 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/registry_controlled_domain.cc')
-rw-r--r-- | net/base/registry_controlled_domain.cc | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/net/base/registry_controlled_domain.cc b/net/base/registry_controlled_domain.cc index f0aad4c..3f4f024 100644 --- a/net/base/registry_controlled_domain.cc +++ b/net/base/registry_controlled_domain.cc @@ -37,16 +37,16 @@ * * ***** END LICENSE BLOCK ***** */ -#include <windows.h> +#include "net/base/registry_controlled_domain.h" #include "base/logging.h" +#include "base/singleton.h" #include "base/string_util.h" #include "googleurl/src/gurl.h" #include "googleurl/src/url_parse.h" #include "net/base/net_module.h" #include "net/base/net_resources.h" #include "net/base/net_util.h" -#include "net/base/registry_controlled_domain.h" namespace net { @@ -258,23 +258,34 @@ size_t RegistryControlledDomainService::GetRegistryLengthImpl( return allow_unknown_registries ? (host.length() - curr_start) : 0; } -RegistryControlledDomainService* RegistryControlledDomainService::instance_ = - NULL; +static RegistryControlledDomainService* test_instance_; + +// static +RegistryControlledDomainService* RegistryControlledDomainService::SetInstance( + RegistryControlledDomainService* instance) { + RegistryControlledDomainService* old_instance = test_instance_; + test_instance_ = instance; + return old_instance; +} + +struct RegistryControlledDomainServiceSingletonTraits : + public DefaultSingletonTraits<RegistryControlledDomainService> { + static RegistryControlledDomainService* New() { + RegistryControlledDomainService* instance = + new RegistryControlledDomainService(); + instance->Init(); + return instance; + } +}; // static RegistryControlledDomainService* RegistryControlledDomainService::GetInstance() { - if (!instance_) { - RegistryControlledDomainService* s = new RegistryControlledDomainService(); - s->Init(); - // TODO(darin): use fix_wp64.h once it lives in base/ - if (InterlockedCompareExchangePointer( - reinterpret_cast<PVOID*>(&instance_), s, NULL)) { - // Oops, another thread initialized instance_ out from under us. - delete s; - } - } - return instance_; + if (test_instance_) + return test_instance_; + + return Singleton<RegistryControlledDomainService, + RegistryControlledDomainServiceSingletonTraits>::get(); } // static |