• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 namespace base {
17 
18 class Value;
19 class DictionaryValue;
20 
21 }  // namespace base
22 
23 namespace dbus {
24 
25 class ObjectPath;
26 
27 }  // namespace dbus
28 
29 namespace chromeos {
30 
31 class 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.
36 class 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 (which must be present). Also sets the Profile
62     // property of the service in ShillServiceClient.
63     virtual bool AddService(const std::string& profile_path,
64                             const std::string& service_path) = 0;
65 
66     // Sets |profiles| to the current list of profile paths.
67     virtual void GetProfilePaths(std::vector<std::string>* profiles) = 0;
68 
69    protected:
~TestInterface()70     virtual ~TestInterface() {}
71   };
72 
73   virtual ~ShillProfileClient();
74 
75   // Factory function, creates a new instance which is owned by the caller.
76   // For normal usage, access the singleton via DBusThreadManager::Get().
77   static ShillProfileClient* Create();
78 
79   // Adds a property changed |observer| for the profile at |profile_path|.
80   virtual void AddPropertyChangedObserver(
81       const dbus::ObjectPath& profile_path,
82       ShillPropertyChangedObserver* observer) = 0;
83 
84   // Removes a property changed |observer| for the profile at |profile_path|.
85   virtual void RemovePropertyChangedObserver(
86       const dbus::ObjectPath& profile_path,
87       ShillPropertyChangedObserver* observer) = 0;
88 
89   // Calls GetProperties method.
90   // |callback| is called after the method call succeeds.
91   virtual void GetProperties(
92       const dbus::ObjectPath& profile_path,
93       const DictionaryValueCallbackWithoutStatus& callback,
94       const ErrorCallback& error_callback) = 0;
95 
96   // Calls GetEntry method.
97   // |callback| is called after the method call succeeds.
98   virtual void GetEntry(const dbus::ObjectPath& profile_path,
99                         const std::string& entry_path,
100                         const DictionaryValueCallbackWithoutStatus& callback,
101                         const ErrorCallback& error_callback) = 0;
102 
103   // Calls DeleteEntry method.
104   // |callback| is called after the method call succeeds.
105   virtual void DeleteEntry(const dbus::ObjectPath& profile_path,
106                            const std::string& entry_path,
107                            const base::Closure& callback,
108                            const ErrorCallback& error_callback) = 0;
109 
110   // Returns an interface for testing (stub only), or returns NULL.
111   virtual TestInterface* GetTestInterface() = 0;
112 
113  protected:
114   friend class ShillProfileClientTest;
115 
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