OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/nacl/renderer/ppb_nacl_private_impl.h" | 5 #include "components/nacl/renderer/ppb_nacl_private_impl.h" |
6 | 6 |
7 #include <numeric> | 7 #include <numeric> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1528 stream_handler_user_data_(stream_handler_user_data), | 1528 stream_handler_user_data_(stream_handler_user_data), |
1529 success_(false), | 1529 success_(false), |
1530 expected_content_length_(-1), | 1530 expected_content_length_(-1), |
1531 weak_factory_(this) {} | 1531 weak_factory_(this) {} |
1532 | 1532 |
1533 void Load(const blink::WebURLRequest& request) { | 1533 void Load(const blink::WebURLRequest& request) { |
1534 url_loader_->loadAsynchronously(request, this); | 1534 url_loader_->loadAsynchronously(request, this); |
1535 } | 1535 } |
1536 | 1536 |
1537 private: | 1537 private: |
1538 virtual void didReceiveResponse(blink::WebURLLoader* loader, | 1538 void didReceiveResponse(blink::WebURLLoader* loader, |
1539 const blink::WebURLResponse& response) { | 1539 const blink::WebURLResponse& response) override { |
1540 success_ = (response.httpStatusCode() == 200); | 1540 success_ = (response.httpStatusCode() == 200); |
1541 if (!success_) | 1541 if (!success_) |
1542 return; | 1542 return; |
1543 | 1543 |
1544 expected_content_length_ = response.expectedContentLength(); | 1544 expected_content_length_ = response.expectedContentLength(); |
1545 | 1545 |
1546 // Defer loading after receiving headers. This is because we may already | 1546 // Defer loading after receiving headers. This is because we may already |
1547 // have a cached translated nexe, so check for that now. | 1547 // have a cached translated nexe, so check for that now. |
1548 url_loader_->setDefersLoading(true); | 1548 url_loader_->setDefersLoading(true); |
1549 | 1549 |
(...skipping 12 matching lines...) Expand all Loading... |
1562 if (base::StringToLowerASCII(cur) == "no-store") | 1562 if (base::StringToLowerASCII(cur) == "no-store") |
1563 has_no_store_header = true; | 1563 has_no_store_header = true; |
1564 } | 1564 } |
1565 | 1565 |
1566 GetNexeFd( | 1566 GetNexeFd( |
1567 instance_, pexe_url_, pexe_opt_level_, last_modified_time, etag, | 1567 instance_, pexe_url_, pexe_opt_level_, last_modified_time, etag, |
1568 has_no_store_header, use_subzero_, | 1568 has_no_store_header, use_subzero_, |
1569 base::Bind(&PexeDownloader::didGetNexeFd, weak_factory_.GetWeakPtr())); | 1569 base::Bind(&PexeDownloader::didGetNexeFd, weak_factory_.GetWeakPtr())); |
1570 } | 1570 } |
1571 | 1571 |
1572 virtual void didGetNexeFd(int32_t pp_error, | 1572 void didGetNexeFd(int32_t pp_error, |
1573 bool cache_hit, | 1573 bool cache_hit, |
1574 PP_FileHandle file_handle) { | 1574 PP_FileHandle file_handle) { |
1575 if (!content::PepperPluginInstance::Get(instance_)) { | 1575 if (!content::PepperPluginInstance::Get(instance_)) { |
1576 delete this; | 1576 delete this; |
1577 return; | 1577 return; |
1578 } | 1578 } |
1579 | 1579 |
1580 HistogramEnumerate("NaCl.Perf.PNaClCache.IsHit", cache_hit, 2); | 1580 HistogramEnumerate("NaCl.Perf.PNaClCache.IsHit", cache_hit, 2); |
1581 HistogramEnumerate(use_subzero_ ? "NaCl.Perf.PNaClCache.IsHit.Subzero" | 1581 HistogramEnumerate(use_subzero_ ? "NaCl.Perf.PNaClCache.IsHit.Subzero" |
1582 : "NaCl.Perf.PNaClCache.IsHit.LLC", | 1582 : "NaCl.Perf.PNaClCache.IsHit.LLC", |
1583 cache_hit, 2); | 1583 cache_hit, 2); |
1584 if (cache_hit) { | 1584 if (cache_hit) { |
1585 stream_handler_->DidCacheHit(stream_handler_user_data_, file_handle); | 1585 stream_handler_->DidCacheHit(stream_handler_user_data_, file_handle); |
1586 | 1586 |
1587 // We delete the PexeDownloader at this point since we successfully got a | 1587 // We delete the PexeDownloader at this point since we successfully got a |
1588 // cached, translated nexe. | 1588 // cached, translated nexe. |
1589 delete this; | 1589 delete this; |
1590 return; | 1590 return; |
1591 } | 1591 } |
1592 stream_handler_->DidCacheMiss(stream_handler_user_data_, | 1592 stream_handler_->DidCacheMiss(stream_handler_user_data_, |
1593 expected_content_length_, | 1593 expected_content_length_, |
1594 file_handle); | 1594 file_handle); |
1595 | 1595 |
1596 // No translated nexe was found in the cache, so we should download the | 1596 // No translated nexe was found in the cache, so we should download the |
1597 // file to start streaming it. | 1597 // file to start streaming it. |
1598 url_loader_->setDefersLoading(false); | 1598 url_loader_->setDefersLoading(false); |
1599 } | 1599 } |
1600 | 1600 |
1601 virtual void didReceiveData(blink::WebURLLoader* loader, | 1601 void didReceiveData(blink::WebURLLoader* loader, |
1602 const char* data, | 1602 const char* data, |
1603 int data_length, | 1603 int data_length, |
1604 int encoded_data_length) { | 1604 int encoded_data_length) override { |
1605 if (content::PepperPluginInstance::Get(instance_)) { | 1605 if (content::PepperPluginInstance::Get(instance_)) { |
1606 // Stream the data we received to the stream callback. | 1606 // Stream the data we received to the stream callback. |
1607 stream_handler_->DidStreamData(stream_handler_user_data_, | 1607 stream_handler_->DidStreamData(stream_handler_user_data_, |
1608 data, | 1608 data, |
1609 data_length); | 1609 data_length); |
1610 } | 1610 } |
1611 } | 1611 } |
1612 | 1612 |
1613 virtual void didFinishLoading(blink::WebURLLoader* loader, | 1613 void didFinishLoading(blink::WebURLLoader* loader, |
1614 double finish_time, | 1614 double finish_time, |
1615 int64_t total_encoded_data_length) { | 1615 int64_t total_encoded_data_length) override { |
1616 int32_t result = success_ ? PP_OK : PP_ERROR_FAILED; | 1616 int32_t result = success_ ? PP_OK : PP_ERROR_FAILED; |
1617 | 1617 |
1618 if (content::PepperPluginInstance::Get(instance_)) | 1618 if (content::PepperPluginInstance::Get(instance_)) |
1619 stream_handler_->DidFinishStream(stream_handler_user_data_, result); | 1619 stream_handler_->DidFinishStream(stream_handler_user_data_, result); |
1620 delete this; | 1620 delete this; |
1621 } | 1621 } |
1622 | 1622 |
1623 virtual void didFail(blink::WebURLLoader* loader, | 1623 void didFail(blink::WebURLLoader* loader, |
1624 const blink::WebURLError& error) { | 1624 const blink::WebURLError& error) override { |
1625 success_ = false; | 1625 if (content::PepperPluginInstance::Get(instance_)) |
| 1626 stream_handler_->DidFinishStream(stream_handler_user_data_, |
| 1627 PP_ERROR_FAILED); |
| 1628 delete this; |
1626 } | 1629 } |
1627 | 1630 |
1628 PP_Instance instance_; | 1631 PP_Instance instance_; |
1629 scoped_ptr<blink::WebURLLoader> url_loader_; | 1632 scoped_ptr<blink::WebURLLoader> url_loader_; |
1630 std::string pexe_url_; | 1633 std::string pexe_url_; |
1631 int32_t pexe_opt_level_; | 1634 int32_t pexe_opt_level_; |
1632 bool use_subzero_; | 1635 bool use_subzero_; |
1633 const PPP_PexeStreamHandler* stream_handler_; | 1636 const PPP_PexeStreamHandler* stream_handler_; |
1634 void* stream_handler_user_data_; | 1637 void* stream_handler_user_data_; |
1635 bool success_; | 1638 bool success_; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1699 &StreamPexe | 1702 &StreamPexe |
1700 }; | 1703 }; |
1701 | 1704 |
1702 } // namespace | 1705 } // namespace |
1703 | 1706 |
1704 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1707 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1705 return &nacl_interface; | 1708 return &nacl_interface; |
1706 } | 1709 } |
1707 | 1710 |
1708 } // namespace nacl | 1711 } // namespace nacl |
OLD | NEW |