| OLD | NEW |
| 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 <stdint.h> |
| 8 |
| 9 #include <limits> |
| 7 #include <set> | 10 #include <set> |
| 8 #include <string> | 11 #include <string> |
| 9 | 12 |
| 10 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 11 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 12 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 13 #include "base/metrics/sparse_histogram.h" | 16 #include "base/metrics/sparse_histogram.h" |
| 14 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/values.h" | 19 #include "base/values.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 return url.ReplaceComponents(replacements); | 205 return url.ReplaceComponents(replacements); |
| 203 } | 206 } |
| 204 } | 207 } |
| 205 return url; | 208 return url; |
| 206 } | 209 } |
| 207 | 210 |
| 208 void FormUploadData(const WifiData& wifi_data, | 211 void FormUploadData(const WifiData& wifi_data, |
| 209 const base::Time& timestamp, | 212 const base::Time& timestamp, |
| 210 const base::string16& access_token, | 213 const base::string16& access_token, |
| 211 std::string* upload_data) { | 214 std::string* upload_data) { |
| 212 int age = kint32min; // Invalid so AddInteger() will ignore. | 215 int age = std::numeric_limits<int32_t>::min(); // Invalid so AddInteger() |
| 216 // will ignore. |
| 213 if (!timestamp.is_null()) { | 217 if (!timestamp.is_null()) { |
| 214 // Convert absolute timestamps into a relative age. | 218 // Convert absolute timestamps into a relative age. |
| 215 int64 delta_ms = (base::Time::Now() - timestamp).InMilliseconds(); | 219 int64_t delta_ms = (base::Time::Now() - timestamp).InMilliseconds(); |
| 216 if (delta_ms >= 0 && delta_ms < kint32max) | 220 if (delta_ms >= 0 && delta_ms < std::numeric_limits<int32_t>::max()) |
| 217 age = static_cast<int>(delta_ms); | 221 age = static_cast<int>(delta_ms); |
| 218 } | 222 } |
| 219 | 223 |
| 220 base::DictionaryValue request; | 224 base::DictionaryValue request; |
| 221 AddWifiData(wifi_data, age, &request); | 225 AddWifiData(wifi_data, age, &request); |
| 222 if (!access_token.empty()) | 226 if (!access_token.empty()) |
| 223 request.SetString(kAccessTokenString, access_token); | 227 request.SetString(kAccessTokenString, access_token); |
| 224 base::JSONWriter::Write(request, upload_data); | 228 base::JSONWriter::Write(request, upload_data); |
| 225 } | 229 } |
| 226 | 230 |
| 227 void AddString(const std::string& property_name, const std::string& value, | 231 void AddString(const std::string& property_name, const std::string& value, |
| 228 base::DictionaryValue* dict) { | 232 base::DictionaryValue* dict) { |
| 229 DCHECK(dict); | 233 DCHECK(dict); |
| 230 if (!value.empty()) | 234 if (!value.empty()) |
| 231 dict->SetString(property_name, value); | 235 dict->SetString(property_name, value); |
| 232 } | 236 } |
| 233 | 237 |
| 234 void AddInteger(const std::string& property_name, int value, | 238 void AddInteger(const std::string& property_name, int value, |
| 235 base::DictionaryValue* dict) { | 239 base::DictionaryValue* dict) { |
| 236 DCHECK(dict); | 240 DCHECK(dict); |
| 237 if (value != kint32min) | 241 if (value != std::numeric_limits<int32_t>::min()) |
| 238 dict->SetInteger(property_name, value); | 242 dict->SetInteger(property_name, value); |
| 239 } | 243 } |
| 240 | 244 |
| 241 void AddWifiData(const WifiData& wifi_data, | 245 void AddWifiData(const WifiData& wifi_data, |
| 242 int age_milliseconds, | 246 int age_milliseconds, |
| 243 base::DictionaryValue* request) { | 247 base::DictionaryValue* request) { |
| 244 DCHECK(request); | 248 DCHECK(request); |
| 245 | 249 |
| 246 if (wifi_data.access_point_data.empty()) | 250 if (wifi_data.access_point_data.empty()) |
| 247 return; | 251 return; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 | 427 |
| 424 // Other fields are optional. | 428 // Other fields are optional. |
| 425 GetAsDouble(*response_object, kAccuracyString, &position->accuracy); | 429 GetAsDouble(*response_object, kAccuracyString, &position->accuracy); |
| 426 | 430 |
| 427 return true; | 431 return true; |
| 428 } | 432 } |
| 429 | 433 |
| 430 } // namespace | 434 } // namespace |
| 431 | 435 |
| 432 } // namespace content | 436 } // namespace content |
| OLD | NEW |