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

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

Issue 658005: Bring Geolocation to life!... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 months 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.h"
6 6
7 #include "chrome/common/geoposition.h" 7 #include "chrome/common/geoposition.h"
8 #include "chrome/browser/geolocation/geolocation_permission_context.h" 8 #include "chrome/browser/geolocation/geolocation_permission_context.h"
9 #include "chrome/browser/renderer_host/render_process_host.h" 9 #include "chrome/browser/renderer_host/render_process_host.h"
10 #include "chrome/browser/renderer_host/render_view_host.h" 10 #include "chrome/browser/renderer_host/render_view_host.h"
11 #include "chrome/browser/renderer_host/render_view_host_notification_task.h" 11 #include "chrome/browser/renderer_host/render_view_host_notification_task.h"
12 #include "chrome/browser/renderer_host/resource_message_filter.h" 12 #include "chrome/browser/renderer_host/resource_message_filter.h"
13 #include "chrome/common/render_messages.h" 13 #include "chrome/common/render_messages.h"
14 14
15 GeolocationDispatcherHost::GeolocationDispatcherHost( 15 GeolocationDispatcherHost::GeolocationDispatcherHost(
16 int resource_message_filter_process_id, 16 int resource_message_filter_process_id,
17 GeolocationPermissionContext* geolocation_permission_context) 17 GeolocationPermissionContext* geolocation_permission_context)
18 : resource_message_filter_process_id_(resource_message_filter_process_id), 18 : resource_message_filter_process_id_(resource_message_filter_process_id),
19 geolocation_permission_context_(geolocation_permission_context) { 19 geolocation_permission_context_(geolocation_permission_context) {
20 // This is initialized by ResourceMessageFilter. Do not add any non-trivial 20 // This is initialized by ResourceMessageFilter. Do not add any non-trivial
21 // initialization here, defer to OnRegisterBridge which is triggered whenever 21 // initialization here, defer to OnRegisterBridge which is triggered whenever
22 // a javascript geolocation object is actually initialized. 22 // a javascript geolocation object is actually initialized.
23 } 23 }
24 24
25 GeolocationDispatcherHost::~GeolocationDispatcherHost() { 25 GeolocationDispatcherHost::~GeolocationDispatcherHost() {
26 if (location_arbitrator_)
27 location_arbitrator_->RemoveObserver(this);
26 } 28 }
27 29
28 bool GeolocationDispatcherHost::OnMessageReceived( 30 bool GeolocationDispatcherHost::OnMessageReceived(
29 const IPC::Message& msg, bool* msg_was_ok) { 31 const IPC::Message& msg, bool* msg_was_ok) {
30 *msg_was_ok = true; 32 *msg_was_ok = true;
31 bool handled = true; 33 bool handled = true;
32 IPC_BEGIN_MESSAGE_MAP_EX(GeolocationDispatcherHost, msg, *msg_was_ok) 34 IPC_BEGIN_MESSAGE_MAP_EX(GeolocationDispatcherHost, msg, *msg_was_ok)
33 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RegisterDispatcher, 35 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RegisterDispatcher,
34 OnRegisterDispatcher) 36 OnRegisterDispatcher)
35 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_UnregisterDispatcher, 37 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_UnregisterDispatcher,
36 OnUnregisterDispatcher) 38 OnUnregisterDispatcher)
37 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RequestPermission, 39 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RequestPermission,
38 OnRequestPermission) 40 OnRequestPermission)
39 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_StartUpdating, 41 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_StartUpdating,
40 OnStartUpdating) 42 OnStartUpdating)
41 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_StopUpdating, 43 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_StopUpdating,
42 OnStopUpdating) 44 OnStopUpdating)
43 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_Suspend, 45 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_Suspend,
44 OnSuspend) 46 OnSuspend)
45 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_Resume, 47 IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_Resume,
46 OnResume) 48 OnResume)
47 IPC_MESSAGE_UNHANDLED(handled = false) 49 IPC_MESSAGE_UNHANDLED(handled = false)
48 IPC_END_MESSAGE_MAP() 50 IPC_END_MESSAGE_MAP()
49 return handled; 51 return handled;
50 } 52 }
51 53
52 void GeolocationDispatcherHost::NotifyPositionUpdated( 54 void GeolocationDispatcherHost::OnLocationUpdate(
53 const Geoposition& geoposition) { 55 const Geoposition& geoposition) {
54 if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
55 ChromeThread::PostTask(
56 ChromeThread::UI, FROM_HERE,
57 NewRunnableMethod(
58 this, &GeolocationDispatcherHost::NotifyPositionUpdated,
59 geoposition));
60 return;
61 }
62 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 56 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
63 57
64 for (std::set<GeolocationServiceRenderId>::iterator geo = 58 for (std::set<GeolocationServiceRenderId>::iterator geo =
65 geolocation_renderers_.begin(); 59 geolocation_renderers_.begin();
66 geo != geolocation_renderers_.end(); 60 geo != geolocation_renderers_.end();
67 ++geo) { 61 ++geo) {
68 IPC::Message* message; 62 IPC::Message* message;
69 if (geoposition.error_code == Geoposition::ERROR_CODE_NONE) { 63 if (geoposition.error_code == Geoposition::ERROR_CODE_NONE) {
70 message = new ViewMsg_Geolocation_PositionUpdated( 64 message = new ViewMsg_Geolocation_PositionUpdated(
71 geo->route_id, geoposition); 65 geo->route_id, geoposition);
(...skipping 20 matching lines...) Expand all
92 void GeolocationDispatcherHost::OnRequestPermission( 86 void GeolocationDispatcherHost::OnRequestPermission(
93 int route_id, int bridge_id, const GURL& origin) { 87 int route_id, int bridge_id, const GURL& origin) {
94 LOG(INFO) << "permission request"; 88 LOG(INFO) << "permission request";
95 geolocation_permission_context_->RequestGeolocationPermission( 89 geolocation_permission_context_->RequestGeolocationPermission(
96 resource_message_filter_process_id_, route_id, bridge_id, origin); 90 resource_message_filter_process_id_, route_id, bridge_id, origin);
97 } 91 }
98 92
99 void GeolocationDispatcherHost::OnStartUpdating( 93 void GeolocationDispatcherHost::OnStartUpdating(
100 int route_id, int bridge_id, bool high_accuracy) { 94 int route_id, int bridge_id, bool high_accuracy) {
101 LOG(INFO) << "start updating" << route_id; 95 LOG(INFO) << "start updating" << route_id;
102 // TODO(bulach): connect this with GeolocationServiceProvider. 96 if (!location_arbitrator_)
97 location_arbitrator_ = GeolocationArbitrator::GetInstance();
98 location_arbitrator_->AddObserver(
99 this, GeolocationArbitrator::UpdateOptions(high_accuracy));
103 } 100 }
104 101
105 void GeolocationDispatcherHost::OnStopUpdating(int route_id, int bridge_id) { 102 void GeolocationDispatcherHost::OnStopUpdating(int route_id, int bridge_id) {
106 LOG(INFO) << "stop updating" << route_id; 103 LOG(INFO) << "stop updating" << route_id;
107 // TODO(bulach): connect this with GeolocationServiceProvider. 104 if (location_arbitrator_)
105 location_arbitrator_->RemoveObserver(this);
106 location_arbitrator_ = NULL;
108 } 107 }
109 108
110 void GeolocationDispatcherHost::OnSuspend(int route_id, int bridge_id) { 109 void GeolocationDispatcherHost::OnSuspend(int route_id, int bridge_id) {
111 LOG(INFO) << "suspend" << route_id; 110 LOG(INFO) << "suspend" << route_id;
112 // TODO(bulach): connect this with GeolocationServiceProvider. 111 // TODO(bulach): connect this with GeolocationServiceProvider.
113 } 112 }
114 113
115 void GeolocationDispatcherHost::OnResume(int route_id, int bridge_id) { 114 void GeolocationDispatcherHost::OnResume(int route_id, int bridge_id) {
116 LOG(INFO) << "resume" << route_id; 115 LOG(INFO) << "resume" << route_id;
117 // TODO(bulach): connect this with GeolocationServiceProvider. 116 // TODO(bulach): connect this with GeolocationServiceProvider.
(...skipping 27 matching lines...) Expand all
145 this, &GeolocationDispatcherHost::UnregisterDispatcher, process_id, 144 this, &GeolocationDispatcherHost::UnregisterDispatcher, process_id,
146 route_id)); 145 route_id));
147 return; 146 return;
148 } 147 }
149 GeolocationServiceRenderId geolocation_render_id(process_id, route_id); 148 GeolocationServiceRenderId geolocation_render_id(process_id, route_id);
150 std::set<GeolocationServiceRenderId>::iterator existing = 149 std::set<GeolocationServiceRenderId>::iterator existing =
151 geolocation_renderers_.find(geolocation_render_id); 150 geolocation_renderers_.find(geolocation_render_id);
152 DCHECK(existing != geolocation_renderers_.end()); 151 DCHECK(existing != geolocation_renderers_.end());
153 geolocation_renderers_.erase(existing); 152 geolocation_renderers_.erase(existing);
154 } 153 }
OLDNEW
« no previous file with comments | « chrome/browser/geolocation/geolocation_dispatcher_host.h ('k') | chrome/browser/geolocation/location_arbitrator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698