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.
4
5#include <string>
6
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"
17
18namespace chromeos {
19
20FakeSMSClient::FakeSMSClient() : weak_ptr_factory_(this) {}
21
22FakeSMSClient::~FakeSMSClient() {}
23
24void FakeSMSClient::Init(dbus::Bus* bus) {}
25
26void FakeSMSClient::GetAll(const std::string& service_name,
27                           const dbus::ObjectPath& object_path,
28                           const GetAllCallback& callback) {
29  if (!CommandLine::ForCurrentProcess()->HasSwitch(
30           chromeos::switches::kSmsTestMessages))
31    return;
32
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");
38
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));
48}
49
50void FakeSMSClient::OnGetAll(base::DictionaryValue* sms,
51                             const GetAllCallback& callback) {
52  callback.Run(*sms);
53}
54
55}  // namespace chromeos
56