43 { |
43 { |
44 if (m_client) |
44 if (m_client) |
45 m_client->geolocationDestroyed(); |
45 m_client->geolocationDestroyed(); |
46 } |
46 } |
47 |
47 |
48 void GeolocationController::addObserver(Geolocation* observer) |
48 void GeolocationController::addObserver(Geolocation* observer, bool enableHighAccuracy) |
49 { |
49 { |
50 // This may be called multiple times with the same observer, though removeObserver() |
50 // This may be called multiple times with the same observer, though removeObserver() |
51 // is called only once with each. |
51 // is called only once with each. |
52 if (m_observers.contains(observer)) |
|
53 return; |
|
54 |
|
55 bool wasEmpty = m_observers.isEmpty(); |
52 bool wasEmpty = m_observers.isEmpty(); |
56 m_observers.add(observer); |
53 m_observers.add(observer); |
57 if (wasEmpty && m_client) |
54 if (enableHighAccuracy) |
58 m_client->startUpdating(); |
55 m_highAccuracyObservers.add(observer); |
|
56 |
|
57 if (m_client) { |
|
58 if (enableHighAccuracy) |
|
59 m_client->setEnableHighAccuracy(true); |
|
60 if (wasEmpty) |
|
61 m_client->startUpdating(); |
|
62 } |
59 } |
63 } |
60 |
64 |
61 void GeolocationController::removeObserver(Geolocation* observer) |
65 void GeolocationController::removeObserver(Geolocation* observer) |
62 { |
66 { |
63 if (!m_observers.contains(observer)) |
67 if (!m_observers.contains(observer)) |
64 return; |
68 return; |
65 |
69 |
66 m_observers.remove(observer); |
70 m_observers.remove(observer); |
67 if (m_observers.isEmpty() && m_client) |
71 m_highAccuracyObservers.remove(observer); |
68 m_client->stopUpdating(); |
72 |
|
73 if (m_client) { |
|
74 if (m_observers.isEmpty()) |
|
75 m_client->stopUpdating(); |
|
76 else if (m_highAccuracyObservers.isEmpty()) |
|
77 m_client->setEnableHighAccuracy(false); |
|
78 } |
69 } |
79 } |
70 |
80 |
71 void GeolocationController::positionChanged(GeolocationPosition* position) |
81 void GeolocationController::positionChanged(GeolocationPosition* position) |
72 { |
82 { |
73 m_lastPosition = position; |
83 m_lastPosition = position; |