1// Copyright (c) 2013 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/shill_ipconfig_client_stub.h"
6
7#include "base/bind.h"
8#include "base/message_loop/message_loop.h"
9#include "base/stl_util.h"
10#include "base/values.h"
11#include "chromeos/dbus/shill_property_changed_observer.h"
12#include "dbus/bus.h"
13#include "dbus/message.h"
14#include "dbus/object_path.h"
15#include "dbus/object_proxy.h"
16#include "dbus/values_util.h"
17#include "third_party/cros_system_api/dbus/service_constants.h"
18
19namespace chromeos {
20
21ShillIPConfigClientStub::ShillIPConfigClientStub() : weak_ptr_factory_(this) {
22}
23
24ShillIPConfigClientStub::~ShillIPConfigClientStub() {
25}
26
27void ShillIPConfigClientStub::AddPropertyChangedObserver(
28    const dbus::ObjectPath& ipconfig_path,
29    ShillPropertyChangedObserver* observer) {
30}
31
32void ShillIPConfigClientStub::RemovePropertyChangedObserver(
33    const dbus::ObjectPath& ipconfig_path,
34    ShillPropertyChangedObserver* observer) {
35}
36
37void ShillIPConfigClientStub::Refresh(const dbus::ObjectPath& ipconfig_path,
38                                      const VoidDBusMethodCallback& callback) {
39}
40
41void ShillIPConfigClientStub::GetProperties(
42    const dbus::ObjectPath& ipconfig_path,
43    const DictionaryValueCallback& callback) {
44  const base::DictionaryValue* dict = NULL;
45  if (!ipconfigs_.GetDictionaryWithoutPathExpansion(ipconfig_path.value(),
46                                                    &dict))
47    return;
48  base::MessageLoop::current()->PostTask(
49        FROM_HERE, base::Bind(&ShillIPConfigClientStub::PassProperties,
50                              weak_ptr_factory_.GetWeakPtr(),
51                              dict,
52                              callback));
53}
54
55base::DictionaryValue* ShillIPConfigClientStub::CallGetPropertiesAndBlock(
56    const dbus::ObjectPath& ipconfig_path) {
57  return new base::DictionaryValue;
58}
59
60void ShillIPConfigClientStub::SetProperty(
61    const dbus::ObjectPath& ipconfig_path,
62    const std::string& name,
63    const base::Value& value,
64    const VoidDBusMethodCallback& callback) {
65  base::DictionaryValue* dict = NULL;
66  if (ipconfigs_.GetDictionaryWithoutPathExpansion(ipconfig_path.value(),
67                                                   &dict)) {
68    // Update existing ip config stub object's properties.
69    dict->SetWithoutPathExpansion(name, value.DeepCopy());
70  } else {
71    // Create a new stub ipconfig object, and update its properties.
72    base::DictionaryValue* dvalue = new base::DictionaryValue;
73    dvalue->SetWithoutPathExpansion(name, value.DeepCopy());
74    ipconfigs_.SetWithoutPathExpansion(ipconfig_path.value(),
75                                       dvalue);
76  }
77  base::MessageLoop::current()->PostTask(
78      FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
79}
80
81void ShillIPConfigClientStub::ClearProperty(
82    const dbus::ObjectPath& ipconfig_path,
83    const std::string& name,
84    const VoidDBusMethodCallback& callback) {
85  base::MessageLoop::current()->PostTask(
86      FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
87}
88
89void ShillIPConfigClientStub::Remove(const dbus::ObjectPath& ipconfig_path,
90                                     const VoidDBusMethodCallback& callback) {
91  base::MessageLoop::current()->PostTask(
92      FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
93}
94
95void ShillIPConfigClientStub::PassProperties(
96    const base::DictionaryValue* values,
97    const DictionaryValueCallback& callback) const {
98  callback.Run(DBUS_METHOD_CALL_SUCCESS, *values);
99}
100
101}  // namespace chromeos
102