| 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 "chrome/browser/chromeos/geolocation/simple_geolocation_request.h" | 5 #include "chrome/browser/chromeos/geolocation/simple_geolocation_request.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 198 |
| 199 if (error_object) { | 199 if (error_object) { |
| 200 if (!error_object->GetStringWithoutPathExpansion( | 200 if (!error_object->GetStringWithoutPathExpansion( |
| 201 kMessageString, &(position->error_message))) { | 201 kMessageString, &(position->error_message))) { |
| 202 position->error_message = "Server returned error without message."; | 202 position->error_message = "Server returned error without message."; |
| 203 } | 203 } |
| 204 | 204 |
| 205 // Ignore result (code defaults to zero). | 205 // Ignore result (code defaults to zero). |
| 206 error_object->GetIntegerWithoutPathExpansion(kCodeString, | 206 error_object->GetIntegerWithoutPathExpansion(kCodeString, |
| 207 &(position->error_code)); | 207 &(position->error_code)); |
| 208 } else { |
| 209 position->error_message.erase(); |
| 208 } | 210 } |
| 209 | 211 |
| 210 if (location_object) { | 212 if (location_object) { |
| 211 if (!location_object->GetDoubleWithoutPathExpansion( | 213 if (!location_object->GetDoubleWithoutPathExpansion( |
| 212 kLatString, &(position->latitude))) { | 214 kLatString, &(position->latitude))) { |
| 213 PrintGeolocationError(server_url, "Missing 'lat' attribute.", position); | 215 PrintGeolocationError(server_url, "Missing 'lat' attribute.", position); |
| 214 RecordUmaEvent(SIMPLE_GEOLOCATION_REQUEST_EVENT_RESPONSE_MALFORMED); | 216 RecordUmaEvent(SIMPLE_GEOLOCATION_REQUEST_EVENT_RESPONSE_MALFORMED); |
| 215 return false; | 217 return false; |
| 216 } | 218 } |
| 217 if (!location_object->GetDoubleWithoutPathExpansion( | 219 if (!location_object->GetDoubleWithoutPathExpansion( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 267 } |
| 266 | 268 |
| 267 } // namespace | 269 } // namespace |
| 268 | 270 |
| 269 SimpleGeolocationRequest::SimpleGeolocationRequest( | 271 SimpleGeolocationRequest::SimpleGeolocationRequest( |
| 270 net::URLRequestContextGetter* url_context_getter, | 272 net::URLRequestContextGetter* url_context_getter, |
| 271 const GURL& service_url, | 273 const GURL& service_url, |
| 272 base::TimeDelta timeout) | 274 base::TimeDelta timeout) |
| 273 : url_context_getter_(url_context_getter), | 275 : url_context_getter_(url_context_getter), |
| 274 service_url_(service_url), | 276 service_url_(service_url), |
| 277 retry_sleep_on_server_error_(base::TimeDelta::FromSeconds( |
| 278 kResolveGeolocationRetrySleepOnServerErrorSeconds)), |
| 279 retry_sleep_on_bad_response_(base::TimeDelta::FromSeconds( |
| 280 kResolveGeolocationRetrySleepBadResponseSeconds)), |
| 275 timeout_(timeout), | 281 timeout_(timeout), |
| 276 retries_(0) { | 282 retries_(0) { |
| 277 } | 283 } |
| 278 | 284 |
| 279 SimpleGeolocationRequest::~SimpleGeolocationRequest() { | 285 SimpleGeolocationRequest::~SimpleGeolocationRequest() { |
| 280 DCHECK(thread_checker_.CalledOnValidThread()); | 286 DCHECK(thread_checker_.CalledOnValidThread()); |
| 281 | 287 |
| 282 // If callback is not empty, request is cancelled. | 288 // If callback is not empty, request is cancelled. |
| 283 if (!callback_.is_null()) { | 289 if (!callback_.is_null()) { |
| 284 RecordUmaResponseTime(base::Time::Now() - request_started_at_, false); | 290 RecordUmaResponseTime(base::Time::Now() - request_started_at_, false); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 307 void SimpleGeolocationRequest::MakeRequest(const ResponseCallback& callback) { | 313 void SimpleGeolocationRequest::MakeRequest(const ResponseCallback& callback) { |
| 308 callback_ = callback; | 314 callback_ = callback; |
| 309 request_url_ = GeolocationRequestURL(service_url_); | 315 request_url_ = GeolocationRequestURL(service_url_); |
| 310 timeout_timer_.Start( | 316 timeout_timer_.Start( |
| 311 FROM_HERE, timeout_, this, &SimpleGeolocationRequest::OnTimeout); | 317 FROM_HERE, timeout_, this, &SimpleGeolocationRequest::OnTimeout); |
| 312 request_started_at_ = base::Time::Now(); | 318 request_started_at_ = base::Time::Now(); |
| 313 StartRequest(); | 319 StartRequest(); |
| 314 } | 320 } |
| 315 | 321 |
| 316 void SimpleGeolocationRequest::Retry(bool server_error) { | 322 void SimpleGeolocationRequest::Retry(bool server_error) { |
| 317 const base::TimeDelta delay = base::TimeDelta::FromSeconds( | 323 base::TimeDelta delay(server_error ? retry_sleep_on_server_error_ |
| 318 server_error ? kResolveGeolocationRetrySleepOnServerErrorSeconds | 324 : retry_sleep_on_bad_response_); |
| 319 : kResolveGeolocationRetrySleepBadResponseSeconds); | |
| 320 request_scheduled_.Start( | 325 request_scheduled_.Start( |
| 321 FROM_HERE, delay, this, &SimpleGeolocationRequest::StartRequest); | 326 FROM_HERE, delay, this, &SimpleGeolocationRequest::StartRequest); |
| 322 } | 327 } |
| 323 | 328 |
| 324 void SimpleGeolocationRequest::OnURLFetchComplete( | 329 void SimpleGeolocationRequest::OnURLFetchComplete( |
| 325 const net::URLFetcher* source) { | 330 const net::URLFetcher* source) { |
| 326 DCHECK_EQ(url_fetcher_.get(), source); | 331 DCHECK_EQ(url_fetcher_.get(), source); |
| 327 | 332 |
| 328 net::URLRequestStatus status = source->GetStatus(); | 333 net::URLRequestStatus status = source->GetStatus(); |
| 329 int response_code = source->GetResponseCode(); | 334 int response_code = source->GetResponseCode(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 ? SIMPLE_GEOLOCATION_REQUEST_RESULT_SERVER_ERROR | 383 ? SIMPLE_GEOLOCATION_REQUEST_RESULT_SERVER_ERROR |
| 379 : SIMPLE_GEOLOCATION_REQUEST_RESULT_FAILURE); | 384 : SIMPLE_GEOLOCATION_REQUEST_RESULT_FAILURE); |
| 380 RecordUmaResult(result, retries_); | 385 RecordUmaResult(result, retries_); |
| 381 position_.status = Geoposition::STATUS_TIMEOUT; | 386 position_.status = Geoposition::STATUS_TIMEOUT; |
| 382 const base::TimeDelta elapsed = base::Time::Now() - request_started_at_; | 387 const base::TimeDelta elapsed = base::Time::Now() - request_started_at_; |
| 383 ReplyAndDestroySelf(elapsed, true /* server_error */); | 388 ReplyAndDestroySelf(elapsed, true /* server_error */); |
| 384 // "this" is already destroyed here. | 389 // "this" is already destroyed here. |
| 385 } | 390 } |
| 386 | 391 |
| 387 } // namespace chromeos | 392 } // namespace chromeos |
| OLD | NEW |