Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: content/browser/geolocation/wifi_data_provider.cc

Issue 486203004: Clean up WifiDataProvider(Manager) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't delete the DCHECK Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 : container_(NULL), 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::SetContainer(WifiDataProviderManager* container) {
18 container_ = container;
19 }
20
21 void WifiDataProvider::AddCallback(WifiDataUpdateCallback* callback) { 17 void WifiDataProvider::AddCallback(WifiDataUpdateCallback* callback) {
22 callbacks_.insert(callback); 18 callbacks_.insert(callback);
23 } 19 }
24 20
25 bool WifiDataProvider::RemoveCallback(WifiDataUpdateCallback* callback) { 21 bool WifiDataProvider::RemoveCallback(WifiDataUpdateCallback* callback) {
26 return callbacks_.erase(callback) == 1; 22 return callbacks_.erase(callback) == 1;
27 } 23 }
28 24
29 bool WifiDataProvider::has_callbacks() const { 25 bool WifiDataProvider::has_callbacks() const {
30 return !callbacks_.empty(); 26 return !callbacks_.empty();
31 } 27 }
32 28
33 void WifiDataProvider::RunCallbacks() { 29 void WifiDataProvider::RunCallbacks() {
34 client_loop_->PostTask(FROM_HERE, 30 client_loop_->PostTask(FROM_HERE,
35 base::Bind(&WifiDataProvider::DoRunCallbacks, this)); 31 base::Bind(&WifiDataProvider::DoRunCallbacks, this));
36 } 32 }
37 33
38 bool WifiDataProvider::CalledOnClientThread() const { 34 bool WifiDataProvider::CalledOnClientThread() const {
39 return base::MessageLoop::current() == this->client_loop_; 35 return base::MessageLoop::current() == this->client_loop_;
40 } 36 }
41 37
42 base::MessageLoop* WifiDataProvider::client_loop() const { 38 base::MessageLoop* WifiDataProvider::client_loop() const {
43 return client_loop_; 39 return client_loop_;
44 } 40 }
45 41
46 void WifiDataProvider::DoRunCallbacks() { 42 void WifiDataProvider::DoRunCallbacks() {
47 // It's possible that all the callbacks (and the container) went away 43 // It's possible that all the callbacks went away whilst this task was
48 // whilst this task was pending. This is fine; the loop will be a no-op. 44 // pending. This is fine; the loop will be a no-op.
49 CallbackSet::const_iterator iter = callbacks_.begin(); 45 CallbackSet::const_iterator iter = callbacks_.begin();
50 while (iter != callbacks_.end()) { 46 while (iter != callbacks_.end()) {
51 WifiDataUpdateCallback* callback = *iter; 47 WifiDataUpdateCallback* callback = *iter;
52 ++iter; // Advance iter before running, in case callback unregisters. 48 ++iter; // Advance iter before running, in case callback unregisters.
53 callback->Run(container_); 49 callback->Run();
54 } 50 }
55 } 51 }
56 52
57 } // namespace content 53 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geolocation/wifi_data_provider.h ('k') | content/browser/geolocation/wifi_data_provider_common_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698