OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/dbus/shill_profile_client.h" | 5 #include "chromeos/dbus/shill_profile_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/containers/scoped_ptr_map.h" |
| 9 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
9 #include "base/stl_util.h" | |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "chromeos/dbus/dbus_thread_manager.h" | 12 #include "chromeos/dbus/dbus_thread_manager.h" |
12 #include "chromeos/dbus/shill_property_changed_observer.h" | 13 #include "chromeos/dbus/shill_property_changed_observer.h" |
13 #include "dbus/bus.h" | 14 #include "dbus/bus.h" |
14 #include "dbus/message.h" | 15 #include "dbus/message.h" |
15 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
16 #include "dbus/values_util.h" | 17 #include "dbus/values_util.h" |
17 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
18 | 19 |
19 namespace chromeos { | 20 namespace chromeos { |
(...skipping 29 matching lines...) Expand all Loading... |
49 const std::string& entry_path, | 50 const std::string& entry_path, |
50 const base::Closure& callback, | 51 const base::Closure& callback, |
51 const ErrorCallback& error_callback) override; | 52 const ErrorCallback& error_callback) override; |
52 | 53 |
53 TestInterface* GetTestInterface() override { return NULL; } | 54 TestInterface* GetTestInterface() override { return NULL; } |
54 | 55 |
55 protected: | 56 protected: |
56 void Init(dbus::Bus* bus) override { bus_ = bus; } | 57 void Init(dbus::Bus* bus) override { bus_ = bus; } |
57 | 58 |
58 private: | 59 private: |
59 typedef std::map<std::string, ShillClientHelper*> HelperMap; | 60 typedef base::ScopedPtrMap<std::string, scoped_ptr<ShillClientHelper>> |
| 61 HelperMap; |
60 | 62 |
61 // Returns the corresponding ShillClientHelper for the profile. | 63 // Returns the corresponding ShillClientHelper for the profile. |
62 ShillClientHelper* GetHelper(const dbus::ObjectPath& profile_path); | 64 ShillClientHelper* GetHelper(const dbus::ObjectPath& profile_path); |
63 | 65 |
64 dbus::Bus* bus_; | 66 dbus::Bus* bus_; |
65 HelperMap helpers_; | 67 HelperMap helpers_; |
66 STLValueDeleter<HelperMap> helpers_deleter_; | |
67 | 68 |
68 DISALLOW_COPY_AND_ASSIGN(ShillProfileClientImpl); | 69 DISALLOW_COPY_AND_ASSIGN(ShillProfileClientImpl); |
69 }; | 70 }; |
70 | 71 |
71 ShillProfileClientImpl::ShillProfileClientImpl() | 72 ShillProfileClientImpl::ShillProfileClientImpl() : bus_(NULL) { |
72 : bus_(NULL), | |
73 helpers_deleter_(&helpers_) { | |
74 } | 73 } |
75 | 74 |
76 ShillClientHelper* ShillProfileClientImpl::GetHelper( | 75 ShillClientHelper* ShillProfileClientImpl::GetHelper( |
77 const dbus::ObjectPath& profile_path) { | 76 const dbus::ObjectPath& profile_path) { |
78 HelperMap::iterator it = helpers_.find(profile_path.value()); | 77 HelperMap::const_iterator it = helpers_.find(profile_path.value()); |
79 if (it != helpers_.end()) | 78 if (it != helpers_.end()) |
80 return it->second; | 79 return it->second; |
81 | 80 |
82 // There is no helper for the profile, create it. | 81 // There is no helper for the profile, create it. |
83 dbus::ObjectProxy* object_proxy = | 82 dbus::ObjectProxy* object_proxy = |
84 bus_->GetObjectProxy(shill::kFlimflamServiceName, profile_path); | 83 bus_->GetObjectProxy(shill::kFlimflamServiceName, profile_path); |
85 ShillClientHelper* helper = new ShillClientHelper(object_proxy); | 84 scoped_ptr<ShillClientHelper> helper(new ShillClientHelper(object_proxy)); |
86 helper->MonitorPropertyChanged(shill::kFlimflamProfileInterface); | 85 helper->MonitorPropertyChanged(shill::kFlimflamProfileInterface); |
87 helpers_.insert(HelperMap::value_type(profile_path.value(), helper)); | 86 ShillClientHelper* helper_ptr = helper.get(); |
88 return helper; | 87 helpers_.insert(profile_path.value(), helper.Pass()); |
| 88 return helper_ptr; |
89 } | 89 } |
90 | 90 |
91 void ShillProfileClientImpl::GetProperties( | 91 void ShillProfileClientImpl::GetProperties( |
92 const dbus::ObjectPath& profile_path, | 92 const dbus::ObjectPath& profile_path, |
93 const DictionaryValueCallbackWithoutStatus& callback, | 93 const DictionaryValueCallbackWithoutStatus& callback, |
94 const ErrorCallback& error_callback) { | 94 const ErrorCallback& error_callback) { |
95 dbus::MethodCall method_call(shill::kFlimflamProfileInterface, | 95 dbus::MethodCall method_call(shill::kFlimflamProfileInterface, |
96 shill::kGetPropertiesFunction); | 96 shill::kGetPropertiesFunction); |
97 GetHelper(profile_path)->CallDictionaryValueMethodWithErrorCallback( | 97 GetHelper(profile_path)->CallDictionaryValueMethodWithErrorCallback( |
98 &method_call, callback, error_callback); | 98 &method_call, callback, error_callback); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 ShillProfileClient* ShillProfileClient::Create() { | 134 ShillProfileClient* ShillProfileClient::Create() { |
135 return new ShillProfileClientImpl(); | 135 return new ShillProfileClientImpl(); |
136 } | 136 } |
137 | 137 |
138 // static | 138 // static |
139 std::string ShillProfileClient::GetSharedProfilePath() { | 139 std::string ShillProfileClient::GetSharedProfilePath() { |
140 return std::string(kSharedProfilePath); | 140 return std::string(kSharedProfilePath); |
141 } | 141 } |
142 | 142 |
143 } // namespace chromeos | 143 } // namespace chromeos |
OLD | NEW |