OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/geolocation/geolocation_dispatcher_host_old.h" | 5 #include "chrome/browser/geolocation/geolocation_dispatcher_host.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "chrome/common/geoposition.h" | 11 #include "chrome/common/geoposition.h" |
12 #include "chrome/browser/geolocation/geolocation_permission_context.h" | 12 #include "chrome/browser/geolocation/geolocation_permission_context.h" |
13 #include "chrome/browser/geolocation/geolocation_provider.h" | 13 #include "chrome/browser/geolocation/geolocation_provider.h" |
14 #include "chrome/browser/renderer_host/render_process_host.h" | 14 #include "chrome/browser/renderer_host/render_process_host.h" |
15 #include "chrome/browser/renderer_host/render_view_host.h" | 15 #include "chrome/browser/renderer_host/render_view_host.h" |
16 #include "chrome/browser/renderer_host/render_view_host_notification_task.h" | 16 #include "chrome/browser/renderer_host/render_view_host_notification_task.h" |
17 #include "chrome/browser/renderer_host/resource_message_filter.h" | 17 #include "chrome/browser/renderer_host/resource_message_filter.h" |
18 #include "chrome/common/render_messages.h" | 18 #include "chrome/common/render_messages.h" |
19 #include "ipc/ipc_message.h" | 19 #include "ipc/ipc_message.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 class GeolocationDispatcherHostOldImpl : public GeolocationDispatcherHostOld, | 22 class GeolocationDispatcherHostImpl : public GeolocationDispatcherHost, |
23 public GeolocationObserver { | 23 public GeolocationObserver { |
24 public: | 24 public: |
25 GeolocationDispatcherHostOldImpl( | 25 GeolocationDispatcherHostImpl( |
26 int resource_message_filter_process_id, | 26 int resource_message_filter_process_id, |
27 GeolocationPermissionContext* geolocation_permission_context); | 27 GeolocationPermissionContext* geolocation_permission_context); |
28 | 28 |
29 // GeolocationDispatcherHostOld | 29 // GeolocationDispatcherHost |
30 // Called to possibly handle the incoming IPC message. Returns true if | 30 // Called to possibly handle the incoming IPC message. Returns true if |
31 // handled. Called in the browser process. | 31 // handled. Called in the browser process. |
bulach
2010/12/13 14:49:50
ditto
| |
32 virtual bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok); | 32 virtual bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok); |
33 | 33 |
34 // GeolocationArbitrator::Delegate | 34 // GeolocationArbitrator::Delegate |
35 virtual void OnLocationUpdate(const Geoposition& position); | 35 virtual void OnLocationUpdate(const Geoposition& position); |
36 | 36 |
37 private: | 37 private: |
38 friend class base::RefCountedThreadSafe<GeolocationDispatcherHostOldImpl>; | 38 virtual ~GeolocationDispatcherHostImpl(); |
39 virtual ~GeolocationDispatcherHostOldImpl(); | |
40 | 39 |
41 void OnRegisterDispatcher(int render_view_id); | 40 void OnRegisterDispatcher(int render_view_id); |
42 void OnUnregisterDispatcher(int render_view_id); | 41 void OnUnregisterDispatcher(int render_view_id); |
43 void OnRequestPermission( | 42 void OnRequestPermission( |
44 int render_view_id, int bridge_id, const GURL& requesting_frame); | 43 int render_view_id, int bridge_id, const GURL& requesting_frame); |
45 void OnCancelPermissionRequest( | 44 void OnCancelPermissionRequest( |
46 int render_view_id, int bridge_id, const GURL& requesting_frame); | 45 int render_view_id, int bridge_id, const GURL& requesting_frame); |
47 void OnStartUpdating( | 46 void OnStartUpdating( |
48 int render_view_id, int bridge_id, const GURL& requesting_frame, | 47 int render_view_id, int bridge_id, const GURL& requesting_frame, |
49 bool enable_high_accuracy); | 48 bool enable_high_accuracy); |
(...skipping 13 matching lines...) Expand all Loading... | |
63 // context switches. | 62 // context switches. |
64 // Only used on the IO thread. | 63 // Only used on the IO thread. |
65 std::set<int> geolocation_renderer_ids_; | 64 std::set<int> geolocation_renderer_ids_; |
66 // Maps <renderer_id, bridge_id> to the location arbitrator update options | 65 // Maps <renderer_id, bridge_id> to the location arbitrator update options |
67 // that correspond to this particular bridge. | 66 // that correspond to this particular bridge. |
68 std::map<std::pair<int, int>, GeolocationObserverOptions> | 67 std::map<std::pair<int, int>, GeolocationObserverOptions> |
69 bridge_update_options_; | 68 bridge_update_options_; |
70 // Only set whilst we are registered with the arbitrator. | 69 // Only set whilst we are registered with the arbitrator. |
71 GeolocationProvider* location_provider_; | 70 GeolocationProvider* location_provider_; |
72 | 71 |
73 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHostOldImpl); | 72 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHostImpl); |
74 }; | 73 }; |
75 | 74 |
76 GeolocationDispatcherHostOldImpl::GeolocationDispatcherHostOldImpl( | 75 GeolocationDispatcherHostImpl::GeolocationDispatcherHostImpl( |
77 int resource_message_filter_process_id, | 76 int resource_message_filter_process_id, |
78 GeolocationPermissionContext* geolocation_permission_context) | 77 GeolocationPermissionContext* geolocation_permission_context) |
79 : resource_message_filter_process_id_(resource_message_filter_process_id), | 78 : resource_message_filter_process_id_(resource_message_filter_process_id), |
80 geolocation_permission_context_(geolocation_permission_context), | 79 geolocation_permission_context_(geolocation_permission_context), |
81 location_provider_(NULL) { | 80 location_provider_(NULL) { |
82 // This is initialized by ResourceMessageFilter. Do not add any non-trivial | 81 // This is initialized by ResourceMessageFilter. Do not add any non-trivial |
83 // initialization here, defer to OnRegisterBridge which is triggered whenever | 82 // initialization here, defer to OnRegisterBridge which is triggered whenever |
84 // a javascript geolocation object is actually initialized. | 83 // a javascript geolocation object is actually initialized. |
85 } | 84 } |
86 | 85 |
87 GeolocationDispatcherHostOldImpl::~GeolocationDispatcherHostOldImpl() { | 86 GeolocationDispatcherHostImpl::~GeolocationDispatcherHostImpl() { |
88 if (location_provider_) | 87 if (location_provider_) |
89 location_provider_->RemoveObserver(this); | 88 location_provider_->RemoveObserver(this); |
90 } | 89 } |
91 | 90 |
92 bool GeolocationDispatcherHostOldImpl::OnMessageReceived( | 91 bool GeolocationDispatcherHostImpl::OnMessageReceived( |
93 const IPC::Message& msg, bool* msg_was_ok) { | 92 const IPC::Message& msg, bool* msg_was_ok) { |
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
95 *msg_was_ok = true; | 94 *msg_was_ok = true; |
96 bool handled = true; | 95 bool handled = true; |
97 IPC_BEGIN_MESSAGE_MAP_EX(GeolocationDispatcherHostOldImpl, msg, *msg_was_ok) | 96 IPC_BEGIN_MESSAGE_MAP_EX(GeolocationDispatcherHostImpl, msg, *msg_was_ok) |
98 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RegisterDispatcher, | 97 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RegisterDispatcher, |
99 OnRegisterDispatcher) | 98 OnRegisterDispatcher) |
100 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_UnregisterDispatcher, | 99 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_UnregisterDispatcher, |
101 OnUnregisterDispatcher) | 100 OnUnregisterDispatcher) |
102 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_CancelPermissionRequest, | 101 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_CancelPermissionRequest, |
103 OnCancelPermissionRequest) | 102 OnCancelPermissionRequest) |
104 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RequestPermission, | 103 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RequestPermission, |
105 OnRequestPermission) | 104 OnRequestPermission) |
106 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_StartUpdating, | 105 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_StartUpdating, |
107 OnStartUpdating) | 106 OnStartUpdating) |
108 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_StopUpdating, | 107 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_StopUpdating, |
109 OnStopUpdating) | 108 OnStopUpdating) |
110 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_Suspend, | 109 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_Suspend, |
111 OnSuspend) | 110 OnSuspend) |
112 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_Resume, | 111 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_Resume, |
113 OnResume) | 112 OnResume) |
114 IPC_MESSAGE_UNHANDLED(handled = false) | 113 IPC_MESSAGE_UNHANDLED(handled = false) |
115 IPC_END_MESSAGE_MAP() | 114 IPC_END_MESSAGE_MAP() |
116 return handled; | 115 return handled; |
117 } | 116 } |
118 | 117 |
119 void GeolocationDispatcherHostOldImpl::OnLocationUpdate( | 118 void GeolocationDispatcherHostImpl::OnLocationUpdate( |
120 const Geoposition& geoposition) { | 119 const Geoposition& geoposition) { |
121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
122 for (std::set<int>::iterator it = geolocation_renderer_ids_.begin(); | 121 for (std::set<int>::iterator it = geolocation_renderer_ids_.begin(); |
123 it != geolocation_renderer_ids_.end(); ++it) { | 122 it != geolocation_renderer_ids_.end(); ++it) { |
124 IPC::Message* message = | 123 IPC::Message* message = |
125 new ViewMsg_Geolocation_PositionUpdated(*it, geoposition); | 124 new ViewMsg_Geolocation_PositionUpdated(*it, geoposition); |
126 CallRenderViewHost(resource_message_filter_process_id_, *it, | 125 CallRenderViewHost(resource_message_filter_process_id_, *it, |
127 &RenderViewHost::Send, message); | 126 &RenderViewHost::Send, message); |
128 } | 127 } |
129 } | 128 } |
130 | 129 |
131 void GeolocationDispatcherHostOldImpl::OnRegisterDispatcher( | 130 void GeolocationDispatcherHostImpl::OnRegisterDispatcher( |
132 int render_view_id) { | 131 int render_view_id) { |
133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
134 DCHECK_EQ(0u, geolocation_renderer_ids_.count(render_view_id)); | 133 DCHECK_EQ(0u, geolocation_renderer_ids_.count(render_view_id)); |
135 geolocation_renderer_ids_.insert(render_view_id); | 134 geolocation_renderer_ids_.insert(render_view_id); |
136 } | 135 } |
137 | 136 |
138 void GeolocationDispatcherHostOldImpl::OnUnregisterDispatcher( | 137 void GeolocationDispatcherHostImpl::OnUnregisterDispatcher( |
139 int render_view_id) { | 138 int render_view_id) { |
140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
141 DCHECK_EQ(1u, geolocation_renderer_ids_.count(render_view_id)); | 140 DCHECK_EQ(1u, geolocation_renderer_ids_.count(render_view_id)); |
142 geolocation_renderer_ids_.erase(render_view_id); | 141 geolocation_renderer_ids_.erase(render_view_id); |
143 } | 142 } |
144 | 143 |
145 void GeolocationDispatcherHostOldImpl::OnRequestPermission( | 144 void GeolocationDispatcherHostImpl::OnRequestPermission( |
146 int render_view_id, | 145 int render_view_id, |
147 int bridge_id, | 146 int bridge_id, |
148 const GURL& requesting_frame) { | 147 const GURL& requesting_frame) { |
149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
150 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":" | 149 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":" |
151 << render_view_id << ":" << bridge_id; | 150 << render_view_id << ":" << bridge_id; |
152 geolocation_permission_context_->RequestGeolocationPermission( | 151 geolocation_permission_context_->RequestGeolocationPermission( |
153 resource_message_filter_process_id_, render_view_id, bridge_id, | 152 resource_message_filter_process_id_, render_view_id, bridge_id, |
154 requesting_frame); | 153 requesting_frame); |
155 } | 154 } |
156 | 155 |
157 void GeolocationDispatcherHostOldImpl::OnCancelPermissionRequest( | 156 void GeolocationDispatcherHostImpl::OnCancelPermissionRequest( |
158 int render_view_id, | 157 int render_view_id, |
159 int bridge_id, | 158 int bridge_id, |
160 const GURL& requesting_frame) { | 159 const GURL& requesting_frame) { |
161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
162 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":" | 161 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":" |
163 << render_view_id << ":" << bridge_id; | 162 << render_view_id << ":" << bridge_id; |
164 geolocation_permission_context_->CancelGeolocationPermissionRequest( | 163 geolocation_permission_context_->CancelGeolocationPermissionRequest( |
165 resource_message_filter_process_id_, render_view_id, bridge_id, | 164 resource_message_filter_process_id_, render_view_id, bridge_id, |
166 requesting_frame); | 165 requesting_frame); |
167 } | 166 } |
168 | 167 |
169 void GeolocationDispatcherHostOldImpl::OnStartUpdating( | 168 void GeolocationDispatcherHostImpl::OnStartUpdating( |
170 int render_view_id, | 169 int render_view_id, |
171 int bridge_id, | 170 int bridge_id, |
172 const GURL& requesting_frame, | 171 const GURL& requesting_frame, |
173 bool enable_high_accuracy) { | 172 bool enable_high_accuracy) { |
173 #if defined(ENABLE_CLIENT_BASED_GEOLOCATION) | |
174 OnRegisterDispatcher(render_view_id); | |
175 #endif | |
174 // WebKit sends the startupdating request before checking permissions, to | 176 // WebKit sends the startupdating request before checking permissions, to |
175 // optimize the no-location-available case and reduce latency in the success | 177 // optimize the no-location-available case and reduce latency in the success |
176 // case (location lookup happens in parallel with the permission request). | 178 // case (location lookup happens in parallel with the permission request). |
177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
178 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":" | 180 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":" |
179 << render_view_id << ":" << bridge_id; | 181 << render_view_id << ":" << bridge_id; |
180 bridge_update_options_[std::make_pair(render_view_id, bridge_id)] = | 182 bridge_update_options_[std::make_pair(render_view_id, bridge_id)] = |
181 GeolocationObserverOptions(enable_high_accuracy); | 183 GeolocationObserverOptions(enable_high_accuracy); |
182 geolocation_permission_context_->StartUpdatingRequested( | 184 geolocation_permission_context_->StartUpdatingRequested( |
183 resource_message_filter_process_id_, render_view_id, bridge_id, | 185 resource_message_filter_process_id_, render_view_id, bridge_id, |
184 requesting_frame); | 186 requesting_frame); |
185 RefreshGeolocationObserverOptions(); | 187 RefreshGeolocationObserverOptions(); |
186 } | 188 } |
187 | 189 |
188 void GeolocationDispatcherHostOldImpl::OnStopUpdating(int render_view_id, | 190 void GeolocationDispatcherHostImpl::OnStopUpdating(int render_view_id, |
189 int bridge_id) { | 191 int bridge_id) { |
190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
191 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":" | 193 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":" |
192 << render_view_id << ":" << bridge_id; | 194 << render_view_id << ":" << bridge_id; |
193 if (bridge_update_options_.erase(std::make_pair(render_view_id, bridge_id))) | 195 if (bridge_update_options_.erase(std::make_pair(render_view_id, bridge_id))) |
194 RefreshGeolocationObserverOptions(); | 196 RefreshGeolocationObserverOptions(); |
195 geolocation_permission_context_->StopUpdatingRequested( | 197 geolocation_permission_context_->StopUpdatingRequested( |
196 resource_message_filter_process_id_, render_view_id, bridge_id); | 198 resource_message_filter_process_id_, render_view_id, bridge_id); |
199 #if defined(ENABLE_CLIENT_BASED_GEOLOCATION) | |
200 OnUnregisterDispatcher(render_view_id); | |
201 #endif | |
197 } | 202 } |
198 | 203 |
199 void GeolocationDispatcherHostOldImpl::OnSuspend(int render_view_id, | 204 void GeolocationDispatcherHostImpl::OnSuspend(int render_view_id, |
200 int bridge_id) { | 205 int bridge_id) { |
201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
202 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":" | 207 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":" |
203 << render_view_id << ":" << bridge_id; | 208 << render_view_id << ":" << bridge_id; |
204 // TODO(bulach): connect this with GeolocationArbitrator. | 209 // TODO(bulach): connect this with GeolocationArbitrator. |
205 } | 210 } |
206 | 211 |
207 void GeolocationDispatcherHostOldImpl::OnResume(int render_view_id, | 212 void GeolocationDispatcherHostImpl::OnResume(int render_view_id, |
208 int bridge_id) { | 213 int bridge_id) { |
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
210 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":" | 215 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":" |
211 << render_view_id << ":" << bridge_id; | 216 << render_view_id << ":" << bridge_id; |
212 // TODO(bulach): connect this with GeolocationArbitrator. | 217 // TODO(bulach): connect this with GeolocationArbitrator. |
213 } | 218 } |
214 | 219 |
215 void GeolocationDispatcherHostOldImpl::RefreshGeolocationObserverOptions() { | 220 void GeolocationDispatcherHostImpl::RefreshGeolocationObserverOptions() { |
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
217 if (bridge_update_options_.empty()) { | 222 if (bridge_update_options_.empty()) { |
218 if (location_provider_) { | 223 if (location_provider_) { |
219 location_provider_->RemoveObserver(this); | 224 location_provider_->RemoveObserver(this); |
220 location_provider_ = NULL; | 225 location_provider_ = NULL; |
221 } | 226 } |
222 } else { | 227 } else { |
223 if (!location_provider_) | 228 if (!location_provider_) |
224 location_provider_ = GeolocationProvider::GetInstance(); | 229 location_provider_ = GeolocationProvider::GetInstance(); |
225 // Re-add to re-establish our options, in case they changed. | 230 // Re-add to re-establish our options, in case they changed. |
226 location_provider_->AddObserver( | 231 location_provider_->AddObserver( |
227 this, | 232 this, |
228 GeolocationObserverOptions::Collapse(bridge_update_options_)); | 233 GeolocationObserverOptions::Collapse(bridge_update_options_)); |
229 } | 234 } |
230 } | 235 } |
231 } // namespace | 236 } // namespace |
232 | 237 |
233 GeolocationDispatcherHostOld* GeolocationDispatcherHostOld::New( | 238 GeolocationDispatcherHost* GeolocationDispatcherHost::New( |
234 int resource_message_filter_process_id, | 239 int resource_message_filter_process_id, |
235 GeolocationPermissionContext* geolocation_permission_context) { | 240 GeolocationPermissionContext* geolocation_permission_context) { |
236 return new GeolocationDispatcherHostOldImpl( | 241 return new GeolocationDispatcherHostImpl( |
237 resource_message_filter_process_id, | 242 resource_message_filter_process_id, |
238 geolocation_permission_context); | 243 geolocation_permission_context); |
239 } | 244 } |
OLD | NEW |