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

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

Issue 477633002: Rename various Geolocation bits for clarity and consistency. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One more rename. Created 6 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 | Annotate | Revision Log
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/network_location_request.h" 5 #include "content/browser/geolocation/network_location_request.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 int age_milliseconds, 96 int age_milliseconds,
97 base::DictionaryValue* request); 97 base::DictionaryValue* request);
98 } // namespace 98 } // namespace
99 99
100 int NetworkLocationRequest::url_fetcher_id_for_tests = 0; 100 int NetworkLocationRequest::url_fetcher_id_for_tests = 0;
101 101
102 NetworkLocationRequest::NetworkLocationRequest( 102 NetworkLocationRequest::NetworkLocationRequest(
103 net::URLRequestContextGetter* context, 103 net::URLRequestContextGetter* context,
104 const GURL& url, 104 const GURL& url,
105 LocationResponseCallback callback) 105 LocationResponseCallback callback)
106 : url_context_(context), 106 : url_context_(context), location_response_callback_(callback), url_(url) {
107 callback_(callback),
108 url_(url) {
109 } 107 }
110 108
111 NetworkLocationRequest::~NetworkLocationRequest() { 109 NetworkLocationRequest::~NetworkLocationRequest() {
112 } 110 }
113 111
114 bool NetworkLocationRequest::MakeRequest(const base::string16& access_token, 112 bool NetworkLocationRequest::MakeRequest(const base::string16& access_token,
115 const WifiData& wifi_data, 113 const WifiData& wifi_data,
116 const base::Time& timestamp) { 114 const base::Time& timestamp) {
117 RecordUmaEvent(NETWORK_LOCATION_REQUEST_EVENT_REQUEST_START); 115 RecordUmaEvent(NETWORK_LOCATION_REQUEST_EVENT_REQUEST_START);
118 RecordUmaAccessPoints(wifi_data.access_point_data.size()); 116 RecordUmaAccessPoints(wifi_data.access_point_data.size());
119 if (url_fetcher_ != NULL) { 117 if (url_fetcher_ != NULL) {
120 DVLOG(1) << "NetworkLocationRequest : Cancelling pending request"; 118 DVLOG(1) << "NetworkLocationRequest : Cancelling pending request";
121 RecordUmaEvent(NETWORK_LOCATION_REQUEST_EVENT_REQUEST_CANCEL); 119 RecordUmaEvent(NETWORK_LOCATION_REQUEST_EVENT_REQUEST_CANCEL);
122 url_fetcher_.reset(); 120 url_fetcher_.reset();
123 } 121 }
124 wifi_data_ = wifi_data; 122 wifi_data_ = wifi_data;
125 timestamp_ = timestamp; 123 wifi_data_timestamp_ = timestamp;
126 124
127 GURL request_url = FormRequestURL(url_); 125 GURL request_url = FormRequestURL(url_);
128 url_fetcher_.reset(net::URLFetcher::Create( 126 url_fetcher_.reset(net::URLFetcher::Create(
129 url_fetcher_id_for_tests, request_url, net::URLFetcher::POST, this)); 127 url_fetcher_id_for_tests, request_url, net::URLFetcher::POST, this));
130 url_fetcher_->SetRequestContext(url_context_.get()); 128 url_fetcher_->SetRequestContext(url_context_.get());
131 std::string upload_data; 129 std::string upload_data;
132 FormUploadData(wifi_data, timestamp, access_token, &upload_data); 130 FormUploadData(wifi_data, timestamp, access_token, &upload_data);
133 url_fetcher_->SetUploadData("application/json", upload_data); 131 url_fetcher_->SetUploadData("application/json", upload_data);
134 url_fetcher_->SetLoadFlags( 132 url_fetcher_->SetLoadFlags(
135 net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | 133 net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE |
136 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES | 134 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES |
137 net::LOAD_DO_NOT_SEND_AUTH_DATA); 135 net::LOAD_DO_NOT_SEND_AUTH_DATA);
138 136
139 start_time_ = base::TimeTicks::Now(); 137 request_start_time_ = base::TimeTicks::Now();
140 url_fetcher_->Start(); 138 url_fetcher_->Start();
141 return true; 139 return true;
142 } 140 }
143 141
144 void NetworkLocationRequest::OnURLFetchComplete( 142 void NetworkLocationRequest::OnURLFetchComplete(
145 const net::URLFetcher* source) { 143 const net::URLFetcher* source) {
146 DCHECK_EQ(url_fetcher_.get(), source); 144 DCHECK_EQ(url_fetcher_.get(), source);
147 145
148 net::URLRequestStatus status = source->GetStatus(); 146 net::URLRequestStatus status = source->GetStatus();
149 int response_code = source->GetResponseCode(); 147 int response_code = source->GetResponseCode();
150 RecordUmaResponseCode(response_code); 148 RecordUmaResponseCode(response_code);
151 149
152 Geoposition position; 150 Geoposition position;
153 base::string16 access_token; 151 base::string16 access_token;
154 std::string data; 152 std::string data;
155 source->GetResponseAsString(&data); 153 source->GetResponseAsString(&data);
156 GetLocationFromResponse(status.is_success(), 154 GetLocationFromResponse(status.is_success(),
157 response_code, 155 response_code,
158 data, 156 data,
159 timestamp_, 157 wifi_data_timestamp_,
160 source->GetURL(), 158 source->GetURL(),
161 &position, 159 &position,
162 &access_token); 160 &access_token);
163 const bool server_error = 161 const bool server_error =
164 !status.is_success() || (response_code >= 500 && response_code < 600); 162 !status.is_success() || (response_code >= 500 && response_code < 600);
165 url_fetcher_.reset(); 163 url_fetcher_.reset();
166 164
167 if (!server_error) { 165 if (!server_error) {
168 const base::TimeDelta request_time = base::TimeTicks::Now() - start_time_; 166 const base::TimeDelta request_time =
167 base::TimeTicks::Now() - request_start_time_;
169 168
170 UMA_HISTOGRAM_CUSTOM_TIMES( 169 UMA_HISTOGRAM_CUSTOM_TIMES(
171 "Net.Wifi.LbsLatency", 170 "Net.Wifi.LbsLatency",
172 request_time, 171 request_time,
173 base::TimeDelta::FromMilliseconds(1), 172 base::TimeDelta::FromMilliseconds(1),
174 base::TimeDelta::FromSeconds(10), 173 base::TimeDelta::FromSeconds(10),
175 100); 174 100);
176 } 175 }
177 176
178 DVLOG(1) << "NetworkLocationRequest::OnURLFetchComplete() : run callback."; 177 DVLOG(1) << "NetworkLocationRequest::OnURLFetchComplete() : run callback.";
179 callback_.Run(position, server_error, access_token, wifi_data_); 178 location_response_callback_.Run(
179 position, server_error, access_token, wifi_data_);
180 } 180 }
181 181
182 // Local functions. 182 // Local functions.
183 namespace { 183 namespace {
184 184
185 struct AccessPointLess { 185 struct AccessPointLess {
186 bool operator()(const AccessPointData* ap1, 186 bool operator()(const AccessPointData* ap1,
187 const AccessPointData* ap2) const { 187 const AccessPointData* ap2) const {
188 return ap2->radio_signal_strength < ap1->radio_signal_strength; 188 return ap2->radio_signal_strength < ap1->radio_signal_strength;
189 } 189 }
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 423
424 // Other fields are optional. 424 // Other fields are optional.
425 GetAsDouble(*response_object, kAccuracyString, &position->accuracy); 425 GetAsDouble(*response_object, kAccuracyString, &position->accuracy);
426 426
427 return true; 427 return true;
428 } 428 }
429 429
430 } // namespace 430 } // namespace
431 431
432 } // namespace content 432 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698