OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/url_request/url_request_redirect_job.h" | 5 #include "net/url_request/url_request_redirect_job.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 void URLRequestRedirectJob::Start() { | 59 void URLRequestRedirectJob::Start() { |
60 request()->net_log().AddEvent( | 60 request()->net_log().AddEvent( |
61 NetLog::TYPE_URL_REQUEST_REDIRECT_JOB, | 61 NetLog::TYPE_URL_REQUEST_REDIRECT_JOB, |
62 NetLog::StringCallback("reason", &redirect_reason_)); | 62 NetLog::StringCallback("reason", &redirect_reason_)); |
63 base::ThreadTaskRunnerHandle::Get()->PostTask( | 63 base::ThreadTaskRunnerHandle::Get()->PostTask( |
64 FROM_HERE, base::Bind(&URLRequestRedirectJob::StartAsync, | 64 FROM_HERE, base::Bind(&URLRequestRedirectJob::StartAsync, |
65 weak_factory_.GetWeakPtr())); | 65 weak_factory_.GetWeakPtr())); |
66 } | 66 } |
67 | 67 |
| 68 void URLRequestRedirectJob::Kill() { |
| 69 weak_factory_.InvalidateWeakPtrs(); |
| 70 URLRequestJob::Kill(); |
| 71 } |
| 72 |
68 bool URLRequestRedirectJob::CopyFragmentOnRedirect(const GURL& location) const { | 73 bool URLRequestRedirectJob::CopyFragmentOnRedirect(const GURL& location) const { |
69 // The instantiators have full control over the desired redirection target, | 74 // The instantiators have full control over the desired redirection target, |
70 // including the reference fragment part of the URL. | 75 // including the reference fragment part of the URL. |
71 return false; | 76 return false; |
72 } | 77 } |
73 | 78 |
74 int URLRequestRedirectJob::GetResponseCode() const { | 79 int URLRequestRedirectJob::GetResponseCode() const { |
75 // Should only be called after the URLRequest has been notified there's header | 80 // Should only be called after the URLRequest has been notified there's header |
76 // information. | 81 // information. |
77 DCHECK(fake_headers_.get()); | 82 DCHECK(fake_headers_.get()); |
78 return response_code_; | 83 return response_code_; |
79 } | 84 } |
80 | 85 |
81 URLRequestRedirectJob::~URLRequestRedirectJob() {} | 86 URLRequestRedirectJob::~URLRequestRedirectJob() {} |
82 | 87 |
83 void URLRequestRedirectJob::StartAsync() { | 88 void URLRequestRedirectJob::StartAsync() { |
| 89 DCHECK(request_); |
| 90 DCHECK(request_->status().is_success()); |
| 91 |
84 receive_headers_end_ = base::TimeTicks::Now(); | 92 receive_headers_end_ = base::TimeTicks::Now(); |
85 response_time_ = base::Time::Now(); | 93 response_time_ = base::Time::Now(); |
86 | 94 |
87 std::string header_string = | 95 std::string header_string = |
88 base::StringPrintf("HTTP/1.1 %i Internal Redirect\n" | 96 base::StringPrintf("HTTP/1.1 %i Internal Redirect\n" |
89 "Location: %s\n" | 97 "Location: %s\n" |
90 "Non-Authoritative-Reason: %s", | 98 "Non-Authoritative-Reason: %s", |
91 response_code_, | 99 response_code_, |
92 redirect_destination_.spec().c_str(), | 100 redirect_destination_.spec().c_str(), |
93 redirect_reason_.c_str()); | 101 redirect_reason_.c_str()); |
(...skipping 25 matching lines...) Expand all Loading... |
119 base::Unretained(fake_headers_.get()))); | 127 base::Unretained(fake_headers_.get()))); |
120 | 128 |
121 // TODO(mmenke): Consider calling the NetworkDelegate with the headers here. | 129 // TODO(mmenke): Consider calling the NetworkDelegate with the headers here. |
122 // There's some weirdness about how to handle the case in which the delegate | 130 // There's some weirdness about how to handle the case in which the delegate |
123 // tries to modify the redirect location, in terms of how IsSafeRedirect | 131 // tries to modify the redirect location, in terms of how IsSafeRedirect |
124 // should behave, and whether the fragment should be copied. | 132 // should behave, and whether the fragment should be copied. |
125 URLRequestJob::NotifyHeadersComplete(); | 133 URLRequestJob::NotifyHeadersComplete(); |
126 } | 134 } |
127 | 135 |
128 } // namespace net | 136 } // namespace net |
OLD | NEW |