shill: refactor supplicant_process_proxy and supplicant_interface_proxy

move these to separate files, and add a layer of indirection. this is
a step towards adding more unittests for wifi. (after breaking out these
classes, we can define mocks of them.)

BUG=chromium-os:16785
TEST=FEATURES="test nostrip noclean" emerge-x86-generic shill

Change-Id: I18570d47514bac0493d053f1a82b4d79a1565ad2
Reviewed-on: http://gerrit.chromium.org/gerrit/4117
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Tested-by: mukesh agrawal <quiche@chromium.org>
diff --git a/Makefile b/Makefile
index 1ea7217..855a094 100644
--- a/Makefile
+++ b/Makefile
@@ -86,6 +86,9 @@
 	shill_daemon.o \
 	shill_event.o \
 	sockets.o \
+	supplicant_interface_proxy.o \
+	supplicant_process_proxy.o \
+	supplicant_proxy_factory.o \
 	wifi.o \
 	wifi_endpoint.o \
 	wifi_service.o
diff --git a/shill_main.cc b/shill_main.cc
index ec8e91c..16703cd 100644
--- a/shill_main.cc
+++ b/shill_main.cc
@@ -17,6 +17,8 @@
 #include "shill/glib.h"
 #include "shill/shill_config.h"
 #include "shill/shill_daemon.h"
+#include "shill/supplicant_proxy_factory.h"
+#include "shill/wifi.h"
 
 using std::string;
 
@@ -93,6 +95,9 @@
 
   shill::Config config; /* (config_dir, default_config_dir) */
 
+  shill::SupplicantProxyFactory live_proxy_factory;
+  shill::WiFi::set_proxy_factory(&live_proxy_factory);
+
   // TODO(pstew): This should be chosen based on config
   shill::DBusControl *dbus_control = new shill::DBusControl();
   dbus_control->Init();
diff --git a/supplicant_interface_proxy.cc b/supplicant_interface_proxy.cc
new file mode 100644
index 0000000..e9e2a78
--- /dev/null
+++ b/supplicant_interface_proxy.cc
@@ -0,0 +1,115 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "shill/supplicant_interface_proxy.h"
+
+#include <map>
+#include <string>
+
+#include <base/logging.h>
+#include <dbus-c++/dbus.h>
+
+#include "shill/wifi.h"
+
+using std::map;
+using std::string;
+
+namespace shill {
+
+SupplicantInterfaceProxy::SupplicantInterfaceProxy(
+    const WiFiRefPtr &wifi,
+    const ::DBus::Path &object_path,
+    const char *dbus_addr)
+    : connection_(DBus::Connection::SystemBus()),
+      proxy_(wifi, &connection_, object_path, dbus_addr) {}
+
+SupplicantInterfaceProxy::~SupplicantInterfaceProxy() {}
+
+::DBus::Path SupplicantInterfaceProxy::AddNetwork(
+    const std::map<std::string, ::DBus::Variant> &args) {
+  return proxy_.AddNetwork(args);
+}
+
+void SupplicantInterfaceProxy::FlushBSS(const uint32_t &age) {
+  return proxy_.FlushBSS(age);
+}
+
+void SupplicantInterfaceProxy::RemoveAllNetworks() {
+  return proxy_.RemoveAllNetworks();
+}
+
+void SupplicantInterfaceProxy::Scan(
+    const std::map<std::string, ::DBus::Variant> &args) {
+  return proxy_.Scan(args);
+}
+
+void SupplicantInterfaceProxy::SelectNetwork(const ::DBus::Path &network) {
+  return proxy_.SelectNetwork(network);
+}
+
+// definitions for private class SupplicantInterfaceProxy::Proxy
+
+SupplicantInterfaceProxy::Proxy::Proxy(
+    const WiFiRefPtr &wifi, DBus::Connection *bus,
+    const DBus::Path &dbus_path, const char *dbus_addr)
+    : DBus::ObjectProxy(*bus, dbus_path, dbus_addr),
+      wifi_(wifi) {}
+
+SupplicantInterfaceProxy::Proxy::~Proxy() {}
+
+void SupplicantInterfaceProxy::Proxy::BlobAdded(const string &blobname) {
+  LOG(INFO) << __func__;
+  // XXX
+}
+
+void SupplicantInterfaceProxy::Proxy::BlobRemoved(const string &blobname) {
+  LOG(INFO) << __func__;
+  // XXX
+}
+
+void SupplicantInterfaceProxy::Proxy::BSSAdded(
+    const ::DBus::Path &BSS,
+    const std::map<string, ::DBus::Variant> &properties) {
+  LOG(INFO) << __func__;
+  wifi_->BSSAdded(BSS, properties);
+}
+
+void SupplicantInterfaceProxy::Proxy::BSSRemoved(const ::DBus::Path &BSS) {
+  LOG(INFO) << __func__;
+  // XXX
+}
+
+void SupplicantInterfaceProxy::Proxy::NetworkAdded(
+    const ::DBus::Path &network,
+    const std::map<string, ::DBus::Variant> &properties) {
+  LOG(INFO) << __func__;
+  // XXX
+}
+
+void SupplicantInterfaceProxy::Proxy::NetworkRemoved(
+    const ::DBus::Path &network) {
+  LOG(INFO) << __func__;
+  // XXX
+}
+
+void SupplicantInterfaceProxy::Proxy::NetworkSelected(
+    const ::DBus::Path &network) {
+  LOG(INFO) << __func__;
+  // XXX
+}
+
+void SupplicantInterfaceProxy::Proxy::PropertiesChanged(
+    const std::map<string, ::DBus::Variant> &properties) {
+  LOG(INFO) << __func__;
+  // XXX
+}
+
+void SupplicantInterfaceProxy::Proxy::ScanDone(const bool& success) {
+  LOG(INFO) << __func__ << " " << success;
+  if (success) {
+    wifi_->ScanDone();
+  }
+}
+
+}  // namespace shill
diff --git a/supplicant_interface_proxy.h b/supplicant_interface_proxy.h
new file mode 100644
index 0000000..cd7a95e
--- /dev/null
+++ b/supplicant_interface_proxy.h
@@ -0,0 +1,76 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SUPPLICANT_INTERFACE_PROXY_H_
+#define SUPPLICANT_INTERFACE_PROXY_H_
+
+#include <map>
+#include <string>
+
+#include <base/basictypes.h>
+
+#include "shill/supplicant-interface.h"
+#include "shill/supplicant_interface_proxy_interface.h"
+#include "shill/refptr_types.h"
+
+namespace shill {
+
+// SupplicantInterfaceProxy. provides access to wpa_supplicant's
+// network-interface APIs via D-Bus.
+class SupplicantInterfaceProxy
+    : public SupplicantInterfaceProxyInterface {
+ public:
+  SupplicantInterfaceProxy(const WiFiRefPtr &wifi,
+                           const ::DBus::Path &object_path,
+                           const char *dbus_addr);
+  virtual ~SupplicantInterfaceProxy();
+
+  virtual ::DBus::Path AddNetwork(
+      const std::map<std::string, ::DBus::Variant> &args);
+  virtual void FlushBSS(const uint32_t &age);
+  virtual void RemoveAllNetworks();
+  virtual void Scan(
+      const std::map<std::string, ::DBus::Variant> &args);
+  virtual void SelectNetwork(const ::DBus::Path &network);
+
+ private:
+  class Proxy : public fi::w1::wpa_supplicant1::Interface_proxy,
+    public ::DBus::ObjectProxy {
+   public:
+    Proxy(const WiFiRefPtr &wifi, DBus::Connection *bus,
+          const ::DBus::Path &object_path, const char *dbus_addr);
+    virtual ~Proxy();
+
+   private:
+    // signal handlers called by dbus-c++, via
+    // fi::w1::wpa_supplicant1::Interface_proxy interface
+    virtual void BlobAdded(const std::string &blobname);
+    virtual void BlobRemoved(const std::string &blobname);
+    virtual void BSSAdded(const ::DBus::Path &BSS,
+                          const std::map<std::string, ::DBus::Variant>
+                          &properties);
+    virtual void BSSRemoved(const ::DBus::Path &BSS);
+    virtual void NetworkAdded(const ::DBus::Path &network,
+                              const std::map<std::string, ::DBus::Variant>
+                              &properties);
+    virtual void NetworkRemoved(const ::DBus::Path &network);
+    virtual void NetworkSelected(const ::DBus::Path &network);
+    virtual void PropertiesChanged(const std::map<std::string, ::DBus::Variant>
+                                   &properties);
+    virtual void ScanDone(const bool &success);
+
+    WiFiRefPtr wifi_;
+    DISALLOW_COPY_AND_ASSIGN(Proxy);
+  };
+
+  DBus::Connection connection_;
+  Proxy proxy_;
+
+  DISALLOW_COPY_AND_ASSIGN(SupplicantInterfaceProxy);
+
+};
+
+}  // namespace shill
+
+#endif  // SUPPLICANT_INTERFACE_PROXY_H_
diff --git a/supplicant_interface_proxy_interface.h b/supplicant_interface_proxy_interface.h
new file mode 100644
index 0000000..c4be6b9
--- /dev/null
+++ b/supplicant_interface_proxy_interface.h
@@ -0,0 +1,32 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SUPPLICANT_INTERFACE_PROXY_INTERFACE_H_
+#define SUPPLICANT_INTERFACE_PROXY_INTERFACE_H_
+
+#include <map>
+#include <string>
+
+#include <dbus-c++/dbus.h>
+
+namespace shill {
+
+// SupplicantInterfaceProxyInterface declares only the subset of
+// fi::w1::wpa_supplicant1::Interface_proxy that is actually used by WiFi.
+class SupplicantInterfaceProxyInterface {
+ public:
+  virtual ~SupplicantInterfaceProxyInterface() {}
+
+  virtual ::DBus::Path AddNetwork(
+      const std::map<std::string, ::DBus::Variant> &args) = 0;
+  virtual void FlushBSS(const uint32_t &age) = 0;
+  virtual void RemoveAllNetworks() = 0;
+  virtual void Scan(
+      const std::map<std::string, ::DBus::Variant> &args) = 0;
+  virtual void SelectNetwork(const ::DBus::Path &network) = 0;
+};
+
+}  // namespace shill
+
+#endif  // SUPPLICANT_INTERFACE_PROXY_INTERFACE_H_
diff --git a/supplicant_process_proxy.cc b/supplicant_process_proxy.cc
new file mode 100644
index 0000000..59f762b
--- /dev/null
+++ b/supplicant_process_proxy.cc
@@ -0,0 +1,65 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "supplicant_process_proxy.h"
+
+#include <map>
+#include <string>
+
+#include <base/logging.h>
+#include <dbus-c++/dbus.h>
+
+using std::map;
+using std::string;
+
+namespace shill {
+
+SupplicantProcessProxy::SupplicantProcessProxy(
+    const char *dbus_path, const char *dbus_addr)
+    : connection_(DBus::Connection::SystemBus()),
+      proxy_(&connection_, dbus_path, dbus_addr) {}
+
+SupplicantProcessProxy::~SupplicantProcessProxy() {}
+
+::DBus::Path SupplicantProcessProxy::CreateInterface(
+    const map<string, ::DBus::Variant> &args) {
+  return proxy_.CreateInterface(args);
+}
+
+void SupplicantProcessProxy::RemoveInterface(const ::DBus::Path &path) {
+  return proxy_.RemoveInterface(path);
+}
+
+::DBus::Path SupplicantProcessProxy::GetInterface(const string &ifname) {
+  return proxy_.GetInterface(ifname);
+}
+
+// definitions for private class SupplicantProcessProxy::Proxy
+
+SupplicantProcessProxy::Proxy::Proxy(
+    DBus::Connection *bus, const char *dbus_path, const char *dbus_addr)
+    : DBus::ObjectProxy(*bus, dbus_path, dbus_addr) {}
+
+SupplicantProcessProxy::Proxy::~Proxy() {}
+
+void SupplicantProcessProxy::Proxy::InterfaceAdded(
+    const ::DBus::Path& path,
+    const map<string, ::DBus::Variant> &properties) {
+  LOG(INFO) << __func__;
+  // XXX
+}
+
+void SupplicantProcessProxy::Proxy::InterfaceRemoved(
+    const ::DBus::Path& path) {
+  LOG(INFO) << __func__;
+  // XXX
+}
+
+void SupplicantProcessProxy::Proxy::PropertiesChanged(
+    const map<string, ::DBus::Variant>& properties) {
+  LOG(INFO) << __func__;
+  // XXX
+}
+
+}  // namespace shill
diff --git a/supplicant_process_proxy.h b/supplicant_process_proxy.h
new file mode 100644
index 0000000..cc7d939
--- /dev/null
+++ b/supplicant_process_proxy.h
@@ -0,0 +1,57 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SUPPLICANT_PROCESS_PROXY_H_
+#define SUPPLICANT_PROCESS_PROXY_H_
+
+#include <map>
+#include <string>
+
+#include <base/basictypes.h>
+
+#include "supplicant-process.h"
+#include "supplicant_process_proxy_interface.h"
+
+namespace shill {
+
+class SupplicantProcessProxy : public SupplicantProcessProxyInterface {
+ public:
+  SupplicantProcessProxy(const char *dbus_path, const char *dbus_addr);
+  virtual ~SupplicantProcessProxy();
+  virtual ::DBus::Path CreateInterface(
+      const std::map<std::string, ::DBus::Variant> &args);
+  virtual void RemoveInterface(const ::DBus::Path &path);
+  virtual ::DBus::Path GetInterface(const std::string &ifname);
+
+ private:
+  class Proxy : public fi::w1::wpa_supplicant1_proxy,
+    public ::DBus::ObjectProxy {
+   public:
+    Proxy(DBus::Connection *bus, const char *dbus_path,
+          const char *dbus_addr);
+    virtual ~Proxy();
+
+   private:
+    // signal handlers called by dbus-c++, via
+    // wpa_supplicant1_proxy interface.
+    virtual void InterfaceAdded(
+        const ::DBus::Path &path,
+        const std::map<std::string, ::DBus::Variant> &properties);
+    virtual void InterfaceRemoved(const ::DBus::Path &path);
+    virtual void PropertiesChanged(
+        const std::map<std::string, ::DBus::Variant> &properties);
+
+    DISALLOW_COPY_AND_ASSIGN(Proxy);
+  };
+
+  DBus::Connection connection_;
+  Proxy proxy_;
+
+  DISALLOW_COPY_AND_ASSIGN(SupplicantProcessProxy);
+
+};
+
+}  // namespace shill
+
+#endif   // SUPPLICANT_PROCESS_PROXY_H_
diff --git a/supplicant_process_proxy_interface.h b/supplicant_process_proxy_interface.h
new file mode 100644
index 0000000..c3a60c1
--- /dev/null
+++ b/supplicant_process_proxy_interface.h
@@ -0,0 +1,28 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SUPPLICANT_PROCESS_PROXY_INTERFACE_H_
+#define SUPPLICANT_PROCESS_PROXY_INTERFACE_H_
+
+#include <map>
+#include <string>
+
+#include <dbus-c++/dbus.h>
+
+namespace shill {
+
+// SupplicantProcessProxyInterface declares only the subset of
+// fi::w1::wpa_supplicant1_proxy that is actually used by WiFi.
+class SupplicantProcessProxyInterface {
+ public:
+  virtual ~SupplicantProcessProxyInterface() {}
+  virtual ::DBus::Path CreateInterface(
+      const std::map<std::string, ::DBus::Variant> &args) = 0;
+  virtual void RemoveInterface(const ::DBus::Path &path) = 0;
+  virtual ::DBus::Path GetInterface(const std::string &ifname) = 0;
+};
+
+}  // namespace shill
+
+#endif   // SUPPLICANT_PROCESS_PROXY_INTERFACE_H_
diff --git a/supplicant_proxy_factory.cc b/supplicant_proxy_factory.cc
new file mode 100644
index 0000000..d7a4274
--- /dev/null
+++ b/supplicant_proxy_factory.cc
@@ -0,0 +1,33 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <dbus-c++/dbus.h>
+
+#include "shill/supplicant_proxy_factory.h"
+
+#include "shill/supplicant_interface_proxy.h"
+#include "shill/supplicant_interface_proxy_interface.h"
+#include "shill/supplicant_process_proxy.h"
+#include "shill/supplicant_process_proxy_interface.h"
+
+namespace shill {
+
+SupplicantProxyFactory::SupplicantProxyFactory() {}
+
+SupplicantProxyFactory::~SupplicantProxyFactory() {}
+
+SupplicantProcessProxyInterface *
+SupplicantProxyFactory::CreateProcessProxy(const char *dbus_path,
+                                           const char *dbus_addr) {
+  return new SupplicantProcessProxy(dbus_path, dbus_addr);
+}
+
+SupplicantInterfaceProxyInterface *
+SupplicantProxyFactory::CreateInterfaceProxy(
+    const WiFiRefPtr &wifi, const ::DBus::Path &object_path,
+    const char *dbus_addr) {
+  return new SupplicantInterfaceProxy(wifi, object_path, dbus_addr);
+}
+
+}  // namespace shill
diff --git a/supplicant_proxy_factory.h b/supplicant_proxy_factory.h
new file mode 100644
index 0000000..e454153
--- /dev/null
+++ b/supplicant_proxy_factory.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SUPPLICANT_PROXY_FACTORY_H_
+#define SUPPLICANT_PROXY_FACTORY_H_
+
+#include <dbus-c++/dbus.h>
+
+#include "shill/refptr_types.h"
+
+namespace shill {
+
+class SupplicantInterfaceProxyInterface;
+class SupplicantProcessProxyInterface;
+
+class SupplicantProxyFactory {
+ public:
+  SupplicantProxyFactory();
+  virtual ~SupplicantProxyFactory();
+
+  virtual SupplicantProcessProxyInterface *CreateProcessProxy(
+      const char *dbus_path, const char *dbus_addr);
+
+  virtual SupplicantInterfaceProxyInterface *CreateInterfaceProxy(
+      const WiFiRefPtr &wifi,
+      const ::DBus::Path &object_path,
+      const char *dbus_addr);
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(SupplicantProxyFactory);
+};
+
+}  // namespace shill
+
+#endif  // SUPPLICANT_PROXY_FACTORY_H_
diff --git a/wifi.cc b/wifi.cc
index 832127d..958b968 100644
--- a/wifi.cc
+++ b/wifi.cc
@@ -21,6 +21,8 @@
 #include "shill/manager.h"
 #include "shill/profile.h"
 #include "shill/shill_event.h"
+#include "shill/supplicant_interface_proxy_interface.h"
+#include "shill/supplicant_process_proxy_interface.h"
 #include "shill/wifi_endpoint.h"
 #include "shill/wifi_service.h"
 
@@ -37,90 +39,9 @@
 const char WiFi::kSupplicantPropertyKeyMode[]     = "key_mgmt";
 const char WiFi::kSupplicantKeyModeNone[] = "NONE";
 
+SupplicantProxyFactory *WiFi::proxy_factory = NULL;
 unsigned int WiFi::service_id_serial_ = 0;
 
-WiFi::SupplicantProcessProxy::SupplicantProcessProxy(DBus::Connection *bus)
-    : DBus::ObjectProxy(*bus, kSupplicantPath, kSupplicantDBusAddr) {}
-
-void WiFi::SupplicantProcessProxy::InterfaceAdded(
-    const ::DBus::Path& path,
-    const std::map<string, ::DBus::Variant> &properties) {
-  LOG(INFO) << __func__;
-  // XXX
-}
-
-void WiFi::SupplicantProcessProxy::InterfaceRemoved(const ::DBus::Path& path) {
-  LOG(INFO) << __func__;
-  // XXX
-}
-
-void WiFi::SupplicantProcessProxy::PropertiesChanged(
-    const std::map<string, ::DBus::Variant>& properties) {
-  LOG(INFO) << __func__;
-  // XXX
-}
-
-WiFi::SupplicantInterfaceProxy::SupplicantInterfaceProxy(
-    const WiFiRefPtr &wifi,
-    DBus::Connection *bus,
-    const ::DBus::Path &object_path)
-    : DBus::ObjectProxy(*bus, object_path, kSupplicantDBusAddr),
-      wifi_(wifi) {}
-
-void WiFi::SupplicantInterfaceProxy::ScanDone(const bool& success) {
-  LOG(INFO) << __func__ << " " << success;
-  if (success) {
-    wifi_->ScanDone();
-  }
-}
-
-void WiFi::SupplicantInterfaceProxy::BSSAdded(
-    const ::DBus::Path &BSS,
-    const std::map<string, ::DBus::Variant> &properties) {
-  LOG(INFO) << __func__;
-  wifi_->BSSAdded(BSS, properties);
-}
-
-void WiFi::SupplicantInterfaceProxy::BSSRemoved(const ::DBus::Path &BSS) {
-  LOG(INFO) << __func__;
-  // XXX
-}
-
-void WiFi::SupplicantInterfaceProxy::BlobAdded(const string &blobname) {
-  LOG(INFO) << __func__;
-  // XXX
-}
-
-void WiFi::SupplicantInterfaceProxy::BlobRemoved(const string &blobname) {
-  LOG(INFO) << __func__;
-  // XXX
-}
-
-void WiFi::SupplicantInterfaceProxy::NetworkAdded(
-    const ::DBus::Path &network,
-    const std::map<string, ::DBus::Variant> &properties) {
-  LOG(INFO) << __func__;
-  // XXX
-}
-
-void WiFi::SupplicantInterfaceProxy::NetworkRemoved(
-    const ::DBus::Path &network) {
-  LOG(INFO) << __func__;
-  // XXX
-}
-
-void WiFi::SupplicantInterfaceProxy::NetworkSelected(
-    const ::DBus::Path &network) {
-  LOG(INFO) << __func__;
-  // XXX
-}
-
-void WiFi::SupplicantInterfaceProxy::PropertiesChanged(
-    const std::map<string, ::DBus::Variant> &properties) {
-  LOG(INFO) << __func__;
-  // XXX
-}
-
 // NB: we assume supplicant is already running. [quiche.20110518]
 WiFi::WiFi(ControlInterface *control_interface,
            EventDispatcher *dispatcher,
@@ -154,14 +75,14 @@
   VLOG(2) << "WiFi device " << link_name() << " initialized.";
 }
 
-WiFi::~WiFi() {
-}
+WiFi::~WiFi() {}
 
 void WiFi::Start() {
-  dbus_.reset(new DBus::Connection(DBus::Connection::SystemBus()));
   ::DBus::Path interface_path;
 
-  supplicant_process_proxy_.reset(new SupplicantProcessProxy(dbus_.get()));
+  supplicant_process_proxy_.reset(
+      proxy_factory->CreateProcessProxy(
+          kSupplicantPath, kSupplicantDBusAddr));
   try {
     std::map<string, DBus::Variant> create_interface_args;
     create_interface_args["Ifname"].writer().
@@ -183,7 +104,8 @@
   }
 
   supplicant_interface_proxy_.reset(
-      new SupplicantInterfaceProxy(this, dbus_.get(), interface_path));
+      proxy_factory->CreateInterfaceProxy(
+          this, interface_path, kSupplicantDBusAddr));
 
   // TODO(quiche) set ApScan=1 and BSSExpireAge=190, like flimflam does?
 
@@ -263,6 +185,11 @@
   // XXX add to favorite networks list?
 }
 
+// static
+void WiFi::set_proxy_factory(SupplicantProxyFactory *new_factory) {
+  proxy_factory = new_factory;
+}
+
 void WiFi::RealScanDone() {
   LOG(INFO) << __func__;
 
diff --git a/wifi.h b/wifi.h
index 21a66cc..a790678 100644
--- a/wifi.h
+++ b/wifi.h
@@ -9,14 +9,17 @@
 #include <string>
 #include <vector>
 
+#include <dbus-c++/dbus.h>
+
 #include "shill/device.h"
 #include "shill/refptr_types.h"
 #include "shill/shill_event.h"
-#include "shill/supplicant-process.h"
-#include "shill/supplicant-interface.h"
+#include "shill/supplicant_proxy_factory.h"
 
 namespace shill {
 
+class SupplicantInterfaceProxyInterface;
+class SupplicantProcessProxyInterface;
 class WiFiService;
 
 // WiFi class. Specialization of Device for WiFi.
@@ -41,61 +44,9 @@
   // called by WiFiService
   void ConnectTo(const WiFiService &service);
 
+  static void set_proxy_factory(SupplicantProxyFactory *factory);
+
  private:
-  // SupplicantProcessProxy. provides access to wpa_supplicant's
-  // process-level D-Bus APIs.
-  class SupplicantProcessProxy :
-      public fi::w1::wpa_supplicant1_proxy,
-        private ::DBus::ObjectProxy  // used by dbus-c++, not WiFi
-  {
-   public:
-    explicit SupplicantProcessProxy(DBus::Connection *bus);
-
-   private:
-    // called by dbus-c++, via wpa_supplicant1_proxy interface,
-    // in response to signals from wpa_supplicant. not exposed
-    // to WiFi.
-    virtual void InterfaceAdded(
-        const ::DBus::Path &path,
-        const std::map<std::string, ::DBus::Variant> &properties);
-    virtual void InterfaceRemoved(const ::DBus::Path &path);
-    virtual void PropertiesChanged(
-        const std::map<std::string, ::DBus::Variant> &properties);
-  };
-
-  // SupplicantInterfaceProxy. provides access to wpa_supplicant's
-  // network-interface D-Bus APIs.
-  class SupplicantInterfaceProxy :
-      public fi::w1::wpa_supplicant1::Interface_proxy,
-      private ::DBus::ObjectProxy  // used by dbus-c++, not WiFi
-  {
-   public:
-    SupplicantInterfaceProxy(const WiFiRefPtr &wifi,
-                             DBus::Connection *bus,
-                             const ::DBus::Path &object_path);
-
-   private:
-    // called by dbus-c++, via Interface_proxy interface,
-    // in response to signals from wpa_supplicant. not exposed
-    // to WiFi.
-    virtual void ScanDone(const bool &success);
-    virtual void BSSAdded(const ::DBus::Path &BSS,
-                          const std::map<std::string, ::DBus::Variant>
-                          &properties);
-    virtual void BSSRemoved(const ::DBus::Path &BSS);
-    virtual void BlobAdded(const std::string &blobname);
-    virtual void BlobRemoved(const std::string &blobname);
-    virtual void NetworkAdded(const ::DBus::Path &network,
-                              const std::map<std::string, ::DBus::Variant>
-                              &properties);
-    virtual void NetworkRemoved(const ::DBus::Path &network);
-    virtual void NetworkSelected(const ::DBus::Path &network);
-    virtual void PropertiesChanged(const std::map<std::string, ::DBus::Variant>
-                                   &properties);
-
-    WiFiRefPtr wifi_;
-  };
-
   typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap;
   typedef std::map<const std::string, ServiceRefPtr> ServiceMap;
 
@@ -110,13 +61,13 @@
 
   void RealScanDone();
 
+  static SupplicantProxyFactory *proxy_factory;
   static unsigned int service_id_serial_;
   ScopedRunnableMethodFactory<WiFi> task_factory_;
   ControlInterface *control_interface_;
   EventDispatcher *dispatcher_;
-  scoped_ptr<DBus::Connection> dbus_;
-  scoped_ptr<SupplicantProcessProxy> supplicant_process_proxy_;
-  scoped_ptr<SupplicantInterfaceProxy> supplicant_interface_proxy_;
+  scoped_ptr<SupplicantProcessProxyInterface> supplicant_process_proxy_;
+  scoped_ptr<SupplicantInterfaceProxyInterface> supplicant_interface_proxy_;
   EndpointMap endpoint_by_bssid_;
   ServiceMap service_by_private_id_;