diff options
Diffstat (limited to 'net/url_request/url_request.cc')
-rw-r--r-- | net/url_request/url_request.cc | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index acf70dd..45043e9 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -44,7 +44,6 @@ URLRequest::URLRequest(const GURL& url, Delegate* delegate) load_flags_(net::LOAD_NORMAL), delegate_(delegate), is_pending_(false), - user_data_(NULL), enable_profiling_(false), redirect_limit_(kMaxRedirects), final_upload_progress_(0), @@ -67,8 +66,6 @@ URLRequest::~URLRequest() { if (job_) OrphanJob(); - - delete user_data_; // NULL check unnecessary for delete } // static @@ -240,10 +237,14 @@ void URLRequest::set_referrer(const std::string& referrer) { } void URLRequest::Start() { + StartJob(GetJobManager()->CreateJob(this)); +} + +void URLRequest::StartJob(URLRequestJob* job) { DCHECK(!is_pending_); DCHECK(!job_); - job_ = GetJobManager()->CreateJob(this); + job_ = job; job_->SetExtraRequestHeaders(extra_request_headers_); if (upload_.get()) @@ -260,6 +261,20 @@ void URLRequest::Start() { job_->Start(); } +void URLRequest::Restart() { + // Should only be called if the original job didn't make any progress. + DCHECK(job_ && !job_->has_response_started()); + RestartWithJob(GetJobManager()->CreateJob(this)); +} + +void URLRequest::RestartWithJob(URLRequestJob *job) { + DCHECK(job->request() == this); + OrphanJob(); + status_ = URLRequestStatus(); + is_pending_ = false; + StartJob(job); +} + void URLRequest::Cancel() { DoCancel(net::ERR_ABORTED, net::SSLInfo()); } @@ -319,6 +334,24 @@ bool URLRequest::Read(net::IOBuffer* dest, int dest_size, int *bytes_read) { return job_->Read(dest, dest_size, bytes_read); } +void URLRequest::ReceivedRedirect(const GURL& location) { + URLRequestJob* job = GetJobManager()->MaybeInterceptRedirect(this, location); + if (job) { + RestartWithJob(job); + } else if (delegate_) { + delegate_->OnReceivedRedirect(this, location); + } +} + +void URLRequest::ResponseStarted() { + URLRequestJob* job = GetJobManager()->MaybeInterceptResponse(this); + if (job) { + RestartWithJob(job); + } else if (delegate_) { + delegate_->OnResponseStarted(this); + } +} + void URLRequest::SetAuth(const wstring& username, const wstring& password) { DCHECK(job_); DCHECK(job_->NeedsAuth()); @@ -422,6 +455,17 @@ int64 URLRequest::GetExpectedContentSize() const { return expected_content_size; } +URLRequest::UserData* URLRequest::GetUserData(void* key) const { + UserDataMap::const_iterator found = user_data_.find(key); + if (found != user_data_.end()) + return found->second.get(); + return NULL; +} + +void URLRequest::SetUserData(void* key, UserData* data) { + user_data_[key] = linked_ptr<UserData>(data); +} + #ifndef NDEBUG URLRequestMetrics::~URLRequestMetrics() { |