OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/geolocation/geolocation_provider.h" | 5 #include "chrome/browser/geolocation/geolocation_provider.h" |
6 | 6 |
7 #include "base/singleton.h" | 7 #include "base/singleton.h" |
8 #include "base/thread_restrictions.h" | |
9 #include "chrome/browser/geolocation/location_arbitrator.h" | 8 #include "chrome/browser/geolocation/location_arbitrator.h" |
10 | 9 |
11 // This class is guaranteed to outlive its internal thread, so ref counting | 10 // This class is guaranteed to outlive its internal thread, so ref counting |
12 // is not required. | 11 // is not required. |
13 DISABLE_RUNNABLE_METHOD_REFCOUNT(GeolocationProvider); | 12 DISABLE_RUNNABLE_METHOD_REFCOUNT(GeolocationProvider); |
14 | 13 |
15 GeolocationProvider* GeolocationProvider::GetInstance() { | 14 GeolocationProvider* GeolocationProvider::GetInstance() { |
16 return Singleton<GeolocationProvider>::get(); | 15 return Singleton<GeolocationProvider>::get(); |
17 } | 16 } |
18 | 17 |
(...skipping 22 matching lines...) Expand all Loading... |
41 bool GeolocationProvider::RemoveObserver(GeolocationObserver* observer) { | 40 bool GeolocationProvider::RemoveObserver(GeolocationObserver* observer) { |
42 DCHECK(OnClientThread()); | 41 DCHECK(OnClientThread()); |
43 size_t remove = observers_.erase(observer); | 42 size_t remove = observers_.erase(observer); |
44 OnObserversChanged(); | 43 OnObserversChanged(); |
45 return remove > 0; | 44 return remove > 0; |
46 } | 45 } |
47 | 46 |
48 void GeolocationProvider::OnObserversChanged() { | 47 void GeolocationProvider::OnObserversChanged() { |
49 DCHECK(OnClientThread()); | 48 DCHECK(OnClientThread()); |
50 if (observers_.empty()) { | 49 if (observers_.empty()) { |
51 // http://crbug.com/66077: This is a bug. The geolocation thread may | |
52 // transitively (via other threads it joins) block on long-running tasks / | |
53 // IO. | |
54 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
55 Stop(); | 50 Stop(); |
56 } else { | 51 } else { |
57 if (!IsRunning()) { | 52 if (!IsRunning()) { |
58 Start(); | 53 Start(); |
59 if (HasPermissionBeenGranted()) | 54 if (HasPermissionBeenGranted()) |
60 InformProvidersPermissionGranted(most_recent_authorized_frame_); | 55 InformProvidersPermissionGranted(most_recent_authorized_frame_); |
61 } | 56 } |
62 // The high accuracy requirement may have changed. | 57 // The high accuracy requirement may have changed. |
63 Task* task = NewRunnableMethod(this, | 58 Task* task = NewRunnableMethod(this, |
64 &GeolocationProvider::SetObserverOptions, | 59 &GeolocationProvider::SetObserverOptions, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 return most_recent_authorized_frame_.is_valid(); | 131 return most_recent_authorized_frame_.is_valid(); |
137 } | 132 } |
138 | 133 |
139 bool GeolocationProvider::OnClientThread() const { | 134 bool GeolocationProvider::OnClientThread() const { |
140 return client_loop_->BelongsToCurrentThread(); | 135 return client_loop_->BelongsToCurrentThread(); |
141 } | 136 } |
142 | 137 |
143 bool GeolocationProvider::OnGeolocationThread() const { | 138 bool GeolocationProvider::OnGeolocationThread() const { |
144 return MessageLoop::current() == message_loop(); | 139 return MessageLoop::current() == message_loop(); |
145 } | 140 } |
OLD | NEW |