Make Enable/Disable work using new callbacks for async support.

Use new-style callbacks to implement the Manager EnableTechnology
and DisableTechnology operations asynchronously. This allows
devices to be enabled and disabled from the UI ,and for the UI
to display available networks once the device is enabled.

Removed the behavior whereby setting the Device.Powered property
had the side effect of enabling or disabling the device. To
replace this, I added new Device.Enable and Device.Disable calls
for enabling and disabling individual devices.

Also separated the in-memory value of the Powered property from
the persisted value. Whenever a client requests that a device
be enabled or disabled, the desired power state is immediately
saved in the profile, but the in-memory value isn't updated until
the operation completes. On startup, shill now automatically
starts any devices for which the persistent Powered property
is set, and does not start devices for which it is not set.

BUG=chromium-os:23319,chromium-os:27814
TEST=Manual testing on device + unit tests passing.

Change-Id: Id676be3fc662cfd5efb730c67687edfd16b2dc6b
Reviewed-on: https://gerrit.chromium.org/gerrit/18123
Commit-Ready: Eric Shienbrood <ers@chromium.org>
Reviewed-by: Eric Shienbrood <ers@chromium.org>
Tested-by: Eric Shienbrood <ers@chromium.org>
diff --git a/cellular.h b/cellular.h
index f10214d..8d115c8 100644
--- a/cellular.h
+++ b/cellular.h
@@ -112,7 +112,8 @@
   void Disconnect(Error *error);
 
   // Asynchronously activates the modem. Returns an error on failure.
-  void Activate(const std::string &carrier, ReturnerInterface *returner);
+  void Activate(const std::string &carrier, Error *error,
+                const ResultCallback &callback);
 
   const CellularServiceRefPtr &service() const { return service_; }
 
@@ -142,25 +143,29 @@
   void OnModemManagerPropertiesChanged(const DBusPropertiesMap &properties);
 
   // Inherited from Device.
-  virtual void Start();
-  virtual void Stop();
+  virtual void Start(Error *error, const EnabledStateChangedCallback &callback);
+  virtual void Stop(Error *error, const EnabledStateChangedCallback &callback);
   virtual bool TechnologyIs(Technology::Identifier type) const;
   virtual void LinkEvent(unsigned int flags, unsigned int change);
   virtual void Scan(Error *error);
   virtual void RegisterOnNetwork(const std::string &network_id,
-                                 ReturnerInterface *returner);
-  virtual void RequirePIN(
-      const std::string &pin, bool require, ReturnerInterface *returner);
-  virtual void EnterPIN(const std::string &pin, ReturnerInterface *returner);
+                                 Error *error,
+                                 const ResultCallback &callback);
+  virtual void RequirePIN(const std::string &pin, bool require,
+                          Error *error, const ResultCallback &callback);
+  virtual void EnterPIN(const std::string &pin,
+                        Error *error, const ResultCallback &callback);
   virtual void UnblockPIN(const std::string &unblock_code,
                           const std::string &pin,
-                          ReturnerInterface *returner);
+                          Error *error, const ResultCallback &callback);
   virtual void ChangePIN(const std::string &old_pin,
                          const std::string &new_pin,
-                         ReturnerInterface *returner);
+                         Error *error, const ResultCallback &callback);
 
-  void OnModemEnabled();
-  void OnModemDisabled();
+  void OnModemStarted(const EnabledStateChangedCallback &callback,
+                      const Error &error);
+  void OnModemStopped(const EnabledStateChangedCallback &callback,
+                      const Error &error);
   void OnConnected();
   void OnConnectFailed();
   void OnDisconnected();
@@ -173,12 +178,13 @@
   friend class CellularCapabilityGSMTest;
   friend class ModemTest;
   FRIEND_TEST(CellularCapabilityCDMATest, CreateFriendlyServiceName);
+  FRIEND_TEST(CellularCapabilityCDMATest, GetRegistrationState);
   FRIEND_TEST(CellularCapabilityGSMTest, CreateFriendlyServiceName);
   FRIEND_TEST(CellularServiceTest, FriendlyName);
   FRIEND_TEST(CellularTest, CreateService);
   FRIEND_TEST(CellularTest, Connect);
   FRIEND_TEST(CellularTest, DisableModem);
-  FRIEND_TEST(CellularTest, DisconnectModem);
+  FRIEND_TEST(CellularTest, Disconnect);
   FRIEND_TEST(CellularTest, StartConnected);
   FRIEND_TEST(CellularTest, StartCDMARegister);
   FRIEND_TEST(CellularTest, StartGSMRegister);
@@ -186,23 +192,18 @@
   FRIEND_TEST(CellularCapabilityTest, AllowRoaming);
   FRIEND_TEST(CellularCapabilityTest, EnableModemFail);
   FRIEND_TEST(CellularCapabilityTest, EnableModemSucceed);
+  FRIEND_TEST(CellularCapabilityTest, FinishEnable);
   FRIEND_TEST(CellularCapabilityTest, GetModemInfo);
   FRIEND_TEST(CellularCapabilityTest, GetModemStatus);
 
   void SetState(State state);
 
-  void ConnectTask(const DBusPropertiesMap &properties);
-  void DisconnectTask();
-  void DisconnectModem();
-
   // Invoked when the modem is connected to the cellular network to transition
   // to the network-connected state and bring the network interface up.
   void EstablishLink();
 
   void InitCapability(Type type, ProxyFactory *proxy_factory);
 
-  void HandleNewRegistrationStateTask();
-
   void CreateService();
   void DestroyService();