Move WifiDataProvider implementation out of header.

Review URL: https://chromiumcodereview.appspot.com/23819030

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222062 0039d316-1c4b-4281-b951-d872f2087c98
parent f8c1caf7
......@@ -13,6 +13,16 @@ WifiDataProvider* WifiDataProvider::instance_ = NULL;
WifiDataProvider::ImplFactoryFunction WifiDataProvider::factory_function_ =
DefaultFactoryFunction;
// static
void WifiDataProvider::SetFactory(ImplFactoryFunction factory_function_in) {
factory_function_ = factory_function_in;
}
// static
void WifiDataProvider::ResetFactory() {
factory_function_ = DefaultFactoryFunction;
}
// static
WifiDataProvider* WifiDataProvider::Register(WifiDataUpdateCallback* callback) {
bool need_to_start_data_provider = false;
......@@ -29,6 +39,24 @@ WifiDataProvider* WifiDataProvider::Register(WifiDataUpdateCallback* callback) {
return instance_;
}
// static
bool WifiDataProvider::Unregister(WifiDataUpdateCallback* callback) {
DCHECK(instance_);
DCHECK(instance_->has_callbacks());
if (!instance_->RemoveCallback(callback)) {
return false;
}
if (!instance_->has_callbacks()) {
// Must stop the data provider (and any implementation threads) before
// destroying to avoid any race conditions in access to the provider in
// the destructor chain.
instance_->StopDataProvider();
delete instance_;
instance_ = NULL;
}
return true;
}
WifiDataProviderImplBase::WifiDataProviderImplBase()
: container_(NULL),
client_loop_(base::MessageLoop::current()) {
......@@ -92,4 +120,28 @@ WifiDataProvider::~WifiDataProvider() {
impl_->SetContainer(NULL);
}
bool WifiDataProvider::GetData(WifiData* data) {
return impl_->GetData(data);
}
void WifiDataProvider::AddCallback(WifiDataUpdateCallback* callback) {
impl_->AddCallback(callback);
}
bool WifiDataProvider::RemoveCallback(WifiDataUpdateCallback* callback) {
return impl_->RemoveCallback(callback);
}
bool WifiDataProvider::has_callbacks() const {
return impl_->has_callbacks();
}
void WifiDataProvider::StartDataProvider() {
impl_->StartDataProvider();
}
void WifiDataProvider::StopDataProvider() {
impl_->StopDataProvider();
}
} // namespace content
......@@ -108,13 +108,10 @@ class CONTENT_EXPORT WifiDataProvider {
// used both to abstract accross platform-specific implementations and to
// inject mock implementations for testing.
typedef WifiDataProviderImplBase* (*ImplFactoryFunction)(void);
static void SetFactory(ImplFactoryFunction factory_function_in) {
factory_function_ = factory_function_in;
}
static void SetFactory(ImplFactoryFunction factory_function_in);
static void ResetFactory() {
factory_function_ = DefaultFactoryFunction;
}
// Resets the factory function to the default.
static void ResetFactory();
typedef base::Callback<void(WifiDataProvider*)> WifiDataUpdateCallback;
......@@ -124,29 +121,12 @@ class CONTENT_EXPORT WifiDataProvider {
// Removes a callback. If this is the last callback, deletes the singleton
// instance. Return value indicates success.
static bool Unregister(WifiDataUpdateCallback* callback) {
DCHECK(instance_);
DCHECK(instance_->has_callbacks());
if (!instance_->RemoveCallback(callback)) {
return false;
}
if (!instance_->has_callbacks()) {
// Must stop the data provider (and any implementation threads) before
// destroying to avoid any race conditions in access to the provider in
// the destructor chain.
instance_->StopDataProvider();
delete instance_;
instance_ = NULL;
}
return true;
}
static bool Unregister(WifiDataUpdateCallback* callback);
// Provides whatever data the provider has, which may be nothing. Return
// value indicates whether this is all the data the provider could ever
// obtain.
bool GetData(WifiData* data) {
return impl_->GetData(data);
}
bool GetData(WifiData* data);
private:
// Private constructor and destructor, callers access singleton through
......@@ -154,25 +134,12 @@ class CONTENT_EXPORT WifiDataProvider {
WifiDataProvider();
virtual ~WifiDataProvider();
void AddCallback(WifiDataUpdateCallback* callback) {
impl_->AddCallback(callback);
}
bool RemoveCallback(WifiDataUpdateCallback* callback) {
return impl_->RemoveCallback(callback);
}
bool has_callbacks() const {
return impl_->has_callbacks();
}
void StartDataProvider() {
impl_->StartDataProvider();
}
void AddCallback(WifiDataUpdateCallback* callback);
bool RemoveCallback(WifiDataUpdateCallback* callback);
bool has_callbacks() const;
void StopDataProvider() {
impl_->StopDataProvider();
}
void StartDataProvider();
void StopDataProvider();
static WifiDataProviderImplBase* DefaultFactoryFunction();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment