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 "content/browser/appcache/appcache_update_job.h" | 5 #include "content/browser/appcache/appcache_update_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 | 154 |
155 void AppCacheUpdateJob::URLFetcher::OnResponseStarted( | 155 void AppCacheUpdateJob::URLFetcher::OnResponseStarted( |
156 net::URLRequest *request) { | 156 net::URLRequest *request) { |
157 DCHECK(request == request_); | 157 DCHECK(request == request_); |
158 int response_code = -1; | 158 int response_code = -1; |
159 if (request->status().is_success()) { | 159 if (request->status().is_success()) { |
160 response_code = request->GetResponseCode(); | 160 response_code = request->GetResponseCode(); |
161 job_->MadeProgress(); | 161 job_->MadeProgress(); |
162 } | 162 } |
163 if ((response_code / 100) == 2) { | 163 if ((response_code / 100) == 2) { |
164 | 164 |
Ryan Sleevi
2014/10/11 00:54:44
unnecessary newline?
michaeln
2014/10/15 19:20:22
Done.
| |
165 // See http://code.google.com/p/chromium/issues/detail?id=69594 | 165 if (url_.SchemeIsSecure()) { |
166 // We willfully violate the HTML5 spec at this point in order | 166 // See http://code.google.com/p/chromium/issues/detail?id=69594 |
167 // to support the appcaching of cross-origin HTTPS resources. | 167 // We willfully violate the HTML5 spec at this point in order |
168 // We've opted for a milder constraint and allow caching unless | 168 // to support the appcaching of cross-origin HTTPS resources. |
169 // the resource has a "no-store" header. A spec change has been | 169 // We've opted for a milder constraint and allow caching unless |
170 // requested on the whatwg list. | 170 // the resource has a "no-store" header. A spec change has been |
171 // TODO(michaeln): Consider doing this for cross-origin HTTP resources too. | 171 // requested on the whatwg list. |
172 if (url_.SchemeIsSecure() && | 172 // TODO(michaeln): Consider doing this for cross-origin HTTP too. |
173 url_.GetOrigin() != job_->manifest_url_.GetOrigin()) { | 173 if (url_.GetOrigin() != job_->manifest_url_.GetOrigin()) { |
174 if (request->response_headers()-> | 174 if (request->response_headers()-> |
175 HasHeaderValue("cache-control", "no-store")) { | 175 HasHeaderValue("cache-control", "no-store")) { |
176 DCHECK_EQ(-1, redirect_response_code_); | |
177 request->Cancel(); | |
178 result_ = SERVER_ERROR; // Not the best match? | |
palmer
2014/10/10 23:48:10
Maybe CANCELED_ERROR, or add a new one, like NOT_S
michaeln
2014/10/15 19:20:22
SECURITY_ERROR?
| |
179 OnResponseCompleted(); | |
180 return; | |
181 } | |
182 } | |
183 | |
184 // Do not cache content with cert errors. | |
185 if (net::IsCertStatusError(request->ssl_info().cert_status)) { | |
palmer
2014/10/10 23:50:32
Lines 186 – 190 duplicate lines 176 – 180; maybe j
michaeln
2014/10/15 19:20:21
Done.
| |
176 DCHECK_EQ(-1, redirect_response_code_); | 186 DCHECK_EQ(-1, redirect_response_code_); |
177 request->Cancel(); | 187 request->Cancel(); |
178 result_ = SERVER_ERROR; // Not the best match? | 188 result_ = SERVER_ERROR; // Not the best match? |
179 OnResponseCompleted(); | 189 OnResponseCompleted(); |
180 return; | 190 return; |
181 } | 191 } |
182 } | 192 } |
183 | 193 |
184 // Write response info to storage for URL fetches. Wait for async write | 194 // Write response info to storage for URL fetches. Wait for async write |
185 // completion before reading any response data. | 195 // completion before reading any response data. |
186 if (fetch_type_ == URL_FETCH || fetch_type_ == MASTER_ENTRY_FETCH) { | 196 if (fetch_type_ == URL_FETCH || fetch_type_ == MASTER_ENTRY_FETCH) { |
187 response_writer_.reset(job_->CreateResponseWriter()); | 197 response_writer_.reset(job_->CreateResponseWriter()); |
188 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer( | 198 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer( |
189 new HttpResponseInfoIOBuffer( | 199 new HttpResponseInfoIOBuffer( |
190 new net::HttpResponseInfo(request->response_info()))); | 200 new net::HttpResponseInfo(request->response_info()))); |
191 response_writer_->WriteInfo( | 201 response_writer_->WriteInfo( |
192 io_buffer.get(), | 202 io_buffer.get(), |
193 base::Bind(&URLFetcher::OnWriteComplete, base::Unretained(this))); | 203 base::Bind(&URLFetcher::OnWriteComplete, base::Unretained(this))); |
194 } else { | 204 } else { |
195 ReadResponseData(); | 205 ReadResponseData(); |
196 } | 206 } |
197 } else { | 207 } else { |
198 if (response_code > 0) | 208 if (response_code > 0) |
199 result_ = SERVER_ERROR; | 209 result_ = SERVER_ERROR; |
200 else | 210 else |
201 result_ = NETWORK_ERROR; | 211 result_ = NETWORK_ERROR; |
202 OnResponseCompleted(); | 212 OnResponseCompleted(); |
Ryan Sleevi
2014/10/11 00:54:44
This reads like error handling under success handl
michaeln
2014/10/15 19:20:21
Thnx, that helped with readability quite a lot.
| |
203 } | 213 } |
204 } | 214 } |
205 | 215 |
206 void AppCacheUpdateJob::URLFetcher::OnReadCompleted( | 216 void AppCacheUpdateJob::URLFetcher::OnReadCompleted( |
207 net::URLRequest* request, int bytes_read) { | 217 net::URLRequest* request, int bytes_read) { |
208 DCHECK(request_ == request); | 218 DCHECK(request_ == request); |
209 bool data_consumed = true; | 219 bool data_consumed = true; |
210 if (request->status().is_success() && bytes_read > 0) { | 220 if (request->status().is_success() && bytes_read > 0) { |
211 job_->MadeProgress(); | 221 job_->MadeProgress(); |
212 data_consumed = ConsumeResponseData(bytes_read); | 222 data_consumed = ConsumeResponseData(bytes_read); |
(...skipping 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1604 | 1614 |
1605 // Break the connection with the group so the group cannot call delete | 1615 // Break the connection with the group so the group cannot call delete |
1606 // on this object after we've posted a task to delete ourselves. | 1616 // on this object after we've posted a task to delete ourselves. |
1607 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); | 1617 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); |
1608 group_ = NULL; | 1618 group_ = NULL; |
1609 | 1619 |
1610 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1620 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
1611 } | 1621 } |
1612 | 1622 |
1613 } // namespace content | 1623 } // namespace content |
OLD | NEW |