Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Unified Diff: net/url_request/url_request.cc

Issue 67019: URLRequest::Interceptor enhancements... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/url_request/url_request.h ('k') | net/url_request/url_request_job.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request.cc
===================================================================
--- net/url_request/url_request.cc (revision 13871)
+++ net/url_request/url_request.cc (working copy)
@@ -44,7 +44,6 @@
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 @@
if (job_)
OrphanJob();
-
- delete user_data_; // NULL check unnecessary for delete
}
// static
@@ -240,10 +237,14 @@
}
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 @@
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 @@
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 @@
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() {
« no previous file with comments | « net/url_request/url_request.h ('k') | net/url_request/url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698