cc: Make picture pile base thread safe.
[chromium-blink-merge.git] / content / child / geofencing / geofencing_dispatcher.h
blob57a2a437b5da9d3c40340f3ec102de8f6c38d2f8
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_
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"
15 namespace base {
16 class MessageLoop;
17 class TaskRunner;
20 namespace IPC {
21 class Message;
24 namespace content {
25 class ThreadSafeSender;
27 class GeofencingDispatcher : public WorkerTaskRunner::Observer {
28 public:
29 explicit GeofencingDispatcher(ThreadSafeSender* sender);
30 ~GeofencingDispatcher() override;
32 bool Send(IPC::Message* msg);
33 void OnMessageReceived(const IPC::Message& msg);
35 // Corresponding to WebGeofencingProvider methods.
36 void RegisterRegion(
37 const blink::WebString& region_id,
38 const blink::WebCircularGeofencingRegion& region,
39 blink::WebServiceWorkerRegistration* service_worker_registration,
40 blink::WebGeofencingCallbacks* callbacks);
41 void UnregisterRegion(
42 const blink::WebString& region_id,
43 blink::WebServiceWorkerRegistration* service_worker_registration,
44 blink::WebGeofencingCallbacks* callbacks);
45 void GetRegisteredRegions(
46 blink::WebServiceWorkerRegistration* service_worker_registration,
47 blink::WebGeofencingRegionsCallbacks* callbacks);
49 // |thread_safe_sender| needs to be passed in because if the call leads to
50 // construction it will be needed.
51 static GeofencingDispatcher* GetOrCreateThreadSpecificInstance(
52 ThreadSafeSender* thread_safe_sender);
54 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new
55 // instance if thread-local instance doesn't exist.
56 static GeofencingDispatcher* GetThreadSpecificInstance();
58 private:
59 void OnRegisterRegionComplete(int thread_id,
60 int request_id,
61 GeofencingStatus status);
62 void OnUnregisterRegionComplete(int thread_id,
63 int request_id,
64 GeofencingStatus status);
65 void OnGetRegisteredRegionsComplete(
66 int thread_id,
67 int request_id,
68 GeofencingStatus status,
69 const std::map<std::string, blink::WebCircularGeofencingRegion>& regions);
71 // WorkerTaskRunner::Observer implementation.
72 void OnWorkerRunLoopStopped() override;
74 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
75 IDMap<blink::WebGeofencingCallbacks, IDMapOwnPointer>
76 region_registration_requests_;
77 IDMap<blink::WebGeofencingCallbacks, IDMapOwnPointer>
78 region_unregistration_requests_;
79 IDMap<blink::WebGeofencingRegionsCallbacks, IDMapOwnPointer>
80 get_registered_regions_requests_;
82 DISALLOW_COPY_AND_ASSIGN(GeofencingDispatcher);
85 } // namespace content
87 #endif // CONTENT_CHILD_GEOFENCING_GEOFENCING_DISPATCHER_H_