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

Side by Side Diff: chromeos/geolocation/simple_geolocation_provider.cc

Issue 1819173002: SimpleGeolocation should support sending WiFi AP data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: UMA added. Created 4 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chromeos/geolocation/simple_geolocation_provider.h" 5 #include "chromeos/geolocation/simple_geolocation_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "chromeos/geolocation/geoposition.h" 11 #include "chromeos/geolocation/geoposition.h"
12 #include "chromeos/network/geolocation_handler.h"
13 #include "chromeos/network/network_handler.h"
12 #include "net/url_request/url_request_context_getter.h" 14 #include "net/url_request/url_request_context_getter.h"
13 15
14 namespace chromeos { 16 namespace chromeos {
15 17
16 namespace { 18 namespace {
17 const char kDefaultGeolocationProviderUrl[] = 19 const char kDefaultGeolocationProviderUrl[] =
18 "https://www.googleapis.com/geolocation/v1/geolocate?"; 20 "https://www.googleapis.com/geolocation/v1/geolocate?";
21
22 scoped_ptr<WifiAccessPointVector> GetAccessPointData() {
23 scoped_ptr<WifiAccessPointVector> result;
24
25 if (!chromeos::NetworkHandler::Get()->geolocation_handler()->wifi_enabled())
26 return result;
27
28 chromeos::WifiAccessPointVector access_points;
stevenjb 2016/03/22 16:39:49 Rather than allocating this locally and copying th
Alexander Alekseev 2016/03/23 00:04:45 Done.
29 int64_t age_ms = 0;
30 if (!NetworkHandler::Get()->geolocation_handler()->GetWifiAccessPoints(
31 &access_points, &age_ms)) {
32 return result;
33 }
34 result.reset(new WifiAccessPointVector(access_points));
35 return result;
36 }
37
19 } // namespace 38 } // namespace
20 39
21 SimpleGeolocationProvider::SimpleGeolocationProvider( 40 SimpleGeolocationProvider::SimpleGeolocationProvider(
22 net::URLRequestContextGetter* url_context_getter, 41 net::URLRequestContextGetter* url_context_getter,
23 const GURL& url) 42 const GURL& url)
24 : url_context_getter_(url_context_getter), url_(url) { 43 : url_context_getter_(url_context_getter), url_(url) {
25 } 44 }
26 45
27 SimpleGeolocationProvider::~SimpleGeolocationProvider() { 46 SimpleGeolocationProvider::~SimpleGeolocationProvider() {
28 DCHECK(thread_checker_.CalledOnValidThread()); 47 DCHECK(thread_checker_.CalledOnValidThread());
29 } 48 }
30 49
31 void SimpleGeolocationProvider::RequestGeolocation( 50 void SimpleGeolocationProvider::RequestGeolocation(
32 base::TimeDelta timeout, 51 base::TimeDelta timeout,
52 bool send_wifi_access_points,
33 SimpleGeolocationRequest::ResponseCallback callback) { 53 SimpleGeolocationRequest::ResponseCallback callback) {
34 DCHECK(thread_checker_.CalledOnValidThread()); 54 DCHECK(thread_checker_.CalledOnValidThread());
35 SimpleGeolocationRequest* request( 55
36 new SimpleGeolocationRequest(url_context_getter_.get(), url_, timeout)); 56 SimpleGeolocationRequest* request(new SimpleGeolocationRequest(
57 url_context_getter_.get(), url_, timeout,
58 send_wifi_access_points ? GetAccessPointData()
59 : scoped_ptr<WifiAccessPointVector>()));
stevenjb 2016/03/22 16:39:49 : nullptr
Alexander Alekseev 2016/03/23 00:04:45 Done.
37 requests_.push_back(request); 60 requests_.push_back(request);
38 61
39 // SimpleGeolocationProvider owns all requests. It is safe to pass unretained 62 // SimpleGeolocationProvider owns all requests. It is safe to pass unretained
40 // "this" because destruction of SimpleGeolocationProvider cancels all 63 // "this" because destruction of SimpleGeolocationProvider cancels all
41 // requests. 64 // requests.
42 SimpleGeolocationRequest::ResponseCallback callback_tmp( 65 SimpleGeolocationRequest::ResponseCallback callback_tmp(
43 base::Bind(&SimpleGeolocationProvider::OnGeolocationResponse, 66 base::Bind(&SimpleGeolocationProvider::OnGeolocationResponse,
44 base::Unretained(this), 67 base::Unretained(this),
45 request, 68 request,
46 callback)); 69 callback));
(...skipping 18 matching lines...) Expand all
65 ScopedVector<SimpleGeolocationRequest>::iterator position = 88 ScopedVector<SimpleGeolocationRequest>::iterator position =
66 std::find(requests_.begin(), requests_.end(), request); 89 std::find(requests_.begin(), requests_.end(), request);
67 DCHECK(position != requests_.end()); 90 DCHECK(position != requests_.end());
68 if (position != requests_.end()) { 91 if (position != requests_.end()) {
69 std::swap(*position, *requests_.rbegin()); 92 std::swap(*position, *requests_.rbegin());
70 requests_.resize(requests_.size() - 1); 93 requests_.resize(requests_.size() - 1);
71 } 94 }
72 } 95 }
73 96
74 } // namespace chromeos 97 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698