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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 GetProxy(service_name, object_path)->Get(index, callback); | 191 GetProxy(service_name, object_path)->Get(index, callback); |
192 } | 192 } |
193 | 193 |
194 // GsmSMSClient override. | 194 // GsmSMSClient override. |
195 virtual void List(const std::string& service_name, | 195 virtual void List(const std::string& service_name, |
196 const dbus::ObjectPath& object_path, | 196 const dbus::ObjectPath& object_path, |
197 const ListCallback& callback) OVERRIDE { | 197 const ListCallback& callback) OVERRIDE { |
198 GetProxy(service_name, object_path)->List(callback); | 198 GetProxy(service_name, object_path)->List(callback); |
199 } | 199 } |
200 | 200 |
| 201 // GsmSMSClient override. |
| 202 virtual void RequestUpdate(const std::string& service_name, |
| 203 const dbus::ObjectPath& object_path) { |
| 204 } |
| 205 |
201 private: | 206 private: |
202 typedef std::map<std::pair<std::string, std::string>, SMSProxy*> ProxyMap; | 207 typedef std::map<std::pair<std::string, std::string>, SMSProxy*> ProxyMap; |
203 | 208 |
204 // Returns a SMSProxy for the given service name and object path. | 209 // Returns a SMSProxy for the given service name and object path. |
205 SMSProxy* GetProxy(const std::string& service_name, | 210 SMSProxy* GetProxy(const std::string& service_name, |
206 const dbus::ObjectPath& object_path) { | 211 const dbus::ObjectPath& object_path) { |
207 const ProxyMap::key_type key(service_name, object_path.value()); | 212 const ProxyMap::key_type key(service_name, object_path.value()); |
208 ProxyMap::iterator it = proxies_.find(key); | 213 ProxyMap::iterator it = proxies_.find(key); |
209 if (it != proxies_.end()) | 214 if (it != proxies_.end()) |
210 return it->second; | 215 return it->second; |
(...skipping 13 matching lines...) Expand all Loading... |
224 | 229 |
225 // A stub implementaion of GsmSMSClient. | 230 // A stub implementaion of GsmSMSClient. |
226 class GsmSMSClientStubImpl : public GsmSMSClient { | 231 class GsmSMSClientStubImpl : public GsmSMSClient { |
227 public: | 232 public: |
228 GsmSMSClientStubImpl() : test_index_(0), weak_ptr_factory_(this) { | 233 GsmSMSClientStubImpl() : test_index_(0), weak_ptr_factory_(this) { |
229 test_messages_.push_back("Test Message 0"); | 234 test_messages_.push_back("Test Message 0"); |
230 test_messages_.push_back("Test Message 1"); | 235 test_messages_.push_back("Test Message 1"); |
231 test_messages_.push_back("Test a relatively long message 2"); | 236 test_messages_.push_back("Test a relatively long message 2"); |
232 test_messages_.push_back("Test a very, the quick brown fox jumped" | 237 test_messages_.push_back("Test a very, the quick brown fox jumped" |
233 " over the lazy dog, long message 3"); | 238 " over the lazy dog, long message 3"); |
| 239 test_messages_.push_back("Test Message 4"); |
| 240 test_messages_.push_back("Test Message 5"); |
| 241 test_messages_.push_back("Test Message 6"); |
234 } | 242 } |
235 | 243 |
236 virtual ~GsmSMSClientStubImpl() {} | 244 virtual ~GsmSMSClientStubImpl() {} |
237 | 245 |
238 // GsmSMSClient override. | 246 // GsmSMSClient override. |
239 virtual void SetSmsReceivedHandler( | 247 virtual void SetSmsReceivedHandler( |
240 const std::string& service_name, | 248 const std::string& service_name, |
241 const dbus::ObjectPath& object_path, | 249 const dbus::ObjectPath& object_path, |
242 const SmsReceivedHandler& handler) OVERRIDE { | 250 const SmsReceivedHandler& handler) OVERRIDE { |
243 handler_ = handler; | 251 handler_ = handler; |
(...skipping 26 matching lines...) Expand all Loading... |
270 return; | 278 return; |
271 } | 279 } |
272 base::DictionaryValue empty_dictionary; | 280 base::DictionaryValue empty_dictionary; |
273 callback.Run(empty_dictionary); | 281 callback.Run(empty_dictionary); |
274 } | 282 } |
275 | 283 |
276 // GsmSMSClient override. | 284 // GsmSMSClient override. |
277 virtual void List(const std::string& service_name, | 285 virtual void List(const std::string& service_name, |
278 const dbus::ObjectPath& object_path, | 286 const dbus::ObjectPath& object_path, |
279 const ListCallback& callback) OVERRIDE { | 287 const ListCallback& callback) OVERRIDE { |
| 288 callback.Run(message_list_); |
| 289 } |
| 290 |
| 291 // GsmSMSClient override. |
| 292 virtual void RequestUpdate(const std::string& service_name, |
| 293 const dbus::ObjectPath& object_path) { |
280 PushTestMessageChain(); | 294 PushTestMessageChain(); |
281 callback.Run(message_list_); | |
282 } | 295 } |
283 | 296 |
284 private: | 297 private: |
285 void PushTestMessageChain() { | 298 void PushTestMessageChain() { |
286 if (PushTestMessage()) { | 299 if (PushTestMessage()) |
287 // Queue up the next message. | 300 PushTestMessageDelayed(); |
288 const int kSmsMessageDelaySeconds = 5; | 301 } |
289 MessageLoop::current()->PostDelayedTask( | 302 |
290 FROM_HERE, | 303 void PushTestMessageDelayed() { |
291 base::Bind(&GsmSMSClientStubImpl::PushTestMessageChain, | 304 const int kSmsMessageDelaySeconds = 5; |
292 weak_ptr_factory_.GetWeakPtr()), | 305 MessageLoop::current()->PostDelayedTask( |
293 base::TimeDelta::FromSeconds(kSmsMessageDelaySeconds)); | 306 FROM_HERE, |
294 } | 307 base::Bind(&GsmSMSClientStubImpl::PushTestMessageChain, |
| 308 weak_ptr_factory_.GetWeakPtr()), |
| 309 base::TimeDelta::FromSeconds(kSmsMessageDelaySeconds)); |
295 } | 310 } |
296 | 311 |
297 bool PushTestMessage() { | 312 bool PushTestMessage() { |
298 if (test_index_ >= test_messages_.size()) | 313 if (test_index_ >= test_messages_.size()) |
299 return false; | 314 return false; |
300 base::DictionaryValue* message = new base::DictionaryValue; | 315 base::DictionaryValue* message = new base::DictionaryValue; |
301 message->SetString("number", "000-000-0000"); | 316 message->SetString("number", "000-000-0000"); |
302 message->SetString("text", test_messages_[test_index_]); | 317 message->SetString("text", test_messages_[test_index_]); |
303 message->SetInteger("index", test_index_); | 318 message->SetInteger("index", test_index_); |
304 int msg_index = message_list_.GetSize(); | 319 int msg_index = message_list_.GetSize(); |
(...skipping 25 matching lines...) Expand all Loading... |
330 // static | 345 // static |
331 GsmSMSClient* GsmSMSClient::Create(DBusClientImplementationType type, | 346 GsmSMSClient* GsmSMSClient::Create(DBusClientImplementationType type, |
332 dbus::Bus* bus) { | 347 dbus::Bus* bus) { |
333 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 348 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
334 return new GsmSMSClientImpl(bus); | 349 return new GsmSMSClientImpl(bus); |
335 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 350 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
336 return new GsmSMSClientStubImpl(); | 351 return new GsmSMSClientStubImpl(); |
337 } | 352 } |
338 | 353 |
339 } // namespace chromeos | 354 } // namespace chromeos |
OLD | NEW |