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..ba6e825d94f7b205e9a38192194bf15035f606e5 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,32 @@ void ServiceWorkerContextWrapper::UnregisterServiceWorker( |
base::Bind(&FinishUnregistrationOnIO, continuation)); |
} |
+static void DidFindRegistrationForDocument( |
falken
2014/12/16 08:16:49
nit: chromium codebase tends to put these in unnam
michaeln
2015/01/09 01:47:36
True, but this class file isn't following that con
falken
2015/01/09 02:27:44
oops didn't notice, sorry
|
+ 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); |
+ if (!url.SchemeIsSecure()) { |
falken
2014/12/16 08:16:49
Is this needed? Can FindRegistrationForDocument re
michaeln
2015/01/09 01:47:36
Done
|
+ RunSoon(base::Bind(callback, net::ERR_CACHE_MISS)); |
+ return; |
+ } |
+ // TODO(michaeln): Use GetContentClient()->browser()->AllowServiceWorker to |
+ // check for 3rd party cookie usage. |
falken
2014/12/16 08:16:50
I'm wondering what is the consequence of not doing
michaeln
2015/01/09 01:47:36
I've removed the todo. They can't be registered wh
falken
2015/01/09 02:27:44
+oshima: do you know why this is CrOS-specific?
|
+ context()->storage()->FindRegistrationForDocument( |
+ url, |
+ base::Bind(&DidFindRegistrationForDocument, callback)); |
+} |
+ |
void ServiceWorkerContextWrapper::GetAllOriginsInfo( |
const GetUsageInfoCallback& callback) { |
DCHECK_CURRENTLY_ON(BrowserThread::IO); |