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

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

Issue 9958045: Reimplement Libcros fucntions using FlimflamProfileClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chromeos/dbus/flimflam_profile_client.h ('k') | chromeos/dbus/mock_flimflam_profile_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/flimflam_profile_client.h" 5 #include "chromeos/dbus/flimflam_profile_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/stl_util.h"
9 #include "base/values.h" 10 #include "base/values.h"
10 #include "dbus/bus.h" 11 #include "dbus/bus.h"
11 #include "dbus/message.h" 12 #include "dbus/message.h"
12 #include "dbus/object_path.h" 13 #include "dbus/object_path.h"
13 #include "dbus/object_proxy.h"
14 #include "dbus/values_util.h" 14 #include "dbus/values_util.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h" 15 #include "third_party/cros_system_api/dbus/service_constants.h"
16 16
17 namespace chromeos { 17 namespace chromeos {
18 18
19 namespace { 19 namespace {
20 20
21 // The FlimflamProfileClient implementation. 21 // The FlimflamProfileClient implementation.
22 class FlimflamProfileClientImpl : public FlimflamProfileClient { 22 class FlimflamProfileClientImpl : public FlimflamProfileClient {
23 public: 23 public:
24 explicit FlimflamProfileClientImpl(dbus::Bus* bus); 24 explicit FlimflamProfileClientImpl(dbus::Bus* bus);
25 25
26 // FlimflamProfileClient overrides: 26 // FlimflamProfileClient overrides:
27 virtual void SetPropertyChangedHandler( 27 virtual void SetPropertyChangedHandler(
28 const dbus::ObjectPath& profile_path,
28 const PropertyChangedHandler& handler) OVERRIDE; 29 const PropertyChangedHandler& handler) OVERRIDE;
29 virtual void ResetPropertyChangedHandler() OVERRIDE; 30 virtual void ResetPropertyChangedHandler(
30 virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE; 31 const dbus::ObjectPath& profile_path) OVERRIDE;
31 virtual void GetEntry(const dbus::ObjectPath& path, 32 virtual void GetProperties(const dbus::ObjectPath& profile_path,
33 const DictionaryValueCallback& callback) OVERRIDE;
34 virtual void GetEntry(const dbus::ObjectPath& profile_path,
35 const std::string& entry_path,
32 const DictionaryValueCallback& callback) OVERRIDE; 36 const DictionaryValueCallback& callback) OVERRIDE;
33 virtual void DeleteEntry(const dbus::ObjectPath& path, 37 virtual void DeleteEntry(const dbus::ObjectPath& profile_path,
38 const std::string& entry_path,
34 const VoidCallback& callback) OVERRIDE; 39 const VoidCallback& callback) OVERRIDE;
35 40
36 private: 41 private:
37 // Handles the result of signal connection setup. 42 typedef std::map<std::string, FlimflamClientHelper*> HelperMap;
38 void OnSignalConnected(const std::string& interface,
39 const std::string& signal,
40 bool success);
41 // Handles PropertyChanged signal.
42 void OnPropertyChanged(dbus::Signal* signal);
43 // Handles responses for methods without results.
44 void OnVoidMethod(const VoidCallback& callback, dbus::Response* response);
45 // Handles responses for methods with DictionaryValue results.
46 void OnDictionaryValueMethod(const DictionaryValueCallback& callback,
47 dbus::Response* response);
48 43
49 dbus::ObjectProxy* proxy_; 44 // Returns the corresponding FlimflamClientHelper for the profile.
50 FlimflamClientHelper helper_; 45 FlimflamClientHelper* GetHelper(const dbus::ObjectPath& profile_path);
46
47 dbus::Bus* bus_;
48 HelperMap helpers_;
49 STLValueDeleter<HelperMap> helpers_deleter_;
51 50
52 DISALLOW_COPY_AND_ASSIGN(FlimflamProfileClientImpl); 51 DISALLOW_COPY_AND_ASSIGN(FlimflamProfileClientImpl);
53 }; 52 };
54 53
55 FlimflamProfileClientImpl::FlimflamProfileClientImpl(dbus::Bus* bus) 54 FlimflamProfileClientImpl::FlimflamProfileClientImpl(dbus::Bus* bus)
56 : proxy_(bus->GetObjectProxy( 55 : bus_(bus),
57 flimflam::kFlimflamServiceName, 56 helpers_deleter_(&helpers_) {
58 dbus::ObjectPath(flimflam::kFlimflamServicePath))), 57 }
59 helper_(proxy_) { 58
60 helper_.MonitorPropertyChanged(flimflam::kFlimflamProfileInterface); 59 FlimflamClientHelper* FlimflamProfileClientImpl::GetHelper(
60 const dbus::ObjectPath& profile_path) {
61 HelperMap::iterator it = helpers_.find(profile_path.value());
62 if (it != helpers_.end())
63 return it->second;
64
65 // There is no helper for the profile, create it.
66 dbus::ObjectProxy* object_proxy =
67 bus_->GetObjectProxy(flimflam::kFlimflamServiceName, profile_path);
68 FlimflamClientHelper* helper = new FlimflamClientHelper(object_proxy);
69 helper->MonitorPropertyChanged(flimflam::kFlimflamProfileInterface);
70 helpers_.insert(HelperMap::value_type(profile_path.value(), helper));
71 return helper;
61 } 72 }
62 73
63 void FlimflamProfileClientImpl::SetPropertyChangedHandler( 74 void FlimflamProfileClientImpl::SetPropertyChangedHandler(
75 const dbus::ObjectPath& profile_path,
64 const PropertyChangedHandler& handler) { 76 const PropertyChangedHandler& handler) {
65 helper_.SetPropertyChangedHandler(handler); 77 GetHelper(profile_path)->SetPropertyChangedHandler(handler);
66 } 78 }
67 79
68 void FlimflamProfileClientImpl::ResetPropertyChangedHandler() { 80 void FlimflamProfileClientImpl::ResetPropertyChangedHandler(
69 helper_.ResetPropertyChangedHandler(); 81 const dbus::ObjectPath& profile_path) {
82 GetHelper(profile_path)->ResetPropertyChangedHandler();
70 } 83 }
71 84
72 void FlimflamProfileClientImpl::GetProperties( 85 void FlimflamProfileClientImpl::GetProperties(
86 const dbus::ObjectPath& profile_path,
73 const DictionaryValueCallback& callback) { 87 const DictionaryValueCallback& callback) {
74 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, 88 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface,
75 flimflam::kGetPropertiesFunction); 89 flimflam::kGetPropertiesFunction);
76 helper_.CallDictionaryValueMethod(&method_call, callback); 90 GetHelper(profile_path)->CallDictionaryValueMethod(&method_call, callback);
77 } 91 }
78 92
79 void FlimflamProfileClientImpl::GetEntry( 93 void FlimflamProfileClientImpl::GetEntry(
80 const dbus::ObjectPath& path, 94 const dbus::ObjectPath& profile_path,
95 const std::string& entry_path,
81 const DictionaryValueCallback& callback) { 96 const DictionaryValueCallback& callback) {
82 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, 97 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface,
83 flimflam::kGetEntryFunction); 98 flimflam::kGetEntryFunction);
84 dbus::MessageWriter writer(&method_call); 99 dbus::MessageWriter writer(&method_call);
85 writer.AppendObjectPath(path); 100 writer.AppendString(entry_path);
86 helper_.CallDictionaryValueMethod(&method_call, callback); 101 GetHelper(profile_path)->CallDictionaryValueMethod(&method_call, callback);
87 } 102 }
88 103
89 void FlimflamProfileClientImpl::DeleteEntry(const dbus::ObjectPath& path, 104 void FlimflamProfileClientImpl::DeleteEntry(
90 const VoidCallback& callback) { 105 const dbus::ObjectPath& profile_path,
106 const std::string& entry_path,
107 const VoidCallback& callback) {
91 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, 108 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface,
92 flimflam::kDeleteEntryFunction); 109 flimflam::kDeleteEntryFunction);
93 dbus::MessageWriter writer(&method_call); 110 dbus::MessageWriter writer(&method_call);
94 writer.AppendObjectPath(path); 111 writer.AppendString(entry_path);
95 helper_.CallVoidMethod(&method_call, callback); 112 GetHelper(profile_path)->CallVoidMethod(&method_call, callback);
96 } 113 }
97 114
98 // A stub implementation of FlimflamProfileClient. 115 // A stub implementation of FlimflamProfileClient.
99 class FlimflamProfileClientStubImpl : public FlimflamProfileClient { 116 class FlimflamProfileClientStubImpl : public FlimflamProfileClient {
100 public: 117 public:
101 FlimflamProfileClientStubImpl() : weak_ptr_factory_(this) {} 118 FlimflamProfileClientStubImpl() : weak_ptr_factory_(this) {}
102 119
103 virtual ~FlimflamProfileClientStubImpl() {} 120 virtual ~FlimflamProfileClientStubImpl() {}
104 121
105 // FlimflamProfileClient override. 122 // FlimflamProfileClient override.
106 virtual void SetPropertyChangedHandler( 123 virtual void SetPropertyChangedHandler(
124 const dbus::ObjectPath& profile_path,
107 const PropertyChangedHandler& handler) OVERRIDE {} 125 const PropertyChangedHandler& handler) OVERRIDE {}
108 126
109 // FlimflamProfileClient override. 127 // FlimflamProfileClient override.
110 virtual void ResetPropertyChangedHandler() OVERRIDE {} 128 virtual void ResetPropertyChangedHandler(
129 const dbus::ObjectPath& profile_path) OVERRIDE {}
111 130
112 // FlimflamProfileClient override. 131 // FlimflamProfileClient override.
113 virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE { 132 virtual void GetProperties(const dbus::ObjectPath& profile_path,
133 const DictionaryValueCallback& callback) OVERRIDE {
114 MessageLoop::current()->PostTask( 134 MessageLoop::current()->PostTask(
115 FROM_HERE, 135 FROM_HERE,
116 base::Bind(&FlimflamProfileClientStubImpl::PassEmptyDictionaryValue, 136 base::Bind(&FlimflamProfileClientStubImpl::PassEmptyDictionaryValue,
117 weak_ptr_factory_.GetWeakPtr(), 137 weak_ptr_factory_.GetWeakPtr(),
118 callback)); 138 callback));
119 } 139 }
120 140
121 // FlimflamProfileClient override. 141 // FlimflamProfileClient override.
122 virtual void GetEntry(const dbus::ObjectPath& path, 142 virtual void GetEntry(const dbus::ObjectPath& profile_path,
143 const std::string& entry_path,
123 const DictionaryValueCallback& callback) OVERRIDE { 144 const DictionaryValueCallback& callback) OVERRIDE {
124 MessageLoop::current()->PostTask( 145 MessageLoop::current()->PostTask(
125 FROM_HERE, 146 FROM_HERE,
126 base::Bind(&FlimflamProfileClientStubImpl::PassEmptyDictionaryValue, 147 base::Bind(&FlimflamProfileClientStubImpl::PassEmptyDictionaryValue,
127 weak_ptr_factory_.GetWeakPtr(), 148 weak_ptr_factory_.GetWeakPtr(),
128 callback)); 149 callback));
129 } 150 }
130 151
131 // FlimflamProfileClient override. 152 // FlimflamProfileClient override.
132 virtual void DeleteEntry(const dbus::ObjectPath& path, 153 virtual void DeleteEntry(const dbus::ObjectPath& profile_path,
154 const std::string& entry_path,
133 const VoidCallback& callback) OVERRIDE { 155 const VoidCallback& callback) OVERRIDE {
134 MessageLoop::current()->PostTask(FROM_HERE, 156 MessageLoop::current()->PostTask(FROM_HERE,
135 base::Bind(callback, 157 base::Bind(callback,
136 DBUS_METHOD_CALL_SUCCESS)); 158 DBUS_METHOD_CALL_SUCCESS));
137 } 159 }
138 160
139 private: 161 private:
140 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const { 162 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const {
141 base::DictionaryValue dictionary; 163 base::DictionaryValue dictionary;
142 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary); 164 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary);
(...skipping 14 matching lines...) Expand all
157 FlimflamProfileClient* FlimflamProfileClient::Create( 179 FlimflamProfileClient* FlimflamProfileClient::Create(
158 DBusClientImplementationType type, 180 DBusClientImplementationType type,
159 dbus::Bus* bus) { 181 dbus::Bus* bus) {
160 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 182 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
161 return new FlimflamProfileClientImpl(bus); 183 return new FlimflamProfileClientImpl(bus);
162 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 184 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
163 return new FlimflamProfileClientStubImpl(); 185 return new FlimflamProfileClientStubImpl();
164 } 186 }
165 187
166 } // namespace chromeos 188 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/flimflam_profile_client.h ('k') | chromeos/dbus/mock_flimflam_profile_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698