diff options
author | Jonathan Dixon <joth@google.com> | 2013-11-14 22:02:59 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-11-14 22:03:00 +0000 |
commit | eae6ad96677247ca0294140bd1e8932c26273500 (patch) | |
tree | d773cc58de76dc78448e413819cc49933b38a3d6 | |
parent | 9f30eaedc3089bd173876e73524af2a6f95a6733 (diff) | |
parent | c155a8319c5ef18219fdabf886505cd79c3ae21a (diff) | |
download | chromium_org-eae6ad96677247ca0294140bd1e8932c26273500.tar.gz |
Merge "Revert "Cherry Pick https://codereview.chromium.org/65273002/ PS 8"" into klp-dev
8 files changed, 48 insertions, 102 deletions
diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc index e1351bdf8e..667043275f 100644 --- a/android_webview/native/aw_contents.cc +++ b/android_webview/native/aw_contents.cc @@ -710,13 +710,11 @@ void AwContents::SetWindowVisibility(JNIEnv* env, jobject obj, bool visible) { void AwContents::SetIsPaused(JNIEnv* env, jobject obj, bool paused) { browser_view_renderer_->SetIsPaused(paused); - ContentViewCore* cvc = - ContentViewCore::FromWebContents(web_contents_.get()); - if (cvc) { - cvc->PauseOrResumeGeolocation(paused); - if (paused) { + if (paused) { + ContentViewCore* cvc = + ContentViewCore::FromWebContents(web_contents_.get()); + if (cvc) cvc->PauseVideo(); - } } } diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc index 583cdfae37..da33b2578a 100644 --- a/content/browser/android/content_view_core_impl.cc +++ b/content/browser/android/content_view_core_impl.cc @@ -351,20 +351,6 @@ void ContentViewCoreImpl::PauseVideo() { host->Send(new ViewMsg_PauseVideo(host->GetRoutingID())); } -void ContentViewCoreImpl::PauseOrResumeGeolocation(bool should_pause) { - RenderViewHostImpl* rvh = - static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); - if (rvh) { - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, - base::Bind(&GeolocationDispatcherHost::PauseOrResume, - static_cast<RenderProcessHostImpl*>( - web_contents_->GetRenderProcessHost())-> - geolocation_dispatcher_host(), - rvh->GetRoutingID(), - should_pause)); - } -} - void ContentViewCoreImpl::OnTabCrashed() { JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); diff --git a/content/browser/android/content_view_core_impl.h b/content/browser/android/content_view_core_impl.h index 9a70c07e23..837a6449a2 100644 --- a/content/browser/android/content_view_core_impl.h +++ b/content/browser/android/content_view_core_impl.h @@ -61,7 +61,6 @@ class ContentViewCoreImpl : public ContentViewCore, virtual void RequestContentClipping(const gfx::Rect& clipping, const gfx::Size& content_size) OVERRIDE; virtual void PauseVideo() OVERRIDE; - virtual void PauseOrResumeGeolocation(bool should_pause) OVERRIDE; // -------------------------------------------------------------------------- // Methods called from Java via JNI diff --git a/content/browser/geolocation/geolocation_dispatcher_host.cc b/content/browser/geolocation/geolocation_dispatcher_host.cc index 8784a56590..53f8e4feaf 100644 --- a/content/browser/geolocation/geolocation_dispatcher_host.cc +++ b/content/browser/geolocation/geolocation_dispatcher_host.cc @@ -67,29 +67,23 @@ class GeolocationDispatcherHostImpl : public GeolocationDispatcherHost { bool enable_high_accuracy); void OnStopUpdating(int render_view_id); - virtual void PauseOrResume(int render_view_id, bool should_pause) OVERRIDE; - // Updates the |location_arbitrator_| with the currently required update - // options. - void RefreshGeolocationOptions(); + // options, based on |renderer_high_accuracy_|. + void RefreshHighAccuracy(); 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. + // Iterated when sending location updates to renderer processes. 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_; - + std::set<int> geolocation_renderer_ids_; + // Maps renderer_id to whether high accuracy is requestd for this particular + // bridge. + std::map<int, bool> renderer_high_accuracy_; // Only set whilst we are registered with the arbitrator. GeolocationProviderImpl* location_provider_; @@ -136,11 +130,9 @@ bool GeolocationDispatcherHostImpl::OnMessageReceived( void GeolocationDispatcherHostImpl::OnLocationUpdate( const Geoposition& geoposition) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - for (std::map<int, RendererGeolocationOptions>::iterator it = - geolocation_renderers_.begin(); - it != geolocation_renderers_.end(); ++it) { - if (!(it->second.is_paused)) - Send(new GeolocationMsg_PositionUpdated(it->first, geoposition)); + for (std::set<int>::iterator it = geolocation_renderer_ids_.begin(); + it != geolocation_renderer_ids_.end(); ++it) { + Send(new GeolocationMsg_PositionUpdated(*it, geoposition)); } } @@ -191,58 +183,44 @@ void GeolocationDispatcherHostImpl::OnStartUpdating( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" << render_view_id; - RendererGeolocationOptions opts = { enable_high_accuracy, false }; - geolocation_renderers_[render_view_id] = opts; - RefreshGeolocationOptions(); + if (!geolocation_renderer_ids_.count(render_view_id)) + geolocation_renderer_ids_.insert(render_view_id); + + renderer_high_accuracy_[render_view_id] = enable_high_accuracy; + RefreshHighAccuracy(); } void GeolocationDispatcherHostImpl::OnStopUpdating(int render_view_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" << render_view_id; - DCHECK_EQ(1U, geolocation_renderers_.count(render_view_id)); - geolocation_renderers_.erase(render_view_id); - RefreshGeolocationOptions(); -} + if (renderer_high_accuracy_.erase(render_view_id)) + RefreshHighAccuracy(); -void GeolocationDispatcherHostImpl::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); - if (it == geolocation_renderers_.end()) - return; - - RendererGeolocationOptions* opts = &(it->second); - if (opts->is_paused != should_pause) { - opts->is_paused = should_pause; - RefreshGeolocationOptions(); - } + DCHECK_EQ(1U, geolocation_renderer_ids_.count(render_view_id)); + geolocation_renderer_ids_.erase(render_view_id); } -void GeolocationDispatcherHostImpl::RefreshGeolocationOptions() { +void GeolocationDispatcherHostImpl::RefreshHighAccuracy() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - bool needs_updates = false; - bool use_high_accuracy = false; - std::map<int, RendererGeolocationOptions>::const_iterator i = - geolocation_renderers_.begin(); - for (; i != geolocation_renderers_.end(); ++i) { - needs_updates |= !(i->second.is_paused); - use_high_accuracy |= i->second.high_accuracy; - if (needs_updates && use_high_accuracy) - break; - } - if (needs_updates) { - if (!location_provider_) - location_provider_ = GeolocationProviderImpl::GetInstance(); - // Re-add to re-establish our options, in case they changed. - location_provider_->AddLocationUpdateCallback( - callback_, use_high_accuracy); - } else { - if (location_provider_) + if (renderer_high_accuracy_.empty()) { + if (location_provider_) { location_provider_->RemoveLocationUpdateCallback(callback_); - location_provider_ = NULL; + location_provider_ = NULL; + } + } else { + if (!location_provider_) + location_provider_ = GeolocationProviderImpl::GetInstance(); + // Re-add to re-establish our options, in case they changed. + bool use_high_accuracy = false; + std::map<int, bool>::iterator i = renderer_high_accuracy_.begin(); + for (; i != renderer_high_accuracy_.end(); ++i) { + if (i->second) { + use_high_accuracy = true; + break; + } + } + location_provider_->AddLocationUpdateCallback(callback_, use_high_accuracy); } } } // namespace diff --git a/content/browser/geolocation/geolocation_dispatcher_host.h b/content/browser/geolocation/geolocation_dispatcher_host.h index 963a4eca50..0631c8718f 100644 --- a/content/browser/geolocation/geolocation_dispatcher_host.h +++ b/content/browser/geolocation/geolocation_dispatcher_host.h @@ -19,10 +19,6 @@ class GeolocationDispatcherHost : public BrowserMessageFilter { int render_process_id, GeolocationPermissionContext* geolocation_permission_context); - // 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. - virtual void PauseOrResume(int render_view_id, bool should_pause) = 0; - protected: GeolocationDispatcherHost(); virtual ~GeolocationDispatcherHost(); diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index fcc7f1e790..20ea4fc434 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -51,6 +51,7 @@ #include "content/browser/download/mhtml_generation_manager.h" #include "content/browser/fileapi/chrome_blob_storage_context.h" #include "content/browser/fileapi/fileapi_message_filter.h" +#include "content/browser/geolocation/geolocation_dispatcher_host.h" #include "content/browser/gpu/gpu_data_manager_impl.h" #include "content/browser/gpu/gpu_process_host.h" #include "content/browser/gpu/shader_disk_cache.h" @@ -635,19 +636,17 @@ void RenderProcessHostImpl::CreateMessageFilters() { channel_->AddFilter(new IndexedDBDispatcherHost( GetID(), storage_partition_impl_->GetIndexedDBContext())); - geolocation_dispatcher_host_ = NULL; if (IsGuest()) { if (!g_browser_plugin_geolocation_context.Get().get()) { g_browser_plugin_geolocation_context.Get() = new BrowserPluginGeolocationPermissionContext(); } - geolocation_dispatcher_host_ = GeolocationDispatcherHost::New( - GetID(), g_browser_plugin_geolocation_context.Get().get()); + channel_->AddFilter(GeolocationDispatcherHost::New( + GetID(), g_browser_plugin_geolocation_context.Get().get())); } else { - geolocation_dispatcher_host_ = GeolocationDispatcherHost::New( - GetID(), browser_context->GetGeolocationPermissionContext()); + channel_->AddFilter(GeolocationDispatcherHost::New( + GetID(), browser_context->GetGeolocationPermissionContext())); } - channel_->AddFilter(geolocation_dispatcher_host_); gpu_message_filter_ = new GpuMessageFilter(GetID(), widget_helper_.get()); channel_->AddFilter(gpu_message_filter_); #if defined(ENABLE_WEBRTC) diff --git a/content/browser/renderer_host/render_process_host_impl.h b/content/browser/renderer_host/render_process_host_impl.h index 985ef3bd2c..72ec846303 100644 --- a/content/browser/renderer_host/render_process_host_impl.h +++ b/content/browser/renderer_host/render_process_host_impl.h @@ -13,7 +13,6 @@ #include "base/process/process.h" #include "base/timer/timer.h" #include "content/browser/child_process_launcher.h" -#include "content/browser/geolocation/geolocation_dispatcher_host.h" #include "content/browser/power_monitor_message_broadcaster.h" #include "content/common/content_export.h" #include "content/public/browser/global_request_id.h" @@ -34,7 +33,6 @@ class Size; } namespace content { -class GeolocationDispatcherHost; class GpuMessageFilter; class PeerConnectionTrackerHost; class RendererMainThread; @@ -146,10 +144,6 @@ class CONTENT_EXPORT RenderProcessHostImpl scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber); void EndFrameSubscription(int route_id); - GeolocationDispatcherHost* geolocation_dispatcher_host() { - return geolocation_dispatcher_host_; - } - // Register/unregister the host identified by the host id in the global host // list. static void RegisterHost(int host_id, RenderProcessHost* host); @@ -330,9 +324,6 @@ class CONTENT_EXPORT RenderProcessHostImpl // Forwards power state messages to the renderer process. PowerMonitorMessageBroadcaster power_monitor_broadcaster_; - // Message filter for geolocation messages. - GeolocationDispatcherHost* geolocation_dispatcher_host_; - DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl); }; diff --git a/content/public/browser/android/content_view_core.h b/content/public/browser/android/content_view_core.h index 9adaf4c39c..79be4c4c12 100644 --- a/content/public/browser/android/content_view_core.h +++ b/content/public/browser/android/content_view_core.h @@ -55,7 +55,6 @@ class CONTENT_EXPORT ContentViewCore { virtual void RequestContentClipping(const gfx::Rect& clipping, const gfx::Size& content_size) = 0; virtual void PauseVideo() = 0; - virtual void PauseOrResumeGeolocation(bool should_pause) = 0; // Observer callback for frame metadata updates. typedef base::Callback<void( |