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 "base/id_map.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "content/child/worker_task_runner.h" |
| 12 #include "content/common/geofencing_status.h" |
| 13 #include "third_party/WebKit/public/platform/WebGeofencingProvider.h" |
| 14 |
| 15 namespace base { |
| 16 class MessageLoop; |
| 17 class TaskRunner; |
| 18 } |
| 19 |
| 20 namespace IPC { |
| 21 class Message; |
| 22 } |
| 23 |
| 24 namespace content { |
| 25 class ThreadSafeSender; |
| 26 |
| 27 class GeofencingDispatcher : public WorkerTaskRunner::Observer { |
| 28 public: |
| 29 explicit GeofencingDispatcher(ThreadSafeSender* sender); |
| 30 virtual ~GeofencingDispatcher(); |
| 31 |
| 32 bool Send(IPC::Message* msg); |
| 33 void OnMessageReceived(const IPC::Message& msg); |
| 34 |
| 35 // Corresponding to WebGeofencingProvider methods. |
| 36 void RegisterRegion(const blink::WebString& region_id, |
| 37 const blink::WebCircularGeofencingRegion& region, |
| 38 blink::WebGeofencingCallbacks* callbacks); |
| 39 void UnregisterRegion(const blink::WebString& region_id, |
| 40 blink::WebGeofencingCallbacks* callbacks); |
| 41 void GetRegisteredRegions(blink::WebGeofencingRegionsCallbacks* callbacks); |
| 42 |
| 43 // |thread_safe_sender| needs to be passed in because if the call leads to |
| 44 // construction it will be needed. |
| 45 static GeofencingDispatcher* GetOrCreateThreadSpecificInstance( |
| 46 ThreadSafeSender* thread_safe_sender); |
| 47 |
| 48 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new |
| 49 // instance if thread-local instance doesn't exist. |
| 50 static GeofencingDispatcher* GetThreadSpecificInstance(); |
| 51 |
| 52 private: |
| 53 void OnRegisterRegionComplete(int thread_id, |
| 54 int request_id, |
| 55 GeofencingStatus status); |
| 56 void OnUnregisterRegionComplete(int thread_id, |
| 57 int request_id, |
| 58 GeofencingStatus status); |
| 59 void OnGetRegisteredRegionsComplete( |
| 60 int thread_id, |
| 61 int request_id, |
| 62 GeofencingStatus status, |
| 63 const std::map<std::string, blink::WebCircularGeofencingRegion>& regions); |
| 64 |
| 65 // WorkerTaskRunner::Observer implementation. |
| 66 virtual void OnWorkerRunLoopStopped() OVERRIDE; |
| 67 |
| 68 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 69 IDMap<blink::WebGeofencingCallbacks, IDMapOwnPointer> |
| 70 region_registration_requests_; |
| 71 IDMap<blink::WebGeofencingCallbacks, IDMapOwnPointer> |
| 72 region_unregistration_requests_; |
| 73 IDMap<blink::WebGeofencingRegionsCallbacks, IDMapOwnPointer> |
| 74 get_registered_regions_requests_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(GeofencingDispatcher); |
| 77 }; |
| 78 |
| 79 } // namespace content |
| 80 |
| 81 #endif // CONTENT_CHILD_GEOFENCING_GEOFENCING_DISPATCHER_H_ |
OLD | NEW |