shill: make WiFiServices aware of their Endpoints

With this CL, WiFi makes a WiFiService aware of its
Endpoints, by calling AddEndpoint when an Endpoint
is found for a Service. Correspondingly, WiFi notifies
a WiFiService of the disappearance via RemoveEndpoint.

WiFiService uses this information to determine whether
or not it (the Service) is visible. Using Endpoint
information to inform the SignalStrength property is
left for a futre CL.

Collateral changes:
- added TODOs to Profile and WiFi
- switched to creating Services as soon as Endpoints
  are found (rather than waiting for a ScanDone signal)

BUG=chromium-os:22996, chromium-os:22948
TEST=unit tests

Change-Id: I7b4acf315418d1c3bc494bd4a37cdd85161c6ab0
Reviewed-on: https://gerrit.chromium.org/gerrit/12401
Tested-by: mukesh agrawal <quiche@chromium.org>
Reviewed-by: Gaurav Shah <gauravsh@chromium.org>
Commit-Ready: mukesh agrawal <quiche@chromium.org>
diff --git a/wifi_service.cc b/wifi_service.cc
index b1522cc..3874a06 100644
--- a/wifi_service.cc
+++ b/wifi_service.cc
@@ -26,6 +26,7 @@
 #include "shill/wifi_endpoint.h"
 #include "shill/wpa_supplicant.h"
 
+using std::set;
 using std::string;
 using std::vector;
 
@@ -124,6 +125,23 @@
   return wifi_->TechnologyIs(type);
 }
 
+void WiFiService::AddEndpoint(WiFiEndpointConstRefPtr endpoint) {
+  DCHECK(endpoint->ssid() == ssid());
+  endpoints_.insert(endpoint);
+}
+
+void WiFiService::RemoveEndpoint(WiFiEndpointConstRefPtr endpoint) {
+  set<WiFiEndpointConstRefPtr>::iterator i = endpoints_.find(endpoint);
+  DCHECK(i != endpoints_.end());
+  if (i == endpoints_.end()) {
+    LOG(WARNING) << "In " << __func__ << "(): "
+                 << "ignorning non-existent endpoint "
+                 << endpoint->bssid_string();
+    return;
+  }
+  endpoints_.erase(i);
+}
+
 string WiFiService::GetStorageIdentifier() const {
   return storage_identifier_;
 }
@@ -162,9 +180,7 @@
 }
 
 bool WiFiService::IsVisible() const {
-  // TODO(quiche): Write a function that returns whether (or which)
-  // endpoints are associated with this service.  crosbug.com/22948
-  const bool is_visible_in_scan = true;
+  const bool is_visible_in_scan = !endpoints_.empty();
 
   // WiFi Services should be displayed only if they are in range (have
   // endpoints that have shown up in a scan) or if the service is actively