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

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

Issue 2200483002: Geolocation cleanup: run clang-format (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/network_location_provider.h" 5 #include "device/geolocation/network_location_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return nullptr; 65 return nullptr;
66 } 66 }
67 CacheMap::const_iterator iter = cache_.find(key); 67 CacheMap::const_iterator iter = cache_.find(key);
68 return iter == cache_.end() ? nullptr : &iter->second; 68 return iter == cache_.end() ? nullptr : &iter->second;
69 } 69 }
70 70
71 // Makes the key for the map of cached positions, using the available data. 71 // Makes the key for the map of cached positions, using the available data.
72 // Returns true if a good key was generated, false otherwise. 72 // Returns true if a good key was generated, false otherwise.
73 // 73 //
74 // static 74 // static
75 bool NetworkLocationProvider::PositionCache::MakeKey( 75 bool NetworkLocationProvider::PositionCache::MakeKey(const WifiData& wifi_data,
76 const WifiData& wifi_data, 76 base::string16* key) {
77 base::string16* key) {
78 // Currently we use only WiFi data and base the key only on the MAC addresses. 77 // Currently we use only WiFi data and base the key only on the MAC addresses.
79 DCHECK(key); 78 DCHECK(key);
80 key->clear(); 79 key->clear();
81 const size_t kCharsPerMacAddress = 6 * 3 + 1; // e.g. "11:22:33:44:55:66|" 80 const size_t kCharsPerMacAddress = 6 * 3 + 1; // e.g. "11:22:33:44:55:66|"
82 key->reserve(wifi_data.access_point_data.size() * kCharsPerMacAddress); 81 key->reserve(wifi_data.access_point_data.size() * kCharsPerMacAddress);
83 const base::string16 separator(base::ASCIIToUTF16("|")); 82 const base::string16 separator(base::ASCIIToUTF16("|"));
84 for (const auto& access_point_data : wifi_data.access_point_data) { 83 for (const auto& access_point_data : wifi_data.access_point_data) {
85 *key += separator; 84 *key += separator;
86 *key += access_point_data.mac_address; 85 *key += access_point_data.mac_address;
87 *key += separator; 86 *key += separator;
88 } 87 }
89 // If the key is the empty string, return false, as we don't want to cache a 88 // If the key is the empty string, return false, as we don't want to cache a
90 // position for such data. 89 // position for such data.
91 return !key->empty(); 90 return !key->empty();
92 } 91 }
93 92
94 // NetworkLocationProvider factory function 93 // NetworkLocationProvider factory function
95 LocationProviderBase* NewNetworkLocationProvider( 94 LocationProviderBase* NewNetworkLocationProvider(
96 const scoped_refptr<AccessTokenStore>& access_token_store, 95 const scoped_refptr<AccessTokenStore>& access_token_store,
97 const scoped_refptr<net::URLRequestContextGetter>& context, 96 const scoped_refptr<net::URLRequestContextGetter>& context,
98 const GURL& url, 97 const GURL& url,
99 const base::string16& access_token) { 98 const base::string16& access_token) {
100 return new NetworkLocationProvider( 99 return new NetworkLocationProvider(access_token_store, context, url,
101 access_token_store, context, url, access_token); 100 access_token);
102 } 101 }
103 102
104 // NetworkLocationProvider 103 // NetworkLocationProvider
105 NetworkLocationProvider::NetworkLocationProvider( 104 NetworkLocationProvider::NetworkLocationProvider(
106 const scoped_refptr<AccessTokenStore>& access_token_store, 105 const scoped_refptr<AccessTokenStore>& access_token_store,
107 const scoped_refptr<net::URLRequestContextGetter>& url_context_getter, 106 const scoped_refptr<net::URLRequestContextGetter>& url_context_getter,
108 const GURL& url, 107 const GURL& url,
109 const base::string16& access_token) 108 const base::string16& access_token)
110 : access_token_store_(access_token_store), 109 : access_token_store_(access_token_store),
111 wifi_data_provider_manager_(nullptr), 110 wifi_data_provider_manager_(nullptr),
112 wifi_data_update_callback_( 111 wifi_data_update_callback_(
113 base::Bind(&NetworkLocationProvider::OnWifiDataUpdate, 112 base::Bind(&NetworkLocationProvider::OnWifiDataUpdate,
114 base::Unretained(this))), 113 base::Unretained(this))),
115 is_wifi_data_complete_(false), 114 is_wifi_data_complete_(false),
116 access_token_(access_token), 115 access_token_(access_token),
117 is_permission_granted_(false), 116 is_permission_granted_(false),
118 is_new_data_available_(false), 117 is_new_data_available_(false),
119 position_cache_(new PositionCache), 118 position_cache_(new PositionCache),
120 weak_factory_(this) { 119 weak_factory_(this) {
121 request_.reset(new NetworkLocationRequest( 120 request_.reset(new NetworkLocationRequest(
122 url_context_getter, 121 url_context_getter, url,
123 url,
124 base::Bind(&NetworkLocationProvider::OnLocationResponse, 122 base::Bind(&NetworkLocationProvider::OnLocationResponse,
125 base::Unretained(this)))); 123 base::Unretained(this))));
126 } 124 }
127 125
128 NetworkLocationProvider::~NetworkLocationProvider() { 126 NetworkLocationProvider::~NetworkLocationProvider() {
129 StopProvider(); 127 StopProvider();
130 } 128 }
131 129
132 // LocationProvider implementation 130 // LocationProvider implementation
133 void NetworkLocationProvider::GetPosition(Geoposition* position) { 131 void NetworkLocationProvider::GetPosition(Geoposition* position) {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 << wifi_data_.access_point_data.size(); 262 << wifi_data_.access_point_data.size();
265 } 263 }
266 request_->MakeRequest(access_token_, wifi_data_, wifi_timestamp_); 264 request_->MakeRequest(access_token_, wifi_data_, wifi_timestamp_);
267 } 265 }
268 266
269 bool NetworkLocationProvider::IsStarted() const { 267 bool NetworkLocationProvider::IsStarted() const {
270 return wifi_data_provider_manager_ != nullptr; 268 return wifi_data_provider_manager_ != nullptr;
271 } 269 }
272 270
273 } // namespace device 271 } // namespace device
OLDNEW
« no previous file with comments | « device/geolocation/network_location_provider.h ('k') | device/geolocation/network_location_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698