OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_internals_ui.h" | 5 #include "content/browser/service_worker/service_worker_internals_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 BrowserThread::IO, | 71 BrowserThread::IO, |
72 FROM_HERE, | 72 FROM_HERE, |
73 base::Bind(CallServiceWorkerVersionMethodWithVersionID, | 73 base::Bind(CallServiceWorkerVersionMethodWithVersionID, |
74 method, | 74 method, |
75 context, | 75 context, |
76 version_id, | 76 version_id, |
77 callback)); | 77 callback)); |
78 return; | 78 return; |
79 } | 79 } |
80 | 80 |
81 if (!context->context()) { | |
82 callback.Run(SERVICE_WORKER_ERROR_ABORT); | |
83 return; | |
84 } | |
85 | |
86 scoped_refptr<ServiceWorkerVersion> version = | 81 scoped_refptr<ServiceWorkerVersion> version = |
87 context->context()->GetLiveVersion(version_id); | 82 context->GetLiveVersion(version_id); |
88 if (!version.get()) { | 83 if (!version.get()) { |
89 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); | 84 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); |
90 return; | 85 return; |
91 } | 86 } |
92 (*version.get().*method)(callback); | 87 (*version.get().*method)(callback); |
93 } | 88 } |
94 | 89 |
95 void DispatchPushEventWithVersionID( | 90 void DispatchPushEventWithVersionID( |
96 scoped_refptr<ServiceWorkerContextWrapper> context, | 91 scoped_refptr<ServiceWorkerContextWrapper> context, |
97 int64 version_id, | 92 int64 version_id, |
98 const ServiceWorkerInternalsUI::StatusCallback& callback) { | 93 const ServiceWorkerInternalsUI::StatusCallback& callback) { |
99 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 94 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
100 BrowserThread::PostTask( | 95 BrowserThread::PostTask( |
101 BrowserThread::IO, | 96 BrowserThread::IO, |
102 FROM_HERE, | 97 FROM_HERE, |
103 base::Bind(DispatchPushEventWithVersionID, | 98 base::Bind(DispatchPushEventWithVersionID, |
104 context, | 99 context, |
105 version_id, | 100 version_id, |
106 callback)); | 101 callback)); |
107 return; | 102 return; |
108 } | 103 } |
109 | 104 |
110 if (!context->context()) { | |
111 callback.Run(SERVICE_WORKER_ERROR_ABORT); | |
112 return; | |
113 } | |
114 | |
115 scoped_refptr<ServiceWorkerVersion> version = | 105 scoped_refptr<ServiceWorkerVersion> version = |
116 context->context()->GetLiveVersion(version_id); | 106 context->GetLiveVersion(version_id); |
117 if (!version.get()) { | 107 if (!version.get()) { |
118 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); | 108 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); |
119 return; | 109 return; |
120 } | 110 } |
121 std::string data = "Test push message from ServiceWorkerInternals."; | 111 std::string data = "Test push message from ServiceWorkerInternals."; |
122 version->DispatchPushEvent(callback, data); | 112 version->DispatchPushEvent(callback, data); |
123 } | 113 } |
124 | 114 |
125 void UnregisterWithScope( | |
126 scoped_refptr<ServiceWorkerContextWrapper> context, | |
127 const GURL& scope, | |
128 const ServiceWorkerInternalsUI::StatusCallback& callback) { | |
129 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | |
130 BrowserThread::PostTask( | |
131 BrowserThread::IO, | |
132 FROM_HERE, | |
133 base::Bind(UnregisterWithScope, context, scope, callback)); | |
134 return; | |
135 } | |
136 | |
137 if (!context->context()) { | |
138 callback.Run(SERVICE_WORKER_ERROR_ABORT); | |
139 return; | |
140 } | |
141 context->context()->UnregisterServiceWorker(scope, callback); | |
142 } | |
143 | |
144 void FindRegistrationForPattern( | |
145 scoped_refptr<ServiceWorkerContextWrapper> context, | |
146 const GURL& scope, | |
147 const ServiceWorkerStorage::FindRegistrationCallback callback) { | |
148 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | |
149 BrowserThread::PostTask( | |
150 BrowserThread::IO, | |
151 FROM_HERE, | |
152 base::Bind(FindRegistrationForPattern, context, scope, callback)); | |
153 return; | |
154 } | |
155 | |
156 if (!context->context()) { | |
157 callback.Run(SERVICE_WORKER_ERROR_ABORT, | |
158 scoped_refptr<ServiceWorkerRegistration>()); | |
159 return; | |
160 } | |
161 context->context()->storage()->FindRegistrationForPattern(scope, callback); | |
162 } | |
163 | |
164 void UpdateVersionInfo(const ServiceWorkerVersionInfo& version, | 115 void UpdateVersionInfo(const ServiceWorkerVersionInfo& version, |
165 DictionaryValue* info) { | 116 DictionaryValue* info) { |
166 switch (version.running_status) { | 117 switch (version.running_status) { |
167 case ServiceWorkerVersion::STOPPED: | 118 case ServiceWorkerVersion::STOPPED: |
168 info->SetString("running_status", "STOPPED"); | 119 info->SetString("running_status", "STOPPED"); |
169 break; | 120 break; |
170 case ServiceWorkerVersion::STARTING: | 121 case ServiceWorkerVersion::STARTING: |
171 info->SetString("running_status", "STARTING"); | 122 info->SetString("running_status", "STARTING"); |
172 break; | 123 break; |
173 case ServiceWorkerVersion::RUNNING: | 124 case ServiceWorkerVersion::RUNNING: |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 result->Append(info); | 200 result->Append(info); |
250 } | 201 } |
251 return result; | 202 return result; |
252 } | 203 } |
253 | 204 |
254 void DidGetStoredRegistrationsOnIOThread( | 205 void DidGetStoredRegistrationsOnIOThread( |
255 scoped_refptr<ServiceWorkerContextWrapper> context, | 206 scoped_refptr<ServiceWorkerContextWrapper> context, |
256 const GetRegistrationsCallback& callback, | 207 const GetRegistrationsCallback& callback, |
257 const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations) { | 208 const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations) { |
258 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 209 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
259 if (!context->context()) { | |
260 BrowserThread::PostTask( | |
261 BrowserThread::UI, FROM_HERE, | |
262 base::Bind(callback, std::vector<ServiceWorkerRegistrationInfo>(), | |
263 std::vector<ServiceWorkerVersionInfo>(), | |
264 std::vector<ServiceWorkerRegistrationInfo>())); | |
265 return; | |
266 } | |
267 | |
268 BrowserThread::PostTask( | 210 BrowserThread::PostTask( |
269 BrowserThread::UI, | 211 BrowserThread::UI, FROM_HERE, |
270 FROM_HERE, | 212 base::Bind(callback, context->GetAllLiveRegistrationInfo(), |
271 base::Bind(callback, | 213 context->GetAllLiveVersionInfo(), stored_registrations)); |
272 context->context()->GetAllLiveRegistrationInfo(), | |
273 context->context()->GetAllLiveVersionInfo(), | |
274 stored_registrations)); | |
275 } | 214 } |
276 | 215 |
277 void GetRegistrationsOnIOThread( | 216 void GetRegistrationsOnIOThread( |
278 scoped_refptr<ServiceWorkerContextWrapper> context, | 217 scoped_refptr<ServiceWorkerContextWrapper> context, |
279 const GetRegistrationsCallback& callback) { | 218 const GetRegistrationsCallback& callback) { |
280 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 219 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
281 if (!context->context()) { | 220 context->GetAllRegistrations( |
282 BrowserThread::PostTask( | |
283 BrowserThread::UI, FROM_HERE, | |
284 base::Bind(callback, std::vector<ServiceWorkerRegistrationInfo>(), | |
285 std::vector<ServiceWorkerVersionInfo>(), | |
286 std::vector<ServiceWorkerRegistrationInfo>())); | |
287 return; | |
288 } | |
289 context->context()->storage()->GetAllRegistrations( | |
290 base::Bind(DidGetStoredRegistrationsOnIOThread, context, callback)); | 221 base::Bind(DidGetStoredRegistrationsOnIOThread, context, callback)); |
291 } | 222 } |
292 | 223 |
293 void DidGetRegistrations( | 224 void DidGetRegistrations( |
294 WeakPtr<ServiceWorkerInternalsUI> internals, | 225 WeakPtr<ServiceWorkerInternalsUI> internals, |
295 int partition_id, | 226 int partition_id, |
296 const base::FilePath& context_path, | 227 const base::FilePath& context_path, |
297 const std::vector<ServiceWorkerRegistrationInfo>& live_registrations, | 228 const std::vector<ServiceWorkerRegistrationInfo>& live_registrations, |
298 const std::vector<ServiceWorkerVersionInfo>& live_versions, | 229 const std::vector<ServiceWorkerVersionInfo>& live_versions, |
299 const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations) { | 230 const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations) { |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 !cmd_args->GetInteger("partition_id", &partition_id) || | 593 !cmd_args->GetInteger("partition_id", &partition_id) || |
663 !GetServiceWorkerContext(partition_id, &context) || | 594 !GetServiceWorkerContext(partition_id, &context) || |
664 !cmd_args->GetString("scope", &scope_string)) { | 595 !cmd_args->GetString("scope", &scope_string)) { |
665 return; | 596 return; |
666 } | 597 } |
667 base::Callback<void(ServiceWorkerStatusCode)> callback = | 598 base::Callback<void(ServiceWorkerStatusCode)> callback = |
668 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); | 599 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); |
669 context->StartServiceWorker(GURL(scope_string), callback); | 600 context->StartServiceWorker(GURL(scope_string), callback); |
670 } | 601 } |
671 | 602 |
| 603 void ServiceWorkerInternalsUI::UnregisterWithScope( |
| 604 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 605 const GURL& scope, |
| 606 const ServiceWorkerInternalsUI::StatusCallback& callback) const { |
| 607 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 608 BrowserThread::PostTask( |
| 609 BrowserThread::IO, FROM_HERE, |
| 610 base::Bind(&ServiceWorkerInternalsUI::UnregisterWithScope, |
| 611 base::Unretained(this), context, scope, callback)); |
| 612 return; |
| 613 } |
| 614 |
| 615 if (!context->context()) { |
| 616 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| 617 return; |
| 618 } |
| 619 |
| 620 // ServiceWorkerContextWrapper::UnregisterServiceWorker doesn't work here |
| 621 // because that reduces a status code to boolean. |
| 622 context->context()->UnregisterServiceWorker(scope, callback); |
| 623 } |
| 624 |
672 } // namespace content | 625 } // namespace content |
OLD | NEW |