| OLD | NEW |
| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 return NULL; | 142 return NULL; |
| 143 return g_dispatcher_tls.Pointer()->Get(); | 143 return g_dispatcher_tls.Pointer()->Get(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void GeofencingDispatcher::OnRegisterRegionComplete(int thread_id, | 146 void GeofencingDispatcher::OnRegisterRegionComplete(int thread_id, |
| 147 int request_id, | 147 int request_id, |
| 148 GeofencingStatus status) { | 148 GeofencingStatus status) { |
| 149 blink::WebGeofencingCallbacks* callbacks = | 149 blink::WebGeofencingCallbacks* callbacks = |
| 150 region_registration_requests_.Lookup(request_id); | 150 region_registration_requests_.Lookup(request_id); |
| 151 DCHECK(callbacks); | 151 DCHECK(callbacks); |
| 152 if (!callbacks) | |
| 153 return; | |
| 154 | 152 |
| 155 if (status == GEOFENCING_STATUS_OK) { | 153 if (status == GEOFENCING_STATUS_OK) { |
| 156 callbacks->onSuccess(); | 154 callbacks->onSuccess(); |
| 157 } else { | 155 } else { |
| 158 callbacks->onError(new WebGeofencingError( | 156 callbacks->onError(new WebGeofencingError( |
| 159 WebGeofencingError::ErrorTypeAbort, | 157 WebGeofencingError::ErrorTypeAbort, |
| 160 blink::WebString::fromUTF8(GeofencingStatusToString(status)))); | 158 blink::WebString::fromUTF8(GeofencingStatusToString(status)))); |
| 161 } | 159 } |
| 162 region_registration_requests_.Remove(request_id); | 160 region_registration_requests_.Remove(request_id); |
| 163 } | 161 } |
| 164 | 162 |
| 165 void GeofencingDispatcher::OnUnregisterRegionComplete(int thread_id, | 163 void GeofencingDispatcher::OnUnregisterRegionComplete(int thread_id, |
| 166 int request_id, | 164 int request_id, |
| 167 GeofencingStatus status) { | 165 GeofencingStatus status) { |
| 168 blink::WebGeofencingCallbacks* callbacks = | 166 blink::WebGeofencingCallbacks* callbacks = |
| 169 region_unregistration_requests_.Lookup(request_id); | 167 region_unregistration_requests_.Lookup(request_id); |
| 170 DCHECK(callbacks); | 168 DCHECK(callbacks); |
| 171 if (!callbacks) | |
| 172 return; | |
| 173 | 169 |
| 174 if (status == GEOFENCING_STATUS_OK) { | 170 if (status == GEOFENCING_STATUS_OK) { |
| 175 callbacks->onSuccess(); | 171 callbacks->onSuccess(); |
| 176 } else { | 172 } else { |
| 177 callbacks->onError(new WebGeofencingError( | 173 callbacks->onError(new WebGeofencingError( |
| 178 WebGeofencingError::ErrorTypeAbort, | 174 WebGeofencingError::ErrorTypeAbort, |
| 179 blink::WebString::fromUTF8(GeofencingStatusToString(status)))); | 175 blink::WebString::fromUTF8(GeofencingStatusToString(status)))); |
| 180 } | 176 } |
| 181 region_unregistration_requests_.Remove(request_id); | 177 region_unregistration_requests_.Remove(request_id); |
| 182 } | 178 } |
| 183 | 179 |
| 184 void GeofencingDispatcher::OnGetRegisteredRegionsComplete( | 180 void GeofencingDispatcher::OnGetRegisteredRegionsComplete( |
| 185 int thread_id, | 181 int thread_id, |
| 186 int request_id, | 182 int request_id, |
| 187 GeofencingStatus status, | 183 GeofencingStatus status, |
| 188 const GeofencingRegistrations& regions) { | 184 const GeofencingRegistrations& regions) { |
| 189 blink::WebGeofencingRegionsCallbacks* callbacks = | 185 blink::WebGeofencingRegionsCallbacks* callbacks = |
| 190 get_registered_regions_requests_.Lookup(request_id); | 186 get_registered_regions_requests_.Lookup(request_id); |
| 191 DCHECK(callbacks); | 187 DCHECK(callbacks); |
| 192 if (!callbacks) | |
| 193 return; | |
| 194 | 188 |
| 195 if (status == GEOFENCING_STATUS_OK) { | 189 if (status == GEOFENCING_STATUS_OK) { |
| 196 scoped_ptr<blink::WebVector<blink::WebGeofencingRegistration>> result( | 190 scoped_ptr<blink::WebVector<blink::WebGeofencingRegistration>> result( |
| 197 new blink::WebVector<blink::WebGeofencingRegistration>(regions.size())); | 191 new blink::WebVector<blink::WebGeofencingRegistration>(regions.size())); |
| 198 size_t index = 0; | 192 size_t index = 0; |
| 199 for (GeofencingRegistrations::const_iterator it = regions.begin(); | 193 for (GeofencingRegistrations::const_iterator it = regions.begin(); |
| 200 it != regions.end(); | 194 it != regions.end(); |
| 201 ++it, ++index) { | 195 ++it, ++index) { |
| 202 (*result)[index].id = blink::WebString::fromUTF8(it->first); | 196 (*result)[index].id = blink::WebString::fromUTF8(it->first); |
| 203 (*result)[index].region = it->second; | 197 (*result)[index].region = it->second; |
| 204 } | 198 } |
| 205 callbacks->onSuccess(result.release()); | 199 callbacks->onSuccess(result.release()); |
| 206 } else { | 200 } else { |
| 207 callbacks->onError(new WebGeofencingError( | 201 callbacks->onError(new WebGeofencingError( |
| 208 WebGeofencingError::ErrorTypeAbort, | 202 WebGeofencingError::ErrorTypeAbort, |
| 209 blink::WebString::fromUTF8(GeofencingStatusToString(status)))); | 203 blink::WebString::fromUTF8(GeofencingStatusToString(status)))); |
| 210 } | 204 } |
| 211 get_registered_regions_requests_.Remove(request_id); | 205 get_registered_regions_requests_.Remove(request_id); |
| 212 } | 206 } |
| 213 | 207 |
| 214 void GeofencingDispatcher::OnWorkerRunLoopStopped() { | 208 void GeofencingDispatcher::OnWorkerRunLoopStopped() { |
| 215 delete this; | 209 delete this; |
| 216 } | 210 } |
| 217 | 211 |
| 218 } // namespace content | 212 } // namespace content |
| OLD | NEW |