OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_CHILD_GEOFENCING_GEOFENCING_DISPATCHER_H_ | |
6 #define CONTENT_CHILD_GEOFENCING_GEOFENCING_DISPATCHER_H_ | |
7 | |
8 #include <map> | |
9 #include <memory> | |
10 #include <string> | |
11 | |
12 #include "base/id_map.h" | |
13 #include "base/macros.h" | |
14 #include "base/memory/ref_counted.h" | |
15 #include "content/common/geofencing_types.h" | |
16 #include "content/public/child/worker_thread.h" | |
17 #include "third_party/WebKit/public/platform/WebGeofencingProvider.h" | |
18 | |
19 namespace base { | |
20 class MessageLoop; | |
21 class TaskRunner; | |
22 } | |
23 | |
24 namespace IPC { | |
25 class Message; | |
26 } | |
27 | |
28 namespace content { | |
29 class ThreadSafeSender; | |
30 | |
31 class GeofencingDispatcher : public WorkerThread::Observer { | |
32 public: | |
33 explicit GeofencingDispatcher(ThreadSafeSender* sender); | |
34 ~GeofencingDispatcher() override; | |
35 | |
36 bool Send(IPC::Message* msg); | |
37 void OnMessageReceived(const IPC::Message& msg); | |
38 | |
39 // Corresponding to WebGeofencingProvider methods. | |
40 void RegisterRegion( | |
41 const blink::WebString& region_id, | |
42 const blink::WebCircularGeofencingRegion& region, | |
43 blink::WebServiceWorkerRegistration* service_worker_registration, | |
44 blink::WebGeofencingCallbacks* callbacks); | |
45 void UnregisterRegion( | |
46 const blink::WebString& region_id, | |
47 blink::WebServiceWorkerRegistration* service_worker_registration, | |
48 blink::WebGeofencingCallbacks* callbacks); | |
49 void GetRegisteredRegions( | |
50 blink::WebServiceWorkerRegistration* service_worker_registration, | |
51 blink::WebGeofencingRegionsCallbacks* callbacks); | |
52 | |
53 // Enables mock geofencing service. |service_available| indicates if the | |
54 // mock service should mock geofencing being available or not. | |
55 void SetMockProvider(bool service_available); | |
56 // Disables mock geofencing service. | |
57 void ClearMockProvider(); | |
58 // Set the mock geofencing position. | |
59 void SetMockPosition(double latitude, double longitude); | |
60 | |
61 // |thread_safe_sender| needs to be passed in because if the call leads to | |
62 // construction it will be needed. | |
63 static GeofencingDispatcher* GetOrCreateThreadSpecificInstance( | |
64 ThreadSafeSender* thread_safe_sender); | |
65 | |
66 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new | |
67 // instance if thread-local instance doesn't exist. | |
68 static GeofencingDispatcher* GetThreadSpecificInstance(); | |
69 | |
70 private: | |
71 void OnRegisterRegionComplete(int thread_id, | |
72 int request_id, | |
73 GeofencingStatus status); | |
74 void OnUnregisterRegionComplete(int thread_id, | |
75 int request_id, | |
76 GeofencingStatus status); | |
77 void OnGetRegisteredRegionsComplete( | |
78 int thread_id, | |
79 int request_id, | |
80 GeofencingStatus status, | |
81 const std::map<std::string, blink::WebCircularGeofencingRegion>& regions); | |
82 | |
83 // WorkerThread::Observer implementation. | |
84 void WillStopCurrentWorkerThread() override; | |
85 | |
86 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | |
87 IDMap<blink::WebGeofencingCallbacks, IDMapOwnPointer> | |
88 region_registration_requests_; | |
89 IDMap<blink::WebGeofencingCallbacks, IDMapOwnPointer> | |
90 region_unregistration_requests_; | |
91 IDMap<blink::WebGeofencingRegionsCallbacks, IDMapOwnPointer> | |
92 get_registered_regions_requests_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(GeofencingDispatcher); | |
95 }; | |
96 | |
97 } // namespace content | |
98 | |
99 #endif // CONTENT_CHILD_GEOFENCING_GEOFENCING_DISPATCHER_H_ | |
OLD | NEW |