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

Side by Side Diff: chromeos/dbus/shill_profile_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 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
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 ScopedPtrMap<std::string, scoped_ptr<ShillClientHelper>> HelperMap;
60 61
61 // Returns the corresponding ShillClientHelper for the profile. 62 // Returns the corresponding ShillClientHelper for the profile.
62 ShillClientHelper* GetHelper(const dbus::ObjectPath& profile_path); 63 ShillClientHelper* GetHelper(const dbus::ObjectPath& profile_path);
63 64
64 dbus::Bus* bus_; 65 dbus::Bus* bus_;
65 HelperMap helpers_; 66 HelperMap helpers_;
66 STLValueDeleter<HelperMap> helpers_deleter_;
67 67
68 DISALLOW_COPY_AND_ASSIGN(ShillProfileClientImpl); 68 DISALLOW_COPY_AND_ASSIGN(ShillProfileClientImpl);
69 }; 69 };
70 70
71 ShillProfileClientImpl::ShillProfileClientImpl() 71 ShillProfileClientImpl::ShillProfileClientImpl() : bus_(NULL) {
72 : bus_(NULL),
73 helpers_deleter_(&helpers_) {
74 } 72 }
75 73
76 ShillClientHelper* ShillProfileClientImpl::GetHelper( 74 ShillClientHelper* ShillProfileClientImpl::GetHelper(
77 const dbus::ObjectPath& profile_path) { 75 const dbus::ObjectPath& profile_path) {
78 HelperMap::iterator it = helpers_.find(profile_path.value()); 76 HelperMap::const_iterator it = helpers_.find(profile_path.value());
79 if (it != helpers_.end()) 77 if (it != helpers_.end())
80 return it->second; 78 return it->second;
81 79
82 // There is no helper for the profile, create it. 80 // There is no helper for the profile, create it.
83 dbus::ObjectProxy* object_proxy = 81 dbus::ObjectProxy* object_proxy =
84 bus_->GetObjectProxy(shill::kFlimflamServiceName, profile_path); 82 bus_->GetObjectProxy(shill::kFlimflamServiceName, profile_path);
85 ShillClientHelper* helper = new ShillClientHelper(object_proxy); 83 scoped_ptr<ShillClientHelper> helper(new ShillClientHelper(object_proxy));
86 helper->MonitorPropertyChanged(shill::kFlimflamProfileInterface); 84 helper->MonitorPropertyChanged(shill::kFlimflamProfileInterface);
87 helpers_.insert(HelperMap::value_type(profile_path.value(), helper)); 85 ShillClientHelper* helper_ptr = helper.get();
88 return helper; 86 helpers_.insert(profile_path.value(), helper.Pass());
87 return helper_ptr;
89 } 88 }
90 89
91 void ShillProfileClientImpl::GetProperties( 90 void ShillProfileClientImpl::GetProperties(
92 const dbus::ObjectPath& profile_path, 91 const dbus::ObjectPath& profile_path,
93 const DictionaryValueCallbackWithoutStatus& callback, 92 const DictionaryValueCallbackWithoutStatus& callback,
94 const ErrorCallback& error_callback) { 93 const ErrorCallback& error_callback) {
95 dbus::MethodCall method_call(shill::kFlimflamProfileInterface, 94 dbus::MethodCall method_call(shill::kFlimflamProfileInterface,
96 shill::kGetPropertiesFunction); 95 shill::kGetPropertiesFunction);
97 GetHelper(profile_path)->CallDictionaryValueMethodWithErrorCallback( 96 GetHelper(profile_path)->CallDictionaryValueMethodWithErrorCallback(
98 &method_call, callback, error_callback); 97 &method_call, callback, error_callback);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 ShillProfileClient* ShillProfileClient::Create() { 133 ShillProfileClient* ShillProfileClient::Create() {
135 return new ShillProfileClientImpl(); 134 return new ShillProfileClientImpl();
136 } 135 }
137 136
138 // static 137 // static
139 std::string ShillProfileClient::GetSharedProfilePath() { 138 std::string ShillProfileClient::GetSharedProfilePath() {
140 return std::string(kSharedProfilePath); 139 return std::string(kSharedProfilePath);
141 } 140 }
142 141
143 } // namespace chromeos 142 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698