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

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

Issue 10915106: Renaming instances of "flimflam" with "shill", now that we're only (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Upload after merge 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chromeos/dbus/flimflam_network_client.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop.h"
9 #include "base/stl_util.h"
10 #include "base/values.h"
11 #include "dbus/bus.h"
12 #include "dbus/message.h"
13 #include "dbus/object_path.h"
14 #include "dbus/object_proxy.h"
15 #include "dbus/values_util.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h"
17
18 namespace chromeos {
19
20 namespace {
21
22 // The FlimflamNetworkClient implementation.
23 class FlimflamNetworkClientImpl : public FlimflamNetworkClient {
24 public:
25 explicit FlimflamNetworkClientImpl(dbus::Bus* bus)
26 : bus_(bus),
27 helpers_deleter_(&helpers_) {
28 }
29
30 // FlimflamNetworkClient override.
31 virtual void SetPropertyChangedHandler(
32 const dbus::ObjectPath& network_path,
33 const PropertyChangedHandler& handler) OVERRIDE {
34 GetHelper(network_path)->SetPropertyChangedHandler(handler);
35 }
36
37 // FlimflamNetworkClient override.
38 virtual void ResetPropertyChangedHandler(
39 const dbus::ObjectPath& network_path) OVERRIDE {
40 GetHelper(network_path)->ResetPropertyChangedHandler();
41 }
42
43 // FlimflamNetworkClient override.
44 virtual void GetProperties(const dbus::ObjectPath& network_path,
45 const DictionaryValueCallback& callback) OVERRIDE {
46 dbus::MethodCall method_call(flimflam::kFlimflamNetworkInterface,
47 flimflam::kGetPropertiesFunction);
48 GetHelper(network_path)->CallDictionaryValueMethod(&method_call, callback);
49 }
50
51 // FlimflamNetworkClient override.
52 virtual base::DictionaryValue* CallGetPropertiesAndBlock(
53 const dbus::ObjectPath& network_path) OVERRIDE {
54 dbus::MethodCall method_call(flimflam::kFlimflamNetworkInterface,
55 flimflam::kGetPropertiesFunction);
56 return GetHelper(network_path)->CallDictionaryValueMethodAndBlock(
57 &method_call);
58 }
59
60 private:
61 typedef std::map<std::string, FlimflamClientHelper*> HelperMap;
62
63 // Returns the corresponding FlimflamClientHelper for the profile.
64 FlimflamClientHelper* GetHelper(const dbus::ObjectPath& network_path) {
65 HelperMap::iterator it = helpers_.find(network_path.value());
66 if (it != helpers_.end())
67 return it->second;
68
69 // There is no helper for the profile, create it.
70 dbus::ObjectProxy* object_proxy =
71 bus_->GetObjectProxy(flimflam::kFlimflamServiceName, network_path);
72 FlimflamClientHelper* helper = new FlimflamClientHelper(bus_, object_proxy);
73 helper->MonitorPropertyChanged(flimflam::kFlimflamNetworkInterface);
74 helpers_.insert(HelperMap::value_type(network_path.value(), helper));
75 return helper;
76 }
77
78 dbus::Bus* bus_;
79 HelperMap helpers_;
80 STLValueDeleter<HelperMap> helpers_deleter_;
81
82 DISALLOW_COPY_AND_ASSIGN(FlimflamNetworkClientImpl);
83 };
84
85 // A stub implementation of FlimflamNetworkClient.
86 class FlimflamNetworkClientStubImpl : public FlimflamNetworkClient {
87 public:
88 FlimflamNetworkClientStubImpl() : weak_ptr_factory_(this) {}
89
90 virtual ~FlimflamNetworkClientStubImpl() {}
91
92 // FlimflamNetworkClient override.
93 virtual void SetPropertyChangedHandler(
94 const dbus::ObjectPath& network_path,
95 const PropertyChangedHandler& handler) OVERRIDE {}
96
97 // FlimflamNetworkClient override.
98 virtual void ResetPropertyChangedHandler(
99 const dbus::ObjectPath& network_path) OVERRIDE {}
100
101 // FlimflamNetworkClient override.
102 virtual void GetProperties(const dbus::ObjectPath& network_path,
103 const DictionaryValueCallback& callback) OVERRIDE {
104 MessageLoop::current()->PostTask(
105 FROM_HERE,
106 base::Bind(&FlimflamNetworkClientStubImpl::PassEmptyDictionaryValue,
107 weak_ptr_factory_.GetWeakPtr(),
108 callback));
109 }
110
111 // FlimflamNetworkClient override.
112 virtual base::DictionaryValue* CallGetPropertiesAndBlock(
113 const dbus::ObjectPath& network_path) OVERRIDE {
114 return new base::DictionaryValue;
115 }
116
117 private:
118 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const {
119 base::DictionaryValue dictionary;
120 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary);
121 }
122
123 // Note: This should remain the last member so it'll be destroyed and
124 // invalidate its weak pointers before any other members are destroyed.
125 base::WeakPtrFactory<FlimflamNetworkClientStubImpl> weak_ptr_factory_;
126
127 DISALLOW_COPY_AND_ASSIGN(FlimflamNetworkClientStubImpl);
128 };
129
130 } // namespace
131
132 FlimflamNetworkClient::FlimflamNetworkClient() {}
133
134 FlimflamNetworkClient::~FlimflamNetworkClient() {}
135
136 // static
137 FlimflamNetworkClient* FlimflamNetworkClient::Create(
138 DBusClientImplementationType type,
139 dbus::Bus* bus) {
140 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
141 return new FlimflamNetworkClientImpl(bus);
142 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
143 return new FlimflamNetworkClientStubImpl();
144 }
145
146 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/flimflam_network_client.h ('k') | chromeos/dbus/flimflam_network_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698