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

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

Issue 10949030: This converts the Shill clients to allow propagation of shill errors (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 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_network_client.h" 5 #include "chromeos/dbus/shill_network_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/stl_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "dbus/bus.h" 11 #include "dbus/bus.h"
12 #include "dbus/message.h" 12 #include "dbus/message.h"
13 #include "dbus/object_path.h" 13 #include "dbus/object_path.h"
14 #include "dbus/object_proxy.h" 14 #include "dbus/object_proxy.h"
15 #include "dbus/values_util.h" 15 #include "dbus/values_util.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h" 16 #include "third_party/cros_system_api/dbus/service_constants.h"
17 17
18 namespace chromeos { 18 namespace chromeos {
19 19
20 namespace { 20 namespace {
21 21
22 // The ShillNetworkClient implementation. 22 // The ShillNetworkClient implementation.
23 class ShillNetworkClientImpl : public ShillNetworkClient { 23 class ShillNetworkClientImpl : public ShillNetworkClient {
24 public: 24 public:
25 explicit ShillNetworkClientImpl(dbus::Bus* bus) 25 explicit ShillNetworkClientImpl(dbus::Bus* bus)
26 : bus_(bus), 26 : bus_(bus),
27 helpers_deleter_(&helpers_) { 27 helpers_deleter_(&helpers_) {
28 } 28 }
29 29
30 // ShillNetworkClient override. 30 //////////////////////////////////////
31 virtual void SetPropertyChangedHandler( 31 // ShillNetworkClient overrides.
32 virtual void AddPropertyChangedObserver(
32 const dbus::ObjectPath& network_path, 33 const dbus::ObjectPath& network_path,
33 const PropertyChangedHandler& handler) OVERRIDE { 34 PropertyChangedObserver* observer) OVERRIDE {
34 GetHelper(network_path)->SetPropertyChangedHandler(handler); 35 GetHelper(network_path)->AddPropertyChangedObserver(observer);
35 } 36 }
36 37
37 // ShillNetworkClient override. 38 virtual void RemovePropertyChangedObserver(
38 virtual void ResetPropertyChangedHandler( 39 const dbus::ObjectPath& network_path,
39 const dbus::ObjectPath& network_path) OVERRIDE { 40 PropertyChangedObserver* observer) OVERRIDE {
40 GetHelper(network_path)->ResetPropertyChangedHandler(); 41 GetHelper(network_path)->RemovePropertyChangedObserver(observer);
41 } 42 }
42 43
43 // ShillNetworkClient override.
44 virtual void GetProperties(const dbus::ObjectPath& network_path, 44 virtual void GetProperties(const dbus::ObjectPath& network_path,
45 const DictionaryValueCallback& callback) OVERRIDE { 45 const DictionaryValueCallback& callback) OVERRIDE {
46 dbus::MethodCall method_call(flimflam::kFlimflamNetworkInterface, 46 dbus::MethodCall method_call(flimflam::kFlimflamNetworkInterface,
47 flimflam::kGetPropertiesFunction); 47 flimflam::kGetPropertiesFunction);
48 GetHelper(network_path)->CallDictionaryValueMethod(&method_call, callback); 48 GetHelper(network_path)->CallDictionaryValueMethod(&method_call, callback);
49 } 49 }
50 50
51 // ShillNetworkClient override.
52 virtual base::DictionaryValue* CallGetPropertiesAndBlock( 51 virtual base::DictionaryValue* CallGetPropertiesAndBlock(
53 const dbus::ObjectPath& network_path) OVERRIDE { 52 const dbus::ObjectPath& network_path) OVERRIDE {
54 dbus::MethodCall method_call(flimflam::kFlimflamNetworkInterface, 53 dbus::MethodCall method_call(flimflam::kFlimflamNetworkInterface,
55 flimflam::kGetPropertiesFunction); 54 flimflam::kGetPropertiesFunction);
56 return GetHelper(network_path)->CallDictionaryValueMethodAndBlock( 55 return GetHelper(network_path)->CallDictionaryValueMethodAndBlock(
57 &method_call); 56 &method_call);
58 } 57 }
59 58
60 private: 59 private:
61 typedef std::map<std::string, ShillClientHelper*> HelperMap; 60 typedef std::map<std::string, ShillClientHelper*> HelperMap;
(...skipping 20 matching lines...) Expand all
82 DISALLOW_COPY_AND_ASSIGN(ShillNetworkClientImpl); 81 DISALLOW_COPY_AND_ASSIGN(ShillNetworkClientImpl);
83 }; 82 };
84 83
85 // A stub implementation of ShillNetworkClient. 84 // A stub implementation of ShillNetworkClient.
86 class ShillNetworkClientStubImpl : public ShillNetworkClient { 85 class ShillNetworkClientStubImpl : public ShillNetworkClient {
87 public: 86 public:
88 ShillNetworkClientStubImpl() : weak_ptr_factory_(this) {} 87 ShillNetworkClientStubImpl() : weak_ptr_factory_(this) {}
89 88
90 virtual ~ShillNetworkClientStubImpl() {} 89 virtual ~ShillNetworkClientStubImpl() {}
91 90
92 // ShillNetworkClient override. 91 /////////////////////////////////////
93 virtual void SetPropertyChangedHandler( 92 // ShillNetworkClient overrides.
93 virtual void AddPropertyChangedObserver(
94 const dbus::ObjectPath& network_path, 94 const dbus::ObjectPath& network_path,
95 const PropertyChangedHandler& handler) OVERRIDE {} 95 PropertyChangedObserver* observer) OVERRIDE {}
96 96
97 // ShillNetworkClient override. 97 virtual void RemovePropertyChangedObserver(
98 virtual void ResetPropertyChangedHandler( 98 const dbus::ObjectPath& network_path,
99 const dbus::ObjectPath& network_path) OVERRIDE {} 99 PropertyChangedObserver* observer) OVERRIDE {}
100 100
101 // ShillNetworkClient override.
102 virtual void GetProperties(const dbus::ObjectPath& network_path, 101 virtual void GetProperties(const dbus::ObjectPath& network_path,
103 const DictionaryValueCallback& callback) OVERRIDE { 102 const DictionaryValueCallback& callback) OVERRIDE {
104 MessageLoop::current()->PostTask( 103 MessageLoop::current()->PostTask(
105 FROM_HERE, 104 FROM_HERE,
106 base::Bind(&ShillNetworkClientStubImpl::PassEmptyDictionaryValue, 105 base::Bind(&ShillNetworkClientStubImpl::PassEmptyDictionaryValue,
107 weak_ptr_factory_.GetWeakPtr(), 106 weak_ptr_factory_.GetWeakPtr(),
108 callback)); 107 callback));
109 } 108 }
110 109
111 // ShillNetworkClient override.
112 virtual base::DictionaryValue* CallGetPropertiesAndBlock( 110 virtual base::DictionaryValue* CallGetPropertiesAndBlock(
113 const dbus::ObjectPath& network_path) OVERRIDE { 111 const dbus::ObjectPath& network_path) OVERRIDE {
114 return new base::DictionaryValue; 112 return new base::DictionaryValue;
115 } 113 }
116 114
117 private: 115 private:
118 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const { 116 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const {
119 base::DictionaryValue dictionary; 117 base::DictionaryValue dictionary;
120 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary); 118 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary);
121 } 119 }
(...skipping 15 matching lines...) Expand all
137 ShillNetworkClient* ShillNetworkClient::Create( 135 ShillNetworkClient* ShillNetworkClient::Create(
138 DBusClientImplementationType type, 136 DBusClientImplementationType type,
139 dbus::Bus* bus) { 137 dbus::Bus* bus) {
140 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 138 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
141 return new ShillNetworkClientImpl(bus); 139 return new ShillNetworkClientImpl(bus);
142 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 140 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
143 return new ShillNetworkClientStubImpl(); 141 return new ShillNetworkClientStubImpl();
144 } 142 }
145 143
146 } // namespace chromeos 144 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698