network_sms_handler.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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
3// found in the LICENSE file.
4
5#ifndef CHROMEOS_NETWORK_NETWORK_SMS_HANDLER_H_
6#define CHROMEOS_NETWORK_NETWORK_SMS_HANDLER_H_
7
8#include <string>
9
10#include "base/memory/scoped_vector.h"
11#include "base/memory/weak_ptr.h"
12#include "base/observer_list.h"
13#include "base/values.h"
14#include "chromeos/chromeos_export.h"
15#include "chromeos/dbus/dbus_method_call_status.h"
16
17namespace chromeos {
18
19// Class to watch sms without Libcros.
20class CHROMEOS_EXPORT NetworkSmsHandler {
21 public:
22  static const char kNumberKey[];
23  static const char kTextKey[];
24  static const char kTimestampKey[];
25
26  class Observer {
27   public:
28    virtual ~Observer() {}
29
30    // Called when a new message arrives. |message| contains the message.
31    // The contents of the dictionary include the keys listed above.
32    virtual void MessageReceived(const base::DictionaryValue& message) = 0;
33  };
34
35  NetworkSmsHandler();
36  ~NetworkSmsHandler();
37
38  // Requests the devices from the netowork manager, sets up observers, and
39  // requests the initial list of messages. Any observers that wish to be
40  // notified with initial messages should be added before calling this.
41  void Init();
42
43  // Requests an immediate check for new messages.
44  void RequestUpdate();
45
46  void AddObserver(Observer* observer);
47  void RemoveObserver(Observer* observer);
48
49 private:
50  class NetworkSmsDeviceHandler;
51  class ModemManagerNetworkSmsDeviceHandler;
52  class ModemManager1NetworkSmsDeviceHandler;
53
54  // Called from NetworkSmsDeviceHandler when a message is received.
55  void NotifyMessageReceived(const base::DictionaryValue& message);
56
57  // Callback to handle the manager properties with the list of devices.
58  void ManagerPropertiesCallback(DBusMethodCallStatus call_status,
59                                 const base::DictionaryValue& properties);
60
61  // Callback to handle the device properties for |device_path|.
62  // A NetworkSmsDeviceHandler will be instantiated for each cellular device.
63  void DevicePropertiesCallback(const std::string& device_path,
64                                DBusMethodCallStatus call_status,
65                                const base::DictionaryValue& properties);
66
67  ObserverList<Observer> observers_;
68  ScopedVector<NetworkSmsDeviceHandler> device_handlers_;
69  base::WeakPtrFactory<NetworkSmsHandler> weak_ptr_factory_;
70
71  DISALLOW_COPY_AND_ASSIGN(NetworkSmsHandler);
72};
73
74}  // namespace
75
76#endif  // CHROMEOS_NETWORK_NETWORK_SMS_HANDLER_H_
77