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

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

Issue 2028823002: Refactor to make BlimpLocationProvider accessible to content layer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses kmarshall's and mvanouwerkerk's comments + code clean up 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"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 return GURL(kDefaultNetworkProviderUrl); 45 return GURL(kDefaultNetworkProviderUrl);
46 } 46 }
47 47
48 void LocationArbitratorImpl::OnPermissionGranted() { 48 void LocationArbitratorImpl::OnPermissionGranted() {
49 is_permission_granted_ = true; 49 is_permission_granted_ = true;
50 for (const auto& provider : providers_) 50 for (const auto& provider : providers_)
51 provider->OnPermissionGranted(); 51 provider->OnPermissionGranted();
52 } 52 }
53 53
54 void LocationArbitratorImpl::StartProviders(bool enable_high_accuracy) { 54 void LocationArbitratorImpl::StartProviders(bool enable_high_accuracy) {
55 // GetAccessTokenStore() will return NULL for embedders not implementing
56 // the AccessTokenStore class, so we report an error to avoid JavaScript
57 // requests of location to wait eternally for a reply.
58 AccessTokenStore* access_token_store = GetAccessTokenStore();
59 if (!access_token_store) {
60 Geoposition position;
61 position.error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED;
62 arbitrator_update_callback_.Run(position);
63 return;
64 }
65
66 // Stash options as OnAccessTokenStoresLoaded has not yet been called. 55 // Stash options as OnAccessTokenStoresLoaded has not yet been called.
67 is_running_ = true; 56 is_running_ = true;
68 enable_high_accuracy_ = enable_high_accuracy; 57 enable_high_accuracy_ = enable_high_accuracy;
58
69 if (providers_.empty()) { 59 if (providers_.empty()) {
70 DCHECK(DefaultNetworkProviderURL().is_valid()); 60 if (GetContentClient()->browser()->UseNetworkLocationProviders()) {
71 access_token_store->LoadAccessTokens( 61 // GetAccessTokenStore() will return NULL for embedders not implementing
72 base::Bind(&LocationArbitratorImpl::OnAccessTokenStoresLoaded, 62 // the AccessTokenStore class, so we report an error to avoid JavaScript
73 base::Unretained(this))); 63 // requests of location to wait eternally for a reply.
64 AccessTokenStore* access_token_store = GetAccessTokenStore();
65 if (!access_token_store) {
66 Geoposition position;
67 position.error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED;
68 arbitrator_update_callback_.Run(position);
69 return;
Kevin M 2016/06/09 20:36:44 What about loading the system providers instead of
CJ 2016/06/09 23:07:06 Done.
70 }
71 DCHECK(DefaultNetworkProviderURL().is_valid());
72 access_token_store->LoadAccessTokens(
73 base::Bind(&LocationArbitratorImpl::OnAccessTokenStoresLoaded,
74 base::Unretained(this)));
75 } else {
Kevin M 2016/06/09 20:36:44 Should this be an "else"? Aren't the network locat
CJ 2016/06/09 23:07:06 Done.
76 RegisterSystemProvider();
77 }
74 } else { 78 } else {
75 DoStartProviders(); 79 DoStartProviders();
76 } 80 }
77 } 81 }
78 82
79 void LocationArbitratorImpl::DoStartProviders() { 83 void LocationArbitratorImpl::DoStartProviders() {
80 for (const auto& provider : providers_) 84 for (const auto& provider : providers_)
81 provider->StartProvider(enable_high_accuracy_); 85 provider->StartProvider(enable_high_accuracy_);
82 } 86 }
83 87
84 void LocationArbitratorImpl::StopProviders() { 88 void LocationArbitratorImpl::StopProviders() {
85 // Reset the reference location state (provider+position) 89 // Reset the reference location state (provider+position)
86 // so that future starts use fresh locations from 90 // so that future starts use fresh locations from
87 // the newly constructed providers. 91 // the newly constructed providers.
88 position_provider_ = NULL; 92 position_provider_ = NULL;
89 position_ = Geoposition(); 93 position_ = Geoposition();
90 94
91 providers_.clear(); 95 providers_.clear();
92 is_running_ = false; 96 is_running_ = false;
93 } 97 }
94 98
99 void LocationArbitratorImpl::RegisterSystemProvider() {
Michael van Ouwerkerk 2016/06/09 13:03:10 Please keep the same order as in the header, so th
CJ 2016/06/09 20:31:50 Done.
100 LocationProvider* provider =
101 GetContentClient()->browser()->OverrideSystemLocationProvider();
102 if (!provider)
103 provider = NewSystemLocationProvider();
104 RegisterProvider(provider);
105 DoStartProviders();
Michael van Ouwerkerk 2016/06/09 13:03:10 I don't think DoStartProviders should be called fo
CJ 2016/06/09 20:31:50 Done.
106 }
107
95 void LocationArbitratorImpl::OnAccessTokenStoresLoaded( 108 void LocationArbitratorImpl::OnAccessTokenStoresLoaded(
96 AccessTokenStore::AccessTokenMap access_token_map, 109 AccessTokenStore::AccessTokenMap access_token_map,
97 net::URLRequestContextGetter* context_getter) { 110 net::URLRequestContextGetter* context_getter) {
98 if (!is_running_ || !providers_.empty()) { 111 if (!is_running_ || !providers_.empty()) {
99 // A second StartProviders() call may have arrived before the first 112 // A second StartProviders() call may have arrived before the first
100 // completed. 113 // completed.
101 return; 114 return;
102 } 115 }
103 LocationProvider* sole_provider = 116 if (GetContentClient()->browser()->UseNetworkLocationProviders()) {
104 GetContentClient()->browser()->SoleLocationProvider();
105 if (!sole_provider) {
106 // If there are no access tokens, boot strap it with the default server URL. 117 // If there are no access tokens, boot strap it with the default server URL.
107 if (access_token_map.empty()) 118 if (access_token_map.empty())
108 access_token_map[DefaultNetworkProviderURL()]; 119 access_token_map[DefaultNetworkProviderURL()];
109 for (const auto& entry : access_token_map) { 120 for (const auto& entry : access_token_map) {
110 RegisterProvider(NewNetworkLocationProvider( 121 RegisterProvider(NewNetworkLocationProvider(
111 GetAccessTokenStore(), context_getter, entry.first, entry.second)); 122 GetAccessTokenStore(), context_getter, entry.first, entry.second));
112 } 123 }
113
114 LocationProvider* provider =
115 GetContentClient()->browser()->OverrideSystemLocationProvider();
116 if (!provider)
117 provider = NewSystemLocationProvider();
118 RegisterProvider(provider);
119 } else {
120 RegisterProvider(sole_provider);
121 } 124 }
122 DoStartProviders(); 125 RegisterSystemProvider();
Kevin M 2016/06/09 20:36:44 Do we need to register system providers in this ca
CJ 2016/06/09 23:07:06 Done.
123 } 126 }
124 127
125 void LocationArbitratorImpl::RegisterProvider( 128 void LocationArbitratorImpl::RegisterProvider(
126 LocationProvider* provider) { 129 LocationProvider* provider) {
127 if (!provider) 130 if (!provider)
128 return; 131 return;
129 provider->SetUpdateCallback(provider_update_callback_); 132 provider->SetUpdateCallback(provider_update_callback_);
130 if (is_permission_granted_) 133 if (is_permission_granted_)
131 provider->OnPermissionGranted(); 134 provider->OnPermissionGranted();
132 providers_.push_back(provider); 135 providers_.push_back(provider);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 207 }
205 } 208 }
206 return false; 209 return false;
207 } 210 }
208 211
209 bool LocationArbitratorImpl::HasPermissionBeenGranted() const { 212 bool LocationArbitratorImpl::HasPermissionBeenGranted() const {
210 return is_permission_granted_; 213 return is_permission_granted_;
211 } 214 }
212 215
213 } // namespace content 216 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698