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

Side by Side Diff: content/browser/geolocation/geolocation_dispatcher_host.cc

Issue 11269002: Introduce GeolocationPermissionRequestID, a wrapper struct to contain the (render process ID, rende… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/geolocation/geolocation_dispatcher_host.h" 5 #include "content/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 "base/bind.h" 11 #include "base/bind.h"
12 #include "content/browser/geolocation/geolocation_provider.h" 12 #include "content/browser/geolocation/geolocation_provider.h"
13 #include "content/browser/renderer_host/render_message_filter.h" 13 #include "content/browser/renderer_host/render_message_filter.h"
14 #include "content/browser/renderer_host/render_process_host_impl.h" 14 #include "content/browser/renderer_host/render_process_host_impl.h"
15 #include "content/browser/renderer_host/render_view_host_impl.h" 15 #include "content/browser/renderer_host/render_view_host_impl.h"
16 #include "content/public/browser/geolocation_permission_context.h" 16 #include "content/public/browser/geolocation_permission_context.h"
17 #include "content/public/common/geoposition.h" 17 #include "content/public/common/geoposition.h"
18 #include "content/common/geolocation_messages.h" 18 #include "content/common/geolocation_messages.h"
19 19
20 using content::BrowserThread; 20 namespace content {
21 using content::GeolocationPermissionContext;
22 using content::Geoposition;
23 using content::RenderViewHostImpl;
24 21
25 namespace { 22 namespace {
26 23
27 void NotifyArbitratorPermissionGranted() { 24 void NotifyArbitratorPermissionGranted() {
28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
29 GeolocationProvider::GetInstance()->OnPermissionGranted(); 26 GeolocationProvider::GetInstance()->OnPermissionGranted();
30 } 27 }
31 28
32 void SendGeolocationPermissionResponse(int render_process_id, 29 void SendGeolocationPermissionResponse(int render_process_id,
33 int render_view_id, 30 int render_view_id,
34 int bridge_id, 31 int bridge_id,
35 bool allowed) { 32 bool allowed) {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
37 RenderViewHostImpl* r = RenderViewHostImpl::FromID( 34 RenderViewHostImpl* r =
38 render_process_id, render_view_id); 35 RenderViewHostImpl::FromID(render_process_id, render_view_id);
39 if (!r) 36 if (!r)
40 return; 37 return;
41 r->Send(new GeolocationMsg_PermissionSet(render_view_id, bridge_id, allowed)); 38 r->Send(new GeolocationMsg_PermissionSet(render_view_id, bridge_id, allowed));
42 39
43 if (allowed) { 40 if (allowed) {
44 BrowserThread::PostTask( 41 BrowserThread::PostTask(
45 BrowserThread::IO, FROM_HERE, 42 BrowserThread::IO, FROM_HERE,
46 base::Bind(&NotifyArbitratorPermissionGranted)); 43 base::Bind(&NotifyArbitratorPermissionGranted));
47 } 44 }
48 } 45 }
49 46
50 class GeolocationDispatcherHostImpl : public GeolocationDispatcherHost, 47 class GeolocationDispatcherHostImpl : public GeolocationDispatcherHost,
51 public GeolocationObserver { 48 public GeolocationObserver {
52 public: 49 public:
53 GeolocationDispatcherHostImpl( 50 GeolocationDispatcherHostImpl(
54 int render_process_id, 51 int render_process_id,
55 GeolocationPermissionContext* geolocation_permission_context); 52 GeolocationPermissionContext* geolocation_permission_context);
56 53
57 // GeolocationDispatcherHost 54 // GeolocationDispatcherHost
58 virtual bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok); 55 virtual bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok);
59 56
60 // GeolocationObserver 57 // GeolocationObserver
61 virtual void OnLocationUpdate(const Geoposition& position); 58 virtual void OnLocationUpdate(const Geoposition& position);
62 59
63 private: 60 private:
64 virtual ~GeolocationDispatcherHostImpl(); 61 virtual ~GeolocationDispatcherHostImpl();
65 62
66 void OnRequestPermission( 63 void OnRequestPermission(int render_view_id,
67 int render_view_id, int bridge_id, const GURL& requesting_frame); 64 int bridge_id,
68 void OnCancelPermissionRequest( 65 const GURL& requesting_frame);
69 int render_view_id, int bridge_id, const GURL& requesting_frame); 66 void OnCancelPermissionRequest(int render_view_id,
70 void OnStartUpdating( 67 int bridge_id,
71 int render_view_id, const GURL& requesting_frame, 68 const GURL& requesting_frame);
72 bool enable_high_accuracy); 69 void OnStartUpdating(int render_view_id,
70 const GURL& requesting_frame,
71 bool enable_high_accuracy);
73 void OnStopUpdating(int render_view_id); 72 void OnStopUpdating(int render_view_id);
74 73
75 // Updates the |location_arbitrator_| with the currently required update 74 // Updates the |location_arbitrator_| with the currently required update
76 // options, based on |renderer_update_options_|. 75 // options, based on |renderer_update_options_|.
77 void RefreshGeolocationObserverOptions(); 76 void RefreshGeolocationObserverOptions();
78 77
79 int render_process_id_; 78 int render_process_id_;
80 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; 79 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_;
81 80
82 // Iterated when sending location updates to renderer processes. The fan out 81 // Iterated when sending location updates to renderer processes. The fan out
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 136
138 void GeolocationDispatcherHostImpl::OnRequestPermission( 137 void GeolocationDispatcherHostImpl::OnRequestPermission(
139 int render_view_id, 138 int render_view_id,
140 int bridge_id, 139 int bridge_id,
141 const GURL& requesting_frame) { 140 const GURL& requesting_frame) {
142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
143 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" 142 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":"
144 << render_view_id << ":" << bridge_id; 143 << render_view_id << ":" << bridge_id;
145 if (geolocation_permission_context_) { 144 if (geolocation_permission_context_) {
146 geolocation_permission_context_->RequestGeolocationPermission( 145 geolocation_permission_context_->RequestGeolocationPermission(
147 render_process_id_, render_view_id, bridge_id, 146 render_process_id_, render_view_id, bridge_id, requesting_frame,
148 requesting_frame, 147 base::Bind(&SendGeolocationPermissionResponse, render_process_id_,
149 base::Bind( 148 render_view_id, bridge_id));
150 &SendGeolocationPermissionResponse,
151 render_process_id_, render_view_id, bridge_id));
152 } else { 149 } else {
153 BrowserThread::PostTask( 150 BrowserThread::PostTask(
154 BrowserThread::UI, FROM_HERE, 151 BrowserThread::UI, FROM_HERE,
155 base::Bind( 152 base::Bind(&SendGeolocationPermissionResponse, render_process_id_,
156 &SendGeolocationPermissionResponse, 153 render_view_id, bridge_id, true));
157 render_process_id_, render_view_id, bridge_id, true));
158 } 154 }
159 } 155 }
160 156
161 void GeolocationDispatcherHostImpl::OnCancelPermissionRequest( 157 void GeolocationDispatcherHostImpl::OnCancelPermissionRequest(
162 int render_view_id, 158 int render_view_id,
163 int bridge_id, 159 int bridge_id,
164 const GURL& requesting_frame) { 160 const GURL& requesting_frame) {
165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
166 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" 162 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":"
167 << render_view_id << ":" << bridge_id; 163 << render_view_id << ":" << bridge_id;
168 if (!geolocation_permission_context_) 164 if (geolocation_permission_context_) {
169 return; 165 geolocation_permission_context_->CancelGeolocationPermissionRequest(
170 geolocation_permission_context_->CancelGeolocationPermissionRequest( 166 render_process_id_, render_view_id, bridge_id, requesting_frame);
171 render_process_id_, render_view_id, bridge_id, 167 }
172 requesting_frame);
173 } 168 }
174 169
175 void GeolocationDispatcherHostImpl::OnStartUpdating( 170 void GeolocationDispatcherHostImpl::OnStartUpdating(
176 int render_view_id, 171 int render_view_id,
177 const GURL& requesting_frame, 172 const GURL& requesting_frame,
178 bool enable_high_accuracy) { 173 bool enable_high_accuracy) {
179 // StartUpdating() can be invoked as a result of high-accuracy mode 174 // StartUpdating() can be invoked as a result of high-accuracy mode
180 // being enabled / disabled. No need to record the dispatcher again. 175 // being enabled / disabled. No need to record the dispatcher again.
181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
182 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" 177 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":"
(...skipping 28 matching lines...) Expand all
211 if (!location_provider_) 206 if (!location_provider_)
212 location_provider_ = GeolocationProvider::GetInstance(); 207 location_provider_ = GeolocationProvider::GetInstance();
213 // Re-add to re-establish our options, in case they changed. 208 // Re-add to re-establish our options, in case they changed.
214 location_provider_->AddObserver( 209 location_provider_->AddObserver(
215 this, 210 this,
216 GeolocationObserverOptions::Collapse(renderer_update_options_)); 211 GeolocationObserverOptions::Collapse(renderer_update_options_));
217 } 212 }
218 } 213 }
219 } // namespace 214 } // namespace
220 215
216
217 // GeolocationDispatcherHost --------------------------------------------------
218
219 // static
221 GeolocationDispatcherHost* GeolocationDispatcherHost::New( 220 GeolocationDispatcherHost* GeolocationDispatcherHost::New(
222 int render_process_id, 221 int render_process_id,
223 GeolocationPermissionContext* geolocation_permission_context) { 222 GeolocationPermissionContext* geolocation_permission_context) {
224 return new GeolocationDispatcherHostImpl( 223 return new GeolocationDispatcherHostImpl(
225 render_process_id, 224 render_process_id,
226 geolocation_permission_context); 225 geolocation_permission_context);
227 } 226 }
227
228 GeolocationDispatcherHost::GeolocationDispatcherHost() {
229 }
230
231 GeolocationDispatcherHost::~GeolocationDispatcherHost() {
232 }
233
234 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geolocation/geolocation_dispatcher_host.h ('k') | content/public/browser/geolocation_permission_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698