Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 1 | // Copyright 2014 The Chromium OS 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 BUFFET_MANAGER_H_ |
| 6 | #define BUFFET_MANAGER_H_ |
| 7 | |
Alex Vakulenko | 24aa122 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 8 | #include <memory> |
Vitaly Buka | da2312c | 2015-06-23 20:11:36 -0700 | [diff] [blame] | 9 | #include <set> |
Alex Vakulenko | 24aa122 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 10 | #include <string> |
Alex Vakulenko | acec6aa | 2015-04-20 11:00:54 -0700 | [diff] [blame] | 11 | #include <vector> |
Alex Vakulenko | 24aa122 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 12 | |
Christopher Wiley | 357deca | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 13 | #include <base/files/file_path.h> |
Alex Vakulenko | 274226b | 2014-09-04 08:59:43 -0700 | [diff] [blame] | 14 | #include <base/macros.h> |
Christopher Wiley | d71774f | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 15 | #include <base/memory/weak_ptr.h> |
Alex Vakulenko | f3d77e5 | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 16 | #include <base/values.h> |
Alex Vakulenko | 95877b5 | 2014-09-19 15:31:09 -0700 | [diff] [blame] | 17 | #include <chromeos/dbus/data_serialization.h> |
Alex Vakulenko | b635153 | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 18 | #include <chromeos/dbus/dbus_object.h> |
Alex Vakulenko | 24e5f5d | 2014-08-27 11:00:57 -0700 | [diff] [blame] | 19 | #include <chromeos/dbus/exported_property_set.h> |
| 20 | #include <chromeos/errors/error.h> |
Vitaly Buka | e2713ac | 2015-08-03 13:50:01 -0700 | [diff] [blame] | 21 | #include <weave/device.h> |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 22 | |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 23 | #include "buffet/org.chromium.Buffet.Manager.h" |
Christopher Wiley | 106686a | 2014-03-27 14:51:26 -0700 | [diff] [blame] | 24 | |
Christopher Wiley | 1aa980e | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 25 | namespace chromeos { |
Christopher Wiley | d71774f | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 26 | namespace dbus_utils { |
| 27 | class ExportedObjectManager; |
| 28 | } // namespace dbus_utils |
Christopher Wiley | 1aa980e | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 29 | } // namespace chromeos |
| 30 | |
Vitaly Buka | 3b08631 | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 31 | namespace buffet { |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 32 | |
Vitaly Buka | a0305d3 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 33 | class DBusCommandDispacher; |
Vitaly Buka | 00882b7 | 2015-08-06 00:32:11 -0700 | [diff] [blame^] | 34 | class HttpTransportClient; |
Vitaly Buka | 58a288b | 2015-07-31 00:33:31 -0700 | [diff] [blame] | 35 | class PeerdClient; |
| 36 | class ShillClient; |
Vitaly Buka | 974647f | 2015-08-02 20:57:43 -0700 | [diff] [blame] | 37 | class WebServClient; |
Vitaly Buka | a0305d3 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 38 | |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 39 | template<typename... Types> |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 40 | using DBusMethodResponsePtr = |
Alex Vakulenko | 8d78ebf | 2015-04-24 18:09:32 -0700 | [diff] [blame] | 41 | std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>; |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 42 | |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 43 | template<typename... Types> |
| 44 | using DBusMethodResponse = |
| 45 | chromeos::dbus_utils::DBusMethodResponse<Types...>; |
| 46 | |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 47 | // The Manager is responsible for global state of Buffet. It exposes |
| 48 | // interfaces which affect the entire device such as device registration and |
| 49 | // device state. |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 50 | class Manager final : public org::chromium::Buffet::ManagerInterface { |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 51 | public: |
Alex Vakulenko | b635153 | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 52 | explicit Manager( |
| 53 | const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>& |
| 54 | object_manager); |
Alex Vakulenko | ecf961a | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 55 | ~Manager(); |
| 56 | |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 57 | void Start(const weave::Device::Options& options, |
Vitaly Buka | 58a288b | 2015-07-31 00:33:31 -0700 | [diff] [blame] | 58 | const std::set<std::string>& device_whitelist, |
Vitaly Buka | 84fd6dd | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 59 | chromeos::dbus_utils::AsyncEventSequencer* sequencer); |
| 60 | |
| 61 | void Stop(); |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 62 | |
| 63 | private: |
Alex Vakulenko | b635153 | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 64 | // DBus methods: |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 65 | void CheckDeviceRegistered( |
| 66 | DBusMethodResponsePtr<std::string> response) override; |
| 67 | void GetDeviceInfo(DBusMethodResponsePtr<std::string> response) override; |
| 68 | void RegisterDevice(DBusMethodResponsePtr<std::string> response, |
Vitaly Buka | cbadabe | 2015-05-14 23:33:32 -0700 | [diff] [blame] | 69 | const std::string& ticket_id) override; |
Vitaly Buka | 760d632 | 2015-04-17 00:41:31 -0700 | [diff] [blame] | 70 | bool UpdateDeviceInfo(chromeos::ErrorPtr* error, |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 71 | const std::string& name, |
| 72 | const std::string& description, |
| 73 | const std::string& location) override; |
Vitaly Buka | 7cd0197 | 2015-05-14 21:25:45 -0700 | [diff] [blame] | 74 | bool UpdateServiceConfig(chromeos::ErrorPtr* error, |
| 75 | const std::string& client_id, |
| 76 | const std::string& client_secret, |
| 77 | const std::string& api_key, |
| 78 | const std::string& oauth_url, |
| 79 | const std::string& service_url) override; |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 80 | void UpdateState(DBusMethodResponsePtr<> response, |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 81 | const chromeos::VariantDictionary& property_set) override; |
Alex Vakulenko | ceab177 | 2015-01-20 10:50:04 -0800 | [diff] [blame] | 82 | bool GetState(chromeos::ErrorPtr* error, std::string* state) override; |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 83 | void AddCommand(DBusMethodResponsePtr<std::string> response, |
Vitaly Buka | c03ec2b | 2015-05-31 23:32:46 -0700 | [diff] [blame] | 84 | const std::string& json_command, |
| 85 | const std::string& in_user_role) override; |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 86 | void GetCommand(DBusMethodResponsePtr<std::string> response, |
Vitaly Buka | 5515de0 | 2015-03-24 11:39:40 -0700 | [diff] [blame] | 87 | const std::string& id) override; |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 88 | std::string TestMethod(const std::string& message) override; |
Vitaly Buka | 7b3ba79 | 2015-06-09 17:01:54 -0700 | [diff] [blame] | 89 | bool EnableWiFiBootstrapping( |
| 90 | chromeos::ErrorPtr* error, |
| 91 | const dbus::ObjectPath& in_listener_path, |
| 92 | const chromeos::VariantDictionary& in_options) override; |
| 93 | bool DisableWiFiBootstrapping(chromeos::ErrorPtr* error) override; |
| 94 | bool EnableGCDBootstrapping( |
| 95 | chromeos::ErrorPtr* error, |
| 96 | const dbus::ObjectPath& in_listener_path, |
| 97 | const chromeos::VariantDictionary& in_options) override; |
| 98 | bool DisableGCDBootstrapping(chromeos::ErrorPtr* error) override; |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 99 | |
Alex Vakulenko | 6c37526 | 2015-06-19 11:01:42 -0700 | [diff] [blame] | 100 | void OnGetDeviceInfoSuccess( |
| 101 | const std::shared_ptr<DBusMethodResponse<std::string>>& response, |
| 102 | const base::DictionaryValue& device_info); |
| 103 | void OnGetDeviceInfoError( |
| 104 | const std::shared_ptr<DBusMethodResponse<std::string>>& response, |
| 105 | const chromeos::Error* error); |
| 106 | |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 107 | void StartPrivet(const weave::Device::Options& options, |
Vitaly Buka | 84fd6dd | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 108 | chromeos::dbus_utils::AsyncEventSequencer* sequencer); |
| 109 | |
Vitaly Buka | 2b30e7a | 2015-05-27 09:27:08 -0700 | [diff] [blame] | 110 | void OnStateChanged(); |
Vitaly Buka | 3b08631 | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 111 | void OnRegistrationChanged(weave::RegistrationStatus status); |
Vitaly Buka | 00b8349 | 2015-07-20 00:37:48 -0700 | [diff] [blame] | 112 | void OnConfigChanged(const weave::Settings& settings); |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 113 | void UpdateWiFiBootstrapState(weave::WifiSetupState state); |
Vitaly Buka | 7b3ba79 | 2015-06-09 17:01:54 -0700 | [diff] [blame] | 114 | void OnPairingStart(const std::string& session_id, |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 115 | weave::PairingType pairing_type, |
Vitaly Buka | 7b3ba79 | 2015-06-09 17:01:54 -0700 | [diff] [blame] | 116 | const std::vector<uint8_t>& code); |
| 117 | void OnPairingEnd(const std::string& session_id); |
Christopher Wiley | 2f77293 | 2015-02-15 15:42:04 -0800 | [diff] [blame] | 118 | |
Alex Vakulenko | 12e2c1a | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 119 | org::chromium::Buffet::ManagerAdaptor dbus_adaptor_{this}; |
Alex Vakulenko | b635153 | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 120 | chromeos::dbus_utils::DBusObject dbus_object_; |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 121 | |
Vitaly Buka | 00882b7 | 2015-08-06 00:32:11 -0700 | [diff] [blame^] | 122 | std::unique_ptr<HttpTransportClient> http_client_; |
Vitaly Buka | 58a288b | 2015-07-31 00:33:31 -0700 | [diff] [blame] | 123 | std::unique_ptr<ShillClient> shill_client_; |
Vitaly Buka | 974647f | 2015-08-02 20:57:43 -0700 | [diff] [blame] | 124 | std::unique_ptr<PeerdClient> peerd_client_; |
| 125 | std::unique_ptr<WebServClient> web_serv_client_; |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 126 | std::unique_ptr<weave::Device> device_; |
Vitaly Buka | a0305d3 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 127 | std::unique_ptr<DBusCommandDispacher> command_dispatcher_; |
Alex Vakulenko | f3d77e5 | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 128 | |
Vitaly Buka | e43871f | 2015-05-11 15:41:33 -0700 | [diff] [blame] | 129 | base::WeakPtrFactory<Manager> weak_ptr_factory_{this}; |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 130 | DISALLOW_COPY_AND_ASSIGN(Manager); |
| 131 | }; |
| 132 | |
| 133 | } // namespace buffet |
| 134 | |
| 135 | #endif // BUFFET_MANAGER_H_ |