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

Side by Side Diff: content/renderer/background_sync/background_sync_client_impl.cc

Issue 1282013004: BackgroundSyncManager tracks client registrations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 3 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 2015 The Chromium Authors. All rights reserved. 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 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/renderer/background_sync/background_sync_client_impl.h" 5 #include "content/renderer/background_sync/background_sync_client_impl.h"
6 6
7 #include "content/child/background_sync/background_sync_provider_thread_proxy.h"
7 #include "content/child/background_sync/background_sync_type_converters.h" 8 #include "content/child/background_sync/background_sync_type_converters.h"
8 #include "content/renderer/service_worker/service_worker_context_client.h" 9 #include "content/renderer/service_worker/service_worker_context_client.h"
10 #include "third_party/WebKit/public/platform/Platform.h"
11 #include "third_party/WebKit/public/platform/WebThread.h"
12 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncProv ider.h"
9 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegi stration.h" 13 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegi stration.h"
10 14
11 namespace content { 15 namespace content {
12 16
13 // static 17 // static
14 void BackgroundSyncClientImpl::Create( 18 void BackgroundSyncClientImpl::Create(
19 int64 service_worker_registration_id,
15 mojo::InterfaceRequest<BackgroundSyncServiceClient> request) { 20 mojo::InterfaceRequest<BackgroundSyncServiceClient> request) {
16 new BackgroundSyncClientImpl(request.Pass()); 21 new BackgroundSyncClientImpl(service_worker_registration_id, request.Pass());
17 } 22 }
18 23
19 BackgroundSyncClientImpl::~BackgroundSyncClientImpl() {} 24 BackgroundSyncClientImpl::~BackgroundSyncClientImpl() {}
20 25
21 BackgroundSyncClientImpl::BackgroundSyncClientImpl( 26 BackgroundSyncClientImpl::BackgroundSyncClientImpl(
27 int64 service_worker_registration_id,
22 mojo::InterfaceRequest<BackgroundSyncServiceClient> request) 28 mojo::InterfaceRequest<BackgroundSyncServiceClient> request)
23 : binding_(this, request.Pass()) {} 29 : service_worker_registration_id_(service_worker_registration_id),
30 binding_(this, request.Pass()) {}
24 31
25 void BackgroundSyncClientImpl::Sync(content::SyncRegistrationPtr registration, 32 void BackgroundSyncClientImpl::Sync(int64 handle_id,
26 const SyncCallback& callback) { 33 const SyncCallback& callback) {
34 DCHECK(!blink::Platform::current()->mainThread()->isCurrentThread());
35 // Get a registration for the given handle_id from the provider. This way
36 // the provider knows about the handle and can delete it once Blink releases
37 // it.
38 // TODO(jkarlin): Change the WebSyncPlatform to support
39 // DuplicateRegistrationHandle and then this cast can go.
40 BackgroundSyncProviderThreadProxy* provider =
41 static_cast<BackgroundSyncProviderThreadProxy*>(
42 blink::Platform::current()->backgroundSyncProvider());
43 DCHECK(provider);
44
45 provider->DuplicateRegistrationHandle(
michaeln 2015/08/28 02:53:11 Eeek, the thread and msg round trips are kinda ugl
jkarlin 2015/09/02 23:51:41 Agreed. On the plus side, this isn't a latency-sen
46 handle_id, service_worker_registration_id_,
47 base::Bind(&BackgroundSyncClientImpl::SyncDidGetRegistration,
48 base::Unretained(this), callback));
49 }
50
51 void BackgroundSyncClientImpl::SyncDidGetRegistration(
52 const SyncCallback& callback,
53 BackgroundSyncError error,
54 const SyncRegistrationPtr& registration) {
55 if (error != BACKGROUND_SYNC_ERROR_NONE) {
56 callback.Run(SERVICE_WORKER_EVENT_STATUS_ABORTED);
57 return;
58 }
59
27 ServiceWorkerContextClient* client = 60 ServiceWorkerContextClient* client =
28 ServiceWorkerContextClient::ThreadSpecificInstance(); 61 ServiceWorkerContextClient::ThreadSpecificInstance();
29 if (!client) { 62 if (!client) {
30 callback.Run(SERVICE_WORKER_EVENT_STATUS_ABORTED); 63 callback.Run(SERVICE_WORKER_EVENT_STATUS_ABORTED);
31 return; 64 return;
32 } 65 }
33 scoped_ptr<blink::WebSyncRegistration> reg = 66
67 scoped_ptr<blink::WebSyncRegistration> web_registration =
34 mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(registration); 68 mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(registration);
35 client->DispatchSyncEvent(*reg, callback); 69
70 client->DispatchSyncEvent(*web_registration, callback);
36 } 71 }
37 72
38 } // namespace content 73 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698