Fix compilation error triggered with -Werror=sign-compare
[chromium-blink-merge.git] / chromeos / dbus / shill_profile_client.cc
blob25f48b6ce0a221669d864ca3c1190ab73eaf0a8a
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.
5 #include "chromeos/dbus/shill_profile_client.h"
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/stl_util.h"
10 #include "base/values.h"
11 #include "chromeos/dbus/dbus_thread_manager.h"
12 #include "chromeos/dbus/shill_property_changed_observer.h"
13 #include "dbus/bus.h"
14 #include "dbus/message.h"
15 #include "dbus/object_path.h"
16 #include "dbus/values_util.h"
17 #include "third_party/cros_system_api/dbus/service_constants.h"
19 namespace chromeos {
21 namespace {
23 const char kSharedProfilePath[] = "/profile/default";
25 class ShillProfileClientImpl : public ShillProfileClient {
26 public:
27 ShillProfileClientImpl();
29 virtual void AddPropertyChangedObserver(
30 const dbus::ObjectPath& profile_path,
31 ShillPropertyChangedObserver* observer) OVERRIDE {
32 GetHelper(profile_path)->AddPropertyChangedObserver(observer);
35 virtual void RemovePropertyChangedObserver(
36 const dbus::ObjectPath& profile_path,
37 ShillPropertyChangedObserver* observer) OVERRIDE {
38 GetHelper(profile_path)->RemovePropertyChangedObserver(observer);
41 virtual void GetProperties(
42 const dbus::ObjectPath& profile_path,
43 const DictionaryValueCallbackWithoutStatus& callback,
44 const ErrorCallback& error_callback) OVERRIDE;
45 virtual void GetEntry(const dbus::ObjectPath& profile_path,
46 const std::string& entry_path,
47 const DictionaryValueCallbackWithoutStatus& callback,
48 const ErrorCallback& error_callback) OVERRIDE;
49 virtual void DeleteEntry(const dbus::ObjectPath& profile_path,
50 const std::string& entry_path,
51 const base::Closure& callback,
52 const ErrorCallback& error_callback) OVERRIDE;
54 virtual TestInterface* GetTestInterface() OVERRIDE {
55 return NULL;
58 protected:
59 virtual void Init(dbus::Bus* bus) OVERRIDE {
60 bus_ = bus;
63 private:
64 typedef std::map<std::string, ShillClientHelper*> HelperMap;
66 // Returns the corresponding ShillClientHelper for the profile.
67 ShillClientHelper* GetHelper(const dbus::ObjectPath& profile_path);
69 dbus::Bus* bus_;
70 HelperMap helpers_;
71 STLValueDeleter<HelperMap> helpers_deleter_;
73 DISALLOW_COPY_AND_ASSIGN(ShillProfileClientImpl);
76 ShillProfileClientImpl::ShillProfileClientImpl()
77 : bus_(NULL),
78 helpers_deleter_(&helpers_) {
81 ShillClientHelper* ShillProfileClientImpl::GetHelper(
82 const dbus::ObjectPath& profile_path) {
83 HelperMap::iterator it = helpers_.find(profile_path.value());
84 if (it != helpers_.end())
85 return it->second;
87 // There is no helper for the profile, create it.
88 dbus::ObjectProxy* object_proxy =
89 bus_->GetObjectProxy(shill::kFlimflamServiceName, profile_path);
90 ShillClientHelper* helper = new ShillClientHelper(object_proxy);
91 helper->MonitorPropertyChanged(shill::kFlimflamProfileInterface);
92 helpers_.insert(HelperMap::value_type(profile_path.value(), helper));
93 return helper;
96 void ShillProfileClientImpl::GetProperties(
97 const dbus::ObjectPath& profile_path,
98 const DictionaryValueCallbackWithoutStatus& callback,
99 const ErrorCallback& error_callback) {
100 dbus::MethodCall method_call(shill::kFlimflamProfileInterface,
101 shill::kGetPropertiesFunction);
102 GetHelper(profile_path)->CallDictionaryValueMethodWithErrorCallback(
103 &method_call, callback, error_callback);
106 void ShillProfileClientImpl::GetEntry(
107 const dbus::ObjectPath& profile_path,
108 const std::string& entry_path,
109 const DictionaryValueCallbackWithoutStatus& callback,
110 const ErrorCallback& error_callback) {
111 dbus::MethodCall method_call(shill::kFlimflamProfileInterface,
112 shill::kGetEntryFunction);
113 dbus::MessageWriter writer(&method_call);
114 writer.AppendString(entry_path);
115 GetHelper(profile_path)->CallDictionaryValueMethodWithErrorCallback(
116 &method_call, callback, error_callback);
119 void ShillProfileClientImpl::DeleteEntry(
120 const dbus::ObjectPath& profile_path,
121 const std::string& entry_path,
122 const base::Closure& callback,
123 const ErrorCallback& error_callback) {
124 dbus::MethodCall method_call(shill::kFlimflamProfileInterface,
125 shill::kDeleteEntryFunction);
126 dbus::MessageWriter writer(&method_call);
127 writer.AppendString(entry_path);
128 GetHelper(profile_path)->CallVoidMethodWithErrorCallback(
129 &method_call, callback, error_callback);
132 } // namespace
134 ShillProfileClient::ShillProfileClient() {}
136 ShillProfileClient::~ShillProfileClient() {}
138 // static
139 ShillProfileClient* ShillProfileClient::Create() {
140 return new ShillProfileClientImpl();
143 // static
144 std::string ShillProfileClient::GetSharedProfilePath() {
145 return std::string(kSharedProfilePath);
148 } // namespace chromeos