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/browser/service_worker/service_worker_request_handler.h" |
24 #include "content/browser/storage_partition_impl.h" | 24 #include "content/browser/storage_partition_impl.h" |
| 25 #include "content/common/service_worker/service_worker_status_code.h" |
25 #include "content/public/browser/browser_context.h" | 26 #include "content/public/browser/browser_context.h" |
26 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/service_worker_context.h" | 28 #include "content/public/browser/service_worker_context.h" |
28 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
29 #include "net/url_request/url_request_context_getter.h" | 30 #include "net/url_request/url_request_context_getter.h" |
30 #include "storage/browser/blob/blob_storage_context.h" | 31 #include "storage/browser/blob/blob_storage_context.h" |
31 #include "storage/browser/quota/quota_manager_proxy.h" | 32 #include "storage/browser/quota/quota_manager_proxy.h" |
32 #include "storage/browser/quota/special_storage_policy.h" | 33 #include "storage/browser/quota/special_storage_policy.h" |
33 | 34 |
34 namespace content { | 35 namespace content { |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 FROM_HERE, | 212 FROM_HERE, |
212 base::Bind(continuation, false)); | 213 base::Bind(continuation, false)); |
213 return; | 214 return; |
214 } | 215 } |
215 | 216 |
216 context()->UnregisterServiceWorker( | 217 context()->UnregisterServiceWorker( |
217 pattern, | 218 pattern, |
218 base::Bind(&FinishUnregistrationOnIO, continuation)); | 219 base::Bind(&FinishUnregistrationOnIO, continuation)); |
219 } | 220 } |
220 | 221 |
| 222 static void CallGetUserDataCallback( |
| 223 const ServiceWorkerContext::GetUserDataCallback& callback, |
| 224 const std::string& data, |
| 225 ServiceWorkerStatusCode service_worker_status) { |
| 226 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 227 bool success = service_worker_status == SERVICE_WORKER_OK; |
| 228 bool not_found = service_worker_status == SERVICE_WORKER_ERROR_NOT_FOUND; |
| 229 callback.Run(data, success, not_found); |
| 230 } |
| 231 |
| 232 static void CallResultCallback( |
| 233 const ServiceWorkerContext::ResultCallback& callback, |
| 234 ServiceWorkerStatusCode service_worker_status) { |
| 235 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 236 bool success = service_worker_status == SERVICE_WORKER_OK; |
| 237 callback.Run(success); |
| 238 } |
| 239 |
| 240 void ServiceWorkerContextWrapper::GetUserData( |
| 241 int64 registration_id, const std::string& key, |
| 242 const GetUserDataCallback& callback) { |
| 243 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 244 context()->storage()->GetUserData(registration_id, key, |
| 245 base::Bind(&CallGetUserDataCallback, |
| 246 callback)); |
| 247 } |
| 248 |
| 249 void ServiceWorkerContextWrapper::StoreUserData( |
| 250 int64 registration_id, const GURL& origin, const std::string& key, |
| 251 const std::string& data, const ResultCallback& callback) { |
| 252 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 253 context()->storage()->StoreUserData(registration_id, origin, key, data, |
| 254 base::Bind(&CallResultCallback, |
| 255 callback)); |
| 256 } |
| 257 |
| 258 void ServiceWorkerContextWrapper::ClearUserData( |
| 259 int64 registration_id, const std::string& key, |
| 260 const ResultCallback& callback) { |
| 261 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 262 context()->storage()->ClearUserData(registration_id, key, |
| 263 base::Bind(&CallResultCallback, |
| 264 callback)); |
| 265 } |
| 266 |
221 static void DidFindRegistrationForDocument( | 267 static void DidFindRegistrationForDocument( |
222 const net::CompletionCallback& callback, | 268 const net::CompletionCallback& callback, |
223 ServiceWorkerStatusCode status, | 269 ServiceWorkerStatusCode status, |
224 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 270 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
225 int rv = registration ? net::OK : net::ERR_CACHE_MISS; | 271 int rv = registration ? net::OK : net::ERR_CACHE_MISS; |
226 // Use RunSoon here because FindRegistrationForDocument can complete | 272 // Use RunSoon here because FindRegistrationForDocument can complete |
227 // immediately but CanHandleMainResourceOffline must be async. | 273 // immediately but CanHandleMainResourceOffline must be async. |
228 RunSoon(base::Bind(callback, rv)); | 274 RunSoon(base::Bind(callback, rv)); |
229 } | 275 } |
230 | 276 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 context_core_.reset(); | 424 context_core_.reset(); |
379 return; | 425 return; |
380 } | 426 } |
381 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 427 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
382 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 428 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
383 | 429 |
384 observer_list_->Notify(&ServiceWorkerContextObserver::OnStorageWiped); | 430 observer_list_->Notify(&ServiceWorkerContextObserver::OnStorageWiped); |
385 } | 431 } |
386 | 432 |
387 } // namespace content | 433 } // namespace content |
OLD | NEW |