OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chromeos/chromeos_switches.h" | 14 #include "chromeos/chromeos_switches.h" |
15 #include "chromeos/dbus/fake_sms_client.h" | 15 #include "chromeos/dbus/fake_sms_client.h" |
16 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
17 | 17 |
18 namespace chromeos { | 18 namespace chromeos { |
19 | 19 |
20 FakeSMSClient::FakeSMSClient() : weak_ptr_factory_(this) {} | 20 FakeSMSClient::FakeSMSClient() : weak_ptr_factory_(this) {} |
21 | 21 |
22 FakeSMSClient::~FakeSMSClient() {} | 22 FakeSMSClient::~FakeSMSClient() {} |
23 | 23 |
24 void FakeSMSClient::Init(dbus::Bus* bus) {} | 24 void FakeSMSClient::Init(dbus::Bus* bus) {} |
25 | 25 |
26 void FakeSMSClient::GetAll(const std::string& service_name, | 26 void FakeSMSClient::GetAll(const std::string& service_name, |
27 const dbus::ObjectPath& object_path, | 27 const dbus::ObjectPath& object_path, |
28 const GetAllCallback& callback) { | 28 const GetAllCallback& callback) { |
29 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 29 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
30 chromeos::switches::kSmsTestMessages)) | 30 chromeos::switches::kSmsTestMessages)) |
31 return; | 31 return; |
32 | 32 |
33 // Ownership passed to callback | 33 // Ownership passed to callback |
34 base::DictionaryValue* sms = new base::DictionaryValue(); | 34 base::DictionaryValue* sms = new base::DictionaryValue(); |
35 sms->SetString("Number", "000-000-0000"); | 35 sms->SetString("Number", "000-000-0000"); |
36 sms->SetString("Text", "FakeSMSClient: Test Message: " + object_path.value()); | 36 sms->SetString("Text", "FakeSMSClient: Test Message: " + object_path.value()); |
37 sms->SetString("Timestamp", "Fri Jun 8 13:26:04 EDT 2012"); | 37 sms->SetString("Timestamp", "Fri Jun 8 13:26:04 EDT 2012"); |
38 | 38 |
39 // Run callback asynchronously. | 39 // Run callback asynchronously. |
40 if (callback.is_null()) | 40 if (callback.is_null()) |
41 return; | 41 return; |
42 base::MessageLoop::current()->PostTask( | 42 base::MessageLoop::current()->PostTask( |
43 FROM_HERE, | 43 FROM_HERE, |
44 base::Bind(&FakeSMSClient::OnGetAll, | 44 base::Bind(&FakeSMSClient::OnGetAll, |
45 weak_ptr_factory_.GetWeakPtr(), | 45 weak_ptr_factory_.GetWeakPtr(), |
46 base::Owned(sms), | 46 base::Owned(sms), |
47 callback)); | 47 callback)); |
48 } | 48 } |
49 | 49 |
50 void FakeSMSClient::OnGetAll(base::DictionaryValue* sms, | 50 void FakeSMSClient::OnGetAll(base::DictionaryValue* sms, |
51 const GetAllCallback& callback) { | 51 const GetAllCallback& callback) { |
52 callback.Run(*sms); | 52 callback.Run(*sms); |
53 } | 53 } |
54 | 54 |
55 } // namespace chromeos | 55 } // namespace chromeos |
OLD | NEW |