OLD | NEW |
| (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 "chrome/browser/chromeos/dbus/flimflam_network_client.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "dbus/bus.h" | |
9 #include "dbus/message.h" | |
10 #include "dbus/object_path.h" | |
11 #include "dbus/object_proxy.h" | |
12 #include "dbus/values_util.h" | |
13 #include "third_party/cros_system_api/dbus/service_constants.h" | |
14 | |
15 namespace chromeos { | |
16 | |
17 namespace { | |
18 | |
19 // The FlimflamNetworkClient implementation. | |
20 class FlimflamNetworkClientImpl : public FlimflamNetworkClient { | |
21 public: | |
22 explicit FlimflamNetworkClientImpl(dbus::Bus* bus) | |
23 : proxy_(bus->GetObjectProxy( | |
24 flimflam::kFlimflamServiceName, | |
25 dbus::ObjectPath(flimflam::kFlimflamServicePath))), | |
26 helper_(proxy_) { | |
27 helper_.MonitorPropertyChanged(flimflam::kFlimflamNetworkInterface); | |
28 } | |
29 | |
30 // FlimflamNetworkClient override. | |
31 virtual void SetPropertyChangedHandler( | |
32 const PropertyChangedHandler& handler) OVERRIDE { | |
33 helper_.SetPropertyChangedHandler(handler); | |
34 } | |
35 | |
36 // FlimflamNetworkClient override. | |
37 virtual void ResetPropertyChangedHandler() OVERRIDE { | |
38 helper_.ResetPropertyChangedHandler(); | |
39 } | |
40 | |
41 // FlimflamNetworkClient override. | |
42 virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE { | |
43 dbus::MethodCall method_call(flimflam::kFlimflamNetworkInterface, | |
44 flimflam::kGetPropertiesFunction); | |
45 helper_.CallDictionaryValueMethod(&method_call, callback); | |
46 } | |
47 | |
48 private: | |
49 dbus::ObjectProxy* proxy_; | |
50 FlimflamClientHelper helper_; | |
51 | |
52 DISALLOW_COPY_AND_ASSIGN(FlimflamNetworkClientImpl); | |
53 }; | |
54 | |
55 // A stub implementation of FlimflamNetworkClient. | |
56 class FlimflamNetworkClientStubImpl : public FlimflamNetworkClient { | |
57 public: | |
58 FlimflamNetworkClientStubImpl() {} | |
59 | |
60 virtual ~FlimflamNetworkClientStubImpl() {} | |
61 | |
62 // FlimflamNetworkClient override. | |
63 virtual void SetPropertyChangedHandler( | |
64 const PropertyChangedHandler& handler) OVERRIDE {} | |
65 | |
66 // FlimflamNetworkClient override. | |
67 virtual void ResetPropertyChangedHandler() OVERRIDE {} | |
68 | |
69 // FlimflamNetworkClient override. | |
70 virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE { | |
71 } | |
72 | |
73 private: | |
74 DISALLOW_COPY_AND_ASSIGN(FlimflamNetworkClientStubImpl); | |
75 }; | |
76 | |
77 } // namespace | |
78 | |
79 FlimflamNetworkClient::FlimflamNetworkClient() {} | |
80 | |
81 FlimflamNetworkClient::~FlimflamNetworkClient() {} | |
82 | |
83 // static | |
84 FlimflamNetworkClient* FlimflamNetworkClient::Create( | |
85 DBusClientImplementationType type, | |
86 dbus::Bus* bus) { | |
87 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | |
88 return new FlimflamNetworkClientImpl(bus); | |
89 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | |
90 return new FlimflamNetworkClientStubImpl(); | |
91 } | |
92 | |
93 } // namespace chromeos | |
OLD | NEW |