shill: wimax: Support WiMaxService::Unload.

On Unload, deregister and destroy all non-default services. Also, when a default
service is stopped (because its network has disappeared), deregister it from
Manager and destroy it -- this makes StartLiveServices symmetrical to
StopDeadServices.

BUG=chrome-os-partner:9942
TEST=unit tests

Change-Id: Ie9598b21529cbaf7a6b195468cbbd1e10edbe076
Reviewed-on: https://gerrit.chromium.org/gerrit/23649
Tested-by: Darin Petkov <petkov@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Ready: Darin Petkov <petkov@chromium.org>
diff --git a/wimax_service.cc b/wimax_service.cc
index 24e0604..3bb7096 100644
--- a/wimax_service.cc
+++ b/wimax_service.cc
@@ -31,7 +31,8 @@
                            Metrics *metrics,
                            Manager *manager)
     : Service(control, dispatcher, metrics, manager, Technology::kWiMax),
-      need_passphrase_(true) {
+      need_passphrase_(true),
+      is_default_(false) {
   PropertyStore *store = this->mutable_store();
   // TODO(benchan): Support networks that require no user credentials or
   // implicitly defined credentials.
@@ -39,6 +40,11 @@
   store->RegisterConstString(kNetworkIdProperty, &network_id_);
 
   IgnoreParameterForConfigure(kNetworkIdProperty);
+
+  // Initialize a default storage identifier based on the service's unique
+  // name. The identifier most likely needs to be reinitialized by the caller
+  // when its components have been set.
+  InitStorageIdentifier();
 }
 
 WiMaxService::~WiMaxService() {}
@@ -73,6 +79,7 @@
     device_->OnServiceStopped(this);
     device_ = NULL;
   }
+  UpdateConnectable();
 }
 
 bool WiMaxService::Start(WiMaxNetworkProxyInterface *proxy) {
@@ -174,8 +181,10 @@
   // Don't use Service::Is8021xConnectable because we don't support the full set
   // of authentication methods.
   bool is_connectable = false;
-  if (!eap().identity.empty()) {
-    is_connectable = !eap().password.empty();
+  if (IsStarted()) {
+    if (!eap().identity.empty()) {
+      is_connectable = !eap().password.empty();
+    }
   }
   set_connectable(is_connectable);
 }
@@ -195,6 +204,14 @@
   return true;
 }
 
+bool WiMaxService::Unload() {
+  // The base method also disconnects the service.
+  Service::Unload();
+  // Notify the WiMAX provider that this service has been unloaded. If the
+  // provider releases ownership of this service, it needs to be deregistered.
+  return manager()->wimax_provider()->OnServiceUnloaded(this);
+}
+
 // static
 WiMaxNetworkId WiMaxService::ConvertIdentifierToNetworkId(uint32 identifier) {
   return base::StringPrintf("%08x", identifier);