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

Side by Side Diff: device/geolocation/location_arbitrator_impl.cc

Issue 2226143002: Gets rid of the LocationArbitrator interface, in preference for LocationProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removes LocationArbitrator.h Created 4 years, 4 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 "device/geolocation/location_arbitrator_impl.h" 5 #include "device/geolocation/location_arbitrator_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory>
9 #include <utility>
8 10
9 #include "base/bind.h" 11 #include "base/bind.h"
10 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
11 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
12 #include "build/build_config.h" 14 #include "build/build_config.h"
13 #include "device/geolocation/access_token_store.h" 15 #include "device/geolocation/access_token_store.h"
14 #include "device/geolocation/geolocation_delegate.h" 16 #include "device/geolocation/geolocation_delegate.h"
15 #include "device/geolocation/network_location_provider.h" 17 #include "device/geolocation/network_location_provider.h"
16 #include "url/gurl.h" 18 #include "url/gurl.h"
17 19
(...skipping 26 matching lines...) Expand all
44 GURL LocationArbitratorImpl::DefaultNetworkProviderURL() { 46 GURL LocationArbitratorImpl::DefaultNetworkProviderURL() {
45 return GURL(kDefaultNetworkProviderUrl); 47 return GURL(kDefaultNetworkProviderUrl);
46 } 48 }
47 49
48 void LocationArbitratorImpl::OnPermissionGranted() { 50 void LocationArbitratorImpl::OnPermissionGranted() {
49 is_permission_granted_ = true; 51 is_permission_granted_ = true;
50 for (const auto& provider : providers_) 52 for (const auto& provider : providers_)
51 provider->OnPermissionGranted(); 53 provider->OnPermissionGranted();
52 } 54 }
53 55
54 void LocationArbitratorImpl::StartProviders(bool enable_high_accuracy) { 56 bool LocationArbitratorImpl::StartProvider(bool enable_high_accuracy) {
55 // Stash options as OnAccessTokenStoresLoaded has not yet been called. 57 // Stash options as OnAccessTokenStoresLoaded has not yet been called.
56 is_running_ = true; 58 is_running_ = true;
57 enable_high_accuracy_ = enable_high_accuracy; 59 enable_high_accuracy_ = enable_high_accuracy;
58 60
59 if (providers_.empty()) { 61 if (providers_.empty()) {
60 RegisterSystemProvider(); 62 RegisterSystemProvider();
61 63
62 const scoped_refptr<AccessTokenStore> access_token_store = 64 const scoped_refptr<AccessTokenStore> access_token_store =
63 GetAccessTokenStore(); 65 GetAccessTokenStore();
64 if (access_token_store && delegate_->UseNetworkLocationProviders()) { 66 if (access_token_store && delegate_->UseNetworkLocationProviders()) {
65 DCHECK(DefaultNetworkProviderURL().is_valid()); 67 DCHECK(DefaultNetworkProviderURL().is_valid());
66 token_store_callback_.Reset( 68 token_store_callback_.Reset(
67 base::Bind(&LocationArbitratorImpl::OnAccessTokenStoresLoaded, 69 base::Bind(&LocationArbitratorImpl::OnAccessTokenStoresLoaded,
68 base::Unretained(this))); 70 base::Unretained(this)));
69 access_token_store->LoadAccessTokens(token_store_callback_.callback()); 71 access_token_store->LoadAccessTokens(token_store_callback_.callback());
70 return; 72 return true;
71 } 73 }
72 } 74 }
73 DoStartProviders(); 75 DoStartProviders();
Wez 2016/08/09 01:17:04 Looks like it might be worthwhile to have DoStartP
CJ 2016/08/11 22:06:43 Done.
76 return true;
74 } 77 }
75 78
76 void LocationArbitratorImpl::DoStartProviders() { 79 void LocationArbitratorImpl::DoStartProviders() {
77 if (providers_.empty()) { 80 if (providers_.empty()) {
78 // If no providers are available, we report an error to avoid 81 // If no providers are available, we report an error to avoid
79 // callers waiting indefinitely for a reply. 82 // callers waiting indefinitely for a reply.
80 Geoposition position; 83 Geoposition position;
81 position.error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED; 84 position.error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED;
82 arbitrator_update_callback_.Run(position); 85 arbitrator_update_callback_.Run(position);
83 return; 86 return;
84 } 87 }
85 for (const auto& provider : providers_) 88 for (const auto& provider : providers_)
86 provider->StartProvider(enable_high_accuracy_); 89 provider->StartProvider(enable_high_accuracy_);
87 } 90 }
88 91
89 void LocationArbitratorImpl::StopProviders() { 92 void LocationArbitratorImpl::StopProvider() {
90 // Reset the reference location state (provider+position) 93 // Reset the reference location state (provider+position)
91 // so that future starts use fresh locations from 94 // so that future starts use fresh locations from
92 // the newly constructed providers. 95 // the newly constructed providers.
93 position_provider_ = nullptr; 96 position_provider_ = nullptr;
94 position_ = Geoposition(); 97 position_ = Geoposition();
95 98
96 providers_.clear(); 99 providers_.clear();
97 is_running_ = false; 100 is_running_ = false;
98 } 101 }
99 102
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 DCHECK(new_position.Validate() || 136 DCHECK(new_position.Validate() ||
134 new_position.error_code != Geoposition::ERROR_CODE_NONE); 137 new_position.error_code != Geoposition::ERROR_CODE_NONE);
135 if (!IsNewPositionBetter(position_, new_position, 138 if (!IsNewPositionBetter(position_, new_position,
136 provider == position_provider_)) 139 provider == position_provider_))
137 return; 140 return;
138 position_provider_ = provider; 141 position_provider_ = provider;
139 position_ = new_position; 142 position_ = new_position;
140 arbitrator_update_callback_.Run(position_); 143 arbitrator_update_callback_.Run(position_);
141 } 144 }
142 145
146 void LocationArbitratorImpl::RequestRefresh() {
147 if (is_permission_granted_) {
148 for (const auto& provider : providers_)
149 provider->RequestRefresh();
Wez 2016/08/09 01:17:04 nit: Interesting that there are no other RequestRe
CJ 2016/08/11 22:06:43 Done.
150 }
151 }
152
153 void LocationArbitratorImpl::GetPosition(Geoposition* position) {
154 DCHECK(position);
Wez 2016/08/09 01:17:04 nit: No need to DCHECK - you're about to assign to
CJ 2016/08/11 22:06:43 Done.
155 position = &position_;
Wez 2016/08/09 01:17:04 This isn't doing what you intend. You're setting
CJ 2016/08/11 22:06:43 Done.
156 }
157
158 void LocationArbitratorImpl::SetUpdateCallback(
159 const LocationProviderUpdateCallback& callback) {
160 provider_update_callback_ = callback;
161 }
162
143 scoped_refptr<AccessTokenStore> LocationArbitratorImpl::NewAccessTokenStore() { 163 scoped_refptr<AccessTokenStore> LocationArbitratorImpl::NewAccessTokenStore() {
144 return delegate_->CreateAccessTokenStore(); 164 return delegate_->CreateAccessTokenStore();
145 } 165 }
146 166
147 scoped_refptr<AccessTokenStore> LocationArbitratorImpl::GetAccessTokenStore() { 167 scoped_refptr<AccessTokenStore> LocationArbitratorImpl::GetAccessTokenStore() {
148 if (!access_token_store_) 168 if (!access_token_store_)
149 access_token_store_ = NewAccessTokenStore(); 169 access_token_store_ = NewAccessTokenStore();
150 return access_token_store_; 170 return access_token_store_;
151 } 171 }
152 172
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } 223 }
204 } 224 }
205 return false; 225 return false;
206 } 226 }
207 227
208 bool LocationArbitratorImpl::HasPermissionBeenGranted() const { 228 bool LocationArbitratorImpl::HasPermissionBeenGranted() const {
209 return is_permission_granted_; 229 return is_permission_granted_;
210 } 230 }
211 231
212 } // namespace device 232 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698