Index: content/browser/service_worker/service_worker_context_wrapper.cc |
diff --git a/content/browser/service_worker/service_worker_context_wrapper.cc b/content/browser/service_worker/service_worker_context_wrapper.cc |
index 786075f8558ae52b561403a6c3f9975ae0a7f6e5..8f9b1db06205cb20187df3d079abd442e3c29f44 100644 |
--- a/content/browser/service_worker/service_worker_context_wrapper.cc |
+++ b/content/browser/service_worker/service_worker_context_wrapper.cc |
@@ -20,9 +20,11 @@ |
#include "content/browser/service_worker/service_worker_context_observer.h" |
#include "content/browser/service_worker/service_worker_process_manager.h" |
#include "content/browser/service_worker/service_worker_quota_client.h" |
+#include "content/browser/service_worker/service_worker_request_handler.h" |
#include "content/public/browser/browser_context.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/service_worker_context.h" |
+#include "net/base/net_errors.h" |
#include "net/url_request/url_request_context_getter.h" |
#include "storage/browser/blob/blob_storage_context.h" |
#include "storage/browser/quota/quota_manager_proxy.h" |
@@ -35,8 +37,13 @@ namespace { |
typedef std::set<std::string> HeaderNameSet; |
base::LazyInstance<HeaderNameSet> g_excluded_header_name_set = |
LAZY_INSTANCE_INITIALIZER; |
+ |
+void RunSoon(const base::Closure& closure) { |
+ base::MessageLoop::current()->PostTask(FROM_HERE, closure); |
} |
+} // namespace |
+ |
void ServiceWorkerContext::AddExcludedHeadersForFetchEvent( |
const std::set<std::string>& header_names) { |
DCHECK_CURRENTLY_ON(BrowserThread::IO); |
@@ -51,6 +58,16 @@ bool ServiceWorkerContext::IsExcludedHeaderNameForFetchEvent( |
g_excluded_header_name_set.Get().end(); |
} |
+ServiceWorkerContext* ServiceWorkerContext::GetServiceWorkerContext( |
+ net::URLRequest* request) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ ServiceWorkerRequestHandler* handler = |
+ ServiceWorkerRequestHandler::GetHandler(request); |
+ if (!handler || !handler->context()) |
+ return nullptr; |
+ return handler->context()->wrapper_; |
+} |
+ |
ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( |
BrowserContext* browser_context) |
: observer_list_( |
@@ -182,6 +199,26 @@ void ServiceWorkerContextWrapper::UnregisterServiceWorker( |
base::Bind(&FinishUnregistrationOnIO, continuation)); |
} |
+static void DidFindRegistrationForDocument( |
+ const net::CompletionCallback& callback, |
+ ServiceWorkerStatusCode status, |
+ const scoped_refptr<ServiceWorkerRegistration>& registration) { |
+ int rv = registration ? net::OK : net::ERR_CACHE_MISS; |
+ // Use RunSoon here because FindRegistrationForDocument can complete |
+ // immediately but CanHandleMainResourceOffline must be async. |
+ RunSoon(base::Bind(callback, rv)); |
+} |
+ |
+void ServiceWorkerContextWrapper::CanHandleMainResourceOffline( |
+ const GURL& url, |
+ const GURL& first_party, |
+ const net::CompletionCallback& callback) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ context()->storage()->FindRegistrationForDocument( |
+ url, |
+ base::Bind(&DidFindRegistrationForDocument, callback)); |
+} |
+ |
void ServiceWorkerContextWrapper::GetAllOriginsInfo( |
const GetUsageInfoCallback& callback) { |
DCHECK_CURRENTLY_ON(BrowserThread::IO); |