From 077851be33ef19822a8ac6497f6618894c30da56 Mon Sep 17 00:00:00 2001 From: "willchan@chromium.org" Date: Tue, 12 Oct 2010 04:33:21 +0000 Subject: Break URLRequestContext=>ProxyScriptFetcher=>URLRequestContext ref cycle. BUG=58572 TEST=None Review URL: http://codereview.chromium.org/3662005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62247 0039d316-1c4b-4281-b951-d872f2087c98 --- net/proxy/proxy_script_fetcher.cc | 46 +++++++++++++++++++++++++++++++++++++++ net/proxy/proxy_script_fetcher.h | 3 +++ 2 files changed, 49 insertions(+) (limited to 'net') diff --git a/net/proxy/proxy_script_fetcher.cc b/net/proxy/proxy_script_fetcher.cc index 719c380..0398134 100644 --- a/net/proxy/proxy_script_fetcher.cc +++ b/net/proxy/proxy_script_fetcher.cc @@ -4,11 +4,16 @@ #include "net/proxy/proxy_script_fetcher.h" +#include + +#include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/i18n/icu_string_conversions.h" +#include "base/lazy_instance.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/ref_counted.h" +#include "base/stl_util-inl.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "net/base/io_buffer.h" @@ -69,8 +74,47 @@ void ConvertResponseToUTF16(const std::string& charset, utf16); } +class ProxyScriptFetcherTracker { + public: + void AddFetcher(ProxyScriptFetcher* fetcher) { + DCHECK(!ContainsKey(fetchers_, fetcher)); + fetchers_.insert(fetcher); + } + + void RemoveFetcher(ProxyScriptFetcher* fetcher) { + DCHECK(ContainsKey(fetchers_, fetcher)); + fetchers_.erase(fetcher); + } + + void CancelAllFetches() { + for (std::set::const_iterator it = fetchers_.begin(); + it != fetchers_.end(); ++it) { + (*it)->Cancel(); + } + } + + private: + ProxyScriptFetcherTracker(); + ~ProxyScriptFetcherTracker(); + + friend struct base::DefaultLazyInstanceTraits; + + std::set fetchers_; + DISALLOW_COPY_AND_ASSIGN(ProxyScriptFetcherTracker); +}; + +ProxyScriptFetcherTracker::ProxyScriptFetcherTracker() {} +ProxyScriptFetcherTracker::~ProxyScriptFetcherTracker() {} + +base::LazyInstance + g_fetcher_tracker(base::LINKER_INITIALIZED); + } // namespace +void EnsureNoProxyScriptFetches() { + g_fetcher_tracker.Get().CancelAllFetches(); +} + class ProxyScriptFetcherImpl : public ProxyScriptFetcher, public URLRequest::Delegate { public: @@ -160,9 +204,11 @@ ProxyScriptFetcherImpl::ProxyScriptFetcherImpl( result_code_(OK), result_text_(NULL) { DCHECK(url_request_context); + g_fetcher_tracker.Get().AddFetcher(this); } ProxyScriptFetcherImpl::~ProxyScriptFetcherImpl() { + g_fetcher_tracker.Get().RemoveFetcher(this); // The URLRequest's destructor will cancel the outstanding request, and // ensure that the delegate (this) is not called again. } diff --git a/net/proxy/proxy_script_fetcher.h b/net/proxy/proxy_script_fetcher.h index f6c1795..3f2602f 100644 --- a/net/proxy/proxy_script_fetcher.h +++ b/net/proxy/proxy_script_fetcher.h @@ -68,6 +68,9 @@ class ProxyScriptFetcher { static size_t SetSizeConstraintForUnittest(size_t size_bytes); }; +// Cancels all current proxy script fetches. +void EnsureNoProxyScriptFetches(); + } // namespace net #endif // NET_PROXY_PROXY_SCRIPT_FETCHER_H_ -- cgit v1.1