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.h" 14#include "chromeos/dbus/shill_client_helper.h" 15 16namespace base { 17 18class Value; 19class DictionaryValue; 20 21} // namespace base 22 23namespace dbus { 24 25class ObjectPath; 26 27} // namespace dbus 28 29namespace chromeos { 30 31class ShillPropertyChangedObserver; 32 33// ShillProfileClient is used to communicate with the Shill Profile 34// service. All methods should be called from the origin thread which 35// initializes the DBusThreadManager instance. 36class CHROMEOS_EXPORT ShillProfileClient : public DBusClient { 37 public: 38 typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler; 39 typedef ShillClientHelper::DictionaryValueCallbackWithoutStatus 40 DictionaryValueCallbackWithoutStatus; 41 typedef ShillClientHelper::ErrorCallback ErrorCallback; 42 43 // Interface for setting up services for testing. Accessed through 44 // GetTestInterface(), only implemented in the stub implementation. 45 // TODO(stevenjb): remove dependencies on entry_path -> service_path 46 // mappings in some of the TestInterface implementations. 47 class TestInterface { 48 public: 49 virtual void AddProfile(const std::string& profile_path, 50 const std::string& userhash) = 0; 51 52 // Adds an entry to the profile only. |entry_path| corresponds to a 53 // 'service_path' and a corresponding entry will be added to 54 // ShillManagerClient ServiceCompleteList. No checking or updating of 55 // ShillServiceClient is performed. 56 virtual void AddEntry(const std::string& profile_path, 57 const std::string& entry_path, 58 const base::DictionaryValue& properties) = 0; 59 60 // Adds a service to the profile, copying properties from the 61 // ShillServiceClient entry matching |service_path|. Returns false if no 62 // Service entry exists or if a Profile entry already exists. Also sets 63 // the Profile property of the service in ShillServiceClient. 64 virtual bool AddService(const std::string& profile_path, 65 const std::string& service_path) = 0; 66 67 // Copies properties from the ShillServiceClient entry matching 68 // |service_path| to the profile entry matching |profile_path|. Returns 69 // false if no Service entry exits or if no Profile entry exists. 70 virtual bool UpdateService(const std::string& profile_path, 71 const std::string& service_path) = 0; 72 73 // Sets |profiles| to the current list of profile paths. 74 virtual void GetProfilePaths(std::vector<std::string>* profiles) = 0; 75 76 // Sets |properties| to the entry for |service_path|, sets |profile_path| 77 // to the path of the profile with the entry, and returns true if the 78 // service exists in any profile. 79 virtual bool GetService(const std::string& service_path, 80 std::string* profile_path, 81 base::DictionaryValue* properties) = 0; 82 83 // Remove all profile entries. 84 virtual void ClearProfiles() = 0; 85 86 protected: 87 virtual ~TestInterface() {} 88 }; 89 90 virtual ~ShillProfileClient(); 91 92 // Factory function, creates a new instance which is owned by the caller. 93 // For normal usage, access the singleton via DBusThreadManager::Get(). 94 static ShillProfileClient* Create(); 95 96 // Returns the shared profile path. 97 static std::string GetSharedProfilePath(); 98 99 // Adds a property changed |observer| for the profile at |profile_path|. 100 virtual void AddPropertyChangedObserver( 101 const dbus::ObjectPath& profile_path, 102 ShillPropertyChangedObserver* observer) = 0; 103 104 // Removes a property changed |observer| for the profile at |profile_path|. 105 virtual void RemovePropertyChangedObserver( 106 const dbus::ObjectPath& profile_path, 107 ShillPropertyChangedObserver* observer) = 0; 108 109 // Calls GetProperties method. 110 // |callback| is called after the method call succeeds. 111 virtual void GetProperties( 112 const dbus::ObjectPath& profile_path, 113 const DictionaryValueCallbackWithoutStatus& callback, 114 const ErrorCallback& error_callback) = 0; 115 116 // Calls GetEntry method. 117 // |callback| is called after the method call succeeds. 118 virtual void GetEntry(const dbus::ObjectPath& profile_path, 119 const std::string& entry_path, 120 const DictionaryValueCallbackWithoutStatus& callback, 121 const ErrorCallback& error_callback) = 0; 122 123 // Calls DeleteEntry method. 124 // |callback| is called after the method call succeeds. 125 virtual void DeleteEntry(const dbus::ObjectPath& profile_path, 126 const std::string& entry_path, 127 const base::Closure& callback, 128 const ErrorCallback& error_callback) = 0; 129 130 // Returns an interface for testing (stub only), or returns NULL. 131 virtual TestInterface* GetTestInterface() = 0; 132 133 protected: 134 friend class ShillProfileClientTest; 135 136 // Create() should be used instead. 137 ShillProfileClient(); 138 139 private: 140 DISALLOW_COPY_AND_ASSIGN(ShillProfileClient); 141}; 142 143} // namespace chromeos 144 145#endif // CHROMEOS_DBUS_SHILL_PROFILE_CLIENT_H_ 146