Home | History | Annotate | Download | only in dbus
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROMEOS_DBUS_SHILL_PROFILE_CLIENT_H_
      6 #define CHROMEOS_DBUS_SHILL_PROFILE_CLIENT_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/callback.h"
     12 #include "chromeos/chromeos_export.h"
     13 #include "chromeos/dbus/dbus_client_implementation_type.h"
     14 #include "chromeos/dbus/shill_client_helper.h"
     15 
     16 namespace base {
     17 
     18 class Value;
     19 class DictionaryValue;
     20 
     21 }  // namespace base
     22 
     23 namespace dbus {
     24 
     25 class Bus;
     26 class ObjectPath;
     27 
     28 }  // namespace dbus
     29 
     30 namespace chromeos {
     31 
     32 class ShillPropertyChangedObserver;
     33 
     34 // ShillProfileClient is used to communicate with the Shill Profile
     35 // service.  All methods should be called from the origin thread which
     36 // initializes the DBusThreadManager instance.
     37 class CHROMEOS_EXPORT ShillProfileClient {
     38  public:
     39   typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler;
     40   typedef ShillClientHelper::DictionaryValueCallbackWithoutStatus
     41       DictionaryValueCallbackWithoutStatus;
     42   typedef ShillClientHelper::ErrorCallback ErrorCallback;
     43 
     44   // Interface for setting up services for testing. Accessed through
     45   // GetTestInterface(), only implemented in the stub implementation.
     46   // TODO(stevenjb): remove dependencies on entry_path -> service_path
     47   // mappings in some of the TestInterface implementations.
     48   class TestInterface {
     49    public:
     50     virtual void AddProfile(const std::string& profile_path,
     51                             const std::string& userhash) = 0;
     52 
     53     // Adds an entry to the profile only. |entry_path| corresponds to a
     54     // 'service_path' and a corresponding entry will be added to
     55     // ShillManagerClient ServiceCompleteList. No checking or updating of
     56     // ShillServiceClient is performed.
     57     virtual void AddEntry(const std::string& profile_path,
     58                           const std::string& entry_path,
     59                           const base::DictionaryValue& properties) = 0;
     60 
     61     // Adds a service to the profile, copying properties from the
     62     // ShillServiceClient entry (which must be present). Also sets the Profile
     63     // property of the service in ShillServiceClient.
     64     virtual bool AddService(const std::string& profile_path,
     65                             const std::string& service_path) = 0;
     66 
     67     // Sets |profiles| to the current list of profile paths.
     68     virtual void GetProfilePaths(std::vector<std::string>* profiles) = 0;
     69 
     70    protected:
     71     virtual ~TestInterface() {}
     72   };
     73 
     74   virtual ~ShillProfileClient();
     75 
     76   // Factory function, creates a new instance which is owned by the caller.
     77   // For normal usage, access the singleton via DBusThreadManager::Get().
     78   static ShillProfileClient* Create(DBusClientImplementationType type,
     79                                     dbus::Bus* bus);
     80 
     81   // Adds a property changed |observer| for the profile at |profile_path|.
     82   virtual void AddPropertyChangedObserver(
     83       const dbus::ObjectPath& profile_path,
     84       ShillPropertyChangedObserver* observer) = 0;
     85 
     86   // Removes a property changed |observer| for the profile at |profile_path|.
     87   virtual void RemovePropertyChangedObserver(
     88       const dbus::ObjectPath& profile_path,
     89       ShillPropertyChangedObserver* observer) = 0;
     90 
     91   // Calls GetProperties method.
     92   // |callback| is called after the method call succeeds.
     93   virtual void GetProperties(
     94       const dbus::ObjectPath& profile_path,
     95       const DictionaryValueCallbackWithoutStatus& callback,
     96       const ErrorCallback& error_callback) = 0;
     97 
     98   // Calls GetEntry method.
     99   // |callback| is called after the method call succeeds.
    100   virtual void GetEntry(const dbus::ObjectPath& profile_path,
    101                         const std::string& entry_path,
    102                         const DictionaryValueCallbackWithoutStatus& callback,
    103                         const ErrorCallback& error_callback) = 0;
    104 
    105   // Calls DeleteEntry method.
    106   // |callback| is called after the method call succeeds.
    107   virtual void DeleteEntry(const dbus::ObjectPath& profile_path,
    108                            const std::string& entry_path,
    109                            const base::Closure& callback,
    110                            const ErrorCallback& error_callback) = 0;
    111 
    112   // Returns an interface for testing (stub only), or returns NULL.
    113   virtual TestInterface* GetTestInterface() = 0;
    114 
    115  protected:
    116   // Create() should be used instead.
    117   ShillProfileClient();
    118 
    119  private:
    120   DISALLOW_COPY_AND_ASSIGN(ShillProfileClient);
    121 };
    122 
    123 }  // namespace chromeos
    124 
    125 #endif  // CHROMEOS_DBUS_SHILL_PROFILE_CLIENT_H_
    126