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.
5 #ifndef CHROMEOS_NETWORK_NETWORK_SMS_HANDLER_H_
6 #define CHROMEOS_NETWORK_NETWORK_SMS_HANDLER_H_
10 #include "base/memory/scoped_vector.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/observer_list.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/dbus/dbus_method_call_status.h"
15 #include "chromeos/dbus/shill_property_changed_observer.h"
18 class DictionaryValue
;
25 // Class to watch sms without Libcros.
26 class CHROMEOS_EXPORT NetworkSmsHandler
: public ShillPropertyChangedObserver
{
28 static const char kNumberKey
[];
29 static const char kTextKey
[];
30 static const char kTimestampKey
[];
34 virtual ~Observer() {}
36 // Called when a new message arrives. |message| contains the message.
37 // The contents of the dictionary include the keys listed above.
38 virtual void MessageReceived(const base::DictionaryValue
& message
) = 0;
41 ~NetworkSmsHandler() override
;
43 // Requests an immediate check for new messages. If |request_existing| is
44 // true then also requests to be notified for any already received messages.
45 void RequestUpdate(bool request_existing
);
47 void AddObserver(Observer
* observer
);
48 void RemoveObserver(Observer
* observer
);
50 // ShillPropertyChangedObserver
51 void OnPropertyChanged(const std::string
& name
,
52 const base::Value
& value
) override
;
55 friend class NetworkHandler
;
56 friend class NetworkSmsHandlerTest
;
58 class NetworkSmsDeviceHandler
;
59 class ModemManagerNetworkSmsDeviceHandler
;
60 class ModemManager1NetworkSmsDeviceHandler
;
64 // Requests the devices from the network manager, sets up observers, and
65 // requests the initial list of messages.
68 // Adds |message| to the list of received messages. If the length of the
69 // list exceeds the maximum number of retained messages, erase the least
70 // recently received message.
71 void AddReceivedMessage(const base::DictionaryValue
& message
);
73 // Notify observers that |message| was received.
74 void NotifyMessageReceived(const base::DictionaryValue
& message
);
76 // Called from NetworkSmsDeviceHandler when a message is received.
77 void MessageReceived(const base::DictionaryValue
& message
);
79 // Callback to handle the manager properties with the list of devices.
80 void ManagerPropertiesCallback(DBusMethodCallStatus call_status
,
81 const base::DictionaryValue
& properties
);
83 // Requests properties for each entry in |devices|.
84 void UpdateDevices(const base::ListValue
* devices
);
86 // Callback to handle the device properties for |device_path|.
87 // A NetworkSmsDeviceHandler will be instantiated for each cellular device.
88 void DevicePropertiesCallback(const std::string
& device_path
,
89 DBusMethodCallStatus call_status
,
90 const base::DictionaryValue
& properties
);
92 ObserverList
<Observer
> observers_
;
93 ScopedVector
<NetworkSmsDeviceHandler
> device_handlers_
;
94 ScopedVector
<base::DictionaryValue
> received_messages_
;
95 base::WeakPtrFactory
<NetworkSmsHandler
> weak_ptr_factory_
;
97 DISALLOW_COPY_AND_ASSIGN(NetworkSmsHandler
);
102 #endif // CHROMEOS_NETWORK_NETWORK_SMS_HANDLER_H_