OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #ifndef IOS_PUBLIC_PROVIDER_CHROME_BROWSER_GEOLOCATION_UPDATER_H |
| 6 #define IOS_PUBLIC_PROVIDER_CHROME_BROWSER_GEOLOCATION_UPDATER_H |
| 7 |
| 8 #import <CoreLocation/CoreLocation.h> |
| 9 #import <Foundation/Foundation.h> |
| 10 |
| 11 #include "base/macros.h" |
| 12 |
| 13 // GeolocationUpdater tracks the current location of the user and sends |
| 14 // NSNotifications when it changes. |
| 15 // The notification names and keys can be obtained using |
| 16 // GeolocationUpdaterProvider. |
| 17 @protocol GeolocationUpdater<NSObject> |
| 18 |
| 19 // Returns the most recently fetched location. Returns nil if disabled. |
| 20 - (CLLocation*)currentLocation; |
| 21 |
| 22 // Prompts the user to authorize access to location information while the app is |
| 23 // in use. Only affects iOS 8+. |
| 24 - (void)requestWhenInUseAuthorization; |
| 25 |
| 26 // Set the |timeout| the before the manager gives up fetching the location |
| 27 // information. If a timer has already been set to stop fetching location, |
| 28 // it will be reset to |timeout| seconds from now. |
| 29 - (void)setStopUpdateDelay:(NSTimeInterval)timeout; |
| 30 |
| 31 // Sets how often should the location manager check for a fresh location. |
| 32 - (void)setUpdateInterval:(NSTimeInterval)interval; |
| 33 |
| 34 // Sets the desired accuracy, distance and update interval. |
| 35 // Desired Accuracy defaults to: kCLLocationAccuracyBest. |
| 36 // Distance Filter defaults to: 20m. |
| 37 - (void)setDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy |
| 38 distanceFilter:(CLLocationDistance)distanceFilter; |
| 39 |
| 40 // Does not take into consideration whether location is disabled by the OS. |
| 41 - (BOOL)isEnabled; |
| 42 |
| 43 // Turns the geolocation updater on or off, depending on the value of flag. |
| 44 // if flag is false, then no more location updates will be requested, and |
| 45 // currentLocation will return nil. |
| 46 - (void)setEnabled:(BOOL)flag; |
| 47 |
| 48 @end |
| 49 |
| 50 namespace ios { |
| 51 |
| 52 class GeolocationUpdaterProvider { |
| 53 public: |
| 54 GeolocationUpdaterProvider(); |
| 55 virtual ~GeolocationUpdaterProvider(); |
| 56 |
| 57 // Creates a new GeolocationUpdater. |
| 58 // The returned object is retained and it is the responsability of the caller |
| 59 // to release it. |
| 60 virtual id<GeolocationUpdater> CreateGeolocationUpdater(bool enabled); |
| 61 |
| 62 // Notification names: |
| 63 |
| 64 // Name of NSNotificationCenter notification posted on user location update. |
| 65 // Passes a |CLLocation| for the new location in the userInfo dictionary with |
| 66 // the key returned by GetUpdateNewLocationKey(). |
| 67 virtual NSString* GetUpdateNotificationName(); |
| 68 // Name of NSNotificationCenter notification posted on when the location |
| 69 // manager's stops. |
| 70 virtual NSString* GetStopNotificationName(); |
| 71 // Name of NSNotificationCenter notification posted when the location |
| 72 // manager's authorization status changes. For example when the user turns |
| 73 // off Locations Services in Settings. The new status is passed as a |
| 74 // |NSNumber| representing the |CLAuthorizationStatus| enum value. |
| 75 virtual NSString* GetAuthorizationChangeNotificationName(); |
| 76 |
| 77 // Notification keys: |
| 78 |
| 79 // Key used in the userInfo dictionaries of this class' notifications. |
| 80 // Contains a |CLLocation *| and is used in the update notification. |
| 81 virtual NSString* GetUpdateNewLocationKey(); |
| 82 |
| 83 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(GeolocationUpdaterProvider); |
| 85 }; |
| 86 |
| 87 } // namespace ios |
| 88 |
| 89 #endif // IOS_PUBLIC_PROVIDER_CHROME_BROWSER_GEOLOCATION_UPDATER_H |
OLD | NEW |