shill: Convert ProxyFactory singleton to LazyInstance.
This makes it consistent with the rest of shill's singletons (DHCPProvider,
Resolver, RoutingTable, RTNLHandler) and improves static object's memory
management.
BUG=chromium-os:19178
TEST=unit tests, tested in a VM
Change-Id: Ib403d31473360b46dd25d12508c799cbc73368fd
Reviewed-on: http://gerrit.chromium.org/gerrit/8861
Tested-by: Darin Petkov <petkov@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Commit-Ready: Darin Petkov <petkov@chromium.org>
diff --git a/proxy_factory.h b/proxy_factory.h
index 6205c77..a55c392 100644
--- a/proxy_factory.h
+++ b/proxy_factory.h
@@ -8,6 +8,7 @@
#include <string>
#include <base/basictypes.h>
+#include <base/lazy_instance.h>
#include <base/memory/scoped_ptr.h>
#include <dbus-c++/dbus.h>
@@ -35,9 +36,11 @@
// Global DBus proxy factory that can be mocked out in tests.
class ProxyFactory {
public:
- ProxyFactory();
virtual ~ProxyFactory();
+ // Since this is a singleton, use ProxyFactory::GetInstance()->Foo()
+ static ProxyFactory *GetInstance();
+
void Init();
virtual DBusPropertiesProxyInterface *CreateDBusPropertiesProxy(
@@ -84,13 +87,13 @@
virtual DHCPProxyInterface *CreateDHCPProxy(const std::string &service);
- static ProxyFactory *factory() { return factory_; }
- static void set_factory(ProxyFactory *factory) { factory_ = factory; }
+ DBus::Connection *connection() const { return connection_.get(); }
- DBus::Connection *connection() { return connection_.get(); }
+ protected:
+ ProxyFactory();
private:
- static ProxyFactory *factory_;
+ friend struct base::DefaultLazyInstanceTraits<ProxyFactory>;
scoped_ptr<DBus::Connection> connection_;