summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-12 04:33:21 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-12 04:33:21 +0000
commit077851be33ef19822a8ac6497f6618894c30da56 (patch)
treef2f0bf33c206c5563fd04f06489bdc5fe9631f4b /net
parent0fa0fbc5767ec406aa44c48ea5f775d158042bb2 (diff)
downloadchromium_src-077851be33ef19822a8ac6497f6618894c30da56.zip
chromium_src-077851be33ef19822a8ac6497f6618894c30da56.tar.gz
chromium_src-077851be33ef19822a8ac6497f6618894c30da56.tar.bz2
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
Diffstat (limited to 'net')
-rw-r--r--net/proxy/proxy_script_fetcher.cc46
-rw-r--r--net/proxy/proxy_script_fetcher.h3
2 files changed, 49 insertions, 0 deletions
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 <set>
+
+#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<ProxyScriptFetcher*>::const_iterator it = fetchers_.begin();
+ it != fetchers_.end(); ++it) {
+ (*it)->Cancel();
+ }
+ }
+
+ private:
+ ProxyScriptFetcherTracker();
+ ~ProxyScriptFetcherTracker();
+
+ friend struct base::DefaultLazyInstanceTraits<ProxyScriptFetcherTracker>;
+
+ std::set<ProxyScriptFetcher*> fetchers_;
+ DISALLOW_COPY_AND_ASSIGN(ProxyScriptFetcherTracker);
+};
+
+ProxyScriptFetcherTracker::ProxyScriptFetcherTracker() {}
+ProxyScriptFetcherTracker::~ProxyScriptFetcherTracker() {}
+
+base::LazyInstance<ProxyScriptFetcherTracker>
+ 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_