shill: group endpoints into services

Previously, we'd create one WiFiService for every WiFiEndpoint.
This would lead to redundant services appearing in the Service
list, and also cause problems with tracking the state of a
Service.

To fix this, we group Endpoints together by using FindService
to check if an appropriate Service exists, and only create a new
Service if no match is found.

BUG=chromium-os:22995
TEST=new unittests, network_WiFiRoaming.008Prefer5GHz

Bonus changes:
- remove some obsolete data structures
- fix a typo on my userid

Change-Id: Id3faa707531e61aa9bcb53582e7d53e7f6546eb3
Reviewed-on: https://gerrit.chromium.org/gerrit/12017
Commit-Ready: mukesh agrawal <quiche@chromium.org>
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Tested-by: mukesh agrawal <quiche@chromium.org>
diff --git a/wifi.h b/wifi.h
index 31c20dc..b804282 100644
--- a/wifi.h
+++ b/wifi.h
@@ -62,9 +62,9 @@
  private:
   friend class WiFiMainTest;  // access to supplicant_*_proxy_, link_up_
   FRIEND_TEST(WiFiMainTest, InitialSupplicantState);  // kInterfaceStateUnknown
+  FRIEND_TEST(WiFiMainTest, ScanResultsWithUpdates);  // EndpointMap
 
   typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap;
-  typedef std::map<const std::string, WiFiServiceRefPtr> ServiceMap;
   typedef std::map<WiFiService *, std::string> ReverseServiceMap;
 
   static const char kManagerErrorPassphraseRequired[];
@@ -83,6 +83,7 @@
   WiFiServiceRefPtr FindService(const std::vector<uint8_t> &ssid,
                                 const std::string &mode,
                                 const std::string &security) const;
+  WiFiServiceRefPtr FindServiceForEndpoint(const WiFiEndpoint &endpoint);
   ByteArrays GetHiddenSSIDList();
   void HandleDisconnect();
   void HandleRoam(const ::DBus::Path &new_bssid);
@@ -93,7 +94,6 @@
       const std::map<std::string, ::DBus::Variant> &properties);
   void ScanDoneTask();
   void ScanTask();
-  WiFiServiceRefPtr GetServiceForEndpoint(const WiFiEndpoint &endpoint);
   void StateChanged(const std::string &new_state);
 
   // Store cached copies of singletons for speed/ease of testing.
@@ -102,11 +102,9 @@
   ScopedRunnableMethodFactory<WiFi> task_factory_;
   scoped_ptr<SupplicantProcessProxyInterface> supplicant_process_proxy_;
   scoped_ptr<SupplicantInterfaceProxyInterface> supplicant_interface_proxy_;
-  EndpointMap endpoint_by_bssid_;
   // The rpcid used as the key is wpa_supplicant's D-Bus path for the
   // Endpoint (BSS, in supplicant parlance).
   EndpointMap endpoint_by_rpcid_;
-  ServiceMap service_by_private_id_;
   // Map from Services to the D-Bus path for the corresponding wpa_supplicant
   // Network.
   ReverseServiceMap rpcid_by_service_;