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