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 #ifndef CONTENT_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_H_ | 5 #ifndef CONTENT_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_H_ |
6 #define CONTENT_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_H_ | 6 #define CONTENT_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "content/browser/geolocation/location_provider.h" | 12 #include "content/browser/geolocation/location_provider.h" |
13 #include "content/browser/geolocation/geolocation_observer.h" | 13 #include "content/browser/geolocation/geolocation_observer.h" |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "content/common/geoposition.h" | |
16 #include "content/public/browser/access_token_store.h" | 15 #include "content/public/browser/access_token_store.h" |
| 16 #include "content/public/common/geoposition.h" |
17 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
18 | 18 |
19 class GeolocationArbitratorDependencyFactory; | 19 class GeolocationArbitratorDependencyFactory; |
20 class LocationProviderBase; | 20 class LocationProviderBase; |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 class AccessTokenStore; | 23 class AccessTokenStore; |
24 } | 24 } |
25 | 25 |
26 namespace net { | 26 namespace net { |
27 class URLRequestContextGetter; | 27 class URLRequestContextGetter; |
28 } | 28 } |
29 | 29 |
30 struct Geoposition; | |
31 | |
32 // This class is responsible for handling updates from multiple underlying | 30 // This class is responsible for handling updates from multiple underlying |
33 // providers and resolving them to a single 'best' location fix at any given | 31 // providers and resolving them to a single 'best' location fix at any given |
34 // moment. | 32 // moment. |
35 class CONTENT_EXPORT GeolocationArbitrator | 33 class CONTENT_EXPORT GeolocationArbitrator |
36 : public LocationProviderBase::ListenerInterface { | 34 : public LocationProviderBase::ListenerInterface { |
37 public: | 35 public: |
38 // Number of milliseconds newer a location provider has to be that it's worth | 36 // Number of milliseconds newer a location provider has to be that it's worth |
39 // switching to this location provider on the basis of it being fresher | 37 // switching to this location provider on the basis of it being fresher |
40 // (regardles of relative accuracy). Public for tests. | 38 // (regardles of relative accuracy). Public for tests. |
41 static const int64 kFixStaleTimeoutMilliseconds; | 39 static const int64 kFixStaleTimeoutMilliseconds; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // Takes ownership of |provider| on entry; it will either be added to | 75 // Takes ownership of |provider| on entry; it will either be added to |
78 // |providers_| or deleted on error (e.g. it fails to start). | 76 // |providers_| or deleted on error (e.g. it fails to start). |
79 void RegisterProvider(LocationProviderBase* provider); | 77 void RegisterProvider(LocationProviderBase* provider); |
80 void OnAccessTokenStoresLoaded( | 78 void OnAccessTokenStoresLoaded( |
81 content::AccessTokenStore::AccessTokenSet access_token_store, | 79 content::AccessTokenStore::AccessTokenSet access_token_store, |
82 net::URLRequestContextGetter* context_getter); | 80 net::URLRequestContextGetter* context_getter); |
83 void DoStartProviders(); | 81 void DoStartProviders(); |
84 // Returns true if |new_position| is an improvement over |old_position|. | 82 // Returns true if |new_position| is an improvement over |old_position|. |
85 // Set |from_same_provider| to true if both the positions came from the same | 83 // Set |from_same_provider| to true if both the positions came from the same |
86 // provider. | 84 // provider. |
87 bool IsNewPositionBetter(const Geoposition& old_position, | 85 bool IsNewPositionBetter(const content::Geoposition& old_position, |
88 const Geoposition& new_position, | 86 const content::Geoposition& new_position, |
89 bool from_same_provider) const; | 87 bool from_same_provider) const; |
90 | 88 |
91 scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_; | 89 scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_; |
92 scoped_refptr<content::AccessTokenStore> access_token_store_; | 90 scoped_refptr<content::AccessTokenStore> access_token_store_; |
93 GetTimeNow get_time_now_; | 91 GetTimeNow get_time_now_; |
94 GeolocationObserver* observer_; | 92 GeolocationObserver* observer_; |
95 ScopedVector<LocationProviderBase> providers_; | 93 ScopedVector<LocationProviderBase> providers_; |
96 GeolocationObserverOptions current_provider_options_; | 94 GeolocationObserverOptions current_provider_options_; |
97 // The provider which supplied the current |position_| | 95 // The provider which supplied the current |position_| |
98 const LocationProviderBase* position_provider_; | 96 const LocationProviderBase* position_provider_; |
99 bool is_permission_granted_; | 97 bool is_permission_granted_; |
100 // The current best estimate of our position. | 98 // The current best estimate of our position. |
101 Geoposition position_; | 99 content::Geoposition position_; |
102 | 100 |
103 DISALLOW_COPY_AND_ASSIGN(GeolocationArbitrator); | 101 DISALLOW_COPY_AND_ASSIGN(GeolocationArbitrator); |
104 }; | 102 }; |
105 | 103 |
106 #endif // CONTENT_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_H_ | 104 #endif // CONTENT_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_H_ |
OLD | NEW |