Revert of Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320) (patchset...
[chromium-blink-merge.git] / chromeos / dbus / fake_sms_client.cc
blob6f2c9968a4859bb246f21306de9a7483be8db0cc
1 // Copyright 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.
5 #include <string>
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/callback.h"
10 #include "base/command_line.h"
11 #include "base/location.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/values.h"
14 #include "chromeos/chromeos_switches.h"
15 #include "chromeos/dbus/fake_sms_client.h"
16 #include "dbus/object_path.h"
18 namespace chromeos {
20 FakeSMSClient::FakeSMSClient() : weak_ptr_factory_(this) {}
22 FakeSMSClient::~FakeSMSClient() {}
24 void FakeSMSClient::Init(dbus::Bus* bus) {}
26 void FakeSMSClient::GetAll(const std::string& service_name,
27 const dbus::ObjectPath& object_path,
28 const GetAllCallback& callback) {
29 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
30 chromeos::switches::kSmsTestMessages))
31 return;
33 // Ownership passed to callback
34 base::DictionaryValue* sms = new base::DictionaryValue();
35 sms->SetString("Number", "000-000-0000");
36 sms->SetString("Text", "FakeSMSClient: Test Message: " + object_path.value());
37 sms->SetString("Timestamp", "Fri Jun 8 13:26:04 EDT 2012");
39 // Run callback asynchronously.
40 if (callback.is_null())
41 return;
42 base::MessageLoop::current()->PostTask(
43 FROM_HERE,
44 base::Bind(&FakeSMSClient::OnGetAll,
45 weak_ptr_factory_.GetWeakPtr(),
46 base::Owned(sms),
47 callback));
50 void FakeSMSClient::OnGetAll(base::DictionaryValue* sms,
51 const GetAllCallback& callback) {
52 callback.Run(*sms);
55 } // namespace chromeos