OLD | NEW |
---|---|
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_provider.h" | 5 #include "content/browser/geolocation/geolocation_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "content/browser/geolocation/location_arbitrator.h" | 14 #include "content/browser/geolocation/location_arbitrator.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 void GeolocationProvider::AddObserver(GeolocationObserver* observer, | 19 void GeolocationProvider::AddObserver(GeolocationObserver* observer, |
20 const GeolocationObserverOptions& update_options) { | 20 const GeolocationObserverOptions& update_options) { |
21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
22 observers_[observer] = update_options; | 22 observers_[observer] = update_options; |
23 OnClientsChanged(); | 23 OnClientsChanged(); |
24 if (position_.Validate() || | 24 if (ignore_location_updates_) { |
25 position_.error_code != Geoposition::ERROR_CODE_NONE) | 25 // Position has been overridden for testing. Tests expect the observers to |
26 observer->OnLocationUpdate(position_); | 26 // be called synchronously in this case. |
27 if (position_.Validate() || | |
28 position_.error_code != Geoposition::ERROR_CODE_NONE) | |
29 observer->OnLocationUpdate(position_); | |
John Knottenbelt
2012/11/18 16:03:07
We don't want to send this if we're the first obse
| |
30 } | |
27 } | 31 } |
28 | 32 |
29 bool GeolocationProvider::RemoveObserver(GeolocationObserver* observer) { | 33 bool GeolocationProvider::RemoveObserver(GeolocationObserver* observer) { |
30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
31 size_t removed = observers_.erase(observer); | 35 size_t removed = observers_.erase(observer); |
32 if (removed) | 36 if (removed) |
33 OnClientsChanged(); | 37 OnClientsChanged(); |
34 return removed > 0; | 38 return removed > 0; |
35 } | 39 } |
36 | 40 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 arbitrator_ = GeolocationArbitrator::Create(this); | 190 arbitrator_ = GeolocationArbitrator::Create(this); |
187 } | 191 } |
188 | 192 |
189 void GeolocationProvider::CleanUp() { | 193 void GeolocationProvider::CleanUp() { |
190 DCHECK(OnGeolocationThread()); | 194 DCHECK(OnGeolocationThread()); |
191 delete arbitrator_; | 195 delete arbitrator_; |
192 arbitrator_ = NULL; | 196 arbitrator_ = NULL; |
193 } | 197 } |
194 | 198 |
195 } // namespace content | 199 } // namespace content |
OLD | NEW |