OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chromeos/dbus/gsm_sms_client.h" | 4 #include "chromeos/dbus/gsm_sms_client.h" |
5 | 5 |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 return; | 270 return; |
271 } | 271 } |
272 base::DictionaryValue empty_dictionary; | 272 base::DictionaryValue empty_dictionary; |
273 callback.Run(empty_dictionary); | 273 callback.Run(empty_dictionary); |
274 } | 274 } |
275 | 275 |
276 // GsmSMSClient override. | 276 // GsmSMSClient override. |
277 virtual void List(const std::string& service_name, | 277 virtual void List(const std::string& service_name, |
278 const dbus::ObjectPath& object_path, | 278 const dbus::ObjectPath& object_path, |
279 const ListCallback& callback) OVERRIDE { | 279 const ListCallback& callback) OVERRIDE { |
280 PushTestMessageChain(); | |
281 callback.Run(message_list_); | 280 callback.Run(message_list_); |
| 281 PushTestMessageDelayed(); |
282 } | 282 } |
283 | 283 |
284 private: | 284 private: |
| 285 void PushTestMessageDelayed() { |
| 286 const int kSmsMessageDelaySeconds = 5; |
| 287 MessageLoop::current()->PostDelayedTask( |
| 288 FROM_HERE, |
| 289 base::Bind(&GsmSMSClientStubImpl::PushTestMessageChain, |
| 290 weak_ptr_factory_.GetWeakPtr()), |
| 291 base::TimeDelta::FromSeconds(kSmsMessageDelaySeconds)); |
| 292 } |
| 293 |
285 void PushTestMessageChain() { | 294 void PushTestMessageChain() { |
286 if (PushTestMessage()) { | 295 if (PushTestMessage()) |
287 // Queue up the next message. | 296 PushTestMessageDelayed(); |
288 const int kSmsMessageDelaySeconds = 5; | |
289 MessageLoop::current()->PostDelayedTask( | |
290 FROM_HERE, | |
291 base::Bind(&GsmSMSClientStubImpl::PushTestMessageChain, | |
292 weak_ptr_factory_.GetWeakPtr()), | |
293 base::TimeDelta::FromSeconds(kSmsMessageDelaySeconds)); | |
294 } | |
295 } | 297 } |
296 | 298 |
297 bool PushTestMessage() { | 299 bool PushTestMessage() { |
298 if (test_index_ >= test_messages_.size()) | 300 if (test_index_ >= test_messages_.size()) |
299 return false; | 301 return false; |
300 base::DictionaryValue* message = new base::DictionaryValue; | 302 base::DictionaryValue* message = new base::DictionaryValue; |
301 message->SetString("number", "000-000-0000"); | 303 message->SetString("number", "000-000-0000"); |
302 message->SetString("text", test_messages_[test_index_]); | 304 message->SetString("text", test_messages_[test_index_]); |
303 message->SetInteger("index", test_index_); | 305 message->SetInteger("index", test_index_); |
304 int msg_index = message_list_.GetSize(); | 306 int msg_index = message_list_.GetSize(); |
(...skipping 25 matching lines...) Expand all Loading... |
330 // static | 332 // static |
331 GsmSMSClient* GsmSMSClient::Create(DBusClientImplementationType type, | 333 GsmSMSClient* GsmSMSClient::Create(DBusClientImplementationType type, |
332 dbus::Bus* bus) { | 334 dbus::Bus* bus) { |
333 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 335 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
334 return new GsmSMSClientImpl(bus); | 336 return new GsmSMSClientImpl(bus); |
335 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 337 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
336 return new GsmSMSClientStubImpl(); | 338 return new GsmSMSClientStubImpl(); |
337 } | 339 } |
338 | 340 |
339 } // namespace chromeos | 341 } // namespace chromeos |
OLD | NEW |