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

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

Issue 8463022: Make chrome communicate with gpsd through libgps/shared memory (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: putting libgps version string into anon namespace Created 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/gps_location_provider_linux.h" 5 #include "content/browser/geolocation/gps_location_provider_linux.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 28 matching lines...) Expand all
39 std::pow(std::fabs(position_1.latitude - position_2.latitude), 2) + 39 std::pow(std::fabs(position_1.latitude - position_2.latitude), 2) +
40 std::pow(std::fabs(position_1.longitude - position_2.longitude), 2)); 40 std::pow(std::fabs(position_1.longitude - position_2.longitude), 2));
41 // Convert to meters. 1 minute of arc of latitude (or longitude at the 41 // Convert to meters. 1 minute of arc of latitude (or longitude at the
42 // equator) is 1 nautical mile or 1852m. 42 // equator) is 1 nautical mile or 1852m.
43 delta *= 60 * 1852; 43 delta *= 60 * 1852;
44 return delta > kMovementThresholdMeters; 44 return delta > kMovementThresholdMeters;
45 } 45 }
46 } // namespace 46 } // namespace
47 47
48 GpsLocationProviderLinux::GpsLocationProviderLinux(LibGpsFactory libgps_factory) 48 GpsLocationProviderLinux::GpsLocationProviderLinux(LibGpsFactory libgps_factory)
49 : libgps_factory_(libgps_factory), 49 : gpsd_reconnect_interval_millis_(kGpsdReconnectRetryIntervalMillis),
50 poll_period_moving_millis_(kPollPeriodMovingMillis),
51 poll_period_stationary_millis_(kPollPeriodStationaryMillis),
52 libgps_factory_(libgps_factory),
50 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 53 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
51 DCHECK(libgps_factory_); 54 DCHECK(libgps_factory_);
52 } 55 }
53 56
54 GpsLocationProviderLinux::~GpsLocationProviderLinux() { 57 GpsLocationProviderLinux::~GpsLocationProviderLinux() {
55 } 58 }
56 59
57 bool GpsLocationProviderLinux::StartProvider(bool high_accuracy) { 60 bool GpsLocationProviderLinux::StartProvider(bool high_accuracy) {
58 if (!high_accuracy) { 61 if (!high_accuracy) {
59 StopProvider(); 62 StopProvider();
60 return true; // Not an error condition, so still return true. 63 return true; // Not an error condition, so still return true.
61 } 64 }
62 if (gps_ != NULL) { 65 if (gps_ != NULL) {
63 DCHECK(weak_factory_.HasWeakPtrs()); 66 DCHECK(weak_factory_.HasWeakPtrs());
64 return true; 67 return true;
65 } 68 }
66 position_.error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; 69 position_.error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE;
67 gps_.reset(libgps_factory_()); 70 gps_.reset(libgps_factory_());
68 if (gps_ == NULL) { 71 if (gps_ == NULL) {
69 DLOG(WARNING) << "libgps.so could not be loaded"; 72 DLOG(WARNING) << "libgps could not be loaded";
70 return false; 73 return false;
71 } 74 }
72 ScheduleNextGpsPoll(0); 75 ScheduleNextGpsPoll(0);
73 return true; 76 return true;
74 } 77 }
75 78
76 void GpsLocationProviderLinux::StopProvider() { 79 void GpsLocationProviderLinux::StopProvider() {
77 weak_factory_.InvalidateWeakPtrs(); 80 weak_factory_.InvalidateWeakPtrs();
78 gps_.reset(); 81 gps_.reset();
79 } 82 }
80 83
81 void GpsLocationProviderLinux::GetPosition(Geoposition* position) { 84 void GpsLocationProviderLinux::GetPosition(Geoposition* position) {
82 DCHECK(position); 85 DCHECK(position);
83 *position = position_; 86 *position = position_;
84 DCHECK(position->IsInitialized()); 87 DCHECK(position->IsInitialized());
85 } 88 }
86 89
87 void GpsLocationProviderLinux::UpdatePosition() { 90 void GpsLocationProviderLinux::UpdatePosition() {
88 ScheduleNextGpsPoll(0); 91 ScheduleNextGpsPoll(0);
89 } 92 }
90 93
91 void GpsLocationProviderLinux::OnPermissionGranted( 94 void GpsLocationProviderLinux::OnPermissionGranted(
92 const GURL& requesting_frame) { 95 const GURL& requesting_frame) {
93 } 96 }
94 97
95 void GpsLocationProviderLinux::DoGpsPollTask() { 98 void GpsLocationProviderLinux::DoGpsPollTask() {
96 if (!gps_->Start()) { 99 if (!gps_->Start()) {
97 DLOG(WARNING) << "Couldn't start GPS provider."; 100 DLOG(WARNING) << "Couldn't start GPS provider.";
98 ScheduleNextGpsPoll(kGpsdReconnectRetryIntervalMillis); 101 ScheduleNextGpsPoll(gpsd_reconnect_interval_millis_);
99 return; 102 return;
100 } 103 }
101 if (!gps_->Poll()) { 104
102 ScheduleNextGpsPoll(kPollPeriodStationaryMillis); 105 Geoposition new_position;
106 if (!gps_->Read(&new_position)) {
107 ScheduleNextGpsPoll(poll_period_stationary_millis_);
103 return; 108 return;
104 } 109 }
105 Geoposition new_position; 110
106 gps_->GetPosition(&new_position);
107 DCHECK(new_position.IsInitialized()); 111 DCHECK(new_position.IsInitialized());
108 const bool differ = PositionsDifferSiginificantly(position_, new_position); 112 const bool differ = PositionsDifferSiginificantly(position_, new_position);
109 ScheduleNextGpsPoll(differ ? kPollPeriodMovingMillis : 113 ScheduleNextGpsPoll(differ ? poll_period_moving_millis_ :
110 kPollPeriodStationaryMillis); 114 poll_period_stationary_millis_);
111 if (differ || new_position.error_code != Geoposition::ERROR_CODE_NONE) { 115 if (differ || new_position.error_code != Geoposition::ERROR_CODE_NONE) {
112 // Update if the new location is interesting or we have an error to report. 116 // Update if the new location is interesting or we have an error to report.
113 position_ = new_position; 117 position_ = new_position;
114 UpdateListeners(); 118 UpdateListeners();
115 } 119 }
116 } 120 }
117 121
118 void GpsLocationProviderLinux::ScheduleNextGpsPoll(int interval) { 122 void GpsLocationProviderLinux::ScheduleNextGpsPoll(int interval) {
119 weak_factory_.InvalidateWeakPtrs(); 123 weak_factory_.InvalidateWeakPtrs();
120 MessageLoop::current()->PostDelayedTask( 124 MessageLoop::current()->PostDelayedTask(
121 FROM_HERE, 125 FROM_HERE,
122 base::Bind(&GpsLocationProviderLinux::DoGpsPollTask, 126 base::Bind(&GpsLocationProviderLinux::DoGpsPollTask,
123 weak_factory_.GetWeakPtr()), 127 weak_factory_.GetWeakPtr()),
124 interval); 128 interval);
125 } 129 }
126 130
127 LocationProviderBase* NewSystemLocationProvider() { 131 LocationProviderBase* NewSystemLocationProvider() {
128 return new GpsLocationProviderLinux(LibGps::New); 132 return new GpsLocationProviderLinux(LibGps::New);
129 } 133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698