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/browser/geofencing/geofencing_manager.h" | 5 #include "content/browser/geofencing/geofencing_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "content/browser/geofencing/geofencing_service.h" | 10 #include "content/browser/geofencing/geofencing_service.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 int64 service_worker_registration_id, | 103 int64 service_worker_registration_id, |
104 const std::string& region_id, | 104 const std::string& region_id, |
105 const blink::WebCircularGeofencingRegion& region, | 105 const blink::WebCircularGeofencingRegion& region, |
106 const StatusCallback& callback) { | 106 const StatusCallback& callback) { |
107 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 107 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
108 | 108 |
109 // TODO(mek): Validate region_id and region. | 109 // TODO(mek): Validate region_id and region. |
110 | 110 |
111 // Look up service worker. | 111 // Look up service worker. |
112 ServiceWorkerRegistration* service_worker_registration = | 112 ServiceWorkerRegistration* service_worker_registration = |
113 service_worker_context_->context()->GetLiveRegistration( | 113 service_worker_context_->GetLiveRegistration( |
114 service_worker_registration_id); | 114 service_worker_registration_id); |
115 if (!service_worker_registration) { | 115 if (!service_worker_registration) { |
116 callback.Run(GEOFENCING_STATUS_OPERATION_FAILED_NO_SERVICE_WORKER); | 116 callback.Run(GEOFENCING_STATUS_OPERATION_FAILED_NO_SERVICE_WORKER); |
117 return; | 117 return; |
118 } | 118 } |
119 | 119 |
120 GURL service_worker_origin = | 120 GURL service_worker_origin = |
121 service_worker_registration->pattern().GetOrigin(); | 121 service_worker_registration->pattern().GetOrigin(); |
122 | 122 |
123 if (!service_->IsServiceAvailable()) { | 123 if (!service_->IsServiceAvailable()) { |
(...skipping 15 matching lines...) Expand all Loading... |
139 | 139 |
140 void GeofencingManager::UnregisterRegion(int64 service_worker_registration_id, | 140 void GeofencingManager::UnregisterRegion(int64 service_worker_registration_id, |
141 const std::string& region_id, | 141 const std::string& region_id, |
142 const StatusCallback& callback) { | 142 const StatusCallback& callback) { |
143 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 143 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
144 | 144 |
145 // TODO(mek): Validate region_id. | 145 // TODO(mek): Validate region_id. |
146 | 146 |
147 // Look up service worker. | 147 // Look up service worker. |
148 ServiceWorkerRegistration* service_worker_registration = | 148 ServiceWorkerRegistration* service_worker_registration = |
149 service_worker_context_->context()->GetLiveRegistration( | 149 service_worker_context_->GetLiveRegistration( |
150 service_worker_registration_id); | 150 service_worker_registration_id); |
151 if (!service_worker_registration) { | 151 if (!service_worker_registration) { |
152 callback.Run(GEOFENCING_STATUS_OPERATION_FAILED_NO_SERVICE_WORKER); | 152 callback.Run(GEOFENCING_STATUS_OPERATION_FAILED_NO_SERVICE_WORKER); |
153 return; | 153 return; |
154 } | 154 } |
155 | 155 |
156 if (!service_->IsServiceAvailable()) { | 156 if (!service_->IsServiceAvailable()) { |
157 callback.Run(GEOFENCING_STATUS_OPERATION_FAILED_SERVICE_NOT_AVAILABLE); | 157 callback.Run(GEOFENCING_STATUS_OPERATION_FAILED_SERVICE_NOT_AVAILABLE); |
158 return; | 158 return; |
159 } | 159 } |
(...skipping 18 matching lines...) Expand all Loading... |
178 } | 178 } |
179 | 179 |
180 GeofencingStatus GeofencingManager::GetRegisteredRegions( | 180 GeofencingStatus GeofencingManager::GetRegisteredRegions( |
181 int64 service_worker_registration_id, | 181 int64 service_worker_registration_id, |
182 std::map<std::string, blink::WebCircularGeofencingRegion>* result) { | 182 std::map<std::string, blink::WebCircularGeofencingRegion>* result) { |
183 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 183 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
184 CHECK(result); | 184 CHECK(result); |
185 | 185 |
186 // Look up service worker. | 186 // Look up service worker. |
187 ServiceWorkerRegistration* service_worker_registration = | 187 ServiceWorkerRegistration* service_worker_registration = |
188 service_worker_context_->context()->GetLiveRegistration( | 188 service_worker_context_->GetLiveRegistration( |
189 service_worker_registration_id); | 189 service_worker_registration_id); |
190 if (!service_worker_registration) { | 190 if (!service_worker_registration) { |
191 return GEOFENCING_STATUS_OPERATION_FAILED_NO_SERVICE_WORKER; | 191 return GEOFENCING_STATUS_OPERATION_FAILED_NO_SERVICE_WORKER; |
192 } | 192 } |
193 | 193 |
194 if (!service_->IsServiceAvailable()) { | 194 if (!service_->IsServiceAvailable()) { |
195 return GEOFENCING_STATUS_OPERATION_FAILED_SERVICE_NOT_AVAILABLE; | 195 return GEOFENCING_STATUS_OPERATION_FAILED_SERVICE_NOT_AVAILABLE; |
196 } | 196 } |
197 | 197 |
198 // Populate result, filtering out inactive registrations. | 198 // Populate result, filtering out inactive registrations. |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 int64 geofencing_registration_id) { | 351 int64 geofencing_registration_id) { |
352 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 352 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
353 Registration* registration = FindRegistrationById(geofencing_registration_id); | 353 Registration* registration = FindRegistrationById(geofencing_registration_id); |
354 if (!registration || | 354 if (!registration || |
355 registration->service_worker_registration_id == | 355 registration->service_worker_registration_id == |
356 kInvalidServiceWorkerRegistrationId) { | 356 kInvalidServiceWorkerRegistrationId) { |
357 // TODO(mek): Log/track these failures. | 357 // TODO(mek): Log/track these failures. |
358 return; | 358 return; |
359 } | 359 } |
360 | 360 |
361 service_worker_context_->context()->storage()->FindRegistrationForId( | 361 service_worker_context_->FindRegistrationForId( |
362 registration->service_worker_registration_id, | 362 registration->service_worker_registration_id, |
363 registration->service_worker_origin, | 363 registration->service_worker_origin, |
364 base::Bind(&GeofencingManager::DeliverGeofencingEvent, | 364 base::Bind(&GeofencingManager::DeliverGeofencingEvent, |
365 this, | 365 this, |
366 event_type, | 366 event_type, |
367 geofencing_registration_id)); | 367 geofencing_registration_id)); |
368 } | 368 } |
369 | 369 |
370 void GeofencingManager::DeliverGeofencingEvent( | 370 void GeofencingManager::DeliverGeofencingEvent( |
371 blink::WebGeofencingEventType event_type, | 371 blink::WebGeofencingEventType event_type, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 } | 408 } |
409 | 409 |
410 void GeofencingManager::DeliverGeofencingEventEnd( | 410 void GeofencingManager::DeliverGeofencingEventEnd( |
411 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration, | 411 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration, |
412 ServiceWorkerStatusCode service_worker_status) { | 412 ServiceWorkerStatusCode service_worker_status) { |
413 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 413 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
414 // TODO(mek): log/check result. | 414 // TODO(mek): log/check result. |
415 } | 415 } |
416 | 416 |
417 } // namespace content | 417 } // namespace content |
OLD | NEW |