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 "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "content/browser/service_worker/service_worker_context_core.h" | 8 #include "content/browser/service_worker/service_worker_context_core.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "webkit/browser/quota/quota_manager_proxy.h" | 10 #include "webkit/browser/quota/quota_manager_proxy.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 38 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
39 BrowserThread::PostTask( | 39 BrowserThread::PostTask( |
40 BrowserThread::IO, FROM_HERE, | 40 BrowserThread::IO, FROM_HERE, |
41 base::Bind(&ServiceWorkerContextWrapper::Shutdown, this)); | 41 base::Bind(&ServiceWorkerContextWrapper::Shutdown, this)); |
42 return; | 42 return; |
43 } | 43 } |
44 context_core_.reset(); | 44 context_core_.reset(); |
45 } | 45 } |
46 | 46 |
47 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 47 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 48 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
49 return context_core_.get(); | 49 return context_core_.get(); |
50 } | 50 } |
51 | 51 |
| 52 static void FinishRegistrationOnIO( |
| 53 const ServiceWorkerContext::ResultCallback& continuation, |
| 54 ServiceWorkerStatusCode status, |
| 55 int64 registration_id) { |
| 56 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 57 BrowserThread::PostTask( |
| 58 BrowserThread::UI, |
| 59 FROM_HERE, |
| 60 base::Bind(continuation, status == SERVICE_WORKER_OK)); |
| 61 } |
| 62 |
| 63 void ServiceWorkerContextWrapper::RegisterServiceWorker( |
| 64 const GURL& pattern, |
| 65 const GURL& script_url, |
| 66 int source_process_id, |
| 67 const ResultCallback& continuation) { |
| 68 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 69 BrowserThread::PostTask( |
| 70 BrowserThread::IO, |
| 71 FROM_HERE, |
| 72 base::Bind(&ServiceWorkerContextWrapper::RegisterServiceWorker, |
| 73 this, |
| 74 pattern, |
| 75 script_url, |
| 76 source_process_id, |
| 77 continuation)); |
| 78 return; |
| 79 } |
| 80 |
| 81 context()->RegisterServiceWorker( |
| 82 pattern, |
| 83 script_url, |
| 84 source_process_id, |
| 85 base::Bind(&FinishRegistrationOnIO, continuation)); |
| 86 } |
| 87 |
| 88 static void FinishUnregistrationOnIO( |
| 89 const ServiceWorkerContext::ResultCallback& continuation, |
| 90 ServiceWorkerStatusCode status) { |
| 91 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 92 BrowserThread::PostTask( |
| 93 BrowserThread::UI, |
| 94 FROM_HERE, |
| 95 base::Bind(continuation, status == SERVICE_WORKER_OK)); |
| 96 } |
| 97 |
| 98 void ServiceWorkerContextWrapper::UnregisterServiceWorker( |
| 99 const GURL& pattern, |
| 100 int source_process_id, |
| 101 const ResultCallback& continuation) { |
| 102 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 103 BrowserThread::PostTask( |
| 104 BrowserThread::IO, |
| 105 FROM_HERE, |
| 106 base::Bind(&ServiceWorkerContextWrapper::UnregisterServiceWorker, |
| 107 this, |
| 108 pattern, |
| 109 source_process_id, |
| 110 continuation)); |
| 111 return; |
| 112 } |
| 113 |
| 114 context()->UnregisterServiceWorker( |
| 115 pattern, |
| 116 source_process_id, |
| 117 base::Bind(&FinishUnregistrationOnIO, continuation)); |
| 118 } |
| 119 |
52 } // namespace content | 120 } // namespace content |
OLD | NEW |