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

Unified Diff: content/browser/appcache/appcache_url_loader_job.cc

Issue 2902653002: Get main frame and subframe AppCache loads to work. (Closed)
Patch Set: Use weak pointers and DeleteSoon in the job and the factory Created 3 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/appcache/appcache_url_loader_job.cc
diff --git a/content/browser/appcache/appcache_url_loader_job.cc b/content/browser/appcache/appcache_url_loader_job.cc
index 09f15459e3bd1a54fd050e1c1669795c9991956b..fba4de3e5f9415e4a0e898841abe9ee781b7403c 100644
--- a/content/browser/appcache/appcache_url_loader_job.cc
+++ b/content/browser/appcache/appcache_url_loader_job.cc
@@ -3,7 +3,10 @@
// found in the LICENSE file.
#include "content/browser/appcache/appcache_url_loader_job.h"
-#include "content/browser/appcache/appcache_entry.h"
+#include "content/browser/appcache/appcache_histograms.h"
+#include "content/browser/url_loader_factory_getter.h"
+#include "content/public/common/resource_type.h"
+#include "net/base/io_buffer.h"
namespace content {
@@ -12,42 +15,203 @@ AppCacheURLLoaderJob::~AppCacheURLLoaderJob() {}
void AppCacheURLLoaderJob::Kill() {}
bool AppCacheURLLoaderJob::IsStarted() const {
- return false;
+ return delivery_type_ != AWAITING_DELIVERY_ORDERS;
}
-bool AppCacheURLLoaderJob::IsWaiting() const {
- return false;
+void AppCacheURLLoaderJob::DeliverAppCachedResponse(const GURL& manifest_url,
+ int64_t cache_id,
+ const AppCacheEntry& entry,
+ bool is_fallback) {
+ delivery_type_ = APPCACHED_DELIVERY;
+
+ AppCacheHistograms::AddAppCacheJobStartDelaySample(base::TimeTicks::Now() -
+ start_time_tick_);
+
+ manifest_url_ = manifest_url;
+ cache_id_ = cache_id;
+ entry_ = entry;
+ is_fallback_ = is_fallback;
+
+ storage_->LoadResponseInfo(manifest_url_, entry_.response_id(), this);
+}
+
+void AppCacheURLLoaderJob::DeliverNetworkResponse() {
+ delivery_type_ = NETWORK_DELIVERY;
+
+ AppCacheHistograms::AddNetworkJobStartDelaySample(base::TimeTicks::Now() -
+ start_time_tick_);
+
+ url_loader_factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart(
michaeln 2017/06/07 02:53:46 I think we want to defer to the network by calling
ananta 2017/06/08 05:58:39 I added call to the loader callback here. We retur
+ mojo::MakeRequest(&url_loader_network_), routing_id_, request_id_,
+ mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_));
}
-bool AppCacheURLLoaderJob::IsDeliveringAppCacheResponse() const {
- return false;
+void AppCacheURLLoaderJob::DeliverErrorResponse() {
+ delivery_type_ = ERROR_DELIVERY;
+
+ AppCacheHistograms::AddErrorJobStartDelaySample(base::TimeTicks::Now() -
+ start_time_tick_);
+ // TODO(ananta)
+ // Add support to send out an error response.
michaeln 2017/06/07 02:53:46 see BlobURLLoader::NotifyCompleted() for an exampl
ananta 2017/06/08 05:58:39 Added a small implementation of NotifyCompleted().
}
-bool AppCacheURLLoaderJob::IsDeliveringNetworkResponse() const {
- return false;
+const GURL& AppCacheURLLoaderJob::GetURL() const {
+ return request_.url;
}
-bool AppCacheURLLoaderJob::IsDeliveringErrorResponse() const {
- return false;
+AppCacheURLLoaderJob* AppCacheURLLoaderJob::AsURLLoaderJob() {
+ return this;
}
-bool AppCacheURLLoaderJob::IsCacheEntryNotFound() const {
- return false;
+void AppCacheURLLoaderJob::FollowRedirect() {
+ if (url_loader_network_)
+ url_loader_network_->FollowRedirect();
}
-void AppCacheURLLoaderJob::DeliverAppCachedResponse(const GURL& manifest_url,
- int64_t cache_id,
- const AppCacheEntry& entry,
- bool is_fallback) {}
+void AppCacheURLLoaderJob::SetPriority(net::RequestPriority priority,
+ int32_t intra_priority_value) {
+ NOTREACHED() << "We don't support SetPriority()";
+}
-void AppCacheURLLoaderJob::DeliverNetworkResponse() {}
+void AppCacheURLLoaderJob::BindEndpoints(
+ const ResourceRequest& request,
+ mojom::URLLoaderAssociatedRequest url_loader_request,
+ int32_t routing_id,
+ int32_t request_id,
+ mojom::URLLoaderClientPtrInfo client_info) {
+ request_ = request;
-void AppCacheURLLoaderJob::DeliverErrorResponse() {}
+ DCHECK(!binding_.is_bound());
+ binding_.Bind(std::move(url_loader_request));
-const GURL& AppCacheURLLoaderJob::GetURL() const {
- return url_;
+ binding_.set_connection_error_handler(base::Bind(
+ &AppCacheURLLoaderJob::OnConnectionError, base::Unretained(this)));
+
+ routing_id_ = routing_id;
+ request_id_ = request_id;
+
+ client_info_.Bind(std::move(client_info));
+
+ // Send the cached AppCacheResponse if any.
+ if (info_.get())
+ SendResponseInfo();
}
-AppCacheURLLoaderJob::AppCacheURLLoaderJob() {}
+void AppCacheURLLoaderJob::SetURLLoaderFactoryGetter(
+ URLLoaderFactoryGetter* url_loader_factory_getter) {
+ url_loader_factory_getter_ = url_loader_factory_getter;
+}
+
+AppCacheURLLoaderJob::AppCacheURLLoaderJob(const ResourceRequest& request,
+ AppCacheStorage* storage)
+ : request_(request),
+ storage_(storage),
+ start_time_tick_(base::TimeTicks::Now()),
+ cache_id_(kAppCacheNoCacheId),
+ is_fallback_(false),
+ buffer_(nullptr),
+ binding_(this),
+ routing_id_(-1),
+ request_id_(-1) {}
+
+void AppCacheURLLoaderJob::OnResponseInfoLoaded(
+ AppCacheResponseInfo* response_info,
+ int64_t response_id) {
+ DCHECK(IsDeliveringAppCacheResponse());
+
+ if (response_info) {
michaeln 2017/06/07 02:53:46 We shouldn't consume the LoaderRequest until here,
ananta 2017/06/08 05:58:39 Thanks. makes sense. done
+ info_ = response_info;
+ reader_.reset(
+ storage_->CreateResponseReader(manifest_url_, entry_.response_id()));
+
+ // TODO(ananta)
+ // Handle range requests.
+
+ buffer_ =
+ new net::IOBuffer(static_cast<size_t>(info_->response_data_size()));
jam 2017/06/07 01:42:17 what if the response is really big, this would end
ananta 2017/06/07 20:57:16 Done.
+ reader_->ReadData(buffer_.get(), info_->response_data_size(),
+ base::Bind(&AppCacheURLLoaderJob::OnReadComplete,
+ StaticAsWeakPtr(this)));
+ if (client_info_)
+ SendResponseInfo();
+ } else {
+ // Error case here. We fallback to the network.
+ DeliverNetworkResponse();
michaeln 2017/06/07 02:53:45 We should call LoaderCallback(nullptr) here to go
ananta 2017/06/07 20:57:16 I don't think we can do that at this point. It is
michaeln 2017/06/08 02:54:01 I'm suggesting that we should defer calling the Lo
ananta 2017/06/08 05:58:39 Done.
+ AppCacheHistograms::CountResponseRetrieval(
+ false, IsResourceTypeFrame(request_.resource_type),
+ manifest_url_.GetOrigin());
+
+ cache_entry_not_found_ = true;
+ }
+}
+
+void AppCacheURLLoaderJob::OnCacheLoaded(AppCache* cache, int64_t cache_id) {
+ NOTREACHED() << "Unhandled at the moment.";
+}
+
+void AppCacheURLLoaderJob::OnReadComplete(int result) {
+ DLOG(WARNING) << "AppCache read completed with result: " << result;
+
+ bool is_main_resource = IsResourceTypeFrame(request_.resource_type);
+
+ if (result == 0) {
+ AppCacheHistograms::CountResponseRetrieval(true, is_main_resource,
+ manifest_url_.GetOrigin());
+ } else if (result < 0) {
+ // Error case here. We fallback to the network.
+ DeliverNetworkResponse();
michaeln 2017/06/07 02:53:46 At this point, it's too late to fallback to the ne
ananta 2017/06/07 20:57:16 Added a call to oncomplete here. Will work on it i
+ AppCacheHistograms::CountResponseRetrieval(false, is_main_resource,
+ manifest_url_.GetOrigin());
+ return;
+ }
+
+ if (result > 0) {
+ uint32_t bytes_written = static_cast<uint32_t>(result);
+ // TODO(ananta)
+ // Use the IO buffer net adapter to efficiently pass the data over to the
+ // cliet.
+ mojo::WriteDataRaw(data_pipe_.producer_handle.get(), buffer_->data(),
michaeln 2017/06/07 02:53:46 We're assuming a MOJO_RESULT_OK here, if the resou
ananta 2017/06/07 20:57:16 Code has changed to async
+ &bytes_written, MOJO_WRITE_DATA_FLAG_NONE);
+ reader_->ReadData(buffer_.get(), info_->response_data_size(),
+ base::Bind(&AppCacheURLLoaderJob::OnReadComplete,
+ base::Unretained(this)));
+ }
+}
+
+void AppCacheURLLoaderJob::OnConnectionError() {
+ base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
+}
+
+void AppCacheURLLoaderJob::SendResponseInfo() {
+ DCHECK(client_info_);
+
+ const net::HttpResponseInfo* http_info = info_->http_response_info();
+
+ ResourceResponseHead response_head;
+ response_head.headers = new net::HttpResponseHeaders("");
+
+ std::string name;
+ std::string value;
+
+ for (size_t it = 0;
+ http_info->headers->EnumerateHeaderLines(&it, &name, &value);) {
michaeln 2017/06/07 02:53:46 HttpResponseHeaders is a refcounted object, would
ananta 2017/06/07 20:57:16 Thanks done.
+ response_head.headers->AddHeader(name + ": " + value);
+ }
+
+ // TODO(ananta)
+ // Copy more fields.
+ http_info->headers->GetMimeType(&response_head.mime_type);
+ http_info->headers->GetCharset(&response_head.charset);
+
+ response_head.request_time = http_info->request_time;
+ response_head.response_time = http_info->response_time;
+ response_head.content_length = info_->response_data_size();
+
+ client_info_->OnReceiveResponse(response_head, http_info->ssl_info,
+ mojom::DownloadedTempFilePtr());
+
+ client_info_->OnStartLoadingResponseBody(
+ std::move(data_pipe_.consumer_handle));
+}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698