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

Side by Side Diff: content/browser/service_worker/service_worker_context_wrapper.cc

Issue 1029553002: [DevTools] Introduce Unregister/Start/Stop/Inspect buttons to ServiceWorkersView [1/2 chromium] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix indent Created 5 years, 9 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 unified diff | Download patch
OLDNEW
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/browser/service_worker/service_worker_request_handler.h"
24 #include "content/browser/service_worker/service_worker_utils.h" 24 #include "content/browser/service_worker/service_worker_utils.h"
25 #include "content/browser/service_worker/service_worker_version.h"
25 #include "content/browser/storage_partition_impl.h" 26 #include "content/browser/storage_partition_impl.h"
26 #include "content/public/browser/browser_context.h" 27 #include "content/public/browser/browser_context.h"
27 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/service_worker_context.h" 29 #include "content/public/browser/service_worker_context.h"
29 #include "net/base/net_errors.h" 30 #include "net/base/net_errors.h"
30 #include "net/base/net_util.h" 31 #include "net/base/net_util.h"
31 #include "net/url_request/url_request_context_getter.h" 32 #include "net/url_request/url_request_context_getter.h"
32 #include "storage/browser/blob/blob_storage_context.h" 33 #include "storage/browser/blob/blob_storage_context.h"
33 #include "storage/browser/quota/quota_manager_proxy.h" 34 #include "storage/browser/quota/quota_manager_proxy.h"
34 #include "storage/browser/quota/special_storage_policy.h" 35 #include "storage/browser/quota/special_storage_policy.h"
35 36
36 namespace content { 37 namespace content {
37 38
38 namespace { 39 namespace {
39 40
40 typedef std::set<std::string> HeaderNameSet; 41 typedef std::set<std::string> HeaderNameSet;
41 base::LazyInstance<HeaderNameSet> g_excluded_header_name_set = 42 base::LazyInstance<HeaderNameSet> g_excluded_header_name_set =
42 LAZY_INSTANCE_INITIALIZER; 43 LAZY_INSTANCE_INITIALIZER;
43 44
44 void RunSoon(const base::Closure& closure) { 45 void RunSoon(const base::Closure& closure) {
45 base::MessageLoop::current()->PostTask(FROM_HERE, closure); 46 base::MessageLoop::current()->PostTask(FROM_HERE, closure);
46 } 47 }
47 48
49 void WorkerStarted(const ServiceWorkerContextWrapper::StatusCallback& callback,
50 ServiceWorkerStatusCode status) {
51 DCHECK_CURRENTLY_ON(BrowserThread::IO);
52 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
53 base::Bind(callback, status));
54 }
55
56 void StartActiveWorkerOnIO(
57 const ServiceWorkerContextWrapper::StatusCallback& callback,
58 ServiceWorkerStatusCode status,
59 const scoped_refptr<ServiceWorkerRegistration>& registration) {
60 DCHECK_CURRENTLY_ON(BrowserThread::IO);
61 if (status == SERVICE_WORKER_OK) {
62 // Pass the reference of |registration| to WorkerStarted callback to prevent
63 // it from being deleted while starting the worker. If the refcount of
64 // |registration| is 1, it will be deleted after WorkerStarted is called.
65 registration->active_version()->StartWorker(
66 base::Bind(WorkerStarted, callback));
67 return;
68 }
69 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
70 base::Bind(callback, SERVICE_WORKER_ERROR_NOT_FOUND));
71 }
72
48 } // namespace 73 } // namespace
49 74
50 void ServiceWorkerContext::AddExcludedHeadersForFetchEvent( 75 void ServiceWorkerContext::AddExcludedHeadersForFetchEvent(
51 const std::set<std::string>& header_names) { 76 const std::set<std::string>& header_names) {
52 DCHECK_CURRENTLY_ON(BrowserThread::IO); 77 DCHECK_CURRENTLY_ON(BrowserThread::IO);
53 g_excluded_header_name_set.Get().insert(header_names.begin(), 78 g_excluded_header_name_set.Get().insert(header_names.begin(),
54 header_names.end()); 79 header_names.end());
55 } 80 }
56 81
57 bool ServiceWorkerContext::IsExcludedHeaderNameForFetchEvent( 82 bool ServiceWorkerContext::IsExcludedHeaderNameForFetchEvent(
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 FROM_HERE, 238 FROM_HERE,
214 base::Bind(continuation, false)); 239 base::Bind(continuation, false));
215 return; 240 return;
216 } 241 }
217 242
218 context()->UnregisterServiceWorker( 243 context()->UnregisterServiceWorker(
219 pattern, 244 pattern,
220 base::Bind(&FinishUnregistrationOnIO, continuation)); 245 base::Bind(&FinishUnregistrationOnIO, continuation));
221 } 246 }
222 247
248 void ServiceWorkerContextWrapper::StartServiceWorker(
249 const GURL& pattern,
250 const StatusCallback& callback) {
251 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
252 BrowserThread::PostTask(
253 BrowserThread::IO, FROM_HERE,
254 base::Bind(&ServiceWorkerContextWrapper::StartServiceWorker, this,
255 pattern, callback));
256 return;
257 }
258 if (!context_core_.get()) {
259 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
260 BrowserThread::PostTask(
261 BrowserThread::UI, FROM_HERE,
262 base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED));
263 return;
264 }
265 context_core_->storage()->FindRegistrationForPattern(
266 pattern, base::Bind(&StartActiveWorkerOnIO, callback));
267 }
268
223 static void DidFindRegistrationForDocument( 269 static void DidFindRegistrationForDocument(
224 const net::CompletionCallback& callback, 270 const net::CompletionCallback& callback,
225 ServiceWorkerStatusCode status, 271 ServiceWorkerStatusCode status,
226 const scoped_refptr<ServiceWorkerRegistration>& registration) { 272 const scoped_refptr<ServiceWorkerRegistration>& registration) {
227 int rv = registration ? net::OK : net::ERR_CACHE_MISS; 273 int rv = registration ? net::OK : net::ERR_CACHE_MISS;
228 // Use RunSoon here because FindRegistrationForDocument can complete 274 // Use RunSoon here because FindRegistrationForDocument can complete
229 // immediately but CanHandleMainResourceOffline must be async. 275 // immediately but CanHandleMainResourceOffline must be async.
230 RunSoon(base::Bind(callback, rv)); 276 RunSoon(base::Bind(callback, rv));
231 } 277 }
232 278
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 return; 472 return;
427 } 473 }
428 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); 474 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this));
429 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; 475 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully.";
430 476
431 observer_list_->Notify(FROM_HERE, 477 observer_list_->Notify(FROM_HERE,
432 &ServiceWorkerContextObserver::OnStorageWiped); 478 &ServiceWorkerContextObserver::OnStorageWiped);
433 } 479 }
434 480
435 } // namespace content 481 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698