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

Side by Side Diff: content/child/geofencing/geofencing_dispatcher.cc

Issue 1235083006: CallbackPromiseAdapter types should be more compatible with WebCallbacks (2/3). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@web-callbacks-3
Patch Set: 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
« no previous file with comments | « no previous file | content/child/notifications/notification_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/child/geofencing/geofencing_dispatcher.h" 5 #include "content/child/geofencing/geofencing_dispatcher.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 void GeofencingDispatcher::OnRegisterRegionComplete(int thread_id, 159 void GeofencingDispatcher::OnRegisterRegionComplete(int thread_id,
160 int request_id, 160 int request_id,
161 GeofencingStatus status) { 161 GeofencingStatus status) {
162 blink::WebGeofencingCallbacks* callbacks = 162 blink::WebGeofencingCallbacks* callbacks =
163 region_registration_requests_.Lookup(request_id); 163 region_registration_requests_.Lookup(request_id);
164 DCHECK(callbacks); 164 DCHECK(callbacks);
165 165
166 if (status == GEOFENCING_STATUS_OK) { 166 if (status == GEOFENCING_STATUS_OK) {
167 callbacks->onSuccess(); 167 callbacks->onSuccess();
168 } else { 168 } else {
169 callbacks->onError(new WebGeofencingError( 169 callbacks->onError(WebGeofencingError(
170 WebGeofencingError::ErrorTypeAbort, 170 WebGeofencingError::ErrorTypeAbort,
171 blink::WebString::fromUTF8(GeofencingStatusToString(status)))); 171 blink::WebString::fromUTF8(GeofencingStatusToString(status))));
172 } 172 }
173 region_registration_requests_.Remove(request_id); 173 region_registration_requests_.Remove(request_id);
174 } 174 }
175 175
176 void GeofencingDispatcher::OnUnregisterRegionComplete(int thread_id, 176 void GeofencingDispatcher::OnUnregisterRegionComplete(int thread_id,
177 int request_id, 177 int request_id,
178 GeofencingStatus status) { 178 GeofencingStatus status) {
179 blink::WebGeofencingCallbacks* callbacks = 179 blink::WebGeofencingCallbacks* callbacks =
180 region_unregistration_requests_.Lookup(request_id); 180 region_unregistration_requests_.Lookup(request_id);
181 DCHECK(callbacks); 181 DCHECK(callbacks);
182 182
183 if (status == GEOFENCING_STATUS_OK) { 183 if (status == GEOFENCING_STATUS_OK) {
184 callbacks->onSuccess(); 184 callbacks->onSuccess();
185 } else { 185 } else {
186 callbacks->onError(new WebGeofencingError( 186 callbacks->onError(WebGeofencingError(
187 WebGeofencingError::ErrorTypeAbort, 187 WebGeofencingError::ErrorTypeAbort,
188 blink::WebString::fromUTF8(GeofencingStatusToString(status)))); 188 blink::WebString::fromUTF8(GeofencingStatusToString(status))));
189 } 189 }
190 region_unregistration_requests_.Remove(request_id); 190 region_unregistration_requests_.Remove(request_id);
191 } 191 }
192 192
193 void GeofencingDispatcher::OnGetRegisteredRegionsComplete( 193 void GeofencingDispatcher::OnGetRegisteredRegionsComplete(
194 int thread_id, 194 int thread_id,
195 int request_id, 195 int request_id,
196 GeofencingStatus status, 196 GeofencingStatus status,
197 const GeofencingRegistrations& regions) { 197 const GeofencingRegistrations& regions) {
198 blink::WebGeofencingRegionsCallbacks* callbacks = 198 blink::WebGeofencingRegionsCallbacks* callbacks =
199 get_registered_regions_requests_.Lookup(request_id); 199 get_registered_regions_requests_.Lookup(request_id);
200 DCHECK(callbacks); 200 DCHECK(callbacks);
201 201
202 if (status == GEOFENCING_STATUS_OK) { 202 if (status == GEOFENCING_STATUS_OK) {
203 scoped_ptr<blink::WebVector<blink::WebGeofencingRegistration>> result( 203 blink::WebVector<blink::WebGeofencingRegistration> result(regions.size());
204 new blink::WebVector<blink::WebGeofencingRegistration>(regions.size()));
205 size_t index = 0; 204 size_t index = 0;
206 for (GeofencingRegistrations::const_iterator it = regions.begin(); 205 for (GeofencingRegistrations::const_iterator it = regions.begin();
207 it != regions.end(); 206 it != regions.end();
208 ++it, ++index) { 207 ++it, ++index) {
209 (*result)[index].id = blink::WebString::fromUTF8(it->first); 208 result[index].id = blink::WebString::fromUTF8(it->first);
210 (*result)[index].region = it->second; 209 result[index].region = it->second;
211 } 210 }
212 callbacks->onSuccess(result.release()); 211 callbacks->onSuccess(result);
213 } else { 212 } else {
214 callbacks->onError(new WebGeofencingError( 213 callbacks->onError(WebGeofencingError(
215 WebGeofencingError::ErrorTypeAbort, 214 WebGeofencingError::ErrorTypeAbort,
216 blink::WebString::fromUTF8(GeofencingStatusToString(status)))); 215 blink::WebString::fromUTF8(GeofencingStatusToString(status))));
217 } 216 }
218 get_registered_regions_requests_.Remove(request_id); 217 get_registered_regions_requests_.Remove(request_id);
219 } 218 }
220 219
221 void GeofencingDispatcher::OnWorkerRunLoopStopped() { 220 void GeofencingDispatcher::OnWorkerRunLoopStopped() {
222 delete this; 221 delete this;
223 } 222 }
224 223
225 } // namespace content 224 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/notifications/notification_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698