OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
6 | 6 |
7 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 7 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 1371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 void ResourceDispatcherHost::ResumeRequest(const GlobalRequestID& request_id) { | 1382 void ResourceDispatcherHost::ResumeRequest(const GlobalRequestID& request_id) { |
1383 PendingRequestList::iterator i = pending_requests_.find(request_id); | 1383 PendingRequestList::iterator i = pending_requests_.find(request_id); |
1384 if (i == pending_requests_.end()) // The request may have been destroyed | 1384 if (i == pending_requests_.end()) // The request may have been destroyed |
1385 return; | 1385 return; |
1386 | 1386 |
1387 net::URLRequest* request = i->second; | 1387 net::URLRequest* request = i->second; |
1388 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1388 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); |
1389 if (!info->is_paused()) | 1389 if (!info->is_paused()) |
1390 return; | 1390 return; |
1391 | 1391 |
1392 VLOG(1) << "Resuming: " << i->second->url().spec(); | 1392 VLOG(1) << "Resuming: \"" << i->second->url().spec() << "\"" |
| 1393 << " paused_read_bytes = " << info->paused_read_bytes() |
| 1394 << " called response started = " << info->called_on_response_started() |
| 1395 << " started reading = " << info->has_started_reading(); |
1393 | 1396 |
1394 info->set_is_paused(false); | 1397 info->set_is_paused(false); |
1395 | 1398 |
1396 if (info->called_on_response_started()) { | 1399 if (info->called_on_response_started()) { |
1397 if (info->has_started_reading()) { | 1400 if (info->has_started_reading()) { |
1398 OnReadCompleted(i->second, info->paused_read_bytes()); | 1401 OnReadCompleted(i->second, info->paused_read_bytes()); |
1399 } else { | 1402 } else { |
1400 StartReading(request); | 1403 StartReading(request); |
1401 } | 1404 } |
1402 } else { | 1405 } else { |
(...skipping 27 matching lines...) Expand all Loading... |
1430 DCHECK(buf); | 1433 DCHECK(buf); |
1431 DCHECK(buf_size > 0); | 1434 DCHECK(buf_size > 0); |
1432 | 1435 |
1433 info->set_has_started_reading(true); | 1436 info->set_has_started_reading(true); |
1434 return request->Read(buf, buf_size, bytes_read); | 1437 return request->Read(buf, buf_size, bytes_read); |
1435 } | 1438 } |
1436 | 1439 |
1437 void ResourceDispatcherHost::OnReadCompleted(net::URLRequest* request, | 1440 void ResourceDispatcherHost::OnReadCompleted(net::URLRequest* request, |
1438 int bytes_read) { | 1441 int bytes_read) { |
1439 DCHECK(request); | 1442 DCHECK(request); |
1440 VLOG(1) << "OnReadCompleted: " << request->url().spec(); | 1443 VLOG(1) << "OnReadCompleted: \"" << request->url().spec() << "\"" |
| 1444 << " bytes_read = " << bytes_read; |
1441 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1445 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); |
1442 | 1446 |
1443 // OnReadCompleted can be called without Read (e.g., for chrome:// URLs). | 1447 // OnReadCompleted can be called without Read (e.g., for chrome:// URLs). |
1444 // Make sure we know that a read has begun. | 1448 // Make sure we know that a read has begun. |
1445 info->set_has_started_reading(true); | 1449 info->set_has_started_reading(true); |
1446 | 1450 |
1447 if (PauseRequestIfNeeded(info)) { | 1451 if (PauseRequestIfNeeded(info)) { |
1448 info->set_paused_read_bytes(bytes_read); | 1452 info->set_paused_read_bytes(bytes_read); |
1449 VLOG(1) << "OnReadCompleted pausing: " << request->url().spec(); | 1453 VLOG(1) << "OnReadCompleted pausing: \"" << request->url().spec() << "\"" |
| 1454 << " bytes_read = " << bytes_read; |
1450 return; | 1455 return; |
1451 } | 1456 } |
1452 | 1457 |
1453 if (request->status().is_success() && CompleteRead(request, &bytes_read)) { | 1458 if (request->status().is_success() && CompleteRead(request, &bytes_read)) { |
1454 // The request can be paused if we realize that the renderer is not | 1459 // The request can be paused if we realize that the renderer is not |
1455 // servicing messages fast enough. | 1460 // servicing messages fast enough. |
1456 if (info->pause_count() == 0 && | 1461 if (info->pause_count() == 0 && |
1457 Read(request, &bytes_read) && | 1462 Read(request, &bytes_read) && |
1458 request->status().is_success()) { | 1463 request->status().is_success()) { |
1459 if (bytes_read == 0) { | 1464 if (bytes_read == 0) { |
1460 CompleteRead(request, &bytes_read); | 1465 CompleteRead(request, &bytes_read); |
1461 } else { | 1466 } else { |
1462 // Force the next CompleteRead / Read pair to run as a separate task. | 1467 // Force the next CompleteRead / Read pair to run as a separate task. |
1463 // This avoids a fast, large network request from monopolizing the IO | 1468 // This avoids a fast, large network request from monopolizing the IO |
1464 // thread and starving other IO operations from running. | 1469 // thread and starving other IO operations from running. |
| 1470 VLOG(1) << "OnReadCompleted postponing: \"" |
| 1471 << request->url().spec() << "\"" |
| 1472 << " bytes_read = " << bytes_read; |
1465 info->set_paused_read_bytes(bytes_read); | 1473 info->set_paused_read_bytes(bytes_read); |
1466 info->set_is_paused(true); | 1474 info->set_is_paused(true); |
1467 GlobalRequestID id(info->child_id(), info->request_id()); | 1475 GlobalRequestID id(info->child_id(), info->request_id()); |
1468 MessageLoop::current()->PostTask( | 1476 MessageLoop::current()->PostTask( |
1469 FROM_HERE, | 1477 FROM_HERE, |
1470 method_runner_.NewRunnableMethod( | 1478 method_runner_.NewRunnableMethod( |
1471 &ResourceDispatcherHost::ResumeRequest, id)); | 1479 &ResourceDispatcherHost::ResumeRequest, id)); |
1472 return; | 1480 return; |
1473 } | 1481 } |
1474 } | 1482 } |
1475 } | 1483 } |
1476 | 1484 |
1477 if (PauseRequestIfNeeded(info)) { | 1485 if (PauseRequestIfNeeded(info)) { |
1478 info->set_paused_read_bytes(bytes_read); | 1486 info->set_paused_read_bytes(bytes_read); |
1479 VLOG(1) << "OnReadCompleted (CompleteRead) pausing: " | 1487 VLOG(1) << "OnReadCompleted (CompleteRead) pausing: \"" |
1480 << request->url().spec(); | 1488 << request->url().spec() << "\"" |
| 1489 << " bytes_read = " << bytes_read; |
1481 return; | 1490 return; |
1482 } | 1491 } |
1483 | 1492 |
1484 // If the status is not IO pending then we've either finished (success) or we | 1493 // If the status is not IO pending then we've either finished (success) or we |
1485 // had an error. Either way, we're done! | 1494 // had an error. Either way, we're done! |
1486 if (!request->status().is_io_pending()) | 1495 if (!request->status().is_io_pending()) |
1487 OnResponseCompleted(request); | 1496 OnResponseCompleted(request); |
1488 } | 1497 } |
1489 | 1498 |
1490 bool ResourceDispatcherHost::CompleteRead(net::URLRequest* request, | 1499 bool ResourceDispatcherHost::CompleteRead(net::URLRequest* request, |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1989 return is_prefetch_enabled_; | 1998 return is_prefetch_enabled_; |
1990 } | 1999 } |
1991 | 2000 |
1992 // static | 2001 // static |
1993 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) { | 2002 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) { |
1994 is_prefetch_enabled_ = value; | 2003 is_prefetch_enabled_ = value; |
1995 } | 2004 } |
1996 | 2005 |
1997 // static | 2006 // static |
1998 bool ResourceDispatcherHost::is_prefetch_enabled_ = false; | 2007 bool ResourceDispatcherHost::is_prefetch_enabled_ = false; |
OLD | NEW |