summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-09 17:01:13 +0000
committerjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-09 17:01:13 +0000
commit203267dbee16ce86f9cbe924cab709afaa77833c (patch)
treeb459e54b57c75e5df07b897c40690153aa3e69ee
parent32455eb425aa485f6f815197920ef529c4459e26 (diff)
downloadchromium_src-203267dbee16ce86f9cbe924cab709afaa77833c.zip
chromium_src-203267dbee16ce86f9cbe924cab709afaa77833c.tar.gz
chromium_src-203267dbee16ce86f9cbe924cab709afaa77833c.tar.bz2
Clean up geolocation_dispatcher_host.h
It was pulling internal geolocation headers into resource_message_filter.cc BUG=none TEST=none Review URL: http://codereview.chromium.org/2742002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49271 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/geolocation/geolocation_dispatcher_host.cc147
-rw-r--r--chrome/browser/geolocation/geolocation_dispatcher_host.h62
-rw-r--r--chrome/browser/geolocation/geolocation_permission_context.cc1
-rwxr-xr-xchrome/browser/renderer_host/resource_message_filter.cc2
4 files changed, 103 insertions, 109 deletions
diff --git a/chrome/browser/geolocation/geolocation_dispatcher_host.cc b/chrome/browser/geolocation/geolocation_dispatcher_host.cc
index c88e41d..5e4dc40 100644
--- a/chrome/browser/geolocation/geolocation_dispatcher_host.cc
+++ b/chrome/browser/geolocation/geolocation_dispatcher_host.cc
@@ -4,8 +4,13 @@
#include "chrome/browser/geolocation/geolocation_dispatcher_host.h"
+#include <map>
+#include <set>
+#include <utility>
+
#include "chrome/common/geoposition.h"
#include "chrome/browser/geolocation/geolocation_permission_context.h"
+#include "chrome/browser/geolocation/location_arbitrator.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_view_host_notification_task.h"
@@ -13,7 +18,62 @@
#include "chrome/common/render_messages.h"
#include "ipc/ipc_message.h"
-GeolocationDispatcherHost::GeolocationDispatcherHost(
+namespace {
+class GeolocationDispatcherHostImpl : public GeolocationDispatcherHost,
+ public GeolocationArbitrator::Delegate {
+ public:
+ GeolocationDispatcherHostImpl(
+ int resource_message_filter_process_id,
+ GeolocationPermissionContext* geolocation_permission_context);
+
+ // GeolocationDispatcherHost
+ // Called to possibly handle the incoming IPC message. Returns true if
+ // handled. Called in the browser process.
+ virtual bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok);
+
+ // GeolocationArbitrator::Delegate
+ virtual void OnLocationUpdate(const Geoposition& position);
+
+ private:
+ friend class base::RefCountedThreadSafe<GeolocationDispatcherHostImpl>;
+ virtual ~GeolocationDispatcherHostImpl();
+
+ void OnRegisterDispatcher(int render_view_id);
+ void OnUnregisterDispatcher(int render_view_id);
+ void OnRequestPermission(
+ int render_view_id, int bridge_id, const GURL& requesting_frame);
+ void OnCancelPermissionRequest(
+ int render_view_id, int bridge_id, const GURL& requesting_frame);
+ void OnStartUpdating(
+ int render_view_id, int bridge_id, const GURL& requesting_frame,
+ bool enable_high_accuracy);
+ void OnStopUpdating(int render_view_id, int bridge_id);
+ void OnSuspend(int render_view_id, int bridge_id);
+ void OnResume(int render_view_id, int bridge_id);
+
+ // Updates the |location_arbitrator_| with the currently required update
+ // options, based on |bridge_update_options_|.
+ void RefreshUpdateOptions();
+
+ int resource_message_filter_process_id_;
+ scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_;
+
+ // 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::set<int> geolocation_renderer_ids_;
+ // Maps <renderer_id, bridge_id> to the location arbitrator update options
+ // that correspond to this particular bridge.
+ std::map<std::pair<int, int>, GeolocationArbitrator::UpdateOptions>
+ bridge_update_options_;
+ // Only set whilst we are registered with the arbitrator.
+ scoped_refptr<GeolocationArbitrator> location_arbitrator_;
+
+ DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHostImpl);
+};
+
+GeolocationDispatcherHostImpl::GeolocationDispatcherHostImpl(
int resource_message_filter_process_id,
GeolocationPermissionContext* geolocation_permission_context)
: resource_message_filter_process_id_(resource_message_filter_process_id),
@@ -23,16 +83,17 @@ GeolocationDispatcherHost::GeolocationDispatcherHost(
// a javascript geolocation object is actually initialized.
}
-GeolocationDispatcherHost::~GeolocationDispatcherHost() {
+GeolocationDispatcherHostImpl::~GeolocationDispatcherHostImpl() {
if (location_arbitrator_)
location_arbitrator_->RemoveObserver(this);
}
-bool GeolocationDispatcherHost::OnMessageReceived(
+bool GeolocationDispatcherHostImpl::OnMessageReceived(
const IPC::Message& msg, bool* msg_was_ok) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
*msg_was_ok = true;
bool handled = true;
- IPC_BEGIN_MESSAGE_MAP_EX(GeolocationDispatcherHost, msg, *msg_was_ok)
+ IPC_BEGIN_MESSAGE_MAP_EX(GeolocationDispatcherHostImpl, msg, *msg_was_ok)
IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RegisterDispatcher,
OnRegisterDispatcher)
IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_UnregisterDispatcher,
@@ -54,10 +115,9 @@ bool GeolocationDispatcherHost::OnMessageReceived(
return handled;
}
-void GeolocationDispatcherHost::OnLocationUpdate(
+void GeolocationDispatcherHostImpl::OnLocationUpdate(
const Geoposition& geoposition) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
-
for (std::set<int>::iterator it = geolocation_renderer_ids_.begin();
it != geolocation_renderer_ids_.end(); ++it) {
IPC::Message* message =
@@ -67,18 +127,21 @@ void GeolocationDispatcherHost::OnLocationUpdate(
}
}
-void GeolocationDispatcherHost::OnRegisterDispatcher(int render_view_id) {
- RegisterDispatcher(
- resource_message_filter_process_id_, render_view_id);
+void GeolocationDispatcherHostImpl::OnRegisterDispatcher(int render_view_id) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ DCHECK_EQ(0u, geolocation_renderer_ids_.count(render_view_id));
+ geolocation_renderer_ids_.insert(render_view_id);
}
-void GeolocationDispatcherHost::OnUnregisterDispatcher(int render_view_id) {
- UnregisterDispatcher(
- resource_message_filter_process_id_, render_view_id);
+void GeolocationDispatcherHostImpl::OnUnregisterDispatcher(int render_view_id) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ DCHECK_EQ(1u, geolocation_renderer_ids_.count(render_view_id));
+ geolocation_renderer_ids_.erase(render_view_id);
}
-void GeolocationDispatcherHost::OnRequestPermission(
+void GeolocationDispatcherHostImpl::OnRequestPermission(
int render_view_id, int bridge_id, const GURL& requesting_frame) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DLOG(INFO) << __FUNCTION__ << " " << resource_message_filter_process_id_
<< ":" << render_view_id << ":" << bridge_id;
geolocation_permission_context_->RequestGeolocationPermission(
@@ -86,8 +149,9 @@ void GeolocationDispatcherHost::OnRequestPermission(
requesting_frame);
}
-void GeolocationDispatcherHost::OnCancelPermissionRequest(
+void GeolocationDispatcherHostImpl::OnCancelPermissionRequest(
int render_view_id, int bridge_id, const GURL& requesting_frame) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DLOG(INFO) << __FUNCTION__ << " " << resource_message_filter_process_id_
<< ":" << render_view_id << ":" << bridge_id;
geolocation_permission_context_->CancelGeolocationPermissionRequest(
@@ -95,12 +159,13 @@ void GeolocationDispatcherHost::OnCancelPermissionRequest(
requesting_frame);
}
-void GeolocationDispatcherHost::OnStartUpdating(
+void GeolocationDispatcherHostImpl::OnStartUpdating(
int render_view_id, int bridge_id, const GURL& requesting_frame,
bool enable_high_accuracy) {
// WebKit sends the startupdating request before checking permissions, to
// optimize the no-location-available case and reduce latency in the success
// case (location lookup happens in parallel with the permission request).
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DLOG(INFO) << __FUNCTION__ << " " << resource_message_filter_process_id_
<< ":" << render_view_id << ":" << bridge_id;
bridge_update_options_[std::make_pair(render_view_id, bridge_id)] =
@@ -112,8 +177,9 @@ void GeolocationDispatcherHost::OnStartUpdating(
RefreshUpdateOptions();
}
-void GeolocationDispatcherHost::OnStopUpdating(
+void GeolocationDispatcherHostImpl::OnStopUpdating(
int render_view_id, int bridge_id) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DLOG(INFO) << __FUNCTION__ << " " << resource_message_filter_process_id_
<< ":" << render_view_id << ":" << bridge_id;
if (bridge_update_options_.erase(std::make_pair(render_view_id, bridge_id)))
@@ -122,55 +188,24 @@ void GeolocationDispatcherHost::OnStopUpdating(
resource_message_filter_process_id_, render_view_id, bridge_id);
}
-void GeolocationDispatcherHost::OnSuspend(
+void GeolocationDispatcherHostImpl::OnSuspend(
int render_view_id, int bridge_id) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DLOG(INFO) << __FUNCTION__ << " " << resource_message_filter_process_id_
<< ":" << render_view_id << ":" << bridge_id;
// TODO(bulach): connect this with GeolocationArbitrator.
}
-void GeolocationDispatcherHost::OnResume(
+void GeolocationDispatcherHostImpl::OnResume(
int render_view_id, int bridge_id) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DLOG(INFO) << __FUNCTION__ << " " << resource_message_filter_process_id_
<< ":" << render_view_id << ":" << bridge_id;
// TODO(bulach): connect this with GeolocationArbitrator.
}
-void GeolocationDispatcherHost::RegisterDispatcher(
- int process_id, int render_view_id) {
- DCHECK_EQ(resource_message_filter_process_id_, process_id);
- if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- NewRunnableMethod(
- this, &GeolocationDispatcherHost::RegisterDispatcher,
- process_id, render_view_id));
- return;
- }
+void GeolocationDispatcherHostImpl::RefreshUpdateOptions() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
-
- DCHECK_EQ(0u, geolocation_renderer_ids_.count(render_view_id));
- geolocation_renderer_ids_.insert(render_view_id);
-}
-
-void GeolocationDispatcherHost::UnregisterDispatcher(
- int process_id, int render_view_id) {
- DCHECK_EQ(resource_message_filter_process_id_, process_id);
- if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- NewRunnableMethod(
- this, &GeolocationDispatcherHost::UnregisterDispatcher,
- process_id, render_view_id));
- return;
- }
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
-
- DCHECK_EQ(1u, geolocation_renderer_ids_.count(render_view_id));
- geolocation_renderer_ids_.erase(render_view_id);
-}
-
-void GeolocationDispatcherHost::RefreshUpdateOptions() {
DCHECK(location_arbitrator_);
if (bridge_update_options_.empty()) {
location_arbitrator_->RemoveObserver(this);
@@ -182,3 +217,11 @@ void GeolocationDispatcherHost::RefreshUpdateOptions() {
bridge_update_options_));
}
}
+} // namespace
+
+GeolocationDispatcherHost* GeolocationDispatcherHost::New(
+ int resource_message_filter_process_id,
+ GeolocationPermissionContext* geolocation_permission_context) {
+ return new GeolocationDispatcherHostImpl(resource_message_filter_process_id,
+ geolocation_permission_context);
+}
diff --git a/chrome/browser/geolocation/geolocation_dispatcher_host.h b/chrome/browser/geolocation/geolocation_dispatcher_host.h
index 31da3a6..234dde1 100644
--- a/chrome/browser/geolocation/geolocation_dispatcher_host.h
+++ b/chrome/browser/geolocation/geolocation_dispatcher_host.h
@@ -5,79 +5,29 @@
#ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_
#define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_
-#include <map>
-#include <set>
-#include <utility>
-
-#include "base/basictypes.h"
#include "base/ref_counted.h"
-#include "chrome/browser/geolocation/location_arbitrator.h"
class GeolocationPermissionContext;
-class GURL;
-class ResourceMessageFilter;
-class URLRequestContextGetter;
-struct Geoposition;
namespace IPC { class Message; }
// GeolocationDispatcherHost is a delegate for Geolocation messages used by
// ResourceMessageFilter.
// It's the complement of GeolocationDispatcher (owned by RenderView).
class GeolocationDispatcherHost
- : public base::RefCountedThreadSafe<GeolocationDispatcherHost>,
- public GeolocationArbitrator::Delegate {
+ : public base::RefCountedThreadSafe<GeolocationDispatcherHost> {
public:
- GeolocationDispatcherHost(
+ static GeolocationDispatcherHost* New(
int resource_message_filter_process_id,
GeolocationPermissionContext* geolocation_permission_context);
// Called to possibly handle the incoming IPC message. Returns true if
// handled. Called in the browser process.
- bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok);
-
- // GeolocationArbitrator::Delegate
- virtual void OnLocationUpdate(const Geoposition& position);
+ virtual bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok) = 0;
- private:
+ protected:
friend class base::RefCountedThreadSafe<GeolocationDispatcherHost>;
- virtual ~GeolocationDispatcherHost();
-
- void OnRegisterDispatcher(int render_view_id);
- void OnUnregisterDispatcher(int render_view_id);
- void OnRequestPermission(
- int render_view_id, int bridge_id, const GURL& requesting_frame);
- void OnCancelPermissionRequest(
- int render_view_id, int bridge_id, const GURL& requesting_frame);
- void OnStartUpdating(
- int render_view_id, int bridge_id, const GURL& requesting_frame,
- bool enable_high_accuracy);
- void OnStopUpdating(int render_view_id, int bridge_id);
- void OnSuspend(int render_view_id, int bridge_id);
- void OnResume(int render_view_id, int bridge_id);
-
- // Registers the bridge created in the renderer side. They'll delegate to the
- // UI thread if not already in there.
- void RegisterDispatcher(int process_id, int render_view_id);
- void UnregisterDispatcher(int process_id, int render_view_id);
- // Updates the |location_arbitrator_| with the currently required update
- // options, based on |bridge_update_options_|.
- void RefreshUpdateOptions();
-
- int resource_message_filter_process_id_;
- scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_;
-
- // 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::set<int> geolocation_renderer_ids_;
- // Maps <renderer_id, bridge_id> to the location arbitrator update options
- // that correspond to this particular bridge.
- typedef std::map<std::pair<int, int>, GeolocationArbitrator::UpdateOptions>
- BridgeUpdateOptionsMap;
- BridgeUpdateOptionsMap bridge_update_options_;
- // Only set whilst we are registered with the arbitrator.
- scoped_refptr<GeolocationArbitrator> location_arbitrator_;
+ GeolocationDispatcherHost() {}
+ virtual ~GeolocationDispatcherHost() {}
DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost);
};
diff --git a/chrome/browser/geolocation/geolocation_permission_context.cc b/chrome/browser/geolocation/geolocation_permission_context.cc
index a040714..c88b659 100644
--- a/chrome/browser/geolocation/geolocation_permission_context.cc
+++ b/chrome/browser/geolocation/geolocation_permission_context.cc
@@ -11,6 +11,7 @@
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
#include "chrome/browser/geolocation/geolocation_dispatcher_host.h"
+#include "chrome/browser/geolocation/location_arbitrator.h"
#include "chrome/browser/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_process_host.h"
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index 2170c78..61ac3d1 100755
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -342,7 +342,7 @@ ResourceMessageFilter::ResourceMessageFilter(
next_route_id_callback_(NewCallbackWithReturnValue(
render_widget_helper, &RenderWidgetHelper::GetNextRoutingID)),
ALLOW_THIS_IN_INITIALIZER_LIST(geolocation_dispatcher_host_(
- new GeolocationDispatcherHost(
+ GeolocationDispatcherHost::New(
this->id(), profile->GetGeolocationPermissionContext()))) {
DCHECK(request_context_);
DCHECK(media_request_context_);