| 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 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1467 void ResourceDispatcherHost::ResumeRequest(const GlobalRequestID& request_id) { | 1467 void ResourceDispatcherHost::ResumeRequest(const GlobalRequestID& request_id) { |
| 1468 PendingRequestList::iterator i = pending_requests_.find(request_id); | 1468 PendingRequestList::iterator i = pending_requests_.find(request_id); |
| 1469 if (i == pending_requests_.end()) // The request may have been destroyed | 1469 if (i == pending_requests_.end()) // The request may have been destroyed |
| 1470 return; | 1470 return; |
| 1471 | 1471 |
| 1472 net::URLRequest* request = i->second; | 1472 net::URLRequest* request = i->second; |
| 1473 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1473 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); |
| 1474 if (!info->is_paused()) | 1474 if (!info->is_paused()) |
| 1475 return; | 1475 return; |
| 1476 | 1476 |
| 1477 VLOG(1) << "Resuming: " << i->second->url().spec(); | 1477 VLOG(1) << "Resuming: \"" << i->second->url().spec() << "\"" |
| 1478 << " paused_read_bytes = " << info->paused_read_bytes() |
| 1479 << " called response started = " << info->called_on_response_started() |
| 1480 << " started reading = " << info->has_started_reading(); |
| 1478 | 1481 |
| 1479 info->set_is_paused(false); | 1482 info->set_is_paused(false); |
| 1480 | 1483 |
| 1481 if (info->called_on_response_started()) { | 1484 if (info->called_on_response_started()) { |
| 1482 if (info->has_started_reading()) { | 1485 if (info->has_started_reading()) { |
| 1483 OnReadCompleted(i->second, info->paused_read_bytes()); | 1486 OnReadCompleted(i->second, info->paused_read_bytes()); |
| 1484 } else { | 1487 } else { |
| 1485 StartReading(request); | 1488 StartReading(request); |
| 1486 } | 1489 } |
| 1487 } else { | 1490 } else { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1515 DCHECK(buf); | 1518 DCHECK(buf); |
| 1516 DCHECK(buf_size > 0); | 1519 DCHECK(buf_size > 0); |
| 1517 | 1520 |
| 1518 info->set_has_started_reading(true); | 1521 info->set_has_started_reading(true); |
| 1519 return request->Read(buf, buf_size, bytes_read); | 1522 return request->Read(buf, buf_size, bytes_read); |
| 1520 } | 1523 } |
| 1521 | 1524 |
| 1522 void ResourceDispatcherHost::OnReadCompleted(net::URLRequest* request, | 1525 void ResourceDispatcherHost::OnReadCompleted(net::URLRequest* request, |
| 1523 int bytes_read) { | 1526 int bytes_read) { |
| 1524 DCHECK(request); | 1527 DCHECK(request); |
| 1525 VLOG(1) << "OnReadCompleted: " << request->url().spec(); | 1528 VLOG(1) << "OnReadCompleted: \"" << request->url().spec() << "\"" |
| 1529 << " bytes_read = " << bytes_read; |
| 1526 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1530 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); |
| 1527 | 1531 |
| 1528 // bytes_read == -1 always implies an error, so we want to skip the | 1532 // bytes_read == -1 always implies an error, so we want to skip the |
| 1529 // pause checks and just call OnResponseCompleted. | 1533 // pause checks and just call OnResponseCompleted. |
| 1530 if (bytes_read == -1) { | 1534 if (bytes_read == -1) { |
| 1531 DCHECK(!request->status().is_success()); | 1535 DCHECK(!request->status().is_success()); |
| 1532 | 1536 |
| 1533 OnResponseCompleted(request); | 1537 OnResponseCompleted(request); |
| 1534 return; | 1538 return; |
| 1535 } | 1539 } |
| 1536 | 1540 |
| 1537 // OnReadCompleted can be called without Read (e.g., for chrome:// URLs). | 1541 // OnReadCompleted can be called without Read (e.g., for chrome:// URLs). |
| 1538 // Make sure we know that a read has begun. | 1542 // Make sure we know that a read has begun. |
| 1539 info->set_has_started_reading(true); | 1543 info->set_has_started_reading(true); |
| 1540 | 1544 |
| 1541 if (PauseRequestIfNeeded(info)) { | 1545 if (PauseRequestIfNeeded(info)) { |
| 1542 info->set_paused_read_bytes(bytes_read); | 1546 info->set_paused_read_bytes(bytes_read); |
| 1543 VLOG(1) << "OnReadCompleted pausing: " << request->url().spec(); | 1547 VLOG(1) << "OnReadCompleted pausing: \"" << request->url().spec() << "\"" |
| 1548 << " bytes_read = " << bytes_read; |
| 1544 return; | 1549 return; |
| 1545 } | 1550 } |
| 1546 | 1551 |
| 1547 if (request->status().is_success() && CompleteRead(request, &bytes_read)) { | 1552 if (request->status().is_success() && CompleteRead(request, &bytes_read)) { |
| 1548 // The request can be paused if we realize that the renderer is not | 1553 // The request can be paused if we realize that the renderer is not |
| 1549 // servicing messages fast enough. | 1554 // servicing messages fast enough. |
| 1550 if (info->pause_count() == 0 && | 1555 if (info->pause_count() == 0 && |
| 1551 Read(request, &bytes_read) && | 1556 Read(request, &bytes_read) && |
| 1552 request->status().is_success()) { | 1557 request->status().is_success()) { |
| 1553 if (bytes_read == 0) { | 1558 if (bytes_read == 0) { |
| 1554 CompleteRead(request, &bytes_read); | 1559 CompleteRead(request, &bytes_read); |
| 1555 } else { | 1560 } else { |
| 1556 // Force the next CompleteRead / Read pair to run as a separate task. | 1561 // Force the next CompleteRead / Read pair to run as a separate task. |
| 1557 // This avoids a fast, large network request from monopolizing the IO | 1562 // This avoids a fast, large network request from monopolizing the IO |
| 1558 // thread and starving other IO operations from running. | 1563 // thread and starving other IO operations from running. |
| 1564 VLOG(1) << "OnReadCompleted postponing: \"" |
| 1565 << request->url().spec() << "\"" |
| 1566 << " bytes_read = " << bytes_read; |
| 1559 info->set_paused_read_bytes(bytes_read); | 1567 info->set_paused_read_bytes(bytes_read); |
| 1560 info->set_is_paused(true); | 1568 info->set_is_paused(true); |
| 1561 GlobalRequestID id(info->child_id(), info->request_id()); | 1569 GlobalRequestID id(info->child_id(), info->request_id()); |
| 1562 MessageLoop::current()->PostTask( | 1570 MessageLoop::current()->PostTask( |
| 1563 FROM_HERE, | 1571 FROM_HERE, |
| 1564 method_runner_.NewRunnableMethod( | 1572 method_runner_.NewRunnableMethod( |
| 1565 &ResourceDispatcherHost::ResumeRequest, id)); | 1573 &ResourceDispatcherHost::ResumeRequest, id)); |
| 1566 return; | 1574 return; |
| 1567 } | 1575 } |
| 1568 } | 1576 } |
| 1569 } | 1577 } |
| 1570 | 1578 |
| 1571 if (PauseRequestIfNeeded(info)) { | 1579 if (PauseRequestIfNeeded(info)) { |
| 1572 info->set_paused_read_bytes(bytes_read); | 1580 info->set_paused_read_bytes(bytes_read); |
| 1573 VLOG(1) << "OnReadCompleted (CompleteRead) pausing: " | 1581 VLOG(1) << "OnReadCompleted (CompleteRead) pausing: \"" |
| 1574 << request->url().spec(); | 1582 << request->url().spec() << "\"" |
| 1583 << " bytes_read = " << bytes_read; |
| 1575 return; | 1584 return; |
| 1576 } | 1585 } |
| 1577 | 1586 |
| 1578 // If the status is not IO pending then we've either finished (success) or we | 1587 // If the status is not IO pending then we've either finished (success) or we |
| 1579 // had an error. Either way, we're done! | 1588 // had an error. Either way, we're done! |
| 1580 if (!request->status().is_io_pending()) | 1589 if (!request->status().is_io_pending()) |
| 1581 OnResponseCompleted(request); | 1590 OnResponseCompleted(request); |
| 1582 } | 1591 } |
| 1583 | 1592 |
| 1584 bool ResourceDispatcherHost::CompleteRead(net::URLRequest* request, | 1593 bool ResourceDispatcherHost::CompleteRead(net::URLRequest* request, |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2039 return is_prefetch_enabled_; | 2048 return is_prefetch_enabled_; |
| 2040 } | 2049 } |
| 2041 | 2050 |
| 2042 // static | 2051 // static |
| 2043 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) { | 2052 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) { |
| 2044 is_prefetch_enabled_ = value; | 2053 is_prefetch_enabled_ = value; |
| 2045 } | 2054 } |
| 2046 | 2055 |
| 2047 // static | 2056 // static |
| 2048 bool ResourceDispatcherHost::is_prefetch_enabled_ = false; | 2057 bool ResourceDispatcherHost::is_prefetch_enabled_ = false; |
| OLD | NEW |