OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ | 5 #ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ |
6 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ | 6 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ |
7 | 7 |
8 #include <map> | |
9 #include <set> | |
10 #include <utility> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
14 #include "chrome/browser/geolocation/location_arbitrator.h" | |
15 | 9 |
16 class GeolocationPermissionContext; | 10 class GeolocationPermissionContext; |
17 class GURL; | |
18 class ResourceMessageFilter; | |
19 class URLRequestContextGetter; | |
20 struct Geoposition; | |
21 namespace IPC { class Message; } | 11 namespace IPC { class Message; } |
22 | 12 |
23 // GeolocationDispatcherHost is a delegate for Geolocation messages used by | 13 // GeolocationDispatcherHost is a delegate for Geolocation messages used by |
24 // ResourceMessageFilter. | 14 // ResourceMessageFilter. |
25 // It's the complement of GeolocationDispatcher (owned by RenderView). | 15 // It's the complement of GeolocationDispatcher (owned by RenderView). |
26 class GeolocationDispatcherHost | 16 class GeolocationDispatcherHost |
27 : public base::RefCountedThreadSafe<GeolocationDispatcherHost>, | 17 : public base::RefCountedThreadSafe<GeolocationDispatcherHost> { |
28 public GeolocationArbitrator::Delegate { | |
29 public: | 18 public: |
30 GeolocationDispatcherHost( | 19 static GeolocationDispatcherHost* New( |
31 int resource_message_filter_process_id, | 20 int resource_message_filter_process_id, |
32 GeolocationPermissionContext* geolocation_permission_context); | 21 GeolocationPermissionContext* geolocation_permission_context); |
33 | 22 |
34 // Called to possibly handle the incoming IPC message. Returns true if | 23 // Called to possibly handle the incoming IPC message. Returns true if |
35 // handled. Called in the browser process. | 24 // handled. Called in the browser process. |
36 bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok); | 25 virtual bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok) = 0; |
37 | 26 |
38 // GeolocationArbitrator::Delegate | 27 protected: |
39 virtual void OnLocationUpdate(const Geoposition& position); | |
40 | |
41 private: | |
42 friend class base::RefCountedThreadSafe<GeolocationDispatcherHost>; | 28 friend class base::RefCountedThreadSafe<GeolocationDispatcherHost>; |
43 virtual ~GeolocationDispatcherHost(); | 29 GeolocationDispatcherHost() {} |
44 | 30 virtual ~GeolocationDispatcherHost() {} |
45 void OnRegisterDispatcher(int render_view_id); | |
46 void OnUnregisterDispatcher(int render_view_id); | |
47 void OnRequestPermission( | |
48 int render_view_id, int bridge_id, const GURL& requesting_frame); | |
49 void OnCancelPermissionRequest( | |
50 int render_view_id, int bridge_id, const GURL& requesting_frame); | |
51 void OnStartUpdating( | |
52 int render_view_id, int bridge_id, const GURL& requesting_frame, | |
53 bool enable_high_accuracy); | |
54 void OnStopUpdating(int render_view_id, int bridge_id); | |
55 void OnSuspend(int render_view_id, int bridge_id); | |
56 void OnResume(int render_view_id, int bridge_id); | |
57 | |
58 // Registers the bridge created in the renderer side. They'll delegate to the | |
59 // UI thread if not already in there. | |
60 void RegisterDispatcher(int process_id, int render_view_id); | |
61 void UnregisterDispatcher(int process_id, int render_view_id); | |
62 // Updates the |location_arbitrator_| with the currently required update | |
63 // options, based on |bridge_update_options_|. | |
64 void RefreshUpdateOptions(); | |
65 | |
66 int resource_message_filter_process_id_; | |
67 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; | |
68 | |
69 // Iterated when sending location updates to renderer processes. The fan out | |
70 // to individual bridge IDs happens renderer side, in order to minimize | |
71 // context switches. | |
72 // Only used on the IO thread. | |
73 std::set<int> geolocation_renderer_ids_; | |
74 // Maps <renderer_id, bridge_id> to the location arbitrator update options | |
75 // that correspond to this particular bridge. | |
76 typedef std::map<std::pair<int, int>, GeolocationArbitrator::UpdateOptions> | |
77 BridgeUpdateOptionsMap; | |
78 BridgeUpdateOptionsMap bridge_update_options_; | |
79 // Only set whilst we are registered with the arbitrator. | |
80 scoped_refptr<GeolocationArbitrator> location_arbitrator_; | |
81 | 31 |
82 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost); | 32 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost); |
83 }; | 33 }; |
84 | 34 |
85 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ | 35 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ |
OLD | NEW |