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