Remove old about scheme URL constants.
[chromium-blink-merge.git] / chromeos / dbus / sms_client.cc
blob2e7b9717a5eb1d15040fc3213859d2291d0744fd
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 #include "chromeos/dbus/sms_client.h"
6 #include <map>
7 #include <utility>
9 #include "base/bind.h"
10 #include "base/command_line.h"
11 #include "base/location.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/message_loop/message_loop.h"
15 #include "base/stl_util.h"
16 #include "base/strings/stringprintf.h"
17 #include "base/values.h"
18 #include "chromeos/chromeos_switches.h"
19 #include "dbus/bus.h"
20 #include "dbus/message.h"
21 #include "dbus/object_proxy.h"
22 #include "dbus/values_util.h"
23 #include "third_party/cros_system_api/dbus/service_constants.h"
25 namespace chromeos {
27 namespace {
29 // SMSClient is used to communicate with the
30 // org.freedesktop.ModemManager1.SMS service. All methods should be
31 // called from the origin thread (UI thread) which initializes the
32 // DBusThreadManager instance.
33 class SMSClientImpl : public SMSClient {
34 public:
35 SMSClientImpl() : bus_(NULL), weak_ptr_factory_(this) {}
37 virtual ~SMSClientImpl() {}
39 // Calls GetAll method. |callback| is called after the method call succeeds.
40 virtual void GetAll(const std::string& service_name,
41 const dbus::ObjectPath& object_path,
42 const GetAllCallback& callback) OVERRIDE {
43 dbus::ObjectProxy *proxy = bus_->GetObjectProxy(service_name, object_path);
44 dbus::MethodCall method_call(dbus::kDBusPropertiesInterface,
45 dbus::kDBusPropertiesGetAll);
46 dbus::MessageWriter writer(&method_call);
47 writer.AppendString(modemmanager::kModemManager1SmsInterface);
48 proxy->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
49 base::Bind(&SMSClientImpl::OnGetAll,
50 weak_ptr_factory_.GetWeakPtr(),
51 callback));
54 protected:
55 virtual void Init(dbus::Bus* bus) OVERRIDE {
56 bus_ = bus;
59 private:
60 // Handles responses of GetAll method calls.
61 void OnGetAll(const GetAllCallback& callback, dbus::Response* response) {
62 if (!response) {
63 // Must invoke the callback, even if there is no message.
64 base::DictionaryValue empty_dictionary;
65 callback.Run(empty_dictionary);
66 return;
68 dbus::MessageReader reader(response);
69 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
70 base::DictionaryValue* dictionary_value = NULL;
71 if (!value.get() || !value->GetAsDictionary(&dictionary_value)) {
72 LOG(WARNING) << "Invalid response: " << response->ToString();
73 base::DictionaryValue empty_dictionary;
74 callback.Run(empty_dictionary);
75 return;
77 callback.Run(*dictionary_value);
80 dbus::Bus* bus_;
82 // Note: This should remain the last member so it'll be destroyed and
83 // invalidate its weak pointers before any other members are destroyed.
84 base::WeakPtrFactory<SMSClientImpl> weak_ptr_factory_;
86 DISALLOW_COPY_AND_ASSIGN(SMSClientImpl);
89 } // namespace
91 ////////////////////////////////////////////////////////////////////////////////
92 // SMSClient
94 SMSClient::SMSClient() {}
96 SMSClient::~SMSClient() {}
99 // static
100 SMSClient* SMSClient::Create() {
101 return new SMSClientImpl();
104 } // namespace chromeos