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