| 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 | 4 |
| 5 #ifndef CHROMEOS_NETWORK_NETWORK_SMS_HANDLER_H_ | 5 #ifndef CHROMEOS_NETWORK_NETWORK_SMS_HANDLER_H_ |
| 6 #define CHROMEOS_NETWORK_NETWORK_SMS_HANDLER_H_ | 6 #define CHROMEOS_NETWORK_NETWORK_SMS_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "base/values.h" | |
| 14 #include "chromeos/chromeos_export.h" | 13 #include "chromeos/chromeos_export.h" |
| 15 #include "chromeos/dbus/dbus_method_call_status.h" | 14 #include "chromeos/dbus/dbus_method_call_status.h" |
| 15 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 16 |
| 17 namespace base { |
| 18 class DictionaryValue; |
| 19 class ListValue; |
| 20 class Value; |
| 21 } |
| 16 | 22 |
| 17 namespace chromeos { | 23 namespace chromeos { |
| 18 | 24 |
| 19 // Class to watch sms without Libcros. | 25 // Class to watch sms without Libcros. |
| 20 class CHROMEOS_EXPORT NetworkSmsHandler { | 26 class CHROMEOS_EXPORT NetworkSmsHandler : public ShillPropertyChangedObserver { |
| 21 public: | 27 public: |
| 22 static const char kNumberKey[]; | 28 static const char kNumberKey[]; |
| 23 static const char kTextKey[]; | 29 static const char kTextKey[]; |
| 24 static const char kTimestampKey[]; | 30 static const char kTimestampKey[]; |
| 25 | 31 |
| 26 class Observer { | 32 class Observer { |
| 27 public: | 33 public: |
| 28 virtual ~Observer() {} | 34 virtual ~Observer() {} |
| 29 | 35 |
| 30 // Called when a new message arrives. |message| contains the message. | 36 // Called when a new message arrives. |message| contains the message. |
| 31 // The contents of the dictionary include the keys listed above. | 37 // The contents of the dictionary include the keys listed above. |
| 32 virtual void MessageReceived(const base::DictionaryValue& message) = 0; | 38 virtual void MessageReceived(const base::DictionaryValue& message) = 0; |
| 33 }; | 39 }; |
| 34 | 40 |
| 35 NetworkSmsHandler(); | 41 NetworkSmsHandler(); |
| 36 ~NetworkSmsHandler(); | 42 ~NetworkSmsHandler(); |
| 37 | 43 |
| 38 // Requests the devices from the netowork manager, sets up observers, and | 44 // Sets the global instance. Must be called before any calls to Get(). |
| 39 // requests the initial list of messages. Any observers that wish to be | 45 static void Initialize(); |
| 40 // notified with initial messages should be added before calling this. | |
| 41 void Init(); | |
| 42 | 46 |
| 43 // Requests an immediate check for new messages. | 47 // Destroys the global instance. |
| 44 void RequestUpdate(); | 48 static void Shutdown(); |
| 49 |
| 50 // Gets the global instance. Initialize() must be called first. |
| 51 static NetworkSmsHandler* Get(); |
| 52 |
| 53 // Requests an immediate check for new messages. If |request_existing| is |
| 54 // true then also requests to be notified for any already received messages. |
| 55 void RequestUpdate(bool request_existing); |
| 45 | 56 |
| 46 void AddObserver(Observer* observer); | 57 void AddObserver(Observer* observer); |
| 47 void RemoveObserver(Observer* observer); | 58 void RemoveObserver(Observer* observer); |
| 48 | 59 |
| 60 // ShillPropertyChangedObserver |
| 61 virtual void OnPropertyChanged(const std::string& name, |
| 62 const base::Value& value) OVERRIDE; |
| 63 |
| 49 private: | 64 private: |
| 50 class NetworkSmsDeviceHandler; | 65 class NetworkSmsDeviceHandler; |
| 51 class ModemManagerNetworkSmsDeviceHandler; | 66 class ModemManagerNetworkSmsDeviceHandler; |
| 52 class ModemManager1NetworkSmsDeviceHandler; | 67 class ModemManager1NetworkSmsDeviceHandler; |
| 53 | 68 |
| 69 // Requests the devices from the network manager, sets up observers, and |
| 70 // requests the initial list of messages. |
| 71 void InitShillDevices(); |
| 72 |
| 54 // Called from NetworkSmsDeviceHandler when a message is received. | 73 // Called from NetworkSmsDeviceHandler when a message is received. |
| 55 void NotifyMessageReceived(const base::DictionaryValue& message); | 74 void NotifyMessageReceived(const base::DictionaryValue& message); |
| 56 | 75 |
| 57 // Callback to handle the manager properties with the list of devices. | 76 // Callback to handle the manager properties with the list of devices. |
| 58 void ManagerPropertiesCallback(DBusMethodCallStatus call_status, | 77 void ManagerPropertiesCallback(DBusMethodCallStatus call_status, |
| 59 const base::DictionaryValue& properties); | 78 const base::DictionaryValue& properties); |
| 60 | 79 |
| 80 // Requests properties for each entry in |devices|. |
| 81 void UpdateDevices(const base::ListValue* devices); |
| 82 |
| 61 // Callback to handle the device properties for |device_path|. | 83 // Callback to handle the device properties for |device_path|. |
| 62 // A NetworkSmsDeviceHandler will be instantiated for each cellular device. | 84 // A NetworkSmsDeviceHandler will be instantiated for each cellular device. |
| 63 void DevicePropertiesCallback(const std::string& device_path, | 85 void DevicePropertiesCallback(const std::string& device_path, |
| 64 DBusMethodCallStatus call_status, | 86 DBusMethodCallStatus call_status, |
| 65 const base::DictionaryValue& properties); | 87 const base::DictionaryValue& properties); |
| 66 | 88 |
| 67 ObserverList<Observer> observers_; | 89 ObserverList<Observer> observers_; |
| 68 ScopedVector<NetworkSmsDeviceHandler> device_handlers_; | 90 ScopedVector<NetworkSmsDeviceHandler> device_handlers_; |
| 91 ScopedVector<base::DictionaryValue> received_messages_; |
| 69 base::WeakPtrFactory<NetworkSmsHandler> weak_ptr_factory_; | 92 base::WeakPtrFactory<NetworkSmsHandler> weak_ptr_factory_; |
| 70 | 93 |
| 71 DISALLOW_COPY_AND_ASSIGN(NetworkSmsHandler); | 94 DISALLOW_COPY_AND_ASSIGN(NetworkSmsHandler); |
| 72 }; | 95 }; |
| 73 | 96 |
| 74 } // namespace | 97 } // namespace |
| 75 | 98 |
| 76 #endif // CHROMEOS_NETWORK_NETWORK_SMS_HANDLER_H_ | 99 #endif // CHROMEOS_NETWORK_NETWORK_SMS_HANDLER_H_ |
| OLD | NEW |