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 "content/browser/service_worker/service_worker_context_wrapper.h" | 5 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/barrier_closure.h" | 12 #include "base/barrier_closure.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
18 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 18 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
19 #include "content/browser/service_worker/service_worker_context_core.h" | 19 #include "content/browser/service_worker/service_worker_context_core.h" |
20 #include "content/browser/service_worker/service_worker_context_observer.h" | 20 #include "content/browser/service_worker/service_worker_context_observer.h" |
21 #include "content/browser/service_worker/service_worker_process_manager.h" | 21 #include "content/browser/service_worker/service_worker_process_manager.h" |
22 #include "content/browser/service_worker/service_worker_quota_client.h" | 22 #include "content/browser/service_worker/service_worker_quota_client.h" |
23 #include "content/browser/service_worker/service_worker_request_handler.h" | |
23 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/service_worker_context.h" | 26 #include "content/public/browser/service_worker_context.h" |
27 #include "net/base/net_errors.h" | |
26 #include "net/url_request/url_request_context_getter.h" | 28 #include "net/url_request/url_request_context_getter.h" |
27 #include "storage/browser/blob/blob_storage_context.h" | 29 #include "storage/browser/blob/blob_storage_context.h" |
28 #include "storage/browser/quota/quota_manager_proxy.h" | 30 #include "storage/browser/quota/quota_manager_proxy.h" |
29 #include "storage/browser/quota/special_storage_policy.h" | 31 #include "storage/browser/quota/special_storage_policy.h" |
30 | 32 |
31 namespace content { | 33 namespace content { |
32 | 34 |
33 namespace { | 35 namespace { |
34 | 36 |
35 typedef std::set<std::string> HeaderNameSet; | 37 typedef std::set<std::string> HeaderNameSet; |
36 base::LazyInstance<HeaderNameSet> g_excluded_header_name_set = | 38 base::LazyInstance<HeaderNameSet> g_excluded_header_name_set = |
37 LAZY_INSTANCE_INITIALIZER; | 39 LAZY_INSTANCE_INITIALIZER; |
40 | |
41 void RunSoon(const base::Closure& closure) { | |
42 base::MessageLoop::current()->PostTask(FROM_HERE, closure); | |
38 } | 43 } |
39 | 44 |
45 } // namespace | |
46 | |
40 void ServiceWorkerContext::AddExcludedHeadersForFetchEvent( | 47 void ServiceWorkerContext::AddExcludedHeadersForFetchEvent( |
41 const std::set<std::string>& header_names) { | 48 const std::set<std::string>& header_names) { |
42 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 49 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
43 g_excluded_header_name_set.Get().insert(header_names.begin(), | 50 g_excluded_header_name_set.Get().insert(header_names.begin(), |
44 header_names.end()); | 51 header_names.end()); |
45 } | 52 } |
46 | 53 |
47 bool ServiceWorkerContext::IsExcludedHeaderNameForFetchEvent( | 54 bool ServiceWorkerContext::IsExcludedHeaderNameForFetchEvent( |
48 const std::string& header_name) { | 55 const std::string& header_name) { |
49 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 56 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
50 return g_excluded_header_name_set.Get().find(header_name) != | 57 return g_excluded_header_name_set.Get().find(header_name) != |
51 g_excluded_header_name_set.Get().end(); | 58 g_excluded_header_name_set.Get().end(); |
52 } | 59 } |
53 | 60 |
61 ServiceWorkerContext* ServiceWorkerContext::GetServiceWorkerContext( | |
62 net::URLRequest* request) { | |
63 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
64 ServiceWorkerRequestHandler* handler = | |
65 ServiceWorkerRequestHandler::GetHandler(request); | |
66 if (!handler || !handler->context()) | |
67 return nullptr; | |
68 return handler->context()->wrapper_; | |
69 } | |
70 | |
54 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( | 71 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( |
55 BrowserContext* browser_context) | 72 BrowserContext* browser_context) |
56 : observer_list_( | 73 : observer_list_( |
57 new ObserverListThreadSafe<ServiceWorkerContextObserver>()), | 74 new ObserverListThreadSafe<ServiceWorkerContextObserver>()), |
58 process_manager_(new ServiceWorkerProcessManager(browser_context)), | 75 process_manager_(new ServiceWorkerProcessManager(browser_context)), |
59 is_incognito_(false) { | 76 is_incognito_(false) { |
60 } | 77 } |
61 | 78 |
62 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { | 79 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { |
63 } | 80 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 FROM_HERE, | 192 FROM_HERE, |
176 base::Bind(continuation, false)); | 193 base::Bind(continuation, false)); |
177 return; | 194 return; |
178 } | 195 } |
179 | 196 |
180 context()->UnregisterServiceWorker( | 197 context()->UnregisterServiceWorker( |
181 pattern, | 198 pattern, |
182 base::Bind(&FinishUnregistrationOnIO, continuation)); | 199 base::Bind(&FinishUnregistrationOnIO, continuation)); |
183 } | 200 } |
184 | 201 |
202 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
| |
203 const net::CompletionCallback& callback, | |
204 ServiceWorkerStatusCode status, | |
205 const scoped_refptr<ServiceWorkerRegistration>& registration) { | |
206 int rv = registration ? net::OK : net::ERR_CACHE_MISS; | |
207 // Use RunSoon here because FindRegistrationForDocument can complete | |
208 // immediately but CanHandleMainResourceOffline must be async. | |
209 RunSoon(base::Bind(callback, rv)); | |
210 } | |
211 | |
212 void ServiceWorkerContextWrapper::CanHandleMainResourceOffline( | |
213 const GURL& url, | |
214 const GURL& first_party, | |
215 const net::CompletionCallback& callback) { | |
216 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
217 if (!url.SchemeIsSecure()) { | |
falken
2014/12/16 08:16:49
Is this needed? Can FindRegistrationForDocument re
michaeln
2015/01/09 01:47:36
Done
| |
218 RunSoon(base::Bind(callback, net::ERR_CACHE_MISS)); | |
219 return; | |
220 } | |
221 // TODO(michaeln): Use GetContentClient()->browser()->AllowServiceWorker to | |
222 // 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?
| |
223 context()->storage()->FindRegistrationForDocument( | |
224 url, | |
225 base::Bind(&DidFindRegistrationForDocument, callback)); | |
226 } | |
227 | |
185 void ServiceWorkerContextWrapper::GetAllOriginsInfo( | 228 void ServiceWorkerContextWrapper::GetAllOriginsInfo( |
186 const GetUsageInfoCallback& callback) { | 229 const GetUsageInfoCallback& callback) { |
187 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 230 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
188 if (!context_core_.get()) { | 231 if (!context_core_.get()) { |
189 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | 232 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; |
190 BrowserThread::PostTask( | 233 BrowserThread::PostTask( |
191 BrowserThread::IO, | 234 BrowserThread::IO, |
192 FROM_HERE, | 235 FROM_HERE, |
193 base::Bind(callback, std::vector<ServiceWorkerUsageInfo>())); | 236 base::Bind(callback, std::vector<ServiceWorkerUsageInfo>())); |
194 return; | 237 return; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 context_core_.reset(); | 365 context_core_.reset(); |
323 return; | 366 return; |
324 } | 367 } |
325 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 368 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
326 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 369 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
327 | 370 |
328 observer_list_->Notify(&ServiceWorkerContextObserver::OnStorageWiped); | 371 observer_list_->Notify(&ServiceWorkerContextObserver::OnStorageWiped); |
329 } | 372 } |
330 | 373 |
331 } // namespace content | 374 } // namespace content |
OLD | NEW |