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