shill: Add cellular hooks for suspend and termination

When ChromeOS suspends or shill terminates, a cellular device should
disconnect from the cellular service.  This CL adds methods to do that
and connects them to the manager's hook table.  The manager runs these
actions when there is a terminate signal.  The shill Daemon has been
modified to signal the manager on a terminate signal.  TODO: Run these
actions on a suspend signal.

This CL modifies the HookTable API to remove the polling action.
Instead, actions are expected to call HookTable::ActionComplete()
to signal the completion of an action.

BUG=chromium-os:22408
TEST=new unittests; ran all existing unittests.  Manual testing
includes executing 'stop shill' and looking at log messages to make
sure the termination actions occurred.

Change-Id: I5bbf0832e76a5c818724fbca4c436beb3e5d182b
Reviewed-on: https://gerrit.chromium.org/gerrit/24261
Reviewed-by: Jason Glasgow <jglasgow@chromium.org>
Tested-by: Gary Morain <gmorain@chromium.org>
Commit-Ready: Gary Morain <gmorain@chromium.org>
diff --git a/cellular.cc b/cellular.cc
index 01cbc7a..2a4e2db 100644
--- a/cellular.cc
+++ b/cellular.cc
@@ -12,6 +12,7 @@
 #include <vector>
 
 #include <base/bind.h>
+#include <base/callback.h>
 #include <base/logging.h>
 #include <base/stringprintf.h>
 #include <chromeos/dbus/service_constants.h>
@@ -37,6 +38,7 @@
 #include "shill/technology.h"
 
 using base::Bind;
+using base::Closure;
 using std::string;
 using std::vector;
 
@@ -422,6 +424,8 @@
     VLOG(2) << "Already connected";
     return;
   }
+  Closure start_cb = Bind(&Cellular::StartTermination, this);
+  manager()->AddTerminationAction(FriendlyName(), start_cb);
   SetState(kStateConnected);
   if (!capability_->AllowRoaming() &&
       service_->roaming_state() == flimflam::kRoamingStateRoaming) {
@@ -456,6 +460,8 @@
     OnDisconnected();
   else
     OnDisconnectFailed();
+  manager()->TerminationActionComplete(FriendlyName());
+  manager()->RemoveTerminationAction(FriendlyName());
 }
 
 void Cellular::OnDisconnected() {
@@ -582,4 +588,10 @@
   adaptor()->EmitBoolChanged(flimflam::kCellularAllowRoamingProperty, value);
 }
 
+void Cellular::StartTermination() {
+  Error error;
+  Disconnect(&error);
+}
+
+
 }  // namespace shill