shill: Implement service sorting

Sort the list of Services for presentation to
RPC callers, essentially copying the current flimflam
sorting criteria.  Introduce the TechnologyOrder to
the Manager.

BUG=chromium-os:20114
TEST=New unit tests

Change-Id: I766b2297ba3170a7a6ab5adfe68425a8011be4fb
Reviewed-on: http://gerrit.chromium.org/gerrit/8205
Tested-by: Paul Stewart <pstew@chromium.org>
Reviewed-by: mukesh agrawal <quiche@chromium.org>
diff --git a/manager.h b/manager.h
index 6c29c1e..ede4f49 100644
--- a/manager.h
+++ b/manager.h
@@ -12,6 +12,7 @@
 #include <base/memory/ref_counted.h>
 #include <base/memory/scoped_ptr.h>
 #include <chromeos/dbus/service_constants.h>
+#include <gtest/gtest_prod.h>  // for FRIEND_TEST
 
 #include "shill/device.h"
 #include "shill/device_info.h"
@@ -72,6 +73,8 @@
   // called via RPC (e.g., from ManagerDBusAdaptor)
   WiFiServiceRefPtr GetWifiService(const KeyValueStore &args, Error *error);
   void RequestScan(const std::string &technology, Error *error);
+  std::string GetTechnologyOrder();
+  void SetTechnologyOrder(const std::string &order, Error *error);
 
   virtual DeviceInfo *device_info() { return &device_info_; }
   PropertyStore *mutable_store() { return &store_; }
@@ -84,6 +87,8 @@
 
  private:
   friend class ManagerAdaptorInterface;
+  friend class ManagerTest;
+  FRIEND_TEST(ManagerTest, SortServices);
 
   static const char kManagerErrorNoDevice[];
 
@@ -104,6 +109,9 @@
                                   Strings(Manager::*get)(void),
                                   bool(Manager::*set)(const Strings&));
 
+  bool OrderServices(ServiceRefPtr a, ServiceRefPtr b);
+  void SortServices();
+
   const FilePath run_path_;
   const FilePath storage_path_;
   const std::string user_storage_format_;
@@ -119,6 +127,9 @@
   ControlInterface *control_interface_;
   GLib *glib_;
 
+  // The priority order of technologies
+  std::vector<Technology::Identifier> technology_order_;
+
   // Properties to be get/set via PropertyStore calls.
   Properties props_;
   PropertyStore store_;