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

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

Issue 205033002: Browser side of new ServiceWorker 'sync' event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 : internals_(internals), original_args_(original_args.Pass()) {} 42 : internals_(internals), original_args_(original_args.Pass()) {}
43 43
44 void GetRegistrationsOnIOThread(ServiceWorkerContextWrapper* context, 44 void GetRegistrationsOnIOThread(ServiceWorkerContextWrapper* context,
45 const base::FilePath& context_path); 45 const base::FilePath& context_path);
46 void UnregisterOnIOThread(scoped_refptr<ServiceWorkerContextWrapper> context, 46 void UnregisterOnIOThread(scoped_refptr<ServiceWorkerContextWrapper> context,
47 const GURL& scope); 47 const GURL& scope);
48 void StartWorkerOnIOThread(scoped_refptr<ServiceWorkerContextWrapper> context, 48 void StartWorkerOnIOThread(scoped_refptr<ServiceWorkerContextWrapper> context,
49 const GURL& scope); 49 const GURL& scope);
50 void StopWorkerOnIOThread(scoped_refptr<ServiceWorkerContextWrapper> context, 50 void StopWorkerOnIOThread(scoped_refptr<ServiceWorkerContextWrapper> context,
51 const GURL& scope); 51 const GURL& scope);
52 void SyncWorkerOnIOThread(scoped_refptr<ServiceWorkerContextWrapper> context,
kinuko 2014/03/24 05:10:08 (ditto for all these method names)
jkarlin 2014/03/25 18:28:17 Done.
53 const GURL& scope);
52 54
53 private: 55 private:
54 friend class base::RefCountedThreadSafe<OperationProxy>; 56 friend class base::RefCountedThreadSafe<OperationProxy>;
55 ~OperationProxy() {} 57 ~OperationProxy() {}
56 void OnHaveRegistrations( 58 void OnHaveRegistrations(
57 const base::FilePath& context_path, 59 const base::FilePath& context_path,
58 const std::vector<ServiceWorkerRegistrationInfo>& registrations); 60 const std::vector<ServiceWorkerRegistrationInfo>& registrations);
59 61
60 void OperationComplete(ServiceWorkerStatusCode status); 62 void OperationComplete(ServiceWorkerStatusCode status);
61 63
62 void StartActiveWorker( 64 void StartActiveWorker(
63 ServiceWorkerStatusCode status, 65 ServiceWorkerStatusCode status,
64 const scoped_refptr<ServiceWorkerRegistration>& registration); 66 const scoped_refptr<ServiceWorkerRegistration>& registration);
65 67
66 void StopActiveWorker( 68 void StopActiveWorker(
67 ServiceWorkerStatusCode status, 69 ServiceWorkerStatusCode status,
68 const scoped_refptr<ServiceWorkerRegistration>& registration); 70 const scoped_refptr<ServiceWorkerRegistration>& registration);
69 71
72 void SyncActiveWorker(
73 ServiceWorkerStatusCode status,
74 const scoped_refptr<ServiceWorkerRegistration>& registration);
75
70 WeakPtr<ServiceWorkerInternalsUI> internals_; 76 WeakPtr<ServiceWorkerInternalsUI> internals_;
71 scoped_ptr<ListValue> original_args_; 77 scoped_ptr<ListValue> original_args_;
72 }; 78 };
73 79
74 ServiceWorkerInternalsUI::ServiceWorkerInternalsUI(WebUI* web_ui) 80 ServiceWorkerInternalsUI::ServiceWorkerInternalsUI(WebUI* web_ui)
75 : WebUIController(web_ui) { 81 : WebUIController(web_ui) {
76 WebUIDataSource* source = 82 WebUIDataSource* source =
77 WebUIDataSource::Create(kChromeUIServiceWorkerInternalsHost); 83 WebUIDataSource::Create(kChromeUIServiceWorkerInternalsHost);
78 source->SetUseJsonJSFormatV2(); 84 source->SetUseJsonJSFormatV2();
79 source->SetJsonPath("strings.js"); 85 source->SetJsonPath("strings.js");
(...skipping 16 matching lines...) Expand all
96 base::Bind(&ServiceWorkerInternalsUI::StartWorker, 102 base::Bind(&ServiceWorkerInternalsUI::StartWorker,
97 base::Unretained(this))); 103 base::Unretained(this)));
98 web_ui->RegisterMessageCallback( 104 web_ui->RegisterMessageCallback(
99 "stop", 105 "stop",
100 base::Bind(&ServiceWorkerInternalsUI::StopWorker, 106 base::Bind(&ServiceWorkerInternalsUI::StopWorker,
101 base::Unretained(this))); 107 base::Unretained(this)));
102 web_ui->RegisterMessageCallback( 108 web_ui->RegisterMessageCallback(
103 "unregister", 109 "unregister",
104 base::Bind(&ServiceWorkerInternalsUI::Unregister, 110 base::Bind(&ServiceWorkerInternalsUI::Unregister,
105 base::Unretained(this))); 111 base::Unretained(this)));
112 web_ui->RegisterMessageCallback(
113 "sync",
114 base::Bind(&ServiceWorkerInternalsUI::SyncWorker,
115 base::Unretained(this)));
106 } 116 }
107 117
108 ServiceWorkerInternalsUI::~ServiceWorkerInternalsUI() {} 118 ServiceWorkerInternalsUI::~ServiceWorkerInternalsUI() {}
109 119
110 void ServiceWorkerInternalsUI::GetAllRegistrations(const ListValue* args) { 120 void ServiceWorkerInternalsUI::GetAllRegistrations(const ListValue* args) {
111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
112 122
113 BrowserContext* browser_context = 123 BrowserContext* browser_context =
114 web_ui()->GetWebContents()->GetBrowserContext(); 124 web_ui()->GetWebContents()->GetBrowserContext();
115 125
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 BrowserContext::StoragePartitionCallback cb = 179 BrowserContext::StoragePartitionCallback cb =
170 base::Bind(&FindContext, *partition_path, &result_partition, context); 180 base::Bind(&FindContext, *partition_path, &result_partition, context);
171 BrowserContext::ForEachStoragePartition(browser_context, cb); 181 BrowserContext::ForEachStoragePartition(browser_context, cb);
172 182
173 if (!result_partition || !(*context)) 183 if (!result_partition || !(*context))
174 return false; 184 return false;
175 185
176 return true; 186 return true;
177 } 187 }
178 188
189 void ServiceWorkerInternalsUI::SyncWorker(const ListValue* args) {
190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
191 base::FilePath partition_path;
192 GURL scope;
193 scoped_refptr<ServiceWorkerContextWrapper> context;
194 if (!GetRegistrationInfo(args, &partition_path, &scope, &context))
195 return;
196
197 scoped_ptr<ListValue> args_copy(args->DeepCopy());
198 BrowserThread::PostTask(
199 BrowserThread::IO,
200 FROM_HERE,
201 base::Bind(
202 &ServiceWorkerInternalsUI::OperationProxy::SyncWorkerOnIOThread,
203 new OperationProxy(AsWeakPtr(), args_copy.Pass()),
204 context,
205 scope));
206 }
207
179 void ServiceWorkerInternalsUI::Unregister(const ListValue* args) { 208 void ServiceWorkerInternalsUI::Unregister(const ListValue* args) {
180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
181 base::FilePath partition_path; 210 base::FilePath partition_path;
182 GURL scope; 211 GURL scope;
183 scoped_refptr<ServiceWorkerContextWrapper> context; 212 scoped_refptr<ServiceWorkerContextWrapper> context;
184 if (!GetRegistrationInfo(args, &partition_path, &scope, &context)) 213 if (!GetRegistrationInfo(args, &partition_path, &scope, &context))
185 return; 214 return;
186 215
187 scoped_ptr<ListValue> args_copy(args->DeepCopy()); 216 scoped_ptr<ListValue> args_copy(args->DeepCopy());
188 BrowserThread::PostTask( 217 BrowserThread::PostTask(
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 const GURL& scope) { 301 const GURL& scope) {
273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
274 // TODO(alecflett): Add support for starting/stopping workers for 303 // TODO(alecflett): Add support for starting/stopping workers for
275 // pending versions too. 304 // pending versions too.
276 context->context()->storage()->FindRegistrationForPattern( 305 context->context()->storage()->FindRegistrationForPattern(
277 scope, 306 scope,
278 base::Bind(&ServiceWorkerInternalsUI::OperationProxy::StopActiveWorker, 307 base::Bind(&ServiceWorkerInternalsUI::OperationProxy::StopActiveWorker,
279 this)); 308 this));
280 } 309 }
281 310
311 void ServiceWorkerInternalsUI::OperationProxy::SyncWorkerOnIOThread(
312 scoped_refptr<ServiceWorkerContextWrapper> context,
313 const GURL& scope) {
314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
315 context->context()->storage()->FindRegistrationForPattern(
316 scope,
317 base::Bind(&ServiceWorkerInternalsUI::OperationProxy::SyncActiveWorker,
318 this));
319 }
320
282 namespace { 321 namespace {
283 void UpdateVersionInfo(const ServiceWorkerVersionInfo& version, 322 void UpdateVersionInfo(const ServiceWorkerVersionInfo& version,
284 DictionaryValue* info) { 323 DictionaryValue* info) {
285 switch (version.running_status) { 324 switch (version.running_status) {
286 case ServiceWorkerVersion::STOPPED: 325 case ServiceWorkerVersion::STOPPED:
287 info->SetString("running_status", "STOPPED"); 326 info->SetString("running_status", "STOPPED");
288 break; 327 break;
289 case ServiceWorkerVersion::STARTING: 328 case ServiceWorkerVersion::STARTING:
290 info->SetString("running_status", "STARTING"); 329 info->SetString("running_status", "STARTING");
291 break; 330 break;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
412 if (status == SERVICE_WORKER_OK) { 451 if (status == SERVICE_WORKER_OK) {
413 registration->active_version()->StopWorker(base::Bind( 452 registration->active_version()->StopWorker(base::Bind(
414 &ServiceWorkerInternalsUI::OperationProxy::OperationComplete, this)); 453 &ServiceWorkerInternalsUI::OperationProxy::OperationComplete, this));
415 return; 454 return;
416 } 455 }
417 456
418 OperationComplete(status); 457 OperationComplete(status);
419 } 458 }
420 459
460 void ServiceWorkerInternalsUI::OperationProxy::SyncActiveWorker(
461 ServiceWorkerStatusCode status,
462 const scoped_refptr<ServiceWorkerRegistration>& registration) {
463 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
464 if (status == SERVICE_WORKER_OK) {
465 registration->active_version()->DispatchSyncEvent(base::Bind(
466 &ServiceWorkerInternalsUI::OperationProxy::OperationComplete, this));
467 return;
468 }
469
470 OperationComplete(status);
471 }
472
421 } // namespace content 473 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698