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 #include "chromeos/dbus/modem_messaging_client.h" | 4 #include "chromeos/dbus/modem_messaging_client.h" |
5 | 5 |
| 6 #include <map> |
6 #include <utility> | 7 #include <utility> |
7 | 8 |
8 #include "base/bind.h" | 9 #include "base/bind.h" |
9 #include "base/containers/scoped_ptr_map.h" | |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "dbus/bus.h" | 14 #include "dbus/bus.h" |
15 #include "dbus/message.h" | 15 #include "dbus/message.h" |
16 #include "dbus/object_proxy.h" | 16 #include "dbus/object_proxy.h" |
17 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
18 | 18 |
19 namespace chromeos { | 19 namespace chromeos { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 void List(const std::string& service_name, | 156 void List(const std::string& service_name, |
157 const dbus::ObjectPath& object_path, | 157 const dbus::ObjectPath& object_path, |
158 const ListCallback& callback) override { | 158 const ListCallback& callback) override { |
159 GetProxy(service_name, object_path)->List(callback); | 159 GetProxy(service_name, object_path)->List(callback); |
160 } | 160 } |
161 | 161 |
162 protected: | 162 protected: |
163 void Init(dbus::Bus* bus) override { bus_ = bus; }; | 163 void Init(dbus::Bus* bus) override { bus_ = bus; }; |
164 | 164 |
165 private: | 165 private: |
166 typedef base::ScopedPtrMap<std::pair<std::string, std::string>, | 166 using ProxyMap = std::map<std::pair<std::string, std::string>, |
167 scoped_ptr<ModemMessagingProxy>> ProxyMap; | 167 scoped_ptr<ModemMessagingProxy>>; |
168 | 168 |
169 // Returns a SMSProxy for the given service name and object path. | 169 // Returns a SMSProxy for the given service name and object path. |
170 ModemMessagingProxy* GetProxy(const std::string& service_name, | 170 ModemMessagingProxy* GetProxy(const std::string& service_name, |
171 const dbus::ObjectPath& object_path) { | 171 const dbus::ObjectPath& object_path) { |
172 const ProxyMap::key_type key(service_name, object_path.value()); | 172 const ProxyMap::key_type key(service_name, object_path.value()); |
173 ProxyMap::const_iterator it = proxies_.find(key); | 173 ProxyMap::const_iterator it = proxies_.find(key); |
174 if (it != proxies_.end()) | 174 if (it != proxies_.end()) |
175 return it->second; | 175 return it->second.get(); |
176 | 176 |
177 // There is no proxy for the service_name and object_path, create it. | 177 // There is no proxy for the service_name and object_path, create it. |
178 scoped_ptr<ModemMessagingProxy> proxy( | 178 scoped_ptr<ModemMessagingProxy> proxy( |
179 new ModemMessagingProxy(bus_, service_name, object_path)); | 179 new ModemMessagingProxy(bus_, service_name, object_path)); |
180 ModemMessagingProxy* proxy_ptr = proxy.get(); | 180 ModemMessagingProxy* proxy_ptr = proxy.get(); |
181 proxies_.insert(key, proxy.Pass()); | 181 proxies_[key] = std::move(proxy); |
182 return proxy_ptr; | 182 return proxy_ptr; |
183 } | 183 } |
184 | 184 |
185 dbus::Bus* bus_; | 185 dbus::Bus* bus_; |
186 ProxyMap proxies_; | 186 ProxyMap proxies_; |
187 | 187 |
188 DISALLOW_COPY_AND_ASSIGN(ModemMessagingClientImpl); | 188 DISALLOW_COPY_AND_ASSIGN(ModemMessagingClientImpl); |
189 }; | 189 }; |
190 | 190 |
191 } // namespace | 191 } // namespace |
192 | 192 |
193 //////////////////////////////////////////////////////////////////////////////// | 193 //////////////////////////////////////////////////////////////////////////////// |
194 // ModemMessagingClient | 194 // ModemMessagingClient |
195 | 195 |
196 ModemMessagingClient::ModemMessagingClient() {} | 196 ModemMessagingClient::ModemMessagingClient() {} |
197 | 197 |
198 ModemMessagingClient::~ModemMessagingClient() {} | 198 ModemMessagingClient::~ModemMessagingClient() {} |
199 | 199 |
200 | 200 |
201 // static | 201 // static |
202 ModemMessagingClient* ModemMessagingClient::Create() { | 202 ModemMessagingClient* ModemMessagingClient::Create() { |
203 return new ModemMessagingClientImpl(); | 203 return new ModemMessagingClientImpl(); |
204 } | 204 } |
205 | 205 |
206 | 206 |
207 } // namespace chromeos | 207 } // namespace chromeos |
OLD | NEW |