| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #import "ios/chrome/browser/geolocation/CLLocation+XGeoHeader.h" | 5 #import "ios/chrome/browser/geolocation/CLLocation+XGeoHeader.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include <stdint.h> |
| 8 |
| 8 #import "third_party/google_toolbox_for_mac/src/Foundation/GTMStringEncoding.h" | 9 #import "third_party/google_toolbox_for_mac/src/Foundation/GTMStringEncoding.h" |
| 9 | 10 |
| 10 NSString* const kGMOLocationDescriptorFormat = | 11 NSString* const kGMOLocationDescriptorFormat = |
| 11 @"role: CURRENT_LOCATION\n" | 12 @"role: CURRENT_LOCATION\n" |
| 12 @"producer: DEVICE_LOCATION\n" | 13 @"producer: DEVICE_LOCATION\n" |
| 13 @"timestamp: %lld\n" | 14 @"timestamp: %lld\n" |
| 14 @"radius: %ld\n" | 15 @"radius: %ld\n" |
| 15 @"latlng <\n" | 16 @"latlng <\n" |
| 16 @" latitude_e7: %.f\n" | 17 @" latitude_e7: %.f\n" |
| 17 @" longitude_e7: %.f\n" | 18 @" longitude_e7: %.f\n" |
| 18 @">"; | 19 @">"; |
| 19 | 20 |
| 20 @implementation CLLocation (XGeoHeader) | 21 @implementation CLLocation (XGeoHeader) |
| 21 | 22 |
| 22 - (NSString*)cr_serializeStringToWebSafeBase64String:(NSString*)data { | 23 - (NSString*)cr_serializeStringToWebSafeBase64String:(NSString*)data { |
| 23 GTMStringEncoding* encoder = | 24 GTMStringEncoding* encoder = |
| 24 [GTMStringEncoding rfc4648Base64WebsafeStringEncoding]; | 25 [GTMStringEncoding rfc4648Base64WebsafeStringEncoding]; |
| 25 NSString* base64 = | 26 NSString* base64 = |
| 26 [encoder encode:[data dataUsingEncoding:NSUTF8StringEncoding]]; | 27 [encoder encode:[data dataUsingEncoding:NSUTF8StringEncoding]]; |
| 27 if (base64) { | 28 if (base64) { |
| 28 return base64; | 29 return base64; |
| 29 } else { | 30 } else { |
| 30 return @""; | 31 return @""; |
| 31 } | 32 } |
| 32 } | 33 } |
| 33 | 34 |
| 34 // Returns the timestamp of this location in microseconds since the UNIX epoch. | 35 // Returns the timestamp of this location in microseconds since the UNIX epoch. |
| 35 // Returns 0 if the timestamp is unavailable or invalid. | 36 // Returns 0 if the timestamp is unavailable or invalid. |
| 36 - (int64)cr_timestampInMicroseconds { | 37 - (int64_t)cr_timestampInMicroseconds { |
| 37 NSTimeInterval seconds = [self.timestamp timeIntervalSince1970]; | 38 NSTimeInterval seconds = [self.timestamp timeIntervalSince1970]; |
| 38 if (seconds > 0) { | 39 if (seconds > 0) { |
| 39 const int64 kSecondsToMicroseconds = 1000000; | 40 const int64_t kSecondsToMicroseconds = 1000000; |
| 40 return (int64)(seconds * kSecondsToMicroseconds); | 41 return (int64_t)(seconds * kSecondsToMicroseconds); |
| 41 } | 42 } |
| 42 return 0; | 43 return 0; |
| 43 } | 44 } |
| 44 | 45 |
| 45 // Returns the horizontal accuracy radius of |location|. The smaller the value, | 46 // Returns the horizontal accuracy radius of |location|. The smaller the value, |
| 46 // the more accurate the location. A value -1 is returned if accuracy is | 47 // the more accurate the location. A value -1 is returned if accuracy is |
| 47 // unavailable. | 48 // unavailable. |
| 48 - (long)cr_accuracyInMillimeters { | 49 - (long)cr_accuracyInMillimeters { |
| 49 const long kMetersToMillimeters = 1000; | 50 const long kMetersToMillimeters = 1000; |
| 50 if (self.horizontalAccuracy > 0) { | 51 if (self.horizontalAccuracy > 0) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 65 | 66 |
| 66 - (NSString*)cr_xGeoString { | 67 - (NSString*)cr_xGeoString { |
| 67 NSString* locationDescriptor = [self cr_locationDescriptor]; | 68 NSString* locationDescriptor = [self cr_locationDescriptor]; |
| 68 // The "a" indicates that it is an ASCII proto. | 69 // The "a" indicates that it is an ASCII proto. |
| 69 return [NSString | 70 return [NSString |
| 70 stringWithFormat:@"a %@", [self cr_serializeStringToWebSafeBase64String: | 71 stringWithFormat:@"a %@", [self cr_serializeStringToWebSafeBase64String: |
| 71 locationDescriptor]]; | 72 locationDescriptor]]; |
| 72 } | 73 } |
| 73 | 74 |
| 74 @end | 75 @end |
| OLD | NEW |