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; ...@@ -13,6 +13,16 @@ WifiDataProvider* WifiDataProvider::instance_ = NULL;
WifiDataProvider::ImplFactoryFunction WifiDataProvider::factory_function_ = WifiDataProvider::ImplFactoryFunction WifiDataProvider::factory_function_ =
DefaultFactoryFunction; DefaultFactoryFunction;
// static
void WifiDataProvider::SetFactory(ImplFactoryFunction factory_function_in) {
factory_function_ = factory_function_in;
}
// static
void WifiDataProvider::ResetFactory() {
factory_function_ = DefaultFactoryFunction;
}
// static // static
WifiDataProvider* WifiDataProvider::Register(WifiDataUpdateCallback* callback) { WifiDataProvider* WifiDataProvider::Register(WifiDataUpdateCallback* callback) {
bool need_to_start_data_provider = false; bool need_to_start_data_provider = false;
...@@ -29,6 +39,24 @@ WifiDataProvider* WifiDataProvider::Register(WifiDataUpdateCallback* callback) { ...@@ -29,6 +39,24 @@ WifiDataProvider* WifiDataProvider::Register(WifiDataUpdateCallback* callback) {
return instance_; 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() WifiDataProviderImplBase::WifiDataProviderImplBase()
: container_(NULL), : container_(NULL),
client_loop_(base::MessageLoop::current()) { client_loop_(base::MessageLoop::current()) {
...@@ -92,4 +120,28 @@ WifiDataProvider::~WifiDataProvider() { ...@@ -92,4 +120,28 @@ WifiDataProvider::~WifiDataProvider() {
impl_->SetContainer(NULL); 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 } // namespace content
...@@ -108,13 +108,10 @@ class CONTENT_EXPORT WifiDataProvider { ...@@ -108,13 +108,10 @@ class CONTENT_EXPORT WifiDataProvider {
// used both to abstract accross platform-specific implementations and to // used both to abstract accross platform-specific implementations and to
// inject mock implementations for testing. // inject mock implementations for testing.
typedef WifiDataProviderImplBase* (*ImplFactoryFunction)(void); typedef WifiDataProviderImplBase* (*ImplFactoryFunction)(void);
static void SetFactory(ImplFactoryFunction factory_function_in) { static void SetFactory(ImplFactoryFunction factory_function_in);
factory_function_ = factory_function_in;
}
static void ResetFactory() { // Resets the factory function to the default.
factory_function_ = DefaultFactoryFunction; static void ResetFactory();
}
typedef base::Callback<void(WifiDataProvider*)> WifiDataUpdateCallback; typedef base::Callback<void(WifiDataProvider*)> WifiDataUpdateCallback;
...@@ -124,29 +121,12 @@ class CONTENT_EXPORT WifiDataProvider { ...@@ -124,29 +121,12 @@ class CONTENT_EXPORT WifiDataProvider {
// Removes a callback. If this is the last callback, deletes the singleton // Removes a callback. If this is the last callback, deletes the singleton
// instance. Return value indicates success. // instance. Return value indicates success.
static bool Unregister(WifiDataUpdateCallback* callback) { 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;
}
// Provides whatever data the provider has, which may be nothing. Return // Provides whatever data the provider has, which may be nothing. Return
// value indicates whether this is all the data the provider could ever // value indicates whether this is all the data the provider could ever
// obtain. // obtain.
bool GetData(WifiData* data) { bool GetData(WifiData* data);
return impl_->GetData(data);
}
private: private:
// Private constructor and destructor, callers access singleton through // Private constructor and destructor, callers access singleton through
...@@ -154,25 +134,12 @@ class CONTENT_EXPORT WifiDataProvider { ...@@ -154,25 +134,12 @@ class CONTENT_EXPORT WifiDataProvider {
WifiDataProvider(); WifiDataProvider();
virtual ~WifiDataProvider(); virtual ~WifiDataProvider();
void AddCallback(WifiDataUpdateCallback* callback) { void AddCallback(WifiDataUpdateCallback* callback);
impl_->AddCallback(callback); bool RemoveCallback(WifiDataUpdateCallback* callback);
} bool has_callbacks() const;
bool RemoveCallback(WifiDataUpdateCallback* callback) {
return impl_->RemoveCallback(callback);
}
bool has_callbacks() const {
return impl_->has_callbacks();
}
void StartDataProvider() {
impl_->StartDataProvider();
}
void StopDataProvider() { void StartDataProvider();
impl_->StopDataProvider(); void StopDataProvider();
}
static WifiDataProviderImplBase* DefaultFactoryFunction(); 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