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
3 // found in the LICENSE file.
5 #include "content/browser/geolocation/wifi_data_provider.h"
9 WifiDataProvider::WifiDataProvider()
10 : client_loop_(base::MessageLoop::current()) {
14 WifiDataProvider::~WifiDataProvider() {
17 void WifiDataProvider::AddCallback(WifiDataUpdateCallback
* callback
) {
18 callbacks_
.insert(callback
);
21 bool WifiDataProvider::RemoveCallback(WifiDataUpdateCallback
* callback
) {
22 return callbacks_
.erase(callback
) == 1;
25 bool WifiDataProvider::has_callbacks() const {
26 return !callbacks_
.empty();
29 void WifiDataProvider::RunCallbacks() {
30 client_loop_
->PostTask(FROM_HERE
,
31 base::Bind(&WifiDataProvider::DoRunCallbacks
, this));
34 bool WifiDataProvider::CalledOnClientThread() const {
35 return base::MessageLoop::current() == this->client_loop_
;
38 base::MessageLoop
* WifiDataProvider::client_loop() const {
42 void WifiDataProvider::DoRunCallbacks() {
43 // It's possible that all the callbacks went away whilst this task was
44 // pending. This is fine; the loop will be a no-op.
45 CallbackSet::const_iterator iter
= callbacks_
.begin();
46 while (iter
!= callbacks_
.end()) {
47 WifiDataUpdateCallback
* callback
= *iter
;
48 ++iter
; // Advance iter before running, in case callback unregisters.
53 } // namespace content