Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: content/browser/geolocation/location_arbitrator_impl.h

Issue 2098553002: Geolocation: extract ContentBrowserClient methods specific to Geolocation into a class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changing to ContentBrowserClient::GetGeolocationServiceOverrides and impl'd in the 6 impl's. Unitte… Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Takes ownership of |service_overrides|.
Michael van Ouwerkerk 2016/06/24 13:57:19 I think that a) taking ownership should be express
mcasas 2016/06/24 19:25:52 Yes, I was just lazy -- and I thought I'd be getti
46 LocationArbitratorImpl(
47 const LocationUpdateCallback& callback,
48 GeolocationProvider::ServiceOverrides* service_overrides);
45 ~LocationArbitratorImpl() override; 49 ~LocationArbitratorImpl() override;
46 50
47 static GURL DefaultNetworkProviderURL(); 51 static GURL DefaultNetworkProviderURL();
48 52
49 // LocationArbitrator 53 // LocationArbitrator
50 void StartProviders(bool enable_high_accuracy) override; 54 void StartProviders(bool enable_high_accuracy) override;
51 void StopProviders() override; 55 void StopProviders() override;
52 void OnPermissionGranted() override; 56 void OnPermissionGranted() override;
53 bool HasPermissionBeenGranted() const override; 57 bool HasPermissionBeenGranted() const override;
54 58
55 protected: 59 protected:
56 AccessTokenStore* GetAccessTokenStore(); 60 AccessTokenStore* GetAccessTokenStore();
57 61
58 // These functions are useful for injection of dependencies in derived 62 // These functions are useful for injection of dependencies in derived
59 // testing classes. 63 // testing classes.
60 virtual AccessTokenStore* NewAccessTokenStore(); 64 virtual AccessTokenStore* NewAccessTokenStore();
61 virtual std::unique_ptr<LocationProvider> NewNetworkLocationProvider( 65 virtual std::unique_ptr<LocationProvider> NewNetworkLocationProvider(
62 AccessTokenStore* access_token_store, 66 AccessTokenStore* access_token_store,
63 net::URLRequestContextGetter* context, 67 net::URLRequestContextGetter* context,
64 const GURL& url, 68 const GURL& url,
65 const base::string16& access_token); 69 const base::string16& access_token);
66 virtual std::unique_ptr<LocationProvider> NewSystemLocationProvider(); 70 virtual std::unique_ptr<LocationProvider> NewSystemLocationProvider();
67 virtual base::Time GetTimeNow() const; 71 virtual base::Time GetTimeNow() const;
68 72
73 GeolocationProvider::ServiceOverrides* GetServiceOverridesForTesting() {
74 return service_overrides_.get();
75 }
76
69 private: 77 private:
70 // Provider will either be added to |providers_| or 78 // Provider will either be added to |providers_| or
71 // deleted on error (e.g. it fails to start). 79 // deleted on error (e.g. it fails to start).
72 void RegisterProvider(std::unique_ptr<LocationProvider> provider); 80 void RegisterProvider(std::unique_ptr<LocationProvider> provider);
73 81
74 void RegisterSystemProvider(); 82 void RegisterSystemProvider();
75 void OnAccessTokenStoresLoaded( 83 void OnAccessTokenStoresLoaded(
76 AccessTokenStore::AccessTokenMap access_token_map, 84 AccessTokenStore::AccessTokenMap access_token_map,
77 net::URLRequestContextGetter* context_getter); 85 net::URLRequestContextGetter* context_getter);
78 void DoStartProviders(); 86 void DoStartProviders();
79 87
80 // Gets called when a provider has a new position. 88 // Gets called when a provider has a new position.
81 void OnLocationUpdate(const LocationProvider* provider, 89 void OnLocationUpdate(const LocationProvider* provider,
82 const Geoposition& new_position); 90 const Geoposition& new_position);
83 91
84 // Returns true if |new_position| is an improvement over |old_position|. 92 // 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 93 // Set |from_same_provider| to true if both the positions came from the same
86 // provider. 94 // provider.
87 bool IsNewPositionBetter(const Geoposition& old_position, 95 bool IsNewPositionBetter(const Geoposition& old_position,
88 const Geoposition& new_position, 96 const Geoposition& new_position,
89 bool from_same_provider) const; 97 bool from_same_provider) const;
90 98
99 std::unique_ptr<GeolocationProvider::ServiceOverrides> service_overrides_;
100
91 scoped_refptr<AccessTokenStore> access_token_store_; 101 scoped_refptr<AccessTokenStore> access_token_store_;
92 LocationUpdateCallback arbitrator_update_callback_; 102 LocationUpdateCallback arbitrator_update_callback_;
93 LocationProvider::LocationProviderUpdateCallback provider_update_callback_; 103 LocationProvider::LocationProviderUpdateCallback provider_update_callback_;
94 104
95 // The CancelableCallback will prevent OnAccessTokenStoresLoaded from being 105 // The CancelableCallback will prevent OnAccessTokenStoresLoaded from being
96 // called multiple times by calling Reset() at the time of binding. 106 // called multiple times by calling Reset() at the time of binding.
97 base::CancelableCallback<void(AccessTokenStore::AccessTokenMap, 107 base::CancelableCallback<void(AccessTokenStore::AccessTokenMap,
98 net::URLRequestContextGetter*)> 108 net::URLRequestContextGetter*)>
99 token_store_callback_; 109 token_store_callback_;
100 std::vector<std::unique_ptr<LocationProvider>> providers_; 110 std::vector<std::unique_ptr<LocationProvider>> providers_;
(...skipping 10 matching lines...) Expand all
111 DISALLOW_COPY_AND_ASSIGN(LocationArbitratorImpl); 121 DISALLOW_COPY_AND_ASSIGN(LocationArbitratorImpl);
112 }; 122 };
113 123
114 // Factory functions for the various types of location provider to abstract 124 // Factory functions for the various types of location provider to abstract
115 // over the platform-dependent implementations. 125 // over the platform-dependent implementations.
116 LocationProvider* NewSystemLocationProvider(); 126 LocationProvider* NewSystemLocationProvider();
117 127
118 } // namespace content 128 } // namespace content
119 129
120 #endif // CONTENT_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_IMPL_H_ 130 #endif // CONTENT_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698