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

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

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 #include "content/browser/geolocation/location_arbitrator_impl.h" 5 #include "content/browser/geolocation/location_arbitrator_impl.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "content/browser/geolocation/network_location_provider.h" 13 #include "content/browser/geolocation/network_location_provider.h"
14 #include "content/public/browser/access_token_store.h" 14 #include "content/public/browser/access_token_store.h"
15 #include "content/public/browser/content_browser_client.h"
16 #include "content/public/common/content_client.h" 15 #include "content/public/common/content_client.h"
17 #include "url/gurl.h" 16 #include "url/gurl.h"
18 17
19 namespace content { 18 namespace content {
20 namespace { 19 namespace {
21 20
22 const char* kDefaultNetworkProviderUrl = 21 const char* kDefaultNetworkProviderUrl =
23 "https://www.googleapis.com/geolocation/v1/geolocate"; 22 "https://www.googleapis.com/geolocation/v1/geolocate";
24 } // namespace 23 } // namespace
25 24
26 // To avoid oscillations, set this to twice the expected update interval of a 25 // To avoid oscillations, set this to twice the expected update interval of a
27 // a GPS-type location provider (in case it misses a beat) plus a little. 26 // a GPS-type location provider (in case it misses a beat) plus a little.
28 const int64_t LocationArbitratorImpl::kFixStaleTimeoutMilliseconds = 27 const int64_t LocationArbitratorImpl::kFixStaleTimeoutMilliseconds =
29 11 * base::Time::kMillisecondsPerSecond; 28 11 * base::Time::kMillisecondsPerSecond;
30 29
31 LocationArbitratorImpl::LocationArbitratorImpl( 30 LocationArbitratorImpl::LocationArbitratorImpl(
32 const LocationUpdateCallback& callback) 31 const LocationUpdateCallback& callback,
33 : arbitrator_update_callback_(callback), 32 GeolocationProvider::ServiceOverrides* service_overrides)
33 : service_overrides_(service_overrides),
34 arbitrator_update_callback_(callback),
34 provider_update_callback_( 35 provider_update_callback_(
35 base::Bind(&LocationArbitratorImpl::OnLocationUpdate, 36 base::Bind(&LocationArbitratorImpl::OnLocationUpdate,
36 base::Unretained(this))), 37 base::Unretained(this))),
37 position_provider_(NULL), 38 position_provider_(NULL),
38 is_permission_granted_(false), 39 is_permission_granted_(false),
39 is_running_(false) { 40 is_running_(false) {}
40 }
41 41
42 LocationArbitratorImpl::~LocationArbitratorImpl() { 42 LocationArbitratorImpl::~LocationArbitratorImpl() {
43 } 43 }
44 44
45 GURL LocationArbitratorImpl::DefaultNetworkProviderURL() { 45 GURL LocationArbitratorImpl::DefaultNetworkProviderURL() {
46 return GURL(kDefaultNetworkProviderUrl); 46 return GURL(kDefaultNetworkProviderUrl);
47 } 47 }
48 48
49 void LocationArbitratorImpl::OnPermissionGranted() { 49 void LocationArbitratorImpl::OnPermissionGranted() {
50 is_permission_granted_ = true; 50 is_permission_granted_ = true;
51 for (const auto& provider : providers_) 51 for (const auto& provider : providers_)
52 provider->OnPermissionGranted(); 52 provider->OnPermissionGranted();
53 } 53 }
54 54
55 void LocationArbitratorImpl::StartProviders(bool enable_high_accuracy) { 55 void LocationArbitratorImpl::StartProviders(bool enable_high_accuracy) {
56 // Stash options as OnAccessTokenStoresLoaded has not yet been called. 56 // Stash options as OnAccessTokenStoresLoaded has not yet been called.
57 is_running_ = true; 57 is_running_ = true;
58 enable_high_accuracy_ = enable_high_accuracy; 58 enable_high_accuracy_ = enable_high_accuracy;
59 59
60 if (providers_.empty()) { 60 if (providers_.empty()) {
61 RegisterSystemProvider(); 61 RegisterSystemProvider();
62 62
63 AccessTokenStore* access_token_store = GetAccessTokenStore(); 63 AccessTokenStore* access_token_store = GetAccessTokenStore();
64 if (access_token_store && 64 if (access_token_store &&
65 GetContentClient()->browser()->UseNetworkLocationProviders()) { 65 service_overrides_->UseNetworkLocationProviders()) {
66 DCHECK(DefaultNetworkProviderURL().is_valid()); 66 DCHECK(DefaultNetworkProviderURL().is_valid());
67 token_store_callback_.Reset( 67 token_store_callback_.Reset(
68 base::Bind(&LocationArbitratorImpl::OnAccessTokenStoresLoaded, 68 base::Bind(&LocationArbitratorImpl::OnAccessTokenStoresLoaded,
69 base::Unretained(this))); 69 base::Unretained(this)));
70 access_token_store->LoadAccessTokens(token_store_callback_.callback()); 70 access_token_store->LoadAccessTokens(token_store_callback_.callback());
71 return; 71 return;
72 } 72 }
73 } 73 }
74 DoStartProviders(); 74 DoStartProviders();
75 } 75 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 std::unique_ptr<LocationProvider> provider) { 115 std::unique_ptr<LocationProvider> provider) {
116 if (!provider) 116 if (!provider)
117 return; 117 return;
118 provider->SetUpdateCallback(provider_update_callback_); 118 provider->SetUpdateCallback(provider_update_callback_);
119 if (is_permission_granted_) 119 if (is_permission_granted_)
120 provider->OnPermissionGranted(); 120 provider->OnPermissionGranted();
121 providers_.push_back(std::move(provider)); 121 providers_.push_back(std::move(provider));
122 } 122 }
123 123
124 void LocationArbitratorImpl::RegisterSystemProvider() { 124 void LocationArbitratorImpl::RegisterSystemProvider() {
125 std::unique_ptr<LocationProvider> provider = base::WrapUnique( 125 std::unique_ptr<LocationProvider> provider =
126 GetContentClient()->browser()->OverrideSystemLocationProvider()); 126 base::WrapUnique(service_overrides_->OverrideSystemLocationProvider());
127 if (!provider) 127 if (!provider)
128 provider = NewSystemLocationProvider(); 128 provider = NewSystemLocationProvider();
129 RegisterProvider(std::move(provider)); 129 RegisterProvider(std::move(provider));
130 } 130 }
131 131
132 void LocationArbitratorImpl::OnLocationUpdate(const LocationProvider* provider, 132 void LocationArbitratorImpl::OnLocationUpdate(const LocationProvider* provider,
133 const Geoposition& new_position) { 133 const Geoposition& new_position) {
134 DCHECK(new_position.Validate() || 134 DCHECK(new_position.Validate() ||
135 new_position.error_code != Geoposition::ERROR_CODE_NONE); 135 new_position.error_code != Geoposition::ERROR_CODE_NONE);
136 if (!IsNewPositionBetter(position_, new_position, 136 if (!IsNewPositionBetter(position_, new_position,
137 provider == position_provider_)) 137 provider == position_provider_))
138 return; 138 return;
139 position_provider_ = provider; 139 position_provider_ = provider;
140 position_ = new_position; 140 position_ = new_position;
141 arbitrator_update_callback_.Run(position_); 141 arbitrator_update_callback_.Run(position_);
142 } 142 }
143 143
144 AccessTokenStore* LocationArbitratorImpl::NewAccessTokenStore() { 144 AccessTokenStore* LocationArbitratorImpl::NewAccessTokenStore() {
145 return GetContentClient()->browser()->CreateAccessTokenStore(); 145 return service_overrides_->CreateAccessTokenStore();
146 } 146 }
147 147
148 AccessTokenStore* LocationArbitratorImpl::GetAccessTokenStore() { 148 AccessTokenStore* LocationArbitratorImpl::GetAccessTokenStore() {
149 if (!access_token_store_.get()) 149 if (!access_token_store_.get())
150 access_token_store_ = NewAccessTokenStore(); 150 access_token_store_ = NewAccessTokenStore();
151 return access_token_store_.get(); 151 return access_token_store_.get();
152 } 152 }
153 153
154 std::unique_ptr<LocationProvider> 154 std::unique_ptr<LocationProvider>
155 LocationArbitratorImpl::NewNetworkLocationProvider( 155 LocationArbitratorImpl::NewNetworkLocationProvider(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } 203 }
204 } 204 }
205 return false; 205 return false;
206 } 206 }
207 207
208 bool LocationArbitratorImpl::HasPermissionBeenGranted() const { 208 bool LocationArbitratorImpl::HasPermissionBeenGranted() const {
209 return is_permission_granted_; 209 return is_permission_granted_;
210 } 210 }
211 211
212 } // namespace content 212 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698