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: chrome/browser/chromeos/dbus/flimflam_client_helper.cc

Issue 9838085: Move files inside chrome/browser/chromeos/dbus to chromeos/dbus (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
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
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 "chrome/browser/chromeos/dbus/flimflam_client_helper.h"
6
7 #include "base/bind.h"
8 #include "base/values.h"
9 #include "dbus/message.h"
10 #include "dbus/object_proxy.h"
11 #include "dbus/values_util.h"
12 #include "third_party/cros_system_api/dbus/service_constants.h"
13
14 namespace chromeos {
15
16 FlimflamClientHelper::FlimflamClientHelper(dbus::ObjectProxy* proxy)
17 : weak_ptr_factory_(this),
18 proxy_(proxy) {
19 }
20
21 FlimflamClientHelper::~FlimflamClientHelper() {
22 }
23
24 void FlimflamClientHelper::SetPropertyChangedHandler(
25 const PropertyChangedHandler& handler) {
26 property_changed_handler_ = handler;
27 }
28
29 void FlimflamClientHelper::ResetPropertyChangedHandler() {
30 property_changed_handler_.Reset();
31 }
32
33 void FlimflamClientHelper::MonitorPropertyChanged(
34 const std::string& interface_name) {
35 // We are not using dbus::PropertySet to monitor PropertyChanged signal
36 // because the interface is not "org.freedesktop.DBus.Properties".
37 proxy_->ConnectToSignal(interface_name,
38 flimflam::kMonitorPropertyChanged,
39 base::Bind(&FlimflamClientHelper::OnPropertyChanged,
40 weak_ptr_factory_.GetWeakPtr()),
41 base::Bind(&FlimflamClientHelper::OnSignalConnected,
42 weak_ptr_factory_.GetWeakPtr()));
43 }
44
45 void FlimflamClientHelper::CallVoidMethod(dbus::MethodCall* method_call,
46 const VoidCallback& callback) {
47 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
48 base::Bind(&FlimflamClientHelper::OnVoidMethod,
49 weak_ptr_factory_.GetWeakPtr(),
50 callback));
51 }
52
53 void FlimflamClientHelper::CallDictionaryValueMethod(
54 dbus::MethodCall* method_call,
55 const DictionaryValueCallback& callback) {
56 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
57 base::Bind(&FlimflamClientHelper::OnDictionaryValueMethod,
58 weak_ptr_factory_.GetWeakPtr(),
59 callback));
60 }
61
62 void FlimflamClientHelper::OnSignalConnected(const std::string& interface,
63 const std::string& signal,
64 bool success) {
65 LOG_IF(ERROR, !success) << "Connect to " << interface << " " << signal
66 << " failed.";
67 }
68
69 void FlimflamClientHelper::OnPropertyChanged(dbus::Signal* signal) {
70 if (property_changed_handler_.is_null())
71 return;
72
73 dbus::MessageReader reader(signal);
74 std::string name;
75 if (!reader.PopString(&name))
76 return;
77 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
78 if (!value.get())
79 return;
80 property_changed_handler_.Run(name, *value);
81 }
82
83 void FlimflamClientHelper::OnVoidMethod(const VoidCallback& callback,
84 dbus::Response* response) {
85 if (!response) {
86 callback.Run(DBUS_METHOD_CALL_FAILURE);
87 return;
88 }
89 callback.Run(DBUS_METHOD_CALL_SUCCESS);
90 }
91
92 void FlimflamClientHelper::OnDictionaryValueMethod(
93 const DictionaryValueCallback& callback,
94 dbus::Response* response) {
95 if (!response) {
96 base::DictionaryValue result;
97 callback.Run(DBUS_METHOD_CALL_FAILURE, result);
98 return;
99 }
100 dbus::MessageReader reader(response);
101 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
102 base::DictionaryValue* result = NULL;
103 if (!value.get() || !value->GetAsDictionary(&result)) {
104 base::DictionaryValue result;
105 callback.Run(DBUS_METHOD_CALL_FAILURE, result);
106 return;
107 }
108 callback.Run(DBUS_METHOD_CALL_SUCCESS, *result);
109 }
110
111 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/dbus/flimflam_client_helper.h ('k') | chrome/browser/chromeos/dbus/flimflam_client_unittest_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698