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

Side by Side Diff: media/blink/resource_multibuffer_data_provider.cc

Issue 2078833003: fix a semi-rare crash in multibuffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « media/blink/multibuffer_data_source_unittest.cc ('k') | media/blink/test_response_generator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "media/blink/resource_multibuffer_data_provider.h" 5 #include "media/blink/resource_multibuffer_data_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 max_enum); // PRESUBMIT_IGNORE_UMA_MAX 251 max_enum); // PRESUBMIT_IGNORE_UMA_MAX
252 } 252 }
253 253
254 reasons >>= 1; 254 reasons >>= 1;
255 ++shift; 255 ++shift;
256 } 256 }
257 257
258 // Expected content length can be |kPositionNotSpecified|, in that case 258 // Expected content length can be |kPositionNotSpecified|, in that case
259 // |content_length_| is not specified and this is a streaming response. 259 // |content_length_| is not specified and this is a streaming response.
260 int64_t content_length = response.expectedContentLength(); 260 int64_t content_length = response.expectedContentLength();
261 bool end_of_file = false;
261 262
262 // We make a strong assumption that when we reach here we have either 263 // We make a strong assumption that when we reach here we have either
263 // received a response from HTTP/HTTPS protocol or the request was 264 // received a response from HTTP/HTTPS protocol or the request was
264 // successful (in particular range request). So we only verify the partial 265 // successful (in particular range request). So we only verify the partial
265 // response for HTTP and HTTPS protocol. 266 // response for HTTP and HTTPS protocol.
266 if (destination_url_data->url().SchemeIsHTTPOrHTTPS()) { 267 if (destination_url_data->url().SchemeIsHTTPOrHTTPS()) {
267 bool partial_response = (response.httpStatusCode() == kHttpPartialContent); 268 bool partial_response = (response.httpStatusCode() == kHttpPartialContent);
268 bool ok_response = (response.httpStatusCode() == kHttpOK); 269 bool ok_response = (response.httpStatusCode() == kHttpOK);
269 270
270 // Check to see whether the server supports byte ranges. 271 // Check to see whether the server supports byte ranges.
271 std::string accept_ranges = 272 std::string accept_ranges =
272 response.httpHeaderField("Accept-Ranges").utf8(); 273 response.httpHeaderField("Accept-Ranges").utf8();
273 if (accept_ranges.find("bytes") != std::string::npos) 274 if (accept_ranges.find("bytes") != std::string::npos)
274 destination_url_data->set_range_supported(); 275 destination_url_data->set_range_supported();
275 276
276 // If we have verified the partial response and it is correct. 277 // If we have verified the partial response and it is correct.
277 // It's also possible for a server to support range requests 278 // It's also possible for a server to support range requests
278 // without advertising "Accept-Ranges: bytes". 279 // without advertising "Accept-Ranges: bytes".
279 if (partial_response && 280 if (partial_response &&
280 VerifyPartialResponse(response, destination_url_data)) { 281 VerifyPartialResponse(response, destination_url_data)) {
281 destination_url_data->set_range_supported(); 282 destination_url_data->set_range_supported();
282 } else if (ok_response && pos_ == 0) { 283 } else if (ok_response && pos_ == 0) {
283 // We accept a 200 response for a Range:0- request, trusting the 284 // We accept a 200 response for a Range:0- request, trusting the
284 // Accept-Ranges header, because Apache thinks that's a reasonable thing 285 // Accept-Ranges header, because Apache thinks that's a reasonable thing
285 // to return. 286 // to return.
286 destination_url_data->set_length(content_length); 287 destination_url_data->set_length(content_length);
287 } else if (response.httpStatusCode() == kHttpRangeNotSatisfiable) { 288 } else if (response.httpStatusCode() == kHttpRangeNotSatisfiable) {
289 // Unsatisfiable range
288 // Really, we should never request a range that doesn't exist, but 290 // Really, we should never request a range that doesn't exist, but
289 // if we do, let's handle it in a sane way. 291 // if we do, let's handle it in a sane way.
290 // Unsatisfiable range 292 // Note, we can't just call OnDataProviderEvent() here, because
291 fifo_.push_back(DataBuffer::CreateEOSBuffer()); 293 // url_data_ hasn't been updated to the final destination yet.
292 destination_url_data->multibuffer()->OnDataProviderEvent(this); 294 end_of_file = true;
293 return;
294 } else { 295 } else {
295 active_loader_ = nullptr; 296 active_loader_ = nullptr;
296 destination_url_data->Fail(); 297 destination_url_data->Fail();
297 return; // "this" may be deleted now. 298 return; // "this" may be deleted now.
298 } 299 }
299 } else { 300 } else {
300 destination_url_data->set_range_supported(); 301 destination_url_data->set_range_supported();
301 if (content_length != kPositionNotSpecified) { 302 if (content_length != kPositionNotSpecified) {
302 destination_url_data->set_length(content_length + byte_pos()); 303 destination_url_data->set_length(content_length + byte_pos());
303 } 304 }
(...skipping 26 matching lines...) Expand all
330 331
331 // This test is vital for security! 332 // This test is vital for security!
332 const GURL& original_url = response.wasFetchedViaServiceWorker() 333 const GURL& original_url = response.wasFetchedViaServiceWorker()
333 ? response.originalURLViaServiceWorker() 334 ? response.originalURLViaServiceWorker()
334 : response.url(); 335 : response.url();
335 if (!url_data_->ValidateDataOrigin(original_url.GetOrigin())) { 336 if (!url_data_->ValidateDataOrigin(original_url.GetOrigin())) {
336 active_loader_ = nullptr; 337 active_loader_ = nullptr;
337 url_data_->Fail(); 338 url_data_->Fail();
338 return; // "this" may be deleted now. 339 return; // "this" may be deleted now.
339 } 340 }
341
342 if (end_of_file) {
343 fifo_.push_back(DataBuffer::CreateEOSBuffer());
344 url_data_->multibuffer()->OnDataProviderEvent(this);
345 }
340 } 346 }
341 347
342 void ResourceMultiBufferDataProvider::didReceiveData(WebURLLoader* loader, 348 void ResourceMultiBufferDataProvider::didReceiveData(WebURLLoader* loader,
343 const char* data, 349 const char* data,
344 int data_length, 350 int data_length,
345 int encoded_data_length) { 351 int encoded_data_length) {
346 DVLOG(1) << "didReceiveData: " << data_length << " bytes"; 352 DVLOG(1) << "didReceiveData: " << data_length << " bytes";
347 DCHECK(!Available()); 353 DCHECK(!Available());
348 DCHECK(active_loader_); 354 DCHECK(active_loader_);
349 DCHECK_GT(data_length, 0); 355 DCHECK_GT(data_length, 0);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 } 528 }
523 529
524 if (byte_pos() != first_byte_position) { 530 if (byte_pos() != first_byte_position) {
525 return false; 531 return false;
526 } 532 }
527 533
528 return true; 534 return true;
529 } 535 }
530 536
531 } // namespace media 537 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/multibuffer_data_source_unittest.cc ('k') | media/blink/test_response_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698