Home | History | Annotate | Download | only in dbus
      1 // Copyright 2013 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_FAKE_SHILL_SERVICE_CLIENT_H_
      6 #define CHROMEOS_DBUS_FAKE_SHILL_SERVICE_CLIENT_H_
      7 
      8 #include <map>
      9 #include <string>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/callback.h"
     13 #include "base/memory/weak_ptr.h"
     14 #include "chromeos/chromeos_export.h"
     15 #include "chromeos/dbus/shill_service_client.h"
     16 
     17 namespace chromeos {
     18 
     19 // A fake implementation of ShillServiceClient. This works in close coordination
     20 // with FakeShillManagerClient and is not intended to be used independently.
     21 class CHROMEOS_EXPORT FakeShillServiceClient :
     22       public ShillServiceClient,
     23       public ShillServiceClient::TestInterface {
     24  public:
     25   FakeShillServiceClient();
     26   virtual ~FakeShillServiceClient();
     27 
     28   // ShillServiceClient overrides
     29   virtual void Init(dbus::Bus* bus) OVERRIDE;
     30   virtual void AddPropertyChangedObserver(
     31       const dbus::ObjectPath& service_path,
     32       ShillPropertyChangedObserver* observer) OVERRIDE;
     33   virtual void RemovePropertyChangedObserver(
     34       const dbus::ObjectPath& service_path,
     35       ShillPropertyChangedObserver* observer) OVERRIDE;
     36   virtual void GetProperties(const dbus::ObjectPath& service_path,
     37                              const DictionaryValueCallback& callback) OVERRIDE;
     38   virtual void SetProperty(const dbus::ObjectPath& service_path,
     39                            const std::string& name,
     40                            const base::Value& value,
     41                            const base::Closure& callback,
     42                            const ErrorCallback& error_callback) OVERRIDE;
     43   virtual void SetProperties(const dbus::ObjectPath& service_path,
     44                              const base::DictionaryValue& properties,
     45                              const base::Closure& callback,
     46                              const ErrorCallback& error_callback) OVERRIDE;
     47   virtual void ClearProperty(const dbus::ObjectPath& service_path,
     48                              const std::string& name,
     49                              const base::Closure& callback,
     50                              const ErrorCallback& error_callback) OVERRIDE;
     51   virtual void ClearProperties(const dbus::ObjectPath& service_path,
     52                                const std::vector<std::string>& names,
     53                                const ListValueCallback& callback,
     54                                const ErrorCallback& error_callback) OVERRIDE;
     55   virtual void Connect(const dbus::ObjectPath& service_path,
     56                        const base::Closure& callback,
     57                        const ErrorCallback& error_callback) OVERRIDE;
     58   virtual void Disconnect(const dbus::ObjectPath& service_path,
     59                           const base::Closure& callback,
     60                           const ErrorCallback& error_callback) OVERRIDE;
     61   virtual void Remove(const dbus::ObjectPath& service_path,
     62                       const base::Closure& callback,
     63                       const ErrorCallback& error_callback) OVERRIDE;
     64   virtual void ActivateCellularModem(
     65       const dbus::ObjectPath& service_path,
     66       const std::string& carrier,
     67       const base::Closure& callback,
     68       const ErrorCallback& error_callback) OVERRIDE;
     69   virtual void CompleteCellularActivation(
     70       const dbus::ObjectPath& service_path,
     71       const base::Closure& callback,
     72       const ErrorCallback& error_callback) OVERRIDE;
     73   virtual void GetLoadableProfileEntries(
     74       const dbus::ObjectPath& service_path,
     75       const DictionaryValueCallback& callback) OVERRIDE;
     76   virtual ShillServiceClient::TestInterface* GetTestInterface() OVERRIDE;
     77 
     78   // ShillServiceClient::TestInterface overrides.
     79   virtual void AddService(const std::string& service_path,
     80                           const std::string& name,
     81                           const std::string& type,
     82                           const std::string& state,
     83                           bool add_to_visible_list,
     84                           bool add_to_watch_list) OVERRIDE;
     85   virtual void AddServiceWithIPConfig(const std::string& service_path,
     86                                       const std::string& name,
     87                                       const std::string& type,
     88                                       const std::string& state,
     89                                       const std::string& ipconfig_path,
     90                                       bool add_to_visible_list,
     91                                       bool add_to_watch_list) OVERRIDE;
     92   virtual void RemoveService(const std::string& service_path) OVERRIDE;
     93   virtual bool SetServiceProperty(const std::string& service_path,
     94                                   const std::string& property,
     95                                   const base::Value& value) OVERRIDE;
     96   virtual const base::DictionaryValue* GetServiceProperties(
     97       const std::string& service_path) const OVERRIDE;
     98   virtual void ClearServices() OVERRIDE;
     99   virtual void SetConnectBehavior(const std::string& service_path,
    100                                   const base::Closure& behavior) OVERRIDE;
    101 
    102  private:
    103   typedef ObserverList<ShillPropertyChangedObserver> PropertyObserverList;
    104 
    105   void NotifyObserversPropertyChanged(const dbus::ObjectPath& service_path,
    106                                       const std::string& property);
    107   base::DictionaryValue* GetModifiableServiceProperties(
    108       const std::string& service_path,
    109       bool create_if_missing);
    110   PropertyObserverList& GetObserverList(const dbus::ObjectPath& device_path);
    111   void SetOtherServicesOffline(const std::string& service_path);
    112   void SetCellularActivated(const dbus::ObjectPath& service_path,
    113                             const ErrorCallback& error_callback);
    114   void ContinueConnect(const std::string& service_path);
    115 
    116   base::DictionaryValue stub_services_;
    117 
    118   // Per network service, stores a closure that is executed on each connection
    119   // attempt. The callback can for example modify the services properties in
    120   // order to simulate a connection failure.
    121   std::map<std::string, base::Closure> connect_behavior_;
    122 
    123   // Observer list for each service.
    124   std::map<dbus::ObjectPath, PropertyObserverList*> observer_list_;
    125 
    126   // Note: This should remain the last member so it'll be destroyed and
    127   // invalidate its weak pointers before any other members are destroyed.
    128   base::WeakPtrFactory<FakeShillServiceClient> weak_ptr_factory_;
    129 
    130   DISALLOW_COPY_AND_ASSIGN(FakeShillServiceClient);
    131 };
    132 
    133 }  // namespace chromeos
    134 
    135 #endif  // CHROMEOS_DBUS_FAKE_SHILL_SERVICE_CLIENT_H_
    136