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

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

Issue 2902653002: Get main frame and subframe AppCache loads to work. (Closed)
Patch Set: Address review comments Created 3 years, 7 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..4745fa6dad0c85603614b20021bbcc190199eef7 100644
--- a/content/browser/appcache/appcache_url_loader_job.cc
+++ b/content/browser/appcache/appcache_url_loader_job.cc
@@ -3,7 +3,9 @@
// 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/public/common/resource_type.h"
+#include "net/base/io_buffer.h"
namespace content {
@@ -12,42 +14,116 @@ 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;
-bool AppCacheURLLoaderJob::IsDeliveringAppCacheResponse() const {
- return false;
-}
+ AppCacheHistograms::AddAppCacheJobStartDelaySample(base::TimeTicks::Now() -
+ start_time_tick_);
-bool AppCacheURLLoaderJob::IsDeliveringNetworkResponse() const {
- return false;
-}
+ manifest_url_ = manifest_url;
+ cache_id_ = cache_id;
+ entry_ = entry;
+ is_fallback_ = is_fallback;
-bool AppCacheURLLoaderJob::IsDeliveringErrorResponse() const {
- return false;
+ storage_->LoadResponseInfo(manifest_url_, entry_.response_id(), this);
}
-bool AppCacheURLLoaderJob::IsCacheEntryNotFound() const {
- return false;
+void AppCacheURLLoaderJob::DeliverNetworkResponse() {
+ delivery_type_ = NETWORK_DELIVERY;
+
+ AppCacheHistograms::AddNetworkJobStartDelaySample(base::TimeTicks::Now() -
+ start_time_tick_);
+
+ if (delegate_)
+ delegate_->SendNetworkResponse();
}
-void AppCacheURLLoaderJob::DeliverAppCachedResponse(const GURL& manifest_url,
- int64_t cache_id,
- const AppCacheEntry& entry,
- bool is_fallback) {}
+void AppCacheURLLoaderJob::DeliverErrorResponse() {
+ delivery_type_ = ERROR_DELIVERY;
-void AppCacheURLLoaderJob::DeliverNetworkResponse() {}
+ AppCacheHistograms::AddErrorJobStartDelaySample(base::TimeTicks::Now() -
+ start_time_tick_);
-void AppCacheURLLoaderJob::DeliverErrorResponse() {}
+ if (delegate_)
+ delegate_->SendErrorResponse();
+}
const GURL& AppCacheURLLoaderJob::GetURL() const {
- return url_;
+ return request_.url;
}
-AppCacheURLLoaderJob::AppCacheURLLoaderJob() {}
+AppCacheURLLoaderJob* AppCacheURLLoaderJob::AsURLLoaderJob() {
+ return this;
+}
+
+AppCacheURLLoaderJob::AppCacheURLLoaderJob(const ResourceRequest& request,
+ AppCacheStorage* storage)
+ : request_(request),
+ delegate_(nullptr),
+ storage_(storage),
+ start_time_tick_(base::TimeTicks::Now()),
+ cache_id_(kAppCacheNoCacheId),
+ is_fallback_(false),
+ buffer_(nullptr) {}
+
+void AppCacheURLLoaderJob::OnResponseInfoLoaded(
+ AppCacheResponseInfo* response_info,
+ int64_t response_id) {
+ DCHECK(IsDeliveringAppCacheResponse());
+
+ if (response_info) {
+ 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()));
+ reader_->ReadData(buffer_.get(), info_->response_data_size(),
+ base::Bind(&AppCacheURLLoaderJob::OnReadComplete,
+ base::Unretained(this)));
+ if (delegate_)
+ delegate_->HandleAppCacheResponseStart(response_info);
+ } else {
+ // Error case here. We fallback to the network.
+ DeliverNetworkResponse();
+ 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();
+ AppCacheHistograms::CountResponseRetrieval(false, is_main_resource,
+ manifest_url_.GetOrigin());
+ return;
+ }
+ if (delegate_)
+ delegate_->HandleAppCacheData(buffer_.get(), result);
michaeln 2017/06/02 01:18:00 What causes the reader to read more? We need to ca
ananta 2017/06/02 03:19:57 Thanks for pointing that out. We now control this
ananta 2017/06/03 01:55:55 Please look at the updated patch. We continue read
+}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698