| 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_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_IMPL_H_ |
| 6 #define CONTENT_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_IMPL_H_ | 6 #define CONTENT_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "content/public/browser/location_provider.h" | 21 #include "content/public/browser/location_provider.h" |
| 22 #include "content/public/common/geoposition.h" | 22 #include "content/public/common/geoposition.h" |
| 23 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
| 24 | 24 |
| 25 namespace net { | 25 namespace net { |
| 26 class URLRequestContextGetter; | 26 class URLRequestContextGetter; |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 class AccessTokenStore; | 30 class AccessTokenStore; |
| 31 class GeolocationDelegate; |
| 31 class LocationProvider; | 32 class LocationProvider; |
| 32 | 33 |
| 33 // This class is responsible for handling updates from multiple underlying | 34 // This class is responsible for handling updates from multiple underlying |
| 34 // providers and resolving them to a single 'best' location fix at any given | 35 // providers and resolving them to a single 'best' location fix at any given |
| 35 // moment. | 36 // moment. |
| 36 class CONTENT_EXPORT LocationArbitratorImpl : public LocationArbitrator { | 37 class CONTENT_EXPORT LocationArbitratorImpl : public LocationArbitrator { |
| 37 public: | 38 public: |
| 38 // Number of milliseconds newer a location provider has to be that it's worth | 39 // 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 | 40 // switching to this location provider on the basis of it being fresher |
| 40 // (regardles of relative accuracy). Public for tests. | 41 // (regardles of relative accuracy). Public for tests. |
| 41 static const int64_t kFixStaleTimeoutMilliseconds; | 42 static const int64_t kFixStaleTimeoutMilliseconds; |
| 42 | 43 |
| 43 typedef base::Callback<void(const Geoposition&)> LocationUpdateCallback; | 44 typedef base::Callback<void(const Geoposition&)> LocationUpdateCallback; |
| 44 | 45 |
| 45 LocationArbitratorImpl(const LocationUpdateCallback& callback, | 46 LocationArbitratorImpl(const LocationUpdateCallback& callback, |
| 46 GeolocationProvider::Delegate* delegate); | 47 GeolocationDelegate* delegate); |
| 47 ~LocationArbitratorImpl() override; | 48 ~LocationArbitratorImpl() override; |
| 48 | 49 |
| 49 static GURL DefaultNetworkProviderURL(); | 50 static GURL DefaultNetworkProviderURL(); |
| 50 | 51 |
| 51 // LocationArbitrator | 52 // LocationArbitrator |
| 52 void StartProviders(bool enable_high_accuracy) override; | 53 void StartProviders(bool enable_high_accuracy) override; |
| 53 void StopProviders() override; | 54 void StopProviders() override; |
| 54 void OnPermissionGranted() override; | 55 void OnPermissionGranted() override; |
| 55 bool HasPermissionBeenGranted() const override; | 56 bool HasPermissionBeenGranted() const override; |
| 56 | 57 |
| 57 protected: | 58 protected: |
| 58 AccessTokenStore* GetAccessTokenStore(); | 59 AccessTokenStore* GetAccessTokenStore(); |
| 59 | 60 |
| 60 // These functions are useful for injection of dependencies in derived | 61 // These functions are useful for injection of dependencies in derived |
| 61 // testing classes. | 62 // testing classes. |
| 62 virtual AccessTokenStore* NewAccessTokenStore(); | 63 virtual AccessTokenStore* NewAccessTokenStore(); |
| 63 virtual std::unique_ptr<LocationProvider> NewNetworkLocationProvider( | 64 virtual std::unique_ptr<LocationProvider> NewNetworkLocationProvider( |
| 64 AccessTokenStore* access_token_store, | 65 AccessTokenStore* access_token_store, |
| 65 net::URLRequestContextGetter* context, | 66 net::URLRequestContextGetter* context, |
| 66 const GURL& url, | 67 const GURL& url, |
| 67 const base::string16& access_token); | 68 const base::string16& access_token); |
| 68 virtual std::unique_ptr<LocationProvider> NewSystemLocationProvider(); | 69 virtual std::unique_ptr<LocationProvider> NewSystemLocationProvider(); |
| 69 virtual base::Time GetTimeNow() const; | 70 virtual base::Time GetTimeNow() const; |
| 70 | 71 |
| 71 GeolocationProvider::Delegate* GetDelegateForTesting() { return delegate_; } | 72 GeolocationDelegate* GetDelegateForTesting() { return delegate_; } |
| 72 | 73 |
| 73 private: | 74 private: |
| 74 // Provider will either be added to |providers_| or | 75 // Provider will either be added to |providers_| or |
| 75 // deleted on error (e.g. it fails to start). | 76 // deleted on error (e.g. it fails to start). |
| 76 void RegisterProvider(std::unique_ptr<LocationProvider> provider); | 77 void RegisterProvider(std::unique_ptr<LocationProvider> provider); |
| 77 | 78 |
| 78 void RegisterSystemProvider(); | 79 void RegisterSystemProvider(); |
| 79 void OnAccessTokenStoresLoaded( | 80 void OnAccessTokenStoresLoaded( |
| 80 AccessTokenStore::AccessTokenMap access_token_map, | 81 AccessTokenStore::AccessTokenMap access_token_map, |
| 81 net::URLRequestContextGetter* context_getter); | 82 net::URLRequestContextGetter* context_getter); |
| 82 void DoStartProviders(); | 83 void DoStartProviders(); |
| 83 | 84 |
| 84 // Gets called when a provider has a new position. | 85 // Gets called when a provider has a new position. |
| 85 void OnLocationUpdate(const LocationProvider* provider, | 86 void OnLocationUpdate(const LocationProvider* provider, |
| 86 const Geoposition& new_position); | 87 const Geoposition& new_position); |
| 87 | 88 |
| 88 // Returns true if |new_position| is an improvement over |old_position|. | 89 // Returns true if |new_position| is an improvement over |old_position|. |
| 89 // Set |from_same_provider| to true if both the positions came from the same | 90 // Set |from_same_provider| to true if both the positions came from the same |
| 90 // provider. | 91 // provider. |
| 91 bool IsNewPositionBetter(const Geoposition& old_position, | 92 bool IsNewPositionBetter(const Geoposition& old_position, |
| 92 const Geoposition& new_position, | 93 const Geoposition& new_position, |
| 93 bool from_same_provider) const; | 94 bool from_same_provider) const; |
| 94 | 95 |
| 95 GeolocationProvider::Delegate* delegate_; | 96 GeolocationDelegate* delegate_; |
| 96 | 97 |
| 97 scoped_refptr<AccessTokenStore> access_token_store_; | 98 scoped_refptr<AccessTokenStore> access_token_store_; |
| 98 LocationUpdateCallback arbitrator_update_callback_; | 99 LocationUpdateCallback arbitrator_update_callback_; |
| 99 LocationProvider::LocationProviderUpdateCallback provider_update_callback_; | 100 LocationProvider::LocationProviderUpdateCallback provider_update_callback_; |
| 100 | 101 |
| 101 // The CancelableCallback will prevent OnAccessTokenStoresLoaded from being | 102 // The CancelableCallback will prevent OnAccessTokenStoresLoaded from being |
| 102 // called multiple times by calling Reset() at the time of binding. | 103 // called multiple times by calling Reset() at the time of binding. |
| 103 base::CancelableCallback<void(AccessTokenStore::AccessTokenMap, | 104 base::CancelableCallback<void(AccessTokenStore::AccessTokenMap, |
| 104 net::URLRequestContextGetter*)> | 105 net::URLRequestContextGetter*)> |
| 105 token_store_callback_; | 106 token_store_callback_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 117 DISALLOW_COPY_AND_ASSIGN(LocationArbitratorImpl); | 118 DISALLOW_COPY_AND_ASSIGN(LocationArbitratorImpl); |
| 118 }; | 119 }; |
| 119 | 120 |
| 120 // Factory functions for the various types of location provider to abstract | 121 // Factory functions for the various types of location provider to abstract |
| 121 // over the platform-dependent implementations. | 122 // over the platform-dependent implementations. |
| 122 LocationProvider* NewSystemLocationProvider(); | 123 LocationProvider* NewSystemLocationProvider(); |
| 123 | 124 |
| 124 } // namespace content | 125 } // namespace content |
| 125 | 126 |
| 126 #endif // CONTENT_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_IMPL_H_ | 127 #endif // CONTENT_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_IMPL_H_ |
| OLD | NEW |