shill: wifi: Load hidden services from storage

When a device or profile comes into existence, the device
will search the profile for hidden services and instantiate
services if they do not exist.  These services will not
be visible in the RPC service list until they either appear
in scan or are actively being connected.

Side effects:
  * Manager now loads the devices with profile data.
  * Manager now respects the "powered" attribute loaded by
    devices from the profile to determine whether or not
    to call Start() on them.
  * Key files can be searched for groups with a certain
    key.  This will be useful when we start supporting GUIDs.
  * On service registration go backward (from top of stack
    downward) through the list of profiles searching for
    configuration instead of forwards.
  * Move the update of the "Services" property of the manager
    to a more centralized spot in SortServices.  This way,
    when the service order changes (or anything else that
    affects the service list) this RPC property will update.
  * Hidden services are not scanned for if they are in the
    ephemeral profile -- it means that whatever profile was
    supporting them does not exist anymore.
  * WiFi services have the unenviable task of also decoding
    storage identifiers in order to glean the address, mode
    and security parameters.

BUG=chromium-os:22073,chromium-os:22074
TEST=New unit tests, Manual on real hardware.
Note: I could not connect to a hidden network, but this
is because we're not setting the ApScan parameter on
wpa_supplicant so on connect it is just doing broadcast
scans.  However if I seed the profile with with a record
containing a hidden SSID, shill will force a scan for
the hidden network, which will allow it to connect.

Change-Id: I97a5b5f6db7c6e6d2aabf212c5c2984ce7f4daaa
Reviewed-on: https://gerrit.chromium.org/gerrit/11558
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Commit-Ready: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/device.h b/device.h
index 4f3d3c0..4e0f26a 100644
--- a/device.h
+++ b/device.h
@@ -77,6 +77,7 @@
   const std::string &link_name() const { return link_name_; }
   int interface_index() const { return interface_index_; }
   const ConnectionRefPtr &connection() const { return connection_; }
+  bool powered() const { return powered_; }
 
   const std::string &FriendlyName() const;
 
@@ -90,7 +91,12 @@
 
   EventDispatcher *dispatcher() const { return dispatcher_; }
 
-  bool Load(StoreInterface *storage);
+  // Load configuration for the device from |storage|.  This may include
+  // instantiating non-visible services for which configuration has been
+  // stored.
+  virtual bool Load(StoreInterface *storage);
+
+  // Save configuration for the device to |storage|.
   virtual bool Save(StoreInterface *storage);
 
   void set_dhcp_provider(DHCPProvider *provider) { dhcp_provider_ = provider; }
@@ -103,6 +109,7 @@
   FRIEND_TEST(DeviceTest, Save);
   FRIEND_TEST(DeviceTest, SelectedService);
   FRIEND_TEST(DeviceTest, Stop);
+  FRIEND_TEST(ManagerTest, DeviceRegistrationAndStart);
   FRIEND_TEST(WiFiMainTest, Connect);
 
   // If there's an IP configuration in |ipconfig_|, releases the IP address and
@@ -139,6 +146,7 @@
   // Property getters reserved for subclasses
   ControlInterface *control_interface() const { return control_interface_; }
   Manager *manager() const { return manager_; }
+  bool running() const { return running_; }
 
  private:
   friend class DeviceAdaptorInterface;
@@ -162,14 +170,14 @@
   std::string GetRpcConnectionIdentifier();
 
   // Properties
-  bool powered_;  // TODO(pstew): Is this what |running_| is for?
+  bool powered_;  // indicates whether the device is configured to operate
   bool reconnect_;
   const std::string hardware_address_;
 
   PropertyStore store_;
 
   const int interface_index_;
-  bool running_;
+  bool running_;  // indicates whether the device is actually in operation
   const std::string link_name_;
   const std::string unique_id_;
   ControlInterface *control_interface_;