summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-27 08:29:50 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-27 08:29:50 +0000
commita1e646a13a0041b19b9e55fef1d7d228835cde3d (patch)
tree23d026ae4e07050f5a43ba009f2bee852224b952 /net/base
parenteb9b19800a9341d18ca777824edad31a4e3b205b (diff)
downloadchromium_src-a1e646a13a0041b19b9e55fef1d7d228835cde3d.zip
chromium_src-a1e646a13a0041b19b9e55fef1d7d228835cde3d.tar.gz
chromium_src-a1e646a13a0041b19b9e55fef1d7d228835cde3d.tar.bz2
Ensure that even if the HostResolver outlives the IO thread, its jobs will not try to complete on the IO thread.
This is an experiment for http://crbug.com/15513 BUG=15513 TBR=willchan Review URL: http://codereview.chromium.org/150001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19463 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r--net/base/host_resolver.cc15
-rw-r--r--net/base/host_resolver.h6
2 files changed, 20 insertions, 1 deletions
diff --git a/net/base/host_resolver.cc b/net/base/host_resolver.cc
index ca742da..4f0ede5 100644
--- a/net/base/host_resolver.cc
+++ b/net/base/host_resolver.cc
@@ -398,7 +398,8 @@ class HostResolver::Job : public base::RefCountedThreadSafe<HostResolver::Job> {
//-----------------------------------------------------------------------------
HostResolver::HostResolver(int max_cache_entries, int cache_duration_ms)
- : cache_(max_cache_entries, cache_duration_ms), next_request_id_(0) {
+ : cache_(max_cache_entries, cache_duration_ms), next_request_id_(0),
+ shutdown_(false) {
#if defined(OS_WIN)
EnsureWinsockInit();
#endif
@@ -421,6 +422,9 @@ int HostResolver::Resolve(const RequestInfo& info,
AddressList* addresses,
CompletionCallback* callback,
Request** out_req) {
+ if (shutdown_)
+ return ERR_UNEXPECTED;
+
// Choose a unique ID number for observers to see.
int request_id = next_request_id_++;
@@ -517,6 +521,15 @@ void HostResolver::RemoveObserver(Observer* observer) {
observers_.erase(it);
}
+void HostResolver::Shutdown() {
+ shutdown_ = true;
+
+ // Cancel the outstanding jobs.
+ for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ++it)
+ it->second->Cancel();
+ jobs_.clear();
+}
+
void HostResolver::AddOutstandingJob(Job* job) {
scoped_refptr<Job>& found_job = jobs_[job->host()];
DCHECK(!found_job);
diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h
index a912661..5a6c548 100644
--- a/net/base/host_resolver.h
+++ b/net/base/host_resolver.h
@@ -162,6 +162,9 @@ class HostResolver : public base::RefCounted<HostResolver> {
// Unregisters an observer previously added by AddObserver().
void RemoveObserver(Observer* observer);
+ // TODO(eroman): temp hack for http://crbug.com/15513
+ void Shutdown();
+
private:
class Job;
typedef std::vector<Request*> RequestsList;
@@ -210,6 +213,9 @@ class HostResolver : public base::RefCounted<HostResolver> {
// Observers are the only consumers of this ID number.
int next_request_id_;
+ // TODO(eroman): temp hack for http://crbug.com/15513
+ bool shutdown_;
+
DISALLOW_COPY_AND_ASSIGN(HostResolver);
};