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

Side by Side Diff: content/child/background_sync/background_sync_provider.cc

Issue 1282013004: BackgroundSyncManager tracks client registrations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up Created 5 years, 4 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/child/background_sync/background_sync_provider.h" 5 #include "content/child/background_sync/background_sync_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "content/child/background_sync/background_sync_type_converters.h" 9 #include "content/child/background_sync/background_sync_type_converters.h"
10 #include "content/child/service_worker/web_service_worker_registration_impl.h" 10 #include "content/child/service_worker/web_service_worker_registration_impl.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 // base::Unretained is safe here, as the mojo channel will be deleted (and 52 // base::Unretained is safe here, as the mojo channel will be deleted (and
53 // will wipe its callbacks) before 'this' is deleted. 53 // will wipe its callbacks) before 'this' is deleted.
54 GetBackgroundSyncServicePtr()->Register( 54 GetBackgroundSyncServicePtr()->Register(
55 mojo::ConvertTo<SyncRegistrationPtr>(*(optionsPtr.get())), 55 mojo::ConvertTo<SyncRegistrationPtr>(*(optionsPtr.get())),
56 service_worker_registration_id, 56 service_worker_registration_id,
57 base::Bind(&BackgroundSyncProvider::RegisterCallback, 57 base::Bind(&BackgroundSyncProvider::RegisterCallback,
58 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); 58 base::Unretained(this), base::Passed(callbacksPtr.Pass())));
59 } 59 }
60 60
61 // TODO(jkarlin) remove |tag| parameter.
61 void BackgroundSyncProvider::unregisterBackgroundSync( 62 void BackgroundSyncProvider::unregisterBackgroundSync(
62 blink::WebSyncRegistration::Periodicity periodicity, 63 blink::WebSyncRegistration::Periodicity periodicity,
63 int64_t id, 64 int64_t id,
64 const blink::WebString& tag, 65 const blink::WebString& tag,
65 blink::WebServiceWorkerRegistration* service_worker_registration, 66 blink::WebServiceWorkerRegistration* service_worker_registration,
66 blink::WebSyncUnregistrationCallbacks* callbacks) { 67 blink::WebSyncUnregistrationCallbacks* callbacks) {
67 DCHECK(service_worker_registration); 68 DCHECK(service_worker_registration);
68 DCHECK(callbacks); 69 DCHECK(callbacks);
69 int64 service_worker_registration_id = 70 int64 service_worker_registration_id =
70 GetServiceWorkerRegistrationId(service_worker_registration); 71 GetServiceWorkerRegistrationId(service_worker_registration);
71 scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacksPtr(callbacks); 72 scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacksPtr(callbacks);
72 73
73 // base::Unretained is safe here, as the mojo channel will be deleted (and 74 // base::Unretained is safe here, as the mojo channel will be deleted (and
74 // will wipe its callbacks) before 'this' is deleted. 75 // will wipe its callbacks) before 'this' is deleted.
75 GetBackgroundSyncServicePtr()->Unregister( 76 GetBackgroundSyncServicePtr()->Unregister(
76 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), id, tag.utf8(), 77 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), id,
77 service_worker_registration_id, 78 service_worker_registration_id,
78 base::Bind(&BackgroundSyncProvider::UnregisterCallback, 79 base::Bind(&BackgroundSyncProvider::UnregisterCallback,
79 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); 80 base::Unretained(this), base::Passed(callbacksPtr.Pass())));
80 } 81 }
81 82
82 void BackgroundSyncProvider::getRegistration( 83 void BackgroundSyncProvider::getRegistration(
83 blink::WebSyncRegistration::Periodicity periodicity, 84 blink::WebSyncRegistration::Periodicity periodicity,
84 const blink::WebString& tag, 85 const blink::WebString& tag,
85 blink::WebServiceWorkerRegistration* service_worker_registration, 86 blink::WebServiceWorkerRegistration* service_worker_registration,
86 blink::WebSyncRegistrationCallbacks* callbacks) { 87 blink::WebSyncRegistrationCallbacks* callbacks) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 132
132 // base::Unretained is safe here, as the mojo channel will be deleted (and 133 // base::Unretained is safe here, as the mojo channel will be deleted (and
133 // will wipe its callbacks) before 'this' is deleted. 134 // will wipe its callbacks) before 'this' is deleted.
134 GetBackgroundSyncServicePtr()->GetPermissionStatus( 135 GetBackgroundSyncServicePtr()->GetPermissionStatus(
135 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), 136 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity),
136 service_worker_registration_id, 137 service_worker_registration_id,
137 base::Bind(&BackgroundSyncProvider::GetPermissionStatusCallback, 138 base::Bind(&BackgroundSyncProvider::GetPermissionStatusCallback,
138 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); 139 base::Unretained(this), base::Passed(callbacksPtr.Pass())));
139 } 140 }
140 141
142 void BackgroundSyncProvider::trackRegistration(
143 blink::WebSyncRegistration* registration) {
144 scoped_ptr<blink::WebSyncRegistration> scoped_registration(registration);
michaeln 2015/08/21 02:39:24 is WebSyncRegistration thread safe? no, it has a
jkarlin 2015/08/25 17:32:58 Good catch. This function is gone now but this is
145 GetBackgroundSyncServicePtr()->TrackRegistration(
146 mojo::ConvertTo<SyncRegistrationPtr>(*registration));
147 }
148
149 void BackgroundSyncProvider::releaseRegistration(int64_t sync_id) {
150 GetBackgroundSyncServicePtr()->ReleaseRegistration(sync_id);
151 }
152
141 void BackgroundSyncProvider::RegisterCallback( 153 void BackgroundSyncProvider::RegisterCallback(
142 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, 154 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks,
143 BackgroundSyncError error, 155 BackgroundSyncError error,
144 const SyncRegistrationPtr& options) { 156 const SyncRegistrationPtr& options) {
145 // TODO(iclelland): Determine the correct error message to return in each case 157 // TODO(iclelland): Determine the correct error message to return in each case
146 scoped_ptr<blink::WebSyncRegistration> result; 158 scoped_ptr<blink::WebSyncRegistration> result;
147 switch (error) { 159 switch (error) {
148 case BACKGROUND_SYNC_ERROR_NONE: 160 case BACKGROUND_SYNC_ERROR_NONE:
149 if (!options.is_null()) 161 if (!options.is_null())
150 result = 162 result =
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 BackgroundSyncServicePtr& 326 BackgroundSyncServicePtr&
315 BackgroundSyncProvider::GetBackgroundSyncServicePtr() { 327 BackgroundSyncProvider::GetBackgroundSyncServicePtr() {
316 if (!background_sync_service_.get()) { 328 if (!background_sync_service_.get()) {
317 service_registry_->ConnectToRemoteService( 329 service_registry_->ConnectToRemoteService(
318 mojo::GetProxy(&background_sync_service_)); 330 mojo::GetProxy(&background_sync_service_));
319 } 331 }
320 return background_sync_service_; 332 return background_sync_service_;
321 } 333 }
322 334
323 } // namespace content 335 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698