shill: On Service::Connect, connect the modem device to the network.

Also, uncouple the DBusProperties signal callbacks from Modem to make the proxy
implementation more consistent with the other proxies.

BUG=chromium-os:18727
TEST=unit tests

Change-Id: Icdddea8d2a30803150f2a159fdc5a719e960f95d
Reviewed-on: http://gerrit.chromium.org/gerrit/5444
Tested-by: Darin Petkov <petkov@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
diff --git a/cellular.h b/cellular.h
index 4f8efbf..dc9b00b 100644
--- a/cellular.h
+++ b/cellular.h
@@ -8,20 +8,23 @@
 #include <string>
 
 #include <base/basictypes.h>
+#include <base/task.h>
 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
 
+#include "shill/dbus_properties.h"
 #include "shill/device.h"
 #include "shill/modem_cdma_proxy_interface.h"
+#include "shill/modem_proxy_interface.h"
 #include "shill/refptr_types.h"
 #include "shill/shill_event.h"
 
 namespace shill {
 
-class ModemProxyInterface;
 class ModemSimpleProxyInterface;
 
 class Cellular : public Device,
-                 public ModemCDMAProxyListener {
+                 public ModemCDMAProxyListener,
+                 public ModemProxyListener {
  public:
   enum Type {
     kTypeGSM,
@@ -79,6 +82,8 @@
     uint32 retries_left;
   };
 
+  static const char kConnectPropertyPhoneNumber[];
+
   // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is
   // the ModemManager.Modem DBus object path (e.g.,
   // "/org/chromium/ModemManager/Gobi/0").
@@ -92,12 +97,19 @@
            const std::string &path);
   virtual ~Cellular();
 
+  // Asynchronously connects the modem to the network.
+  void Connect();
+
   // Inherited from Device.
   virtual void Start();
   virtual void Stop();
   virtual bool TechnologyIs(Technology type);
 
  private:
+  static const char kPhoneNumberCDMA[];
+  static const char kPhoneNumberGSM[];
+
+  FRIEND_TEST(CellularTest, Connect);
   FRIEND_TEST(CellularTest, GetCDMARegistrationState);
   FRIEND_TEST(CellularTest, GetCDMASignalQuality);
   FRIEND_TEST(CellularTest, GetModemInfo);
@@ -108,6 +120,8 @@
   FRIEND_TEST(CellularTest, InitProxiesGSM);
   FRIEND_TEST(CellularTest, Start);
 
+  void ConnectTask(const DBusPropertiesMap &properties);
+
   Stringmaps EnumerateNetworks();
   StrIntPair SimLockStatusToProperty();
   void HelpRegisterDerivedStringmaps(const std::string &name,
@@ -155,11 +169,16 @@
   // device |state_|.
   bool IsModemRegistered();
 
-  // Signal callbacks from ModemCDMAProxyListener.
+  // Signal callbacks inherited from ModemCDMAProxyListener.
   virtual void OnCDMARegistrationStateChanged(uint32 state_1x,
                                               uint32 state_evdo);
   virtual void OnCDMASignalQualityChanged(uint32 strength);
 
+  // Signal callbacks inherited from ModemProxyListener.
+  virtual void OnModemStateChanged(uint32 old_state,
+                                   uint32 new_state,
+                                   uint32 reason);
+
   Type type_;
   State state_;
 
@@ -174,6 +193,8 @@
   CellularServiceRefPtr service_;
   bool service_registered_;
 
+  ScopedRunnableMethodFactory<Cellular> task_factory_;
+
   // Properties
   bool allow_roaming_;
   std::string carrier_;