diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-02 22:43:31 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-02 22:43:31 +0000 |
commit | dd91e6125ec19e41e1108d43326f7ab8bb912bcc (patch) | |
tree | 03489fa661c91b5c6477f7c98efa5535b1f71d1f /content/browser/geolocation | |
parent | 3f0aa2d85a2934f51457a353ca1a13ca15d5b407 (diff) | |
download | chromium_src-dd91e6125ec19e41e1108d43326f7ab8bb912bcc.zip chromium_src-dd91e6125ec19e41e1108d43326f7ab8bb912bcc.tar.gz chromium_src-dd91e6125ec19e41e1108d43326f7ab8bb912bcc.tar.bz2 |
Merge GeolocationDispatcherHostImpl with GeolocationDispatcherHost. None of the other message filters hide the internal in the cc file, and it just makes reading/modifying this code harder.
BUG=304341
R=avi@chromium.org, mvanouwerkerk@chromium.org
Review URL: https://codereview.chromium.org/262753006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267948 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/geolocation')
-rw-r--r-- | content/browser/geolocation/geolocation_dispatcher_host.cc | 118 | ||||
-rw-r--r-- | content/browser/geolocation/geolocation_dispatcher_host.h | 65 |
2 files changed, 76 insertions, 107 deletions
diff --git a/content/browser/geolocation/geolocation_dispatcher_host.cc b/content/browser/geolocation/geolocation_dispatcher_host.cc index 9502382..5479446 100644 --- a/content/browser/geolocation/geolocation_dispatcher_host.cc +++ b/content/browser/geolocation/geolocation_dispatcher_host.cc @@ -4,13 +4,10 @@ #include "content/browser/geolocation/geolocation_dispatcher_host.h" -#include <map> -#include <set> #include <utility> #include "base/bind.h" #include "base/metrics/histogram.h" -#include "content/browser/geolocation/geolocation_provider_impl.h" #include "content/browser/renderer_host/render_message_filter.h" #include "content/browser/renderer_host/render_process_host_impl.h" #include "content/browser/renderer_host/render_view_host_impl.h" @@ -88,96 +85,34 @@ void SendGeolocationPermissionResponse(int render_process_id, } } -class GeolocationDispatcherHostImpl : public GeolocationDispatcherHost { - public: - GeolocationDispatcherHostImpl( - int render_process_id, - GeolocationPermissionContext* geolocation_permission_context); - - // GeolocationDispatcherHost - virtual bool OnMessageReceived(const IPC::Message& msg, - bool* msg_was_ok) OVERRIDE; - - private: - virtual ~GeolocationDispatcherHostImpl(); - - void OnRequestPermission(int render_view_id, - int bridge_id, - const GURL& requesting_frame, - bool user_gesture); - void OnCancelPermissionRequest(int render_view_id, - int bridge_id, - const GURL& requesting_frame); - void OnStartUpdating(int render_view_id, - const GURL& requesting_frame, - bool enable_high_accuracy); - void OnStopUpdating(int render_view_id); - - - virtual void PauseOrResume(int render_view_id, bool should_pause) OVERRIDE; - - // Updates the |geolocation_provider_| with the currently required update - // options. - void RefreshGeolocationOptions(); - - void OnLocationUpdate(const Geoposition& position); - - int render_process_id_; - scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; - - struct RendererGeolocationOptions { - bool high_accuracy; - bool is_paused; - }; - - // Used to keep track of the renderers in this process that are using - // geolocation and the options associated with them. The map is iterated - // when a location update is available and the fan out to individual bridge - // IDs happens renderer side, in order to minimize context switches. - // Only used on the IO thread. - std::map<int, RendererGeolocationOptions> geolocation_renderers_; - - // Used by Android WebView to support that case that a renderer is in the - // 'paused' state but not yet using geolocation. If the renderer does start - // using geolocation while paused, we move from this set into - // |geolocation_renderers_|. If the renderer doesn't end up wanting to use - // geolocation while 'paused' then we remove from this set. A renderer id - // can exist only in this set or |geolocation_renderers_|, never both. - std::set<int> pending_paused_geolocation_renderers_; - - // Only set whilst we are registered with the geolocation provider. - GeolocationProviderImpl* geolocation_provider_; - - GeolocationProviderImpl::LocationUpdateCallback callback_; - - DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHostImpl); -}; +} // namespace -GeolocationDispatcherHostImpl::GeolocationDispatcherHostImpl( +GeolocationDispatcherHost::GeolocationDispatcherHost( int render_process_id, GeolocationPermissionContext* geolocation_permission_context) - : render_process_id_(render_process_id), + : BrowserMessageFilter(GeolocationMsgStart), + render_process_id_(render_process_id), geolocation_permission_context_(geolocation_permission_context), geolocation_provider_(NULL) { callback_ = base::Bind( - &GeolocationDispatcherHostImpl::OnLocationUpdate, base::Unretained(this)); + &GeolocationDispatcherHost::OnLocationUpdate, base::Unretained(this)); // This is initialized by ResourceMessageFilter. Do not add any non-trivial // initialization here, defer to OnRegisterBridge which is triggered whenever // a javascript geolocation object is actually initialized. } -GeolocationDispatcherHostImpl::~GeolocationDispatcherHostImpl() { +GeolocationDispatcherHost::~GeolocationDispatcherHost() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); if (geolocation_provider_) geolocation_provider_->RemoveLocationUpdateCallback(callback_); } -bool GeolocationDispatcherHostImpl::OnMessageReceived( +bool GeolocationDispatcherHost::OnMessageReceived( const IPC::Message& msg, bool* msg_was_ok) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); *msg_was_ok = true; bool handled = true; - IPC_BEGIN_MESSAGE_MAP_EX(GeolocationDispatcherHostImpl, msg, *msg_was_ok) + IPC_BEGIN_MESSAGE_MAP_EX(GeolocationDispatcherHost, msg, *msg_was_ok) IPC_MESSAGE_HANDLER(GeolocationHostMsg_CancelPermissionRequest, OnCancelPermissionRequest) IPC_MESSAGE_HANDLER(GeolocationHostMsg_RequestPermission, @@ -189,7 +124,7 @@ bool GeolocationDispatcherHostImpl::OnMessageReceived( return handled; } -void GeolocationDispatcherHostImpl::OnLocationUpdate( +void GeolocationDispatcherHost::OnLocationUpdate( const Geoposition& geoposition) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); RecordGeopositionErrorCode(geoposition.error_code); @@ -201,7 +136,7 @@ void GeolocationDispatcherHostImpl::OnLocationUpdate( } } -void GeolocationDispatcherHostImpl::OnRequestPermission( +void GeolocationDispatcherHost::OnRequestPermission( int render_view_id, int bridge_id, const GURL& requesting_frame, @@ -228,7 +163,7 @@ void GeolocationDispatcherHostImpl::OnRequestPermission( } } -void GeolocationDispatcherHostImpl::OnCancelPermissionRequest( +void GeolocationDispatcherHost::OnCancelPermissionRequest( int render_view_id, int bridge_id, const GURL& requesting_frame) { @@ -241,7 +176,7 @@ void GeolocationDispatcherHostImpl::OnCancelPermissionRequest( } } -void GeolocationDispatcherHostImpl::OnStartUpdating( +void GeolocationDispatcherHost::OnStartUpdating( int render_view_id, const GURL& requesting_frame, bool enable_high_accuracy) { @@ -272,7 +207,7 @@ void GeolocationDispatcherHostImpl::OnStartUpdating( RefreshGeolocationOptions(); } -void GeolocationDispatcherHostImpl::OnStopUpdating(int render_view_id) { +void GeolocationDispatcherHost::OnStopUpdating(int render_view_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" << render_view_id; @@ -281,8 +216,8 @@ void GeolocationDispatcherHostImpl::OnStopUpdating(int render_view_id) { RefreshGeolocationOptions(); } -void GeolocationDispatcherHostImpl::PauseOrResume(int render_view_id, - bool should_pause) { +void GeolocationDispatcherHost::PauseOrResume(int render_view_id, + bool should_pause) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); std::map<int, RendererGeolocationOptions>::iterator it = geolocation_renderers_.find(render_view_id); @@ -302,7 +237,7 @@ void GeolocationDispatcherHostImpl::PauseOrResume(int render_view_id, } } -void GeolocationDispatcherHostImpl::RefreshGeolocationOptions() { +void GeolocationDispatcherHost::RefreshGeolocationOptions() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); bool needs_updates = false; @@ -328,25 +263,4 @@ void GeolocationDispatcherHostImpl::RefreshGeolocationOptions() { } } -} // namespace - - -// GeolocationDispatcherHost -------------------------------------------------- - -// static -GeolocationDispatcherHost* GeolocationDispatcherHost::New( - int render_process_id, - GeolocationPermissionContext* geolocation_permission_context) { - return new GeolocationDispatcherHostImpl( - render_process_id, - geolocation_permission_context); -} - -GeolocationDispatcherHost::GeolocationDispatcherHost() - : BrowserMessageFilter(GeolocationMsgStart) { -} - -GeolocationDispatcherHost::~GeolocationDispatcherHost() { -} - } // namespace content diff --git a/content/browser/geolocation/geolocation_dispatcher_host.h b/content/browser/geolocation/geolocation_dispatcher_host.h index 5620e26..0dede17 100644 --- a/content/browser/geolocation/geolocation_dispatcher_host.h +++ b/content/browser/geolocation/geolocation_dispatcher_host.h @@ -5,8 +5,14 @@ #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ +#include <map> +#include <set> + +#include "content/browser/geolocation/geolocation_provider_impl.h" #include "content/public/browser/browser_message_filter.h" +class GURL; + namespace content { class GeolocationPermissionContext; @@ -15,20 +21,69 @@ class GeolocationPermissionContext; // It's the complement of GeolocationDispatcher (owned by RenderView). class GeolocationDispatcherHost : public BrowserMessageFilter { public: - static GeolocationDispatcherHost* New( + GeolocationDispatcherHost( int render_process_id, GeolocationPermissionContext* geolocation_permission_context); + virtual ~GeolocationDispatcherHost(); // Pause or resumes geolocation for the given |render_view_id|. Should // be called on the IO thread. Resuming when nothing is paused is a no-op. // If a renderer is paused while not currently using geolocation but // then goes on to do so before being resumed, then that renderer will // not get geolocation updates until it is resumed. - virtual void PauseOrResume(int render_view_id, bool should_pause) = 0; + void PauseOrResume(int render_view_id, bool should_pause); - protected: - GeolocationDispatcherHost(); - virtual ~GeolocationDispatcherHost(); + private: + // GeolocationDispatcherHost + virtual bool OnMessageReceived(const IPC::Message& msg, + bool* msg_was_ok) OVERRIDE; + + // Message handlers: + void OnRequestPermission(int render_view_id, + int bridge_id, + const GURL& requesting_frame, + bool user_gesture); + void OnCancelPermissionRequest(int render_view_id, + int bridge_id, + const GURL& requesting_frame); + void OnStartUpdating(int render_view_id, + const GURL& requesting_frame, + bool enable_high_accuracy); + void OnStopUpdating(int render_view_id); + + // Updates the |geolocation_provider_| with the currently required update + // options. + void RefreshGeolocationOptions(); + + void OnLocationUpdate(const Geoposition& position); + + int render_process_id_; + scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; + + struct RendererGeolocationOptions { + bool high_accuracy; + bool is_paused; + }; + + // Used to keep track of the renderers in this process that are using + // geolocation and the options associated with them. The map is iterated + // when a location update is available and the fan out to individual bridge + // IDs happens renderer side, in order to minimize context switches. + // Only used on the IO thread. + std::map<int, RendererGeolocationOptions> geolocation_renderers_; + + // Used by Android WebView to support that case that a renderer is in the + // 'paused' state but not yet using geolocation. If the renderer does start + // using geolocation while paused, we move from this set into + // |geolocation_renderers_|. If the renderer doesn't end up wanting to use + // geolocation while 'paused' then we remove from this set. A renderer id + // can exist only in this set or |geolocation_renderers_|, never both. + std::set<int> pending_paused_geolocation_renderers_; + + // Only set whilst we are registered with the geolocation provider. + GeolocationProviderImpl* geolocation_provider_; + + GeolocationProviderImpl::LocationUpdateCallback callback_; DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost); }; |