OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ |
6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ |
7 | 7 |
8 #include <map> | |
9 #include <set> | |
10 | |
11 #include "content/browser/geolocation/geolocation_provider_impl.h" | |
12 #include "content/public/browser/browser_message_filter.h" | 8 #include "content/public/browser/browser_message_filter.h" |
13 | 9 |
14 class GURL; | |
15 | |
16 namespace content { | 10 namespace content { |
17 | 11 |
18 class GeolocationPermissionContext; | 12 class GeolocationPermissionContext; |
19 | 13 |
20 // GeolocationDispatcherHost is a browser filter for Geolocation messages. | 14 // GeolocationDispatcherHost is a browser filter for Geolocation messages. |
21 // It's the complement of GeolocationDispatcher (owned by RenderView). | 15 // It's the complement of GeolocationDispatcher (owned by RenderView). |
22 class GeolocationDispatcherHost : public BrowserMessageFilter { | 16 class GeolocationDispatcherHost : public BrowserMessageFilter { |
23 public: | 17 public: |
24 GeolocationDispatcherHost( | 18 static GeolocationDispatcherHost* New( |
25 int render_process_id, | 19 int render_process_id, |
26 GeolocationPermissionContext* geolocation_permission_context); | 20 GeolocationPermissionContext* geolocation_permission_context); |
27 virtual ~GeolocationDispatcherHost(); | |
28 | 21 |
29 // Pause or resumes geolocation for the given |render_view_id|. Should | 22 // Pause or resumes geolocation for the given |render_view_id|. Should |
30 // be called on the IO thread. Resuming when nothing is paused is a no-op. | 23 // be called on the IO thread. Resuming when nothing is paused is a no-op. |
31 // If a renderer is paused while not currently using geolocation but | 24 // If a renderer is paused while not currently using geolocation but |
32 // then goes on to do so before being resumed, then that renderer will | 25 // then goes on to do so before being resumed, then that renderer will |
33 // not get geolocation updates until it is resumed. | 26 // not get geolocation updates until it is resumed. |
34 void PauseOrResume(int render_view_id, bool should_pause); | 27 virtual void PauseOrResume(int render_view_id, bool should_pause) = 0; |
35 | 28 |
36 private: | 29 protected: |
37 // GeolocationDispatcherHost | 30 GeolocationDispatcherHost(); |
38 virtual bool OnMessageReceived(const IPC::Message& msg, | 31 virtual ~GeolocationDispatcherHost(); |
39 bool* msg_was_ok) OVERRIDE; | |
40 | |
41 // Message handlers: | |
42 void OnRequestPermission(int render_view_id, | |
43 int bridge_id, | |
44 const GURL& requesting_frame, | |
45 bool user_gesture); | |
46 void OnCancelPermissionRequest(int render_view_id, | |
47 int bridge_id, | |
48 const GURL& requesting_frame); | |
49 void OnStartUpdating(int render_view_id, | |
50 const GURL& requesting_frame, | |
51 bool enable_high_accuracy); | |
52 void OnStopUpdating(int render_view_id); | |
53 | |
54 // Updates the |geolocation_provider_| with the currently required update | |
55 // options. | |
56 void RefreshGeolocationOptions(); | |
57 | |
58 void OnLocationUpdate(const Geoposition& position); | |
59 | |
60 int render_process_id_; | |
61 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; | |
62 | |
63 struct RendererGeolocationOptions { | |
64 bool high_accuracy; | |
65 bool is_paused; | |
66 }; | |
67 | |
68 // Used to keep track of the renderers in this process that are using | |
69 // geolocation and the options associated with them. The map is iterated | |
70 // when a location update is available and the fan out to individual bridge | |
71 // IDs happens renderer side, in order to minimize context switches. | |
72 // Only used on the IO thread. | |
73 std::map<int, RendererGeolocationOptions> geolocation_renderers_; | |
74 | |
75 // Used by Android WebView to support that case that a renderer is in the | |
76 // 'paused' state but not yet using geolocation. If the renderer does start | |
77 // using geolocation while paused, we move from this set into | |
78 // |geolocation_renderers_|. If the renderer doesn't end up wanting to use | |
79 // geolocation while 'paused' then we remove from this set. A renderer id | |
80 // can exist only in this set or |geolocation_renderers_|, never both. | |
81 std::set<int> pending_paused_geolocation_renderers_; | |
82 | |
83 // Only set whilst we are registered with the geolocation provider. | |
84 GeolocationProviderImpl* geolocation_provider_; | |
85 | |
86 GeolocationProviderImpl::LocationUpdateCallback callback_; | |
87 | 32 |
88 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost); | 33 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost); |
89 }; | 34 }; |
90 | 35 |
91 } // namespace content | 36 } // namespace content |
92 | 37 |
93 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ | 38 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ |
OLD | NEW |