Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: chromeos/dbus/gsm_sms_client.cc

Issue 1096983002: Update usages of std::map to use ScopedPtrMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@passwordmanager-scopedmemory
Patch Set: Fix Mac compile. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/gsm_sms_client.h" 4 #include "chromeos/dbus/gsm_sms_client.h"
5 5
6 #include <map>
7 #include <utility> 6 #include <utility>
8 #include <vector> 7 #include <vector>
9 8
10 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/containers/scoped_ptr_map.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/stl_util.h"
15 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
16 #include "base/values.h" 15 #include "base/values.h"
17 #include "dbus/bus.h" 16 #include "dbus/bus.h"
18 #include "dbus/message.h" 17 #include "dbus/message.h"
19 #include "dbus/object_proxy.h" 18 #include "dbus/object_proxy.h"
20 #include "dbus/values_util.h" 19 #include "dbus/values_util.h"
21 #include "third_party/cros_system_api/dbus/service_constants.h" 20 #include "third_party/cros_system_api/dbus/service_constants.h"
22 21
23 namespace chromeos { 22 namespace chromeos {
24 23
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // Note: This should remain the last member so it'll be destroyed and 154 // Note: This should remain the last member so it'll be destroyed and
156 // invalidate its weak pointers before any other members are destroyed. 155 // invalidate its weak pointers before any other members are destroyed.
157 base::WeakPtrFactory<SMSProxy> weak_ptr_factory_; 156 base::WeakPtrFactory<SMSProxy> weak_ptr_factory_;
158 157
159 DISALLOW_COPY_AND_ASSIGN(SMSProxy); 158 DISALLOW_COPY_AND_ASSIGN(SMSProxy);
160 }; 159 };
161 160
162 // The GsmSMSClient implementation. 161 // The GsmSMSClient implementation.
163 class GsmSMSClientImpl : public GsmSMSClient { 162 class GsmSMSClientImpl : public GsmSMSClient {
164 public: 163 public:
165 GsmSMSClientImpl() : bus_(NULL), proxies_deleter_(&proxies_) {} 164 GsmSMSClientImpl() : bus_(NULL) {}
166 165
167 // GsmSMSClient override. 166 // GsmSMSClient override.
168 void SetSmsReceivedHandler(const std::string& service_name, 167 void SetSmsReceivedHandler(const std::string& service_name,
169 const dbus::ObjectPath& object_path, 168 const dbus::ObjectPath& object_path,
170 const SmsReceivedHandler& handler) override { 169 const SmsReceivedHandler& handler) override {
171 GetProxy(service_name, object_path)->SetSmsReceivedHandler(handler); 170 GetProxy(service_name, object_path)->SetSmsReceivedHandler(handler);
172 } 171 }
173 172
174 // GsmSMSClient override. 173 // GsmSMSClient override.
175 void ResetSmsReceivedHandler(const std::string& service_name, 174 void ResetSmsReceivedHandler(const std::string& service_name,
(...skipping 25 matching lines...) Expand all
201 } 200 }
202 201
203 // GsmSMSClient override. 202 // GsmSMSClient override.
204 void RequestUpdate(const std::string& service_name, 203 void RequestUpdate(const std::string& service_name,
205 const dbus::ObjectPath& object_path) override {} 204 const dbus::ObjectPath& object_path) override {}
206 205
207 protected: 206 protected:
208 void Init(dbus::Bus* bus) override { bus_ = bus; } 207 void Init(dbus::Bus* bus) override { bus_ = bus; }
209 208
210 private: 209 private:
211 typedef std::map<std::pair<std::string, std::string>, SMSProxy*> ProxyMap; 210 typedef ScopedPtrMap<std::pair<std::string, std::string>,
211 scoped_ptr<SMSProxy>> ProxyMap;
212 212
213 // Returns a SMSProxy for the given service name and object path. 213 // Returns a SMSProxy for the given service name and object path.
214 SMSProxy* GetProxy(const std::string& service_name, 214 SMSProxy* GetProxy(const std::string& service_name,
215 const dbus::ObjectPath& object_path) { 215 const dbus::ObjectPath& object_path) {
216 const ProxyMap::key_type key(service_name, object_path.value()); 216 const ProxyMap::key_type key(service_name, object_path.value());
217 ProxyMap::iterator it = proxies_.find(key); 217 ProxyMap::const_iterator it = proxies_.find(key);
218 if (it != proxies_.end()) 218 if (it != proxies_.end())
219 return it->second; 219 return it->second;
stevenjb 2015/06/18 15:32:02 Does this compile? It seems like this would now re
Matt Giuca 2015/06/22 05:40:41 Missed this earlier. It actually returns a SMSPro
stevenjb 2015/06/23 17:01:03 For the record, "EW". I see now how ScopedPtrMap::
Matt Giuca 2015/06/24 05:21:34 Yeah, it can't really be solved until we get real
220 220
221 // There is no proxy for the service_name and object_path, create it. 221 // There is no proxy for the service_name and object_path, create it.
222 SMSProxy* proxy = new SMSProxy(bus_, service_name, object_path); 222 scoped_ptr<SMSProxy> proxy(new SMSProxy(bus_, service_name, object_path));
223 proxies_.insert(ProxyMap::value_type(key, proxy)); 223 SMSProxy* proxy_ptr = proxy.get();
224 return proxy; 224 proxies_.insert(key, proxy.Pass());
225 return proxy_ptr;
225 } 226 }
226 227
227 dbus::Bus* bus_; 228 dbus::Bus* bus_;
228 ProxyMap proxies_; 229 ProxyMap proxies_;
229 STLValueDeleter<ProxyMap> proxies_deleter_;
230 230
231 DISALLOW_COPY_AND_ASSIGN(GsmSMSClientImpl); 231 DISALLOW_COPY_AND_ASSIGN(GsmSMSClientImpl);
232 }; 232 };
233 233
234 } // namespace 234 } // namespace
235 235
236 //////////////////////////////////////////////////////////////////////////////// 236 ////////////////////////////////////////////////////////////////////////////////
237 // GsmSMSClient 237 // GsmSMSClient
238 238
239 GsmSMSClient::GsmSMSClient() {} 239 GsmSMSClient::GsmSMSClient() {}
240 240
241 GsmSMSClient::~GsmSMSClient() {} 241 GsmSMSClient::~GsmSMSClient() {}
242 242
243 // static 243 // static
244 GsmSMSClient* GsmSMSClient::Create() { 244 GsmSMSClient* GsmSMSClient::Create() {
245 return new GsmSMSClientImpl(); 245 return new GsmSMSClientImpl();
246 } 246 }
247 247
248 } // namespace chromeos 248 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698