OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "chromeos/dbus/fake_gsm_sms_client.h" | 7 #include "chromeos/dbus/fake_gsm_sms_client.h" |
8 | 8 |
9 namespace chromeos { | 9 namespace chromeos { |
10 | 10 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 void FakeGsmSMSClient::RequestUpdate(const std::string& service_name, | 67 void FakeGsmSMSClient::RequestUpdate(const std::string& service_name, |
68 const dbus::ObjectPath& object_path) { | 68 const dbus::ObjectPath& object_path) { |
69 if (!sms_test_message_switch_present_) | 69 if (!sms_test_message_switch_present_) |
70 return; | 70 return; |
71 | 71 |
72 if (test_index_ >= 0) | 72 if (test_index_ >= 0) |
73 return; | 73 return; |
74 test_index_ = 0; | 74 test_index_ = 0; |
75 // Call PushTestMessageChain asynchronously so that the handler_ callback | 75 // Call PushTestMessageChain asynchronously so that the handler_ callback |
76 // does not get called from the update request. | 76 // does not get called from the update request. |
77 MessageLoop::current()->PostTask( | 77 base::MessageLoop::current()->PostTask( |
78 FROM_HERE, | 78 FROM_HERE, |
79 base::Bind(&FakeGsmSMSClient::PushTestMessageChain, | 79 base::Bind(&FakeGsmSMSClient::PushTestMessageChain, |
80 weak_ptr_factory_.GetWeakPtr())); | 80 weak_ptr_factory_.GetWeakPtr())); |
81 } | 81 } |
82 | 82 |
83 void FakeGsmSMSClient::PushTestMessageChain() { | 83 void FakeGsmSMSClient::PushTestMessageChain() { |
84 if (PushTestMessage()) | 84 if (PushTestMessage()) |
85 PushTestMessageDelayed(); | 85 PushTestMessageDelayed(); |
86 } | 86 } |
87 | 87 |
88 void FakeGsmSMSClient::PushTestMessageDelayed() { | 88 void FakeGsmSMSClient::PushTestMessageDelayed() { |
89 const int kSmsMessageDelaySeconds = 5; | 89 const int kSmsMessageDelaySeconds = 5; |
90 MessageLoop::current()->PostDelayedTask( | 90 base::MessageLoop::current()->PostDelayedTask( |
91 FROM_HERE, | 91 FROM_HERE, |
92 base::Bind(&FakeGsmSMSClient::PushTestMessageChain, | 92 base::Bind(&FakeGsmSMSClient::PushTestMessageChain, |
93 weak_ptr_factory_.GetWeakPtr()), | 93 weak_ptr_factory_.GetWeakPtr()), |
94 base::TimeDelta::FromSeconds(kSmsMessageDelaySeconds)); | 94 base::TimeDelta::FromSeconds(kSmsMessageDelaySeconds)); |
95 } | 95 } |
96 | 96 |
97 bool FakeGsmSMSClient::PushTestMessage() { | 97 bool FakeGsmSMSClient::PushTestMessage() { |
98 if (test_index_ >= static_cast<int>(test_messages_.size())) | 98 if (test_index_ >= static_cast<int>(test_messages_.size())) |
99 return false; | 99 return false; |
100 base::DictionaryValue* message = new base::DictionaryValue; | 100 base::DictionaryValue* message = new base::DictionaryValue; |
101 message->SetString("number", "000-000-0000"); | 101 message->SetString("number", "000-000-0000"); |
102 message->SetString("text", test_messages_[test_index_]); | 102 message->SetString("text", test_messages_[test_index_]); |
103 message->SetInteger("index", test_index_); | 103 message->SetInteger("index", test_index_); |
104 int msg_index = message_list_.GetSize(); | 104 int msg_index = message_list_.GetSize(); |
105 message_list_.Append(message); | 105 message_list_.Append(message); |
106 if (!handler_.is_null()) | 106 if (!handler_.is_null()) |
107 handler_.Run(msg_index, true); | 107 handler_.Run(msg_index, true); |
108 ++test_index_; | 108 ++test_index_; |
109 return true; | 109 return true; |
110 } | 110 } |
111 | 111 |
112 } // namespace chromeos | 112 } // namespace chromeos |
OLD | NEW |