| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 static GURL DefaultNetworkProviderURL(); | 50 static GURL DefaultNetworkProviderURL(); |
| 51 | 51 |
| 52 // LocationArbitrator | 52 // LocationArbitrator |
| 53 void StartProviders(bool enable_high_accuracy) override; | 53 void StartProviders(bool enable_high_accuracy) override; |
| 54 void StopProviders() override; | 54 void StopProviders() override; |
| 55 void OnPermissionGranted() override; | 55 void OnPermissionGranted() override; |
| 56 bool HasPermissionBeenGranted() const override; | 56 bool HasPermissionBeenGranted() const override; |
| 57 | 57 |
| 58 protected: | 58 protected: |
| 59 AccessTokenStore* GetAccessTokenStore(); | |
| 60 | |
| 61 // These functions are useful for injection of dependencies in derived | 59 // These functions are useful for injection of dependencies in derived |
| 62 // testing classes. | 60 // testing classes. |
| 63 virtual AccessTokenStore* NewAccessTokenStore(); | 61 virtual scoped_refptr<AccessTokenStore> NewAccessTokenStore(); |
| 64 virtual std::unique_ptr<LocationProvider> NewNetworkLocationProvider( | 62 virtual std::unique_ptr<LocationProvider> NewNetworkLocationProvider( |
| 65 AccessTokenStore* access_token_store, | 63 const scoped_refptr<AccessTokenStore>& access_token_store, |
| 66 net::URLRequestContextGetter* context, | 64 const scoped_refptr<net::URLRequestContextGetter>& context, |
| 67 const GURL& url, | 65 const GURL& url, |
| 68 const base::string16& access_token); | 66 const base::string16& access_token); |
| 69 virtual std::unique_ptr<LocationProvider> NewSystemLocationProvider(); | 67 virtual std::unique_ptr<LocationProvider> NewSystemLocationProvider(); |
| 70 virtual base::Time GetTimeNow() const; | 68 virtual base::Time GetTimeNow() const; |
| 71 | 69 |
| 72 private: | 70 private: |
| 73 friend class TestingLocationArbitrator; | 71 friend class TestingLocationArbitrator; |
| 74 | 72 |
| 73 scoped_refptr<AccessTokenStore> GetAccessTokenStore(); |
| 74 |
| 75 // Provider will either be added to |providers_| or | 75 // Provider will either be added to |providers_| or |
| 76 // deleted on error (e.g. it fails to start). | 76 // deleted on error (e.g. it fails to start). |
| 77 void RegisterProvider(std::unique_ptr<LocationProvider> provider); | 77 void RegisterProvider(std::unique_ptr<LocationProvider> provider); |
| 78 | 78 |
| 79 void RegisterSystemProvider(); | 79 void RegisterSystemProvider(); |
| 80 void OnAccessTokenStoresLoaded( | 80 void OnAccessTokenStoresLoaded( |
| 81 AccessTokenStore::AccessTokenMap access_token_map, | 81 AccessTokenStore::AccessTokenMap access_token_map, |
| 82 net::URLRequestContextGetter* context_getter); | 82 const scoped_refptr<net::URLRequestContextGetter>& context_getter); |
| 83 void DoStartProviders(); | 83 void DoStartProviders(); |
| 84 | 84 |
| 85 // Gets called when a provider has a new position. | 85 // Gets called when a provider has a new position. |
| 86 void OnLocationUpdate(const LocationProvider* provider, | 86 void OnLocationUpdate(const LocationProvider* provider, |
| 87 const Geoposition& new_position); | 87 const Geoposition& new_position); |
| 88 | 88 |
| 89 // Returns true if |new_position| is an improvement over |old_position|. | 89 // Returns true if |new_position| is an improvement over |old_position|. |
| 90 // 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 |
| 91 // provider. | 91 // provider. |
| 92 bool IsNewPositionBetter(const Geoposition& old_position, | 92 bool IsNewPositionBetter(const Geoposition& old_position, |
| 93 const Geoposition& new_position, | 93 const Geoposition& new_position, |
| 94 bool from_same_provider) const; | 94 bool from_same_provider) const; |
| 95 | 95 |
| 96 GeolocationDelegate* delegate_; | 96 GeolocationDelegate* delegate_; |
| 97 | 97 |
| 98 scoped_refptr<AccessTokenStore> access_token_store_; | 98 scoped_refptr<AccessTokenStore> access_token_store_; |
| 99 LocationUpdateCallback arbitrator_update_callback_; | 99 LocationUpdateCallback arbitrator_update_callback_; |
| 100 LocationProvider::LocationProviderUpdateCallback provider_update_callback_; | 100 LocationProvider::LocationProviderUpdateCallback provider_update_callback_; |
| 101 | 101 |
| 102 // The CancelableCallback will prevent OnAccessTokenStoresLoaded from being | 102 // The CancelableCallback will prevent OnAccessTokenStoresLoaded from being |
| 103 // called multiple times by calling Reset() at the time of binding. | 103 // called multiple times by calling Reset() at the time of binding. |
| 104 base::CancelableCallback<void(AccessTokenStore::AccessTokenMap, | 104 base::CancelableCallback<void( |
| 105 net::URLRequestContextGetter*)> | 105 AccessTokenStore::AccessTokenMap, |
| 106 const scoped_refptr<net::URLRequestContextGetter>&)> |
| 106 token_store_callback_; | 107 token_store_callback_; |
| 107 std::vector<std::unique_ptr<LocationProvider>> providers_; | 108 std::vector<std::unique_ptr<LocationProvider>> providers_; |
| 108 bool enable_high_accuracy_; | 109 bool enable_high_accuracy_; |
| 109 // The provider which supplied the current |position_| | 110 // The provider which supplied the current |position_| |
| 110 const LocationProvider* position_provider_; | 111 const LocationProvider* position_provider_; |
| 111 bool is_permission_granted_; | 112 bool is_permission_granted_; |
| 112 // The current best estimate of our position. | 113 // The current best estimate of our position. |
| 113 Geoposition position_; | 114 Geoposition position_; |
| 114 | 115 |
| 115 // Tracks whether providers should be running. | 116 // Tracks whether providers should be running. |
| 116 bool is_running_; | 117 bool is_running_; |
| 117 | 118 |
| 118 DISALLOW_COPY_AND_ASSIGN(LocationArbitratorImpl); | 119 DISALLOW_COPY_AND_ASSIGN(LocationArbitratorImpl); |
| 119 }; | 120 }; |
| 120 | 121 |
| 121 // Factory functions for the various types of location provider to abstract | 122 // Factory functions for the various types of location provider to abstract |
| 122 // over the platform-dependent implementations. | 123 // over the platform-dependent implementations. |
| 123 LocationProvider* NewSystemLocationProvider(); | 124 std::unique_ptr<LocationProvider> NewSystemLocationProvider(); |
| 124 | 125 |
| 125 } // namespace content | 126 } // namespace content |
| 126 | 127 |
| 127 #endif // CONTENT_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_IMPL_H_ | 128 #endif // CONTENT_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_IMPL_H_ |
| OLD | NEW |