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

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

Issue 1171173002: [Background Sync] Use Mojo IPC to fire background sync events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make mojo event return path generic Created 5 years, 6 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/service_worker/service_worker_event_dispatcher.h"
6
7 #include "content/public/browser/render_process_host.h"
8 #include "content/public/common/service_registry.h"
9
10 namespace content {
11
12 namespace {
13
14 // Converts mojo enum content::ServiceWorkerEventStatus values to Chromium
15 // content::ServiceWorkerStatusCode values.
16 // TODO(iclelland): Make these enums equivalent so that conversion can be a
17 // static cast.
18 ServiceWorkerStatusCode statusCodeFromMojoStatus(
19 ServiceWorkerEventStatus status) {
20 ServiceWorkerStatusCode status_code = SERVICE_WORKER_OK;
21 if (status == SERVICE_WORKER_EVENT_STATUS_REJECTED) {
22 status_code = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED;
23 } else if (status == SERVICE_WORKER_EVENT_STATUS_ABORT) {
24 status_code = SERVICE_WORKER_ERROR_ABORT;
25 }
jkarlin 2015/06/12 21:08:12 how about an else { NOTREACHED(); } for good measu
iclelland 2015/06/16 15:59:15 Done. The TODO will also take care of that, but th
26 return status_code;
27 }
28
29 } // namespace
30
31 ServiceWorkerEventDispatcher::ServiceWorkerEventDispatcher() {
32 }
33
34 void ServiceWorkerEventDispatcher::DispatchSyncEvent(
35 int render_process_id,
36 int thread_id,
37 const ServiceWorkerVersion::StatusCallback& callback,
38 const scoped_refptr<base::TaskRunner>& task_runner) {
39 DCHECK_CURRENTLY_ON(BrowserThread::UI);
40 // TODO(iclelland): Replace this with the real event registration details
41 // crbug.com/482066
42 content::SyncRegistrationPtr TEMP_null_event(
43 content::SyncRegistration::New());
44
45 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id);
46 content::ServiceRegistry* registry = host->GetServiceRegistry();
47 if (!registry)
48 return;
49
50 if (!background_sync_client_.get())
51 registry->ConnectToRemoteService(mojo::GetProxy(&background_sync_client_));
52 background_sync_client_->Sync(
53 TEMP_null_event.Pass(), thread_id,
54 base::Bind(&ServiceWorkerEventDispatcher::OnEventFinished, this, callback,
55 task_runner));
56 }
57
58 ServiceWorkerEventDispatcher::~ServiceWorkerEventDispatcher() {
jkarlin 2015/06/12 21:08:12 DCHECK_CURRENTLY_ON(BrowserThread::UI);
59 }
60
61 void ServiceWorkerEventDispatcher::OnEventFinished(
jkarlin 2015/06/12 21:08:13 DCHECK_CURRENTLY_ON(BrowserThread::UI);
62 const ServiceWorkerVersion::StatusCallback& callback,
63 const scoped_refptr<base::TaskRunner>& task_runner,
64 ServiceWorkerEventStatus result) {
65 task_runner->PostTask(FROM_HERE,
66 base::Bind(callback, statusCodeFromMojoStatus(result)));
67 }
68
69 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698