| 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_impl.h" | 5 #include "content/browser/geolocation/geolocation_provider_impl.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" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 45 bool was_permission_granted = user_did_opt_into_location_services_; | 45 bool was_permission_granted = user_did_opt_into_location_services_; |
| 46 user_did_opt_into_location_services_ = true; | 46 user_did_opt_into_location_services_ = true; |
| 47 if (IsRunning() && !was_permission_granted) | 47 if (IsRunning() && !was_permission_granted) |
| 48 InformProvidersPermissionGranted(); | 48 InformProvidersPermissionGranted(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void GeolocationProviderImpl::OverrideLocationForTesting( | 51 void GeolocationProviderImpl::OverrideLocationForTesting( |
| 52 const Geoposition& position) { | 52 const Geoposition& position) { |
| 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 54 position_ = position; | |
| 55 ignore_location_updates_ = true; | 54 ignore_location_updates_ = true; |
| 56 NotifyClients(position); | 55 NotifyClients(position); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void GeolocationProviderImpl::OnLocationUpdate(const Geoposition& position) { | 58 void GeolocationProviderImpl::OnLocationUpdate(const Geoposition& position) { |
| 60 DCHECK(OnGeolocationThread()); | 59 DCHECK(OnGeolocationThread()); |
| 61 // Will be true only in testing. | 60 // Will be true only in testing. |
| 62 if (ignore_location_updates_) | 61 if (ignore_location_updates_) |
| 63 return; | 62 return; |
| 64 BrowserThread::PostTask(BrowserThread::UI, | 63 BrowserThread::PostTask(BrowserThread::UI, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 93 | 92 |
| 94 bool GeolocationProviderImpl::OnGeolocationThread() const { | 93 bool GeolocationProviderImpl::OnGeolocationThread() const { |
| 95 return base::MessageLoop::current() == message_loop(); | 94 return base::MessageLoop::current() == message_loop(); |
| 96 } | 95 } |
| 97 | 96 |
| 98 void GeolocationProviderImpl::OnClientsChanged() { | 97 void GeolocationProviderImpl::OnClientsChanged() { |
| 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 100 base::Closure task; | 99 base::Closure task; |
| 101 if (high_accuracy_callbacks_.empty() && low_accuracy_callbacks_.empty()) { | 100 if (high_accuracy_callbacks_.empty() && low_accuracy_callbacks_.empty()) { |
| 102 DCHECK(IsRunning()); | 101 DCHECK(IsRunning()); |
| 103 // We have no more observers, so we clear the cached geoposition so that | 102 if (!ignore_location_updates_) { |
| 104 // when the next observer is added we will not provide a stale position. | 103 // We have no more observers, so we clear the cached geoposition so that |
| 105 position_ = Geoposition(); | 104 // when the next observer is added we will not provide a stale position. |
| 105 position_ = Geoposition(); |
| 106 } |
| 106 task = base::Bind(&GeolocationProviderImpl::StopProviders, | 107 task = base::Bind(&GeolocationProviderImpl::StopProviders, |
| 107 base::Unretained(this)); | 108 base::Unretained(this)); |
| 108 } else { | 109 } else { |
| 109 if (!IsRunning()) { | 110 if (!IsRunning()) { |
| 110 Start(); | 111 Start(); |
| 111 if (user_did_opt_into_location_services_) | 112 if (user_did_opt_into_location_services_) |
| 112 InformProvidersPermissionGranted(); | 113 InformProvidersPermissionGranted(); |
| 113 } | 114 } |
| 114 // Determine a set of options that satisfies all clients. | 115 // Determine a set of options that satisfies all clients. |
| 115 bool use_high_accuracy = !high_accuracy_callbacks_.empty(); | 116 bool use_high_accuracy = !high_accuracy_callbacks_.empty(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 arbitrator_ = NULL; | 171 arbitrator_ = NULL; |
| 171 } | 172 } |
| 172 | 173 |
| 173 LocationArbitrator* GeolocationProviderImpl::CreateArbitrator() { | 174 LocationArbitrator* GeolocationProviderImpl::CreateArbitrator() { |
| 174 LocationArbitratorImpl::LocationUpdateCallback callback = base::Bind( | 175 LocationArbitratorImpl::LocationUpdateCallback callback = base::Bind( |
| 175 &GeolocationProviderImpl::OnLocationUpdate, base::Unretained(this)); | 176 &GeolocationProviderImpl::OnLocationUpdate, base::Unretained(this)); |
| 176 return new LocationArbitratorImpl(callback); | 177 return new LocationArbitratorImpl(callback); |
| 177 } | 178 } |
| 178 | 179 |
| 179 } // namespace content | 180 } // namespace content |
| OLD | NEW |