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* serviceworker, | |
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 int serviceworker_id = -1; |
70 CurrentWorkerId(), request_id, region_id.utf8(), region)); | 72 if (serviceworker) |
73 serviceworker_id = static_cast<WebServiceWorkerRegistrationImpl*>( | |
74 serviceworker)->handle_id(); | |
75 Send(new GeofencingHostMsg_RegisterRegion(CurrentWorkerId(), | |
76 request_id, | |
77 region_id.utf8(), | |
78 region, | |
79 serviceworker_id)); | |
71 } | 80 } |
72 | 81 |
73 void GeofencingDispatcher::UnregisterRegion( | 82 void GeofencingDispatcher::UnregisterRegion( |
74 const blink::WebString& region_id, | 83 const blink::WebString& region_id, |
84 blink::WebServiceWorkerRegistration* serviceworker, | |
75 blink::WebGeofencingCallbacks* callbacks) { | 85 blink::WebGeofencingCallbacks* callbacks) { |
76 DCHECK(callbacks); | 86 DCHECK(callbacks); |
77 int request_id = region_unregistration_requests_.Add(callbacks); | 87 int request_id = region_unregistration_requests_.Add(callbacks); |
88 int serviceworker_id = -1; | |
89 if (serviceworker) | |
jsbell
2014/10/08 18:41:30
nit: need braces around multi-line if body
Marijn Kruisselbrink
2014/10/13 19:29:48
Done.
| |
90 serviceworker_id = static_cast<WebServiceWorkerRegistrationImpl*>( | |
91 serviceworker)->handle_id(); | |
78 Send(new GeofencingHostMsg_UnregisterRegion( | 92 Send(new GeofencingHostMsg_UnregisterRegion( |
79 CurrentWorkerId(), request_id, region_id.utf8())); | 93 CurrentWorkerId(), request_id, region_id.utf8(), serviceworker_id)); |
80 } | 94 } |
81 | 95 |
82 void GeofencingDispatcher::GetRegisteredRegions( | 96 void GeofencingDispatcher::GetRegisteredRegions( |
97 blink::WebServiceWorkerRegistration* serviceworker, | |
83 blink::WebGeofencingRegionsCallbacks* callbacks) { | 98 blink::WebGeofencingRegionsCallbacks* callbacks) { |
84 DCHECK(callbacks); | 99 DCHECK(callbacks); |
85 int request_id = get_registered_regions_requests_.Add(callbacks); | 100 int request_id = get_registered_regions_requests_.Add(callbacks); |
86 Send(new GeofencingHostMsg_GetRegisteredRegions(CurrentWorkerId(), | 101 int serviceworker_id = -1; |
87 request_id)); | 102 if (serviceworker) |
jsbell
2014/10/08 18:41:30
nit: need braces around multi-line if body
Marijn Kruisselbrink
2014/10/13 19:29:48
Done.
| |
103 serviceworker_id = static_cast<WebServiceWorkerRegistrationImpl*>( | |
104 serviceworker)->handle_id(); | |
105 Send(new GeofencingHostMsg_GetRegisteredRegions( | |
106 CurrentWorkerId(), request_id, serviceworker_id)); | |
88 } | 107 } |
89 | 108 |
90 GeofencingDispatcher* GeofencingDispatcher::GetOrCreateThreadSpecificInstance( | 109 GeofencingDispatcher* GeofencingDispatcher::GetOrCreateThreadSpecificInstance( |
91 ThreadSafeSender* thread_safe_sender) { | 110 ThreadSafeSender* thread_safe_sender) { |
92 if (g_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { | 111 if (g_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { |
93 NOTREACHED() << "Re-instantiating TLS GeofencingDispatcher."; | 112 NOTREACHED() << "Re-instantiating TLS GeofencingDispatcher."; |
94 g_dispatcher_tls.Pointer()->Set(NULL); | 113 g_dispatcher_tls.Pointer()->Set(NULL); |
95 } | 114 } |
96 if (g_dispatcher_tls.Pointer()->Get()) | 115 if (g_dispatcher_tls.Pointer()->Get()) |
97 return g_dispatcher_tls.Pointer()->Get(); | 116 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)))); | 194 blink::WebString::fromUTF8(GeofencingStatusToString(status)))); |
176 } | 195 } |
177 get_registered_regions_requests_.Remove(request_id); | 196 get_registered_regions_requests_.Remove(request_id); |
178 } | 197 } |
179 | 198 |
180 void GeofencingDispatcher::OnWorkerRunLoopStopped() { | 199 void GeofencingDispatcher::OnWorkerRunLoopStopped() { |
181 delete this; | 200 delete this; |
182 } | 201 } |
183 | 202 |
184 } // namespace content | 203 } // namespace content |
OLD | NEW |