Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #import "third_party/google_toolbox_for_mac/src/Foundation/GTMStringEncoding.h" | 9 #import "third_party/google_toolbox_for_mac/src/Foundation/GTMStringEncoding.h" |
| 10 | 10 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 12 #error "This file requires ARC support." | |
| 13 #endif | |
| 14 | |
| 11 NSString* const kGMOLocationDescriptorFormat = | 15 NSString* const kGMOLocationDescriptorFormat = |
| 12 @"role: CURRENT_LOCATION\n" | 16 @"role: CURRENT_LOCATION\n" |
| 13 @"producer: DEVICE_LOCATION\n" | 17 @"producer: DEVICE_LOCATION\n" |
| 14 @"timestamp: %lld\n" | 18 @"timestamp: %lld\n" |
| 15 @"radius: %ld\n" | 19 @"radius: %ld\n" |
| 16 @"latlng <\n" | 20 @"latlng <\n" |
| 17 @" latitude_e7: %.f\n" | 21 @" latitude_e7: %.f\n" |
| 18 @" longitude_e7: %.f\n" | 22 @" longitude_e7: %.f\n" |
| 19 @">"; | 23 @">"; |
| 20 | 24 |
| 21 @implementation CLLocation (XGeoHeader) | 25 @implementation CLLocation (XGeoHeader) |
| 22 | 26 |
| 23 - (NSString*)cr_serializeStringToWebSafeBase64String:(NSString*)data { | 27 - (NSString*)cr_serializeStringToWebSafeBase64String:(NSString*)data { |
| 24 GTMStringEncoding* encoder = | 28 GTMStringEncoding* encoder = |
| 25 [GTMStringEncoding rfc4648Base64WebsafeStringEncoding]; | 29 [GTMStringEncoding rfc4648Base64WebsafeStringEncoding]; |
| 26 NSString* base64 = | 30 NSString* base64 = |
| 27 [encoder encode:[data dataUsingEncoding:NSUTF8StringEncoding] | 31 [encoder encode:[data dataUsingEncoding:NSUTF8StringEncoding] |
| 28 error:nullptr]; | 32 error:nullptr]; |
| 29 if (base64) { | 33 if (base64) { |
| 30 return base64; | 34 return base64; |
| 31 } else { | 35 } else { |
|
sdefresne
2016/11/25 10:16:46
nit: no else after return
stkhapugin
2016/11/25 14:57:16
Done.
| |
| 32 return @""; | 36 return @""; |
| 33 } | 37 } |
| 34 } | 38 } |
| 35 | 39 |
| 36 // Returns the timestamp of this location in microseconds since the UNIX epoch. | 40 // Returns the timestamp of this location in microseconds since the UNIX epoch. |
| 37 // Returns 0 if the timestamp is unavailable or invalid. | 41 // Returns 0 if the timestamp is unavailable or invalid. |
| 38 - (int64_t)cr_timestampInMicroseconds { | 42 - (int64_t)cr_timestampInMicroseconds { |
| 39 NSTimeInterval seconds = [self.timestamp timeIntervalSince1970]; | 43 NSTimeInterval seconds = [self.timestamp timeIntervalSince1970]; |
| 40 if (seconds > 0) { | 44 if (seconds > 0) { |
| 41 const int64_t kSecondsToMicroseconds = 1000000; | 45 const int64_t kSecondsToMicroseconds = 1000000; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 67 | 71 |
| 68 - (NSString*)cr_xGeoString { | 72 - (NSString*)cr_xGeoString { |
| 69 NSString* locationDescriptor = [self cr_locationDescriptor]; | 73 NSString* locationDescriptor = [self cr_locationDescriptor]; |
| 70 // The "a" indicates that it is an ASCII proto. | 74 // The "a" indicates that it is an ASCII proto. |
| 71 return [NSString | 75 return [NSString |
| 72 stringWithFormat:@"a %@", [self cr_serializeStringToWebSafeBase64String: | 76 stringWithFormat:@"a %@", [self cr_serializeStringToWebSafeBase64String: |
| 73 locationDescriptor]]; | 77 locationDescriptor]]; |
| 74 } | 78 } |
| 75 | 79 |
| 76 @end | 80 @end |
| OLD | NEW |