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

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

Issue 23819030: Move WifiDataProvider implementation out of header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 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
« no previous file with comments | « content/browser/geolocation/wifi_data_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // static 9 // static
10 WifiDataProvider* WifiDataProvider::instance_ = NULL; 10 WifiDataProvider* WifiDataProvider::instance_ = NULL;
11 11
12 // static 12 // static
13 WifiDataProvider::ImplFactoryFunction WifiDataProvider::factory_function_ = 13 WifiDataProvider::ImplFactoryFunction WifiDataProvider::factory_function_ =
14 DefaultFactoryFunction; 14 DefaultFactoryFunction;
15 15
16 // static 16 // static
17 void WifiDataProvider::SetFactory(ImplFactoryFunction factory_function_in) {
18 factory_function_ = factory_function_in;
19 }
20
21 // static
22 void WifiDataProvider::ResetFactory() {
23 factory_function_ = DefaultFactoryFunction;
24 }
25
26 // static
17 WifiDataProvider* WifiDataProvider::Register(WifiDataUpdateCallback* callback) { 27 WifiDataProvider* WifiDataProvider::Register(WifiDataUpdateCallback* callback) {
18 bool need_to_start_data_provider = false; 28 bool need_to_start_data_provider = false;
19 if (!instance_) { 29 if (!instance_) {
20 instance_ = new WifiDataProvider(); 30 instance_ = new WifiDataProvider();
21 need_to_start_data_provider = true; 31 need_to_start_data_provider = true;
22 } 32 }
23 DCHECK(instance_); 33 DCHECK(instance_);
24 instance_->AddCallback(callback); 34 instance_->AddCallback(callback);
25 // Start the provider after adding the callback, to avoid any race in 35 // Start the provider after adding the callback, to avoid any race in
26 // it running early. 36 // it running early.
27 if (need_to_start_data_provider) 37 if (need_to_start_data_provider)
28 instance_->StartDataProvider(); 38 instance_->StartDataProvider();
29 return instance_; 39 return instance_;
30 } 40 }
31 41
42 // static
43 bool WifiDataProvider::Unregister(WifiDataUpdateCallback* callback) {
44 DCHECK(instance_);
45 DCHECK(instance_->has_callbacks());
46 if (!instance_->RemoveCallback(callback)) {
47 return false;
48 }
49 if (!instance_->has_callbacks()) {
50 // Must stop the data provider (and any implementation threads) before
51 // destroying to avoid any race conditions in access to the provider in
52 // the destructor chain.
53 instance_->StopDataProvider();
54 delete instance_;
55 instance_ = NULL;
56 }
57 return true;
58 }
59
32 WifiDataProviderImplBase::WifiDataProviderImplBase() 60 WifiDataProviderImplBase::WifiDataProviderImplBase()
33 : container_(NULL), 61 : container_(NULL),
34 client_loop_(base::MessageLoop::current()) { 62 client_loop_(base::MessageLoop::current()) {
35 DCHECK(client_loop_); 63 DCHECK(client_loop_);
36 } 64 }
37 65
38 WifiDataProviderImplBase::~WifiDataProviderImplBase() { 66 WifiDataProviderImplBase::~WifiDataProviderImplBase() {
39 } 67 }
40 68
41 void WifiDataProviderImplBase::SetContainer(WifiDataProvider* container) { 69 void WifiDataProviderImplBase::SetContainer(WifiDataProvider* container) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 impl_ = (*factory_function_)(); 113 impl_ = (*factory_function_)();
86 DCHECK(impl_.get()); 114 DCHECK(impl_.get());
87 impl_->SetContainer(this); 115 impl_->SetContainer(this);
88 } 116 }
89 117
90 WifiDataProvider::~WifiDataProvider() { 118 WifiDataProvider::~WifiDataProvider() {
91 DCHECK(impl_.get()); 119 DCHECK(impl_.get());
92 impl_->SetContainer(NULL); 120 impl_->SetContainer(NULL);
93 } 121 }
94 122
123 bool WifiDataProvider::GetData(WifiData* data) {
124 return impl_->GetData(data);
125 }
126
127 void WifiDataProvider::AddCallback(WifiDataUpdateCallback* callback) {
128 impl_->AddCallback(callback);
129 }
130
131 bool WifiDataProvider::RemoveCallback(WifiDataUpdateCallback* callback) {
132 return impl_->RemoveCallback(callback);
133 }
134
135 bool WifiDataProvider::has_callbacks() const {
136 return impl_->has_callbacks();
137 }
138
139 void WifiDataProvider::StartDataProvider() {
140 impl_->StartDataProvider();
141 }
142
143 void WifiDataProvider::StopDataProvider() {
144 impl_->StopDataProvider();
145 }
146
95 } // namespace content 147 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geolocation/wifi_data_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698