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 #include "content/browser/geolocation/wifi_data_provider.h" | 5 #include "content/browser/geolocation/wifi_data_provider.h" |
6 | 6 |
7 namespace content { | 7 namespace content { |
8 | 8 |
9 WifiDataProvider::WifiDataProvider() | 9 WifiDataProvider::WifiDataProvider() |
10 : client_loop_(base::MessageLoop::current()) { | 10 : client_loop_(base::MessageLoop::current()) { |
11 DCHECK(client_loop_); | 11 DCHECK(client_loop_); |
12 } | 12 } |
13 | 13 |
14 WifiDataProvider::~WifiDataProvider() { | 14 WifiDataProvider::~WifiDataProvider() { |
15 } | 15 } |
16 | 16 |
17 void WifiDataProvider::AddCallback(WifiDataUpdateCallback* callback) { | 17 void WifiDataProvider::AddCallback(WifiDataUpdateCallback* callback) { |
18 callbacks_.insert(callback); | 18 callbacks_.insert(callback); |
19 } | 19 } |
20 | 20 |
21 bool WifiDataProvider::RemoveCallback(WifiDataUpdateCallback* callback) { | 21 bool WifiDataProvider::RemoveCallback(WifiDataUpdateCallback* callback) { |
22 return callbacks_.erase(callback) == 1; | 22 return callbacks_.erase(callback) == 1; |
23 } | 23 } |
24 | 24 |
25 bool WifiDataProvider::has_callbacks() const { | 25 bool WifiDataProvider::has_callbacks() const { |
26 return !callbacks_.empty(); | 26 return !callbacks_.empty(); |
27 } | 27 } |
28 | 28 |
29 void WifiDataProvider::RunCallbacks() { | 29 void WifiDataProvider::RunCallbacks() { |
30 client_loop_->PostTask(FROM_HERE, | 30 client_loop_->task_runner()->PostTask( |
31 base::Bind(&WifiDataProvider::DoRunCallbacks, this)); | 31 FROM_HERE, base::Bind(&WifiDataProvider::DoRunCallbacks, this)); |
32 } | 32 } |
33 | 33 |
34 bool WifiDataProvider::CalledOnClientThread() const { | 34 bool WifiDataProvider::CalledOnClientThread() const { |
35 return base::MessageLoop::current() == this->client_loop_; | 35 return base::MessageLoop::current() == this->client_loop_; |
36 } | 36 } |
37 | 37 |
38 base::MessageLoop* WifiDataProvider::client_loop() const { | 38 base::MessageLoop* WifiDataProvider::client_loop() const { |
39 return client_loop_; | 39 return client_loop_; |
40 } | 40 } |
41 | 41 |
42 void WifiDataProvider::DoRunCallbacks() { | 42 void WifiDataProvider::DoRunCallbacks() { |
43 // It's possible that all the callbacks went away whilst this task was | 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. | 44 // pending. This is fine; the loop will be a no-op. |
45 CallbackSet::const_iterator iter = callbacks_.begin(); | 45 CallbackSet::const_iterator iter = callbacks_.begin(); |
46 while (iter != callbacks_.end()) { | 46 while (iter != callbacks_.end()) { |
47 WifiDataUpdateCallback* callback = *iter; | 47 WifiDataUpdateCallback* callback = *iter; |
48 ++iter; // Advance iter before running, in case callback unregisters. | 48 ++iter; // Advance iter before running, in case callback unregisters. |
49 callback->Run(); | 49 callback->Run(); |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 } // namespace content | 53 } // namespace content |
OLD | NEW |