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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/geolocation/CLLocation+OmniboxGeolocation.mm
diff --git a/ios/chrome/browser/geolocation/CLLocation+OmniboxGeolocation.mm b/ios/chrome/browser/geolocation/CLLocation+OmniboxGeolocation.mm
new file mode 100644
index 0000000000000000000000000000000000000000..1449373d84271dae2de0ee428eabc032cd0c69bc
--- /dev/null
+++ b/ios/chrome/browser/geolocation/CLLocation+OmniboxGeolocation.mm
@@ -0,0 +1,52 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/geolocation/CLLocation+OmniboxGeolocation.h"
+
+#import <objc/runtime.h>
+
+#include "base/mac/scoped_nsobject.h"
+
+namespace {
+
+// The key needed for objc_setAssociatedObject. Any value will do, because the
+// address is the key.
+static char g_acquisitionIntervalKey = 'k';
+
+// Number of seconds before a location is no longer considered to be fresh
+// enough to use for an Omnibox query.
+const NSTimeInterval kLocationIsFreshAge = 24.0 * 60.0 * 60.0; // 24 hours
+
+// Number of seconds before we will try to refresh the device location.
+const NSTimeInterval kLocationShouldRefreshAge = 5.0 * 60.0; // 5 minutes
+
+} // namespace
+
+@implementation CLLocation (OmniboxGeolocation)
+
+- (NSTimeInterval)cr_acquisitionInterval {
+ NSNumber* interval =
+ objc_getAssociatedObject(self, &g_acquisitionIntervalKey);
+ return [interval doubleValue];
+}
+
+- (void)cr_setAcquisitionInterval:(NSTimeInterval)interval {
+ base::scoped_nsobject<NSNumber> boxedInterval(
+ [[NSNumber alloc] initWithDouble:interval]);
+ objc_setAssociatedObject(self, &g_acquisitionIntervalKey, boxedInterval.get(),
+ OBJC_ASSOCIATION_RETAIN);
+}
+
+- (BOOL)cr_isFreshEnough {
+ NSTimeInterval age = -[self.timestamp timeIntervalSinceNow];
+ return (age >= 0) && (age <= kLocationIsFreshAge);
+}
+
+- (BOOL)cr_shouldRefresh {
+ NSTimeInterval age = -[self.timestamp timeIntervalSinceNow];
+ // Note: if age < 0 (the location is from the future), don't believe it.
+ return (age < 0) || (age > kLocationShouldRefreshAge);
+}
+
+@end
« 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