Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 std::unique_ptr<WifiAccessPointVector> result( | 27 std::unique_ptr<WifiAccessPointVector> result( |
| 28 new chromeos::WifiAccessPointVector); | 28 new chromeos::WifiAccessPointVector); |
| 29 int64_t age_ms = 0; | 29 int64_t age_ms = 0; |
| 30 if (!NetworkHandler::Get()->geolocation_handler()->GetWifiAccessPoints( | 30 if (!NetworkHandler::Get()->geolocation_handler()->GetWifiAccessPoints( |
| 31 result.get(), &age_ms)) { | 31 result.get(), &age_ms)) { |
| 32 return nullptr; | 32 return nullptr; |
| 33 } | 33 } |
| 34 return result; | 34 return result; |
| 35 } | 35 } |
| 36 | 36 |
| 37 std::unique_ptr<CellTowerVector> GetCellTowerData() { | |
| 38 if (!chromeos::NetworkHandler::Get() | |
| 39 ->geolocation_handler() | |
| 40 ->cellular_enabled()) { | |
| 41 return nullptr; | |
| 42 } | |
| 43 | |
| 44 std::unique_ptr<CellTowerVector> result(new chromeos::CellTowerVector); | |
|
Ben Chan
2017/02/02 20:49:24
auto result = base::MakeUnique<chromeos::CellTower
can Skylar cook
2017/02/03 00:15:17
Done.
| |
| 45 int64_t age_ms = 0; | |
| 46 if (!NetworkHandler::Get()->geolocation_handler()->GetCellTowers(result.get(), | |
| 47 &age_ms)) { | |
| 48 return nullptr; | |
| 49 } | |
| 50 return result; | |
| 51 } | |
| 52 | |
| 37 } // namespace | 53 } // namespace |
| 38 | 54 |
| 39 SimpleGeolocationProvider::SimpleGeolocationProvider( | 55 SimpleGeolocationProvider::SimpleGeolocationProvider( |
| 40 net::URLRequestContextGetter* url_context_getter, | 56 net::URLRequestContextGetter* url_context_getter, |
| 41 const GURL& url) | 57 const GURL& url) |
| 42 : url_context_getter_(url_context_getter), url_(url) { | 58 : url_context_getter_(url_context_getter), url_(url) { |
| 43 } | 59 } |
| 44 | 60 |
| 45 SimpleGeolocationProvider::~SimpleGeolocationProvider() { | 61 SimpleGeolocationProvider::~SimpleGeolocationProvider() { |
| 46 DCHECK(thread_checker_.CalledOnValidThread()); | 62 DCHECK(thread_checker_.CalledOnValidThread()); |
| 47 } | 63 } |
| 48 | 64 |
| 49 void SimpleGeolocationProvider::RequestGeolocation( | 65 void SimpleGeolocationProvider::RequestGeolocation( |
| 50 base::TimeDelta timeout, | 66 base::TimeDelta timeout, |
| 51 bool send_wifi_access_points, | 67 bool send_wifi_access_points, |
| 68 bool send_cell_towers, | |
| 52 SimpleGeolocationRequest::ResponseCallback callback) { | 69 SimpleGeolocationRequest::ResponseCallback callback) { |
| 53 DCHECK(thread_checker_.CalledOnValidThread()); | 70 DCHECK(thread_checker_.CalledOnValidThread()); |
| 54 | 71 |
| 55 SimpleGeolocationRequest* request(new SimpleGeolocationRequest( | 72 SimpleGeolocationRequest* request(new SimpleGeolocationRequest( |
| 56 url_context_getter_.get(), url_, timeout, | 73 url_context_getter_.get(), url_, timeout, |
| 57 send_wifi_access_points ? GetAccessPointData() : nullptr)); | 74 send_wifi_access_points ? GetAccessPointData() : nullptr, |
| 75 send_cell_towers ? GetCellTowerData() : nullptr)); | |
| 58 requests_.push_back(base::WrapUnique(request)); | 76 requests_.push_back(base::WrapUnique(request)); |
| 59 | 77 |
| 60 // SimpleGeolocationProvider owns all requests. It is safe to pass unretained | 78 // SimpleGeolocationProvider owns all requests. It is safe to pass unretained |
| 61 // "this" because destruction of SimpleGeolocationProvider cancels all | 79 // "this" because destruction of SimpleGeolocationProvider cancels all |
| 62 // requests. | 80 // requests. |
| 63 SimpleGeolocationRequest::ResponseCallback callback_tmp( | 81 SimpleGeolocationRequest::ResponseCallback callback_tmp( |
| 64 base::Bind(&SimpleGeolocationProvider::OnGeolocationResponse, | 82 base::Bind(&SimpleGeolocationProvider::OnGeolocationResponse, |
| 65 base::Unretained(this), | 83 base::Unretained(this), |
| 66 request, | 84 request, |
| 67 callback)); | 85 callback)); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 90 return req.get() == request; | 108 return req.get() == request; |
| 91 }); | 109 }); |
| 92 DCHECK(position != requests_.end()); | 110 DCHECK(position != requests_.end()); |
| 93 if (position != requests_.end()) { | 111 if (position != requests_.end()) { |
| 94 std::swap(*position, *requests_.rbegin()); | 112 std::swap(*position, *requests_.rbegin()); |
| 95 requests_.resize(requests_.size() - 1); | 113 requests_.resize(requests_.size() - 1); |
| 96 } | 114 } |
| 97 } | 115 } |
| 98 | 116 |
| 99 } // namespace chromeos | 117 } // namespace chromeos |
| OLD | NEW |