Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1312)

Side by Side Diff: chrome/browser/geolocation/geolocation_dispatcher_host_old.cc

Issue 5744005: Revert rev 69137 due to incorrect change log. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.h" 5 #include "chrome/browser/geolocation/geolocation_dispatcher_host_old.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_message_filter.h" 14 #include "chrome/browser/renderer_host/render_message_filter.h"
15 #include "chrome/browser/renderer_host/render_process_host.h" 15 #include "chrome/browser/renderer_host/render_process_host.h"
16 #include "chrome/browser/renderer_host/render_view_host.h" 16 #include "chrome/browser/renderer_host/render_view_host.h"
17 #include "chrome/browser/renderer_host/render_view_host_notification_task.h" 17 #include "chrome/browser/renderer_host/render_view_host_notification_task.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 GeolocationDispatcherHostImpl : public GeolocationDispatcherHost, 22 class GeolocationDispatcherHostOldImpl : public GeolocationDispatcherHostOld,
23 public GeolocationObserver { 23 public GeolocationObserver {
24 public: 24 public:
25 GeolocationDispatcherHostImpl( 25 GeolocationDispatcherHostOldImpl(
26 int render_process_id, 26 int resource_message_filter_process_id,
27 GeolocationPermissionContext* geolocation_permission_context); 27 GeolocationPermissionContext* geolocation_permission_context);
28 28
29 // GeolocationDispatcherHost 29 // GeolocationDispatcherHostOld
30 // Called to possibly handle the incoming IPC message. Returns true if
31 // handled. Called in the browser process.
30 virtual bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok); 32 virtual bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok);
31 33
32 // GeolocationObserver 34 // GeolocationArbitrator::Delegate
33 virtual void OnLocationUpdate(const Geoposition& position); 35 virtual void OnLocationUpdate(const Geoposition& position);
34 36
35 private: 37 private:
36 virtual ~GeolocationDispatcherHostImpl(); 38 friend class base::RefCountedThreadSafe<GeolocationDispatcherHostOldImpl>;
39 virtual ~GeolocationDispatcherHostOldImpl();
37 40
38 void OnRegisterDispatcher(int render_view_id); 41 void OnRegisterDispatcher(int render_view_id);
39 void OnUnregisterDispatcher(int render_view_id); 42 void OnUnregisterDispatcher(int render_view_id);
40 void OnRequestPermission( 43 void OnRequestPermission(
41 int render_view_id, int bridge_id, const GURL& requesting_frame); 44 int render_view_id, int bridge_id, const GURL& requesting_frame);
42 void OnCancelPermissionRequest( 45 void OnCancelPermissionRequest(
43 int render_view_id, int bridge_id, const GURL& requesting_frame); 46 int render_view_id, int bridge_id, const GURL& requesting_frame);
44 void OnStartUpdating( 47 void OnStartUpdating(
45 int render_view_id, int bridge_id, const GURL& requesting_frame, 48 int render_view_id, int bridge_id, const GURL& requesting_frame,
46 bool enable_high_accuracy); 49 bool enable_high_accuracy);
47 void OnStopUpdating(int render_view_id, int bridge_id); 50 void OnStopUpdating(int render_view_id, int bridge_id);
48 void OnSuspend(int render_view_id, int bridge_id); 51 void OnSuspend(int render_view_id, int bridge_id);
49 void OnResume(int render_view_id, int bridge_id); 52 void OnResume(int render_view_id, int bridge_id);
50 53
51 // Updates the |location_arbitrator_| with the currently required update 54 // Updates the |location_arbitrator_| with the currently required update
52 // options, based on |bridge_update_options_|. 55 // options, based on |bridge_update_options_|.
53 void RefreshGeolocationObserverOptions(); 56 void RefreshGeolocationObserverOptions();
54 57
55 int render_process_id_; 58 int resource_message_filter_process_id_;
56 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; 59 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_;
57 60
58 // Iterated when sending location updates to renderer processes. The fan out 61 // Iterated when sending location updates to renderer processes. The fan out
59 // to individual bridge IDs happens renderer side, in order to minimize 62 // to individual bridge IDs happens renderer side, in order to minimize
60 // context switches. 63 // context switches.
61 // Only used on the IO thread. 64 // Only used on the IO thread.
62 std::set<int> geolocation_renderer_ids_; 65 std::set<int> geolocation_renderer_ids_;
63 // Maps <renderer_id, bridge_id> to the location arbitrator update options 66 // Maps <renderer_id, bridge_id> to the location arbitrator update options
64 // that correspond to this particular bridge. 67 // that correspond to this particular bridge.
65 std::map<std::pair<int, int>, GeolocationObserverOptions> 68 std::map<std::pair<int, int>, GeolocationObserverOptions>
66 bridge_update_options_; 69 bridge_update_options_;
67 // Only set whilst we are registered with the arbitrator. 70 // Only set whilst we are registered with the arbitrator.
68 GeolocationProvider* location_provider_; 71 GeolocationProvider* location_provider_;
69 72
70 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHostImpl); 73 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHostOldImpl);
71 }; 74 };
72 75
73 GeolocationDispatcherHostImpl::GeolocationDispatcherHostImpl( 76 GeolocationDispatcherHostOldImpl::GeolocationDispatcherHostOldImpl(
74 int render_process_id, 77 int resource_message_filter_process_id,
75 GeolocationPermissionContext* geolocation_permission_context) 78 GeolocationPermissionContext* geolocation_permission_context)
76 : render_process_id_(render_process_id), 79 : resource_message_filter_process_id_(resource_message_filter_process_id),
77 geolocation_permission_context_(geolocation_permission_context), 80 geolocation_permission_context_(geolocation_permission_context),
78 location_provider_(NULL) { 81 location_provider_(NULL) {
79 // This is initialized by ResourceMessageFilter. Do not add any non-trivial 82 // This is initialized by ResourceMessageFilter. Do not add any non-trivial
80 // initialization here, defer to OnRegisterBridge which is triggered whenever 83 // initialization here, defer to OnRegisterBridge which is triggered whenever
81 // a javascript geolocation object is actually initialized. 84 // a javascript geolocation object is actually initialized.
82 } 85 }
83 86
84 GeolocationDispatcherHostImpl::~GeolocationDispatcherHostImpl() { 87 GeolocationDispatcherHostOldImpl::~GeolocationDispatcherHostOldImpl() {
85 if (location_provider_) 88 if (location_provider_)
86 location_provider_->RemoveObserver(this); 89 location_provider_->RemoveObserver(this);
87 } 90 }
88 91
89 bool GeolocationDispatcherHostImpl::OnMessageReceived( 92 bool GeolocationDispatcherHostOldImpl::OnMessageReceived(
90 const IPC::Message& msg, bool* msg_was_ok) { 93 const IPC::Message& msg, bool* msg_was_ok) {
91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
92 *msg_was_ok = true; 95 *msg_was_ok = true;
93 bool handled = true; 96 bool handled = true;
94 IPC_BEGIN_MESSAGE_MAP_EX(GeolocationDispatcherHostImpl, msg, *msg_was_ok) 97 IPC_BEGIN_MESSAGE_MAP_EX(GeolocationDispatcherHostOldImpl, msg, *msg_was_ok)
95 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RegisterDispatcher, 98 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RegisterDispatcher,
96 OnRegisterDispatcher) 99 OnRegisterDispatcher)
97 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_UnregisterDispatcher, 100 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_UnregisterDispatcher,
98 OnUnregisterDispatcher) 101 OnUnregisterDispatcher)
99 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_CancelPermissionRequest, 102 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_CancelPermissionRequest,
100 OnCancelPermissionRequest) 103 OnCancelPermissionRequest)
101 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RequestPermission, 104 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RequestPermission,
102 OnRequestPermission) 105 OnRequestPermission)
103 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_StartUpdating, 106 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_StartUpdating,
104 OnStartUpdating) 107 OnStartUpdating)
105 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_StopUpdating, 108 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_StopUpdating,
106 OnStopUpdating) 109 OnStopUpdating)
107 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_Suspend, 110 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_Suspend,
108 OnSuspend) 111 OnSuspend)
109 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_Resume, 112 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_Resume,
110 OnResume) 113 OnResume)
111 IPC_MESSAGE_UNHANDLED(handled = false) 114 IPC_MESSAGE_UNHANDLED(handled = false)
112 IPC_END_MESSAGE_MAP() 115 IPC_END_MESSAGE_MAP()
113 return handled; 116 return handled;
114 } 117 }
115 118
116 void GeolocationDispatcherHostImpl::OnLocationUpdate( 119 void GeolocationDispatcherHostOldImpl::OnLocationUpdate(
117 const Geoposition& geoposition) { 120 const Geoposition& geoposition) {
118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
119 for (std::set<int>::iterator it = geolocation_renderer_ids_.begin(); 122 for (std::set<int>::iterator it = geolocation_renderer_ids_.begin();
120 it != geolocation_renderer_ids_.end(); ++it) { 123 it != geolocation_renderer_ids_.end(); ++it) {
121 IPC::Message* message = 124 IPC::Message* message =
122 new ViewMsg_Geolocation_PositionUpdated(*it, geoposition); 125 new ViewMsg_Geolocation_PositionUpdated(*it, geoposition);
123 CallRenderViewHost(render_process_id_, *it, 126 CallRenderViewHost(resource_message_filter_process_id_, *it,
124 &RenderViewHost::Send, message); 127 &RenderViewHost::Send, message);
125 } 128 }
126 } 129 }
127 130
128 void GeolocationDispatcherHostImpl::OnRegisterDispatcher( 131 void GeolocationDispatcherHostOldImpl::OnRegisterDispatcher(
129 int render_view_id) { 132 int render_view_id) {
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
131 DCHECK_EQ(0u, geolocation_renderer_ids_.count(render_view_id)); 134 DCHECK_EQ(0u, geolocation_renderer_ids_.count(render_view_id));
132 geolocation_renderer_ids_.insert(render_view_id); 135 geolocation_renderer_ids_.insert(render_view_id);
133 } 136 }
134 137
135 void GeolocationDispatcherHostImpl::OnUnregisterDispatcher( 138 void GeolocationDispatcherHostOldImpl::OnUnregisterDispatcher(
136 int render_view_id) { 139 int render_view_id) {
137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
138 DCHECK_EQ(1u, geolocation_renderer_ids_.count(render_view_id)); 141 DCHECK_EQ(1u, geolocation_renderer_ids_.count(render_view_id));
139 geolocation_renderer_ids_.erase(render_view_id); 142 geolocation_renderer_ids_.erase(render_view_id);
140 } 143 }
141 144
142 void GeolocationDispatcherHostImpl::OnRequestPermission( 145 void GeolocationDispatcherHostOldImpl::OnRequestPermission(
143 int render_view_id, 146 int render_view_id,
144 int bridge_id, 147 int bridge_id,
145 const GURL& requesting_frame) { 148 const GURL& requesting_frame) {
146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
147 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" 150 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":"
148 << render_view_id << ":" << bridge_id; 151 << render_view_id << ":" << bridge_id;
149 geolocation_permission_context_->RequestGeolocationPermission( 152 geolocation_permission_context_->RequestGeolocationPermission(
150 render_process_id_, render_view_id, bridge_id, 153 resource_message_filter_process_id_, render_view_id, bridge_id,
151 requesting_frame); 154 requesting_frame);
152 } 155 }
153 156
154 void GeolocationDispatcherHostImpl::OnCancelPermissionRequest( 157 void GeolocationDispatcherHostOldImpl::OnCancelPermissionRequest(
155 int render_view_id, 158 int render_view_id,
156 int bridge_id, 159 int bridge_id,
157 const GURL& requesting_frame) { 160 const GURL& requesting_frame) {
158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
159 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" 162 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":"
160 << render_view_id << ":" << bridge_id; 163 << render_view_id << ":" << bridge_id;
161 geolocation_permission_context_->CancelGeolocationPermissionRequest( 164 geolocation_permission_context_->CancelGeolocationPermissionRequest(
162 render_process_id_, render_view_id, bridge_id, 165 resource_message_filter_process_id_, render_view_id, bridge_id,
163 requesting_frame); 166 requesting_frame);
164 } 167 }
165 168
166 void GeolocationDispatcherHostImpl::OnStartUpdating( 169 void GeolocationDispatcherHostOldImpl::OnStartUpdating(
167 int render_view_id, 170 int render_view_id,
168 int bridge_id, 171 int bridge_id,
169 const GURL& requesting_frame, 172 const GURL& requesting_frame,
170 bool enable_high_accuracy) { 173 bool enable_high_accuracy) {
171 #if defined(ENABLE_CLIENT_BASED_GEOLOCATION)
172 // StartUpdating() can be invoked as a result of high-accuracy mode
173 // being enabled / disabled. No need to register the dispatcher again.
174 if (!geolocation_renderer_ids_.count(render_view_id))
175 OnRegisterDispatcher(render_view_id);
176 #endif
177 // WebKit sends the startupdating request before checking permissions, to 174 // WebKit sends the startupdating request before checking permissions, to
178 // optimize the no-location-available case and reduce latency in the success 175 // optimize the no-location-available case and reduce latency in the success
179 // case (location lookup happens in parallel with the permission request). 176 // case (location lookup happens in parallel with the permission request).
180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
181 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" 178 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":"
182 << render_view_id << ":" << bridge_id; 179 << render_view_id << ":" << bridge_id;
183 bridge_update_options_[std::make_pair(render_view_id, bridge_id)] = 180 bridge_update_options_[std::make_pair(render_view_id, bridge_id)] =
184 GeolocationObserverOptions(enable_high_accuracy); 181 GeolocationObserverOptions(enable_high_accuracy);
185 geolocation_permission_context_->StartUpdatingRequested( 182 geolocation_permission_context_->StartUpdatingRequested(
186 render_process_id_, render_view_id, bridge_id, 183 resource_message_filter_process_id_, render_view_id, bridge_id,
187 requesting_frame); 184 requesting_frame);
188 RefreshGeolocationObserverOptions(); 185 RefreshGeolocationObserverOptions();
189 } 186 }
190 187
191 void GeolocationDispatcherHostImpl::OnStopUpdating(int render_view_id, 188 void GeolocationDispatcherHostOldImpl::OnStopUpdating(int render_view_id,
192 int bridge_id) { 189 int bridge_id) {
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
194 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" 191 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":"
195 << render_view_id << ":" << bridge_id; 192 << render_view_id << ":" << bridge_id;
196 if (bridge_update_options_.erase(std::make_pair(render_view_id, bridge_id))) 193 if (bridge_update_options_.erase(std::make_pair(render_view_id, bridge_id)))
197 RefreshGeolocationObserverOptions(); 194 RefreshGeolocationObserverOptions();
198 geolocation_permission_context_->StopUpdatingRequested( 195 geolocation_permission_context_->StopUpdatingRequested(
199 render_process_id_, render_view_id, bridge_id); 196 resource_message_filter_process_id_, render_view_id, bridge_id);
200 #if defined(ENABLE_CLIENT_BASED_GEOLOCATION)
201 OnUnregisterDispatcher(render_view_id);
202 #endif
203 } 197 }
204 198
205 void GeolocationDispatcherHostImpl::OnSuspend(int render_view_id, 199 void GeolocationDispatcherHostOldImpl::OnSuspend(int render_view_id,
206 int bridge_id) { 200 int bridge_id) {
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
208 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" 202 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":"
209 << render_view_id << ":" << bridge_id; 203 << render_view_id << ":" << bridge_id;
210 // TODO(bulach): connect this with GeolocationArbitrator. 204 // TODO(bulach): connect this with GeolocationArbitrator.
211 } 205 }
212 206
213 void GeolocationDispatcherHostImpl::OnResume(int render_view_id, 207 void GeolocationDispatcherHostOldImpl::OnResume(int render_view_id,
214 int bridge_id) { 208 int bridge_id) {
215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
216 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" 210 DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":"
217 << render_view_id << ":" << bridge_id; 211 << render_view_id << ":" << bridge_id;
218 // TODO(bulach): connect this with GeolocationArbitrator. 212 // TODO(bulach): connect this with GeolocationArbitrator.
219 } 213 }
220 214
221 void GeolocationDispatcherHostImpl::RefreshGeolocationObserverOptions() { 215 void GeolocationDispatcherHostOldImpl::RefreshGeolocationObserverOptions() {
222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
223 if (bridge_update_options_.empty()) { 217 if (bridge_update_options_.empty()) {
224 if (location_provider_) { 218 if (location_provider_) {
225 location_provider_->RemoveObserver(this); 219 location_provider_->RemoveObserver(this);
226 location_provider_ = NULL; 220 location_provider_ = NULL;
227 } 221 }
228 } else { 222 } else {
229 if (!location_provider_) 223 if (!location_provider_)
230 location_provider_ = GeolocationProvider::GetInstance(); 224 location_provider_ = GeolocationProvider::GetInstance();
231 // Re-add to re-establish our options, in case they changed. 225 // Re-add to re-establish our options, in case they changed.
232 location_provider_->AddObserver( 226 location_provider_->AddObserver(
233 this, 227 this,
234 GeolocationObserverOptions::Collapse(bridge_update_options_)); 228 GeolocationObserverOptions::Collapse(bridge_update_options_));
235 } 229 }
236 } 230 }
237 } // namespace 231 } // namespace
238 232
239 GeolocationDispatcherHost* GeolocationDispatcherHost::New( 233 GeolocationDispatcherHostOld* GeolocationDispatcherHostOld::New(
240 int render_process_id, 234 int resource_message_filter_process_id,
241 GeolocationPermissionContext* geolocation_permission_context) { 235 GeolocationPermissionContext* geolocation_permission_context) {
242 return new GeolocationDispatcherHostImpl( 236 return new GeolocationDispatcherHostOldImpl(
243 render_process_id, 237 resource_message_filter_process_id,
244 geolocation_permission_context); 238 geolocation_permission_context);
245 } 239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698