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

Side by Side Diff: ios/chrome/browser/geolocation/CLLocation+OmniboxGeolocation.mm

Issue 1103293002: [iOS] Upstream iOS geolocation code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 5 years, 7 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/geolocation/CLLocation+OmniboxGeolocation.h"
6
7 #import <objc/runtime.h>
8
9 #include "base/mac/scoped_nsobject.h"
10
11 namespace {
12
13 // The key needed for objc_setAssociatedObject. Any value will do, because the
14 // address is the key.
15 static char g_acquisitionIntervalKey = 'k';
16
17 // Number of seconds before a location is no longer considered to be fresh
18 // enough to use for an Omnibox query.
19 const NSTimeInterval kLocationIsFreshAge = 24.0 * 60.0 * 60.0; // 24 hours
20
21 // Number of seconds before we will try to refresh the device location.
22 const NSTimeInterval kLocationShouldRefreshAge = 5.0 * 60.0; // 5 minutes
23
24 } // namespace
25
26 @implementation CLLocation (OmniboxGeolocation)
27
28 - (NSTimeInterval)cr_acquisitionInterval {
29 NSNumber* interval =
30 objc_getAssociatedObject(self, &g_acquisitionIntervalKey);
31 return [interval doubleValue];
32 }
33
34 - (void)cr_setAcquisitionInterval:(NSTimeInterval)interval {
35 base::scoped_nsobject<NSNumber> boxedInterval(
36 [[NSNumber alloc] initWithDouble:interval]);
37 objc_setAssociatedObject(self, &g_acquisitionIntervalKey, boxedInterval.get(),
38 OBJC_ASSOCIATION_RETAIN);
39 }
40
41 - (BOOL)cr_isFreshEnough {
42 NSTimeInterval age = -[self.timestamp timeIntervalSinceNow];
43 return (age >= 0) && (age <= kLocationIsFreshAge);
44 }
45
46 - (BOOL)cr_shouldRefresh {
47 NSTimeInterval age = -[self.timestamp timeIntervalSinceNow];
48 // Note: if age < 0 (the location is from the future), don't believe it.
49 return (age < 0) || (age > kLocationShouldRefreshAge);
50 }
51
52 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/geolocation/CLLocation+OmniboxGeolocation.h ('k') | ios/chrome/browser/geolocation/CLLocation+XGeoHeader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698