Home | History | Annotate | Download | only in dbus
      1 // Copyright (c) 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_SHILL_MANAGER_CLIENT_STUB_H_
      6 #define CHROMEOS_DBUS_SHILL_MANAGER_CLIENT_STUB_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/callback.h"
     12 #include "chromeos/dbus/shill_manager_client.h"
     13 
     14 namespace chromeos {
     15 
     16 // A stub implementation of ShillManagerClient. This works in close coordination
     17 // with ShillServiceClientStub. ShillDeviceClientStub, and
     18 // ShillProfileClientStub, and is not intended to be used independently.
     19 class ShillManagerClientStub : public ShillManagerClient,
     20                                public ShillManagerClient::TestInterface {
     21  public:
     22   ShillManagerClientStub();
     23   virtual ~ShillManagerClientStub();
     24 
     25   // ShillManagerClient overrides.
     26   virtual void AddPropertyChangedObserver(
     27       ShillPropertyChangedObserver* observer) OVERRIDE;
     28   virtual void RemovePropertyChangedObserver(
     29       ShillPropertyChangedObserver* observer) OVERRIDE;
     30   virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE;
     31   virtual void GetNetworksForGeolocation(
     32       const DictionaryValueCallback& callback) OVERRIDE;
     33   virtual void SetProperty(const std::string& name,
     34                            const base::Value& value,
     35                            const base::Closure& callback,
     36                            const ErrorCallback& error_callback) OVERRIDE;
     37   virtual void RequestScan(const std::string& type,
     38                            const base::Closure& callback,
     39                            const ErrorCallback& error_callback) OVERRIDE;
     40   virtual void EnableTechnology(
     41       const std::string& type,
     42       const base::Closure& callback,
     43       const ErrorCallback& error_callback) OVERRIDE;
     44   virtual void DisableTechnology(
     45       const std::string& type,
     46       const base::Closure& callback,
     47       const ErrorCallback& error_callback) OVERRIDE;
     48   virtual void ConfigureService(
     49       const base::DictionaryValue& properties,
     50       const ObjectPathCallback& callback,
     51       const ErrorCallback& error_callback) OVERRIDE;
     52   virtual void ConfigureServiceForProfile(
     53       const dbus::ObjectPath& profile_path,
     54       const base::DictionaryValue& properties,
     55       const ObjectPathCallback& callback,
     56       const ErrorCallback& error_callback) OVERRIDE;
     57   virtual void GetService(
     58       const base::DictionaryValue& properties,
     59       const ObjectPathCallback& callback,
     60       const ErrorCallback& error_callback) OVERRIDE;
     61   virtual void VerifyDestination(const VerificationProperties& properties,
     62                                  const BooleanCallback& callback,
     63                                  const ErrorCallback& error_callback) OVERRIDE;
     64   virtual void VerifyAndEncryptCredentials(
     65       const VerificationProperties& properties,
     66       const std::string& service_path,
     67       const StringCallback& callback,
     68       const ErrorCallback& error_callback) OVERRIDE;
     69   virtual void VerifyAndEncryptData(
     70       const VerificationProperties& properties,
     71       const std::string& data,
     72       const StringCallback& callback,
     73       const ErrorCallback& error_callback) OVERRIDE;
     74   virtual void ConnectToBestServices(
     75       const base::Closure& callback,
     76       const ErrorCallback& error_callback) OVERRIDE;
     77   virtual ShillManagerClient::TestInterface* GetTestInterface() OVERRIDE;
     78 
     79   // ShillManagerClient::TestInterface overrides.
     80   virtual void AddDevice(const std::string& device_path) OVERRIDE;
     81   virtual void RemoveDevice(const std::string& device_path) OVERRIDE;
     82   virtual void ClearDevices() OVERRIDE;
     83   virtual void AddTechnology(const std::string& type, bool enabled) OVERRIDE;
     84   virtual void RemoveTechnology(const std::string& type) OVERRIDE;
     85   virtual void SetTechnologyInitializing(const std::string& type,
     86                                          bool initializing) OVERRIDE;
     87   virtual void AddGeoNetwork(const std::string& technology,
     88                              const base::DictionaryValue& network) OVERRIDE;
     89   virtual void AddProfile(const std::string& profile_path) OVERRIDE;
     90   virtual void ClearProperties() OVERRIDE;
     91   virtual void AddManagerService(const std::string& service_path,
     92                                  bool add_to_visible_list,
     93                                  bool add_to_watch_list) OVERRIDE;
     94   virtual void RemoveManagerService(const std::string& service_path) OVERRIDE;
     95   virtual void ClearManagerServices() OVERRIDE;
     96   virtual void SortManagerServices() OVERRIDE;
     97 
     98  private:
     99   void AddServiceToWatchList(const std::string& service_path);
    100   void SetDefaultProperties();
    101   void PassStubProperties(const DictionaryValueCallback& callback) const;
    102   void PassStubGeoNetworks(const DictionaryValueCallback& callback) const;
    103   void CallNotifyObserversPropertyChanged(const std::string& property,
    104                                           int delay_ms);
    105   void NotifyObserversPropertyChanged(const std::string& property);
    106   base::ListValue* GetListProperty(const std::string& property);
    107   bool TechnologyEnabled(const std::string& type) const;
    108   void SetTechnologyEnabled(const std::string& type,
    109                             const base::Closure& callback,
    110                             bool enabled);
    111   base::ListValue* GetEnabledServiceList(const std::string& property) const;
    112   void ScanCompleted(const std::string& device_path,
    113                      const base::Closure& callback);
    114 
    115   // Dictionary of property name -> property value
    116   base::DictionaryValue stub_properties_;
    117   // Dictionary of technology -> list of property dictionaries
    118   base::DictionaryValue stub_geo_networks_;
    119 
    120   ObserverList<ShillPropertyChangedObserver> observer_list_;
    121 
    122   // Note: This should remain the last member so it'll be destroyed and
    123   // invalidate its weak pointers before any other members are destroyed.
    124   base::WeakPtrFactory<ShillManagerClientStub> weak_ptr_factory_;
    125 
    126   DISALLOW_COPY_AND_ASSIGN(ShillManagerClientStub);
    127 };
    128 
    129 }  // namespace chromeos
    130 
    131 #endif  // CHROMEOS_DBUS_SHILL_MANAGER_CLIENT_STUB_H_
    132