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

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

Issue 875573002: Service Worker: Expose Get/Store/ClearUserData to content layer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@publicrouter
Patch Set: Fix typo Created 5 years, 11 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/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
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 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
230 base::Bind(callback, data, success, not_found));
nhiroki 2015/01/26 03:25:26 I'd prefer to run the callback on the IO thread be
johnme 2015/01/26 11:02:58 Done (oops, that was actually my intention, but I
231 }
232
233 static void CallResultCallback(
234 const ServiceWorkerContext::ResultCallback& callback,
235 ServiceWorkerStatusCode service_worker_status) {
236 DCHECK_CURRENTLY_ON(BrowserThread::IO);
237 bool success = service_worker_status == SERVICE_WORKER_OK;
238 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
239 base::Bind(callback, success));
240 }
241
242 void ServiceWorkerContextWrapper::GetUserData(
243 int64 registration_id, const std::string& key,
244 const GetUserDataCallback& callback) {
245 DCHECK_CURRENTLY_ON(BrowserThread::IO);
246 context()->storage()->GetUserData(registration_id, key,
247 base::Bind(&CallGetUserDataCallback,
248 callback));
249 }
250
251 void ServiceWorkerContextWrapper::StoreUserData(
252 int64 registration_id, const GURL& origin, const std::string& key,
253 const std::string& data, const ResultCallback& callback) {
254 DCHECK_CURRENTLY_ON(BrowserThread::IO);
255 context()->storage()->StoreUserData(registration_id, origin, key, data,
256 base::Bind(&CallResultCallback,
257 callback));
258 }
259
260 void ServiceWorkerContextWrapper::ClearUserData(
261 int64 registration_id, const std::string& key,
262 const ResultCallback& callback) {
263 DCHECK_CURRENTLY_ON(BrowserThread::IO);
264 context()->storage()->ClearUserData(registration_id, key,
265 base::Bind(&CallResultCallback,
266 callback));
267 }
268
221 static void DidFindRegistrationForDocument( 269 static void DidFindRegistrationForDocument(
222 const net::CompletionCallback& callback, 270 const net::CompletionCallback& callback,
223 ServiceWorkerStatusCode status, 271 ServiceWorkerStatusCode status,
224 const scoped_refptr<ServiceWorkerRegistration>& registration) { 272 const scoped_refptr<ServiceWorkerRegistration>& registration) {
225 int rv = registration ? net::OK : net::ERR_CACHE_MISS; 273 int rv = registration ? net::OK : net::ERR_CACHE_MISS;
226 // Use RunSoon here because FindRegistrationForDocument can complete 274 // Use RunSoon here because FindRegistrationForDocument can complete
227 // immediately but CanHandleMainResourceOffline must be async. 275 // immediately but CanHandleMainResourceOffline must be async.
228 RunSoon(base::Bind(callback, rv)); 276 RunSoon(base::Bind(callback, rv));
229 } 277 }
230 278
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 context_core_.reset(); 426 context_core_.reset();
379 return; 427 return;
380 } 428 }
381 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); 429 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this));
382 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; 430 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully.";
383 431
384 observer_list_->Notify(&ServiceWorkerContextObserver::OnStorageWiped); 432 observer_list_->Notify(&ServiceWorkerContextObserver::OnStorageWiped);
385 } 433 }
386 434
387 } // namespace content 435 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_context_wrapper.h ('k') | content/public/browser/service_worker_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698