Chromium Code Reviews| 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" |
| 11 #include "content/child/service_worker/web_service_worker_registration_impl.h" | |
| 11 #include "content/child/thread_safe_sender.h" | 12 #include "content/child/thread_safe_sender.h" |
| 12 #include "content/child/worker_thread_task_runner.h" | 13 #include "content/child/worker_thread_task_runner.h" |
| 13 #include "content/common/geofencing_messages.h" | 14 #include "content/common/geofencing_messages.h" |
| 14 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h" | 15 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h" |
| 15 #include "third_party/WebKit/public/platform/WebGeofencingError.h" | 16 #include "third_party/WebKit/public/platform/WebGeofencingError.h" |
| 16 #include "third_party/WebKit/public/platform/WebGeofencingRegistration.h" | 17 #include "third_party/WebKit/public/platform/WebGeofencingRegistration.h" |
| 17 | 18 |
| 18 using blink::WebGeofencingError; | 19 using blink::WebGeofencingError; |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 IPC_MESSAGE_HANDLER(GeofencingMsg_GetRegisteredRegionsComplete, | 57 IPC_MESSAGE_HANDLER(GeofencingMsg_GetRegisteredRegionsComplete, |
| 57 OnGetRegisteredRegionsComplete) | 58 OnGetRegisteredRegionsComplete) |
| 58 IPC_MESSAGE_UNHANDLED(handled = false) | 59 IPC_MESSAGE_UNHANDLED(handled = false) |
| 59 IPC_END_MESSAGE_MAP() | 60 IPC_END_MESSAGE_MAP() |
| 60 DCHECK(handled) << "Unhandled message:" << msg.type(); | 61 DCHECK(handled) << "Unhandled message:" << msg.type(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void GeofencingDispatcher::RegisterRegion( | 64 void GeofencingDispatcher::RegisterRegion( |
| 64 const blink::WebString& region_id, | 65 const blink::WebString& region_id, |
| 65 const blink::WebCircularGeofencingRegion& region, | 66 const blink::WebCircularGeofencingRegion& region, |
| 67 blink::WebServiceWorkerRegistration* service_worker_registration, | |
| 66 blink::WebGeofencingCallbacks* callbacks) { | 68 blink::WebGeofencingCallbacks* callbacks) { |
| 67 DCHECK(callbacks); | 69 DCHECK(callbacks); |
| 68 int request_id = region_registration_requests_.Add(callbacks); | 70 int request_id = region_registration_requests_.Add(callbacks); |
| 69 Send(new GeofencingHostMsg_RegisterRegion( | 71 // TODO(mek): Reject requests without a service worker registration without |
| 70 CurrentWorkerId(), request_id, region_id.utf8(), region)); | 72 // bouncing through browser process. |
| 73 int64 serviceworker_registration_id = -1; | |
|
michaeln
2014/10/14 01:03:52
could use kInvalidServiceWorkerRegistrationId here
Marijn Kruisselbrink
2014/10/14 18:51:22
Done.
| |
| 74 if (service_worker_registration) { | |
| 75 serviceworker_registration_id = | |
| 76 static_cast<WebServiceWorkerRegistrationImpl*>( | |
| 77 service_worker_registration)->registration_id(); | |
| 78 } | |
| 79 Send(new GeofencingHostMsg_RegisterRegion(CurrentWorkerId(), | |
| 80 request_id, | |
| 81 region_id.utf8(), | |
| 82 region, | |
| 83 serviceworker_registration_id)); | |
| 71 } | 84 } |
| 72 | 85 |
| 73 void GeofencingDispatcher::UnregisterRegion( | 86 void GeofencingDispatcher::UnregisterRegion( |
| 74 const blink::WebString& region_id, | 87 const blink::WebString& region_id, |
| 88 blink::WebServiceWorkerRegistration* service_worker_registration, | |
| 75 blink::WebGeofencingCallbacks* callbacks) { | 89 blink::WebGeofencingCallbacks* callbacks) { |
| 76 DCHECK(callbacks); | 90 DCHECK(callbacks); |
| 77 int request_id = region_unregistration_requests_.Add(callbacks); | 91 int request_id = region_unregistration_requests_.Add(callbacks); |
| 78 Send(new GeofencingHostMsg_UnregisterRegion( | 92 // TODO(mek): Reject requests without a service worker registration without |
| 79 CurrentWorkerId(), request_id, region_id.utf8())); | 93 // bouncing through browser process. |
| 94 int64 serviceworker_registration_id = -1; | |
| 95 if (service_worker_registration) { | |
| 96 serviceworker_registration_id = | |
| 97 static_cast<WebServiceWorkerRegistrationImpl*>( | |
| 98 service_worker_registration)->registration_id(); | |
| 99 } | |
| 100 Send(new GeofencingHostMsg_UnregisterRegion(CurrentWorkerId(), | |
| 101 request_id, | |
| 102 region_id.utf8(), | |
| 103 serviceworker_registration_id)); | |
| 80 } | 104 } |
| 81 | 105 |
| 82 void GeofencingDispatcher::GetRegisteredRegions( | 106 void GeofencingDispatcher::GetRegisteredRegions( |
| 107 blink::WebServiceWorkerRegistration* service_worker_registration, | |
| 83 blink::WebGeofencingRegionsCallbacks* callbacks) { | 108 blink::WebGeofencingRegionsCallbacks* callbacks) { |
| 84 DCHECK(callbacks); | 109 DCHECK(callbacks); |
| 85 int request_id = get_registered_regions_requests_.Add(callbacks); | 110 int request_id = get_registered_regions_requests_.Add(callbacks); |
| 86 Send(new GeofencingHostMsg_GetRegisteredRegions(CurrentWorkerId(), | 111 // TODO(mek): Reject requests without a service worker registration without |
| 87 request_id)); | 112 // bouncing through browser process. |
| 113 int64 serviceworker_registration_id = -1; | |
| 114 if (service_worker_registration) { | |
| 115 serviceworker_registration_id = | |
| 116 static_cast<WebServiceWorkerRegistrationImpl*>( | |
| 117 service_worker_registration)->registration_id(); | |
| 118 } | |
| 119 Send(new GeofencingHostMsg_GetRegisteredRegions( | |
| 120 CurrentWorkerId(), request_id, serviceworker_registration_id)); | |
| 88 } | 121 } |
| 89 | 122 |
| 90 GeofencingDispatcher* GeofencingDispatcher::GetOrCreateThreadSpecificInstance( | 123 GeofencingDispatcher* GeofencingDispatcher::GetOrCreateThreadSpecificInstance( |
| 91 ThreadSafeSender* thread_safe_sender) { | 124 ThreadSafeSender* thread_safe_sender) { |
| 92 if (g_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { | 125 if (g_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { |
| 93 NOTREACHED() << "Re-instantiating TLS GeofencingDispatcher."; | 126 NOTREACHED() << "Re-instantiating TLS GeofencingDispatcher."; |
| 94 g_dispatcher_tls.Pointer()->Set(NULL); | 127 g_dispatcher_tls.Pointer()->Set(NULL); |
| 95 } | 128 } |
| 96 if (g_dispatcher_tls.Pointer()->Get()) | 129 if (g_dispatcher_tls.Pointer()->Get()) |
| 97 return g_dispatcher_tls.Pointer()->Get(); | 130 return g_dispatcher_tls.Pointer()->Get(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 blink::WebString::fromUTF8(GeofencingStatusToString(status)))); | 208 blink::WebString::fromUTF8(GeofencingStatusToString(status)))); |
| 176 } | 209 } |
| 177 get_registered_regions_requests_.Remove(request_id); | 210 get_registered_regions_requests_.Remove(request_id); |
| 178 } | 211 } |
| 179 | 212 |
| 180 void GeofencingDispatcher::OnWorkerRunLoopStopped() { | 213 void GeofencingDispatcher::OnWorkerRunLoopStopped() { |
| 181 delete this; | 214 delete this; |
| 182 } | 215 } |
| 183 | 216 |
| 184 } // namespace content | 217 } // namespace content |
| OLD | NEW |