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

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

Issue 208843004: Add the beginning of a public Service Worker API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix kinuko's comments. Created 6 years, 8 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 | Annotate | Revision Log
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 "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
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::StatusCallback& continuation,
54 ServiceWorkerStatusCode status,
55 int64 registration_id) {
56 DCHECK_CURRENTLY_ON(BrowserThread::IO);
57 BrowserThread::PostTask(
58 BrowserThread::UI, FROM_HERE, base::Bind(continuation, status));
59 }
60
61 void ServiceWorkerContextWrapper::RegisterServiceWorker(
62 const GURL& pattern,
63 const GURL& script_url,
64 int source_process_id,
65 const StatusCallback& continuation) {
66 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
67 BrowserThread::PostTask(
68 BrowserThread::IO,
69 FROM_HERE,
70 base::Bind(&ServiceWorkerContextWrapper::RegisterServiceWorker,
71 this,
72 pattern,
73 script_url,
74 source_process_id,
75 continuation));
76 return;
77 }
78
79 context()->RegisterServiceWorker(
80 pattern,
81 script_url,
82 source_process_id,
83 base::Bind(&FinishRegistrationOnIO, continuation));
84 }
85
86 static void FinishUnregistrationOnIO(
87 const ServiceWorkerContext::StatusCallback& continuation,
88 ServiceWorkerStatusCode status) {
89 DCHECK_CURRENTLY_ON(BrowserThread::IO);
90 BrowserThread::PostTask(
91 BrowserThread::UI, FROM_HERE, base::Bind(continuation, status));
92 }
93
94 void ServiceWorkerContextWrapper::UnregisterServiceWorker(
95 const GURL& pattern,
96 int source_process_id,
97 const StatusCallback& continuation) {
98 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
99 BrowserThread::PostTask(
100 BrowserThread::IO,
101 FROM_HERE,
102 base::Bind(&ServiceWorkerContextWrapper::UnregisterServiceWorker,
103 this,
104 pattern,
105 source_process_id,
106 continuation));
107 return;
108 }
109
110 context()->UnregisterServiceWorker(
111 pattern,
112 source_process_id,
113 base::Bind(&FinishUnregistrationOnIO, continuation));
114 }
115
52 } // namespace content 116 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698