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/location_manager.h" | 5 #import "ios/chrome/browser/geolocation/location_manager.h" |
6 | 6 |
7 #import "base/ios/weak_nsobject.h" | 7 #import "base/ios/weak_nsobject.h" |
8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
9 #import "ios/chrome/browser/geolocation/CLLocation+OmniboxGeolocation.h" | 9 #import "ios/chrome/browser/geolocation/CLLocation+OmniboxGeolocation.h" |
10 #import "ios/chrome/browser/geolocation/location_manager+Testing.h" | 10 #import "ios/chrome/browser/geolocation/location_manager+Testing.h" |
11 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 11 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
12 #import "ios/public/provider/chrome/browser/geolocation_updater_provider.h" | 12 #import "ios/public/provider/chrome/browser/geolocation_updater_provider.h" |
13 | 13 |
| 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 15 #error "This file requires ARC support." |
| 16 #endif |
| 17 |
14 namespace { | 18 namespace { |
15 | 19 |
16 const CLLocationDistance kLocationDesiredAccuracy = | 20 const CLLocationDistance kLocationDesiredAccuracy = |
17 kCLLocationAccuracyHundredMeters; | 21 kCLLocationAccuracyHundredMeters; |
18 // Number of seconds to wait before automatically stopping location updates. | 22 // Number of seconds to wait before automatically stopping location updates. |
19 const NSTimeInterval kLocationStopUpdateDelay = 5.0; | 23 const NSTimeInterval kLocationStopUpdateDelay = 5.0; |
20 // A large value to disable automatic location updates in GeolocationUpdater. | 24 // A large value to disable automatic location updates in GeolocationUpdater. |
21 const NSTimeInterval kLocationUpdateInterval = 365.0 * 24.0 * 60.0 * 60.0; | 25 const NSTimeInterval kLocationUpdateInterval = 365.0 * 24.0 * 60.0 * 60.0; |
22 | 26 |
23 } // namespace | 27 } // namespace |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 selector:@selector(handleAuthorizationChangeNotification:) | 73 selector:@selector(handleAuthorizationChangeNotification:) |
70 name:provider->GetAuthorizationChangeNotificationName() | 74 name:provider->GetAuthorizationChangeNotificationName() |
71 object:nil]; | 75 object:nil]; |
72 } | 76 } |
73 } | 77 } |
74 return self; | 78 return self; |
75 } | 79 } |
76 | 80 |
77 - (void)dealloc { | 81 - (void)dealloc { |
78 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 82 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
79 [super dealloc]; | |
80 } | 83 } |
81 | 84 |
82 - (CLAuthorizationStatus)authorizationStatus { | 85 - (CLAuthorizationStatus)authorizationStatus { |
83 return [CLLocationManager authorizationStatus]; | 86 return [CLLocationManager authorizationStatus]; |
84 } | 87 } |
85 | 88 |
86 - (CLLocation*)currentLocation { | 89 - (CLLocation*)currentLocation { |
87 if (!_currentLocation) | 90 if (!_currentLocation) |
88 _currentLocation.reset([[_locationUpdater currentLocation] retain]); | 91 _currentLocation.reset([_locationUpdater currentLocation]); |
89 return _currentLocation; | 92 return _currentLocation; |
90 } | 93 } |
91 | 94 |
92 - (id<LocationManagerDelegate>)delegate { | 95 - (id<LocationManagerDelegate>)delegate { |
93 return _delegate; | 96 return _delegate; |
94 } | 97 } |
95 | 98 |
96 - (void)setDelegate:(id<LocationManagerDelegate>)delegate { | 99 - (void)setDelegate:(id<LocationManagerDelegate>)delegate { |
97 _delegate.reset(delegate); | 100 _delegate.reset(delegate); |
98 } | 101 } |
(...skipping 18 matching lines...) Expand all Loading... |
117 } | 120 } |
118 | 121 |
119 #pragma mark - Private | 122 #pragma mark - Private |
120 | 123 |
121 - (void)handleLocationUpdateNotification:(NSNotification*)notification { | 124 - (void)handleLocationUpdateNotification:(NSNotification*)notification { |
122 NSString* newLocationKey = ios::GetChromeBrowserProvider() | 125 NSString* newLocationKey = ios::GetChromeBrowserProvider() |
123 ->GetGeolocationUpdaterProvider() | 126 ->GetGeolocationUpdaterProvider() |
124 ->GetUpdateNewLocationKey(); | 127 ->GetUpdateNewLocationKey(); |
125 CLLocation* location = [[notification userInfo] objectForKey:newLocationKey]; | 128 CLLocation* location = [[notification userInfo] objectForKey:newLocationKey]; |
126 if (location) { | 129 if (location) { |
127 _currentLocation.reset([location retain]); | 130 _currentLocation.reset(location); |
128 | 131 |
129 if (_startTime) { | 132 if (_startTime) { |
130 NSTimeInterval interval = -[_startTime timeIntervalSinceNow]; | 133 NSTimeInterval interval = -[_startTime timeIntervalSinceNow]; |
131 [_currentLocation cr_setAcquisitionInterval:interval]; | 134 [_currentLocation cr_setAcquisitionInterval:interval]; |
132 } | 135 } |
133 } | 136 } |
134 } | 137 } |
135 | 138 |
136 - (void)handleLocationStopNotification:(NSNotification*)notification { | 139 - (void)handleLocationStopNotification:(NSNotification*)notification { |
137 [_locationUpdater setEnabled:NO]; | 140 [_locationUpdater setEnabled:NO]; |
138 } | 141 } |
139 | 142 |
140 - (void)handleAuthorizationChangeNotification:(NSNotification*)notification { | 143 - (void)handleAuthorizationChangeNotification:(NSNotification*)notification { |
141 [_delegate locationManagerDidChangeAuthorizationStatus:self]; | 144 [_delegate locationManagerDidChangeAuthorizationStatus:self]; |
142 } | 145 } |
143 | 146 |
144 #pragma mark - LocationManager+Testing | 147 #pragma mark - LocationManager+Testing |
145 | 148 |
146 - (void)setGeolocationUpdater:(id<GeolocationUpdater>)geolocationUpdater { | 149 - (void)setGeolocationUpdater:(id<GeolocationUpdater>)geolocationUpdater { |
147 _locationUpdater.reset([geolocationUpdater retain]); | 150 _locationUpdater.reset(geolocationUpdater); |
148 } | 151 } |
149 | 152 |
150 @end | 153 @end |
OLD | NEW |