blob: 016c25f400bcbd53a5c4d962d251a387304ff35f [file] [log] [blame]
Christopher Wiley4b5f04c2014-03-27 14:45:37 -07001// 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#include "buffet/manager.h"
6
Alex Vakulenko7c3226e2014-05-07 17:35:24 -07007#include <map>
Alex Vakulenkoec41a0c2015-04-17 15:35:34 -07008#include <set>
Alex Vakulenko7c3226e2014-05-07 17:35:24 -07009#include <string>
10
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070011#include <base/bind.h>
12#include <base/bind_helpers.h>
Alex Vakulenko4f7778e2014-09-11 16:57:24 -070013#include <base/json/json_reader.h>
Christopher Wiley2ffa0042014-05-05 16:09:16 -070014#include <base/json/json_writer.h>
Alex Vakulenkof7754542015-06-26 12:59:50 -070015#include <base/message_loop/message_loop.h>
Christopher Wiley8994e012015-02-06 17:51:43 -080016#include <base/time/time.h>
Alex Vakulenko24e5f5d2014-08-27 11:00:57 -070017#include <chromeos/dbus/async_event_sequencer.h>
18#include <chromeos/dbus/exported_object_manager.h>
19#include <chromeos/errors/error.h>
Garret Kelly89ba0362015-05-29 15:56:52 -040020#include <chromeos/http/http_transport.h>
Anton Muhin53e882a2014-11-22 05:59:14 +040021#include <chromeos/key_value_store.h>
Christopher Wiley2ffa0042014-05-05 16:09:16 -070022#include <dbus/bus.h>
Christopher Wiley54028f92014-04-01 17:33:29 -070023#include <dbus/object_path.h>
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070024#include <dbus/values_util.h>
Vitaly Bukae2713ac2015-08-03 13:50:01 -070025#include <weave/enum_to_string.h>
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070026
Vitaly Bukaa0305d32015-07-27 16:08:51 -070027#include "buffet/dbus_command_dispatcher.h"
28#include "buffet/dbus_conversion.h"
Vitaly Buka00882b72015-08-06 00:32:11 -070029#include "buffet/http_transport_client.h"
Alex Vakulenko15aea552015-08-17 09:34:08 -070030#include "buffet/mdns_client.h"
31#include "buffet/network_client.h"
Alex Vakulenkod78756d2015-08-11 12:32:02 -070032//#include "buffet/webserv_client.h"
Vitaly Buka03319c22015-07-17 14:48:30 -070033
Christopher Wiley68c07cc2014-07-29 14:07:10 -070034using chromeos::dbus_utils::AsyncEventSequencer;
Christopher Wiley1aa980e2014-08-11 10:51:20 -070035using chromeos::dbus_utils::ExportedObjectManager;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070036
37namespace buffet {
38
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070039namespace {
Vitaly Buka7b3ba792015-06-09 17:01:54 -070040
Vitaly Buka7b3ba792015-06-09 17:01:54 -070041const char kPairingSessionIdKey[] = "sessionId";
42const char kPairingModeKey[] = "mode";
43const char kPairingCodeKey[] = "code";
44
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070045const char kErrorDomain[] = "buffet";
46const char kNotImplemented[] = "notImplemented";
47
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070048} // anonymous namespace
49
Alex Vakulenkob6351532014-08-15 11:49:35 -070050Manager::Manager(const base::WeakPtr<ExportedObjectManager>& object_manager)
51 : dbus_object_(object_manager.get(),
52 object_manager->GetBus(),
Vitaly Buka91cc7152015-03-20 09:46:57 -070053 org::chromium::Buffet::ManagerAdaptor::GetObjectPath()) {
54}
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070055
Vitaly Buka91cc7152015-03-20 09:46:57 -070056Manager::~Manager() {
57}
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070058
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070059void Manager::Start(const weave::Device::Options& options,
Vitaly Buka58a288b2015-07-31 00:33:31 -070060 const std::set<std::string>& device_whitelist,
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070061 AsyncEventSequencer* sequencer) {
Vitaly Buka00882b72015-08-06 00:32:11 -070062 http_client_.reset(new HttpTransportClient);
Alex Vakulenko15aea552015-08-17 09:34:08 -070063 network_client_.reset(new NetworkClient/*{device_whitelist}*/);
64 if (!options.disable_privet) {
65 mdns_client_.reset(new MdnsClient);
Alex Vakulenkod78756d2015-08-11 12:32:02 -070066// web_serv_client_.reset(new WebServClient{dbus_object_.GetBus(), sequencer});
Alex Vakulenko15aea552015-08-17 09:34:08 -070067 }
Vitaly Buka7042c582015-07-30 17:02:14 -070068
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070069 device_ = weave::Device::Create();
Alex Vakulenko15aea552015-08-17 09:34:08 -070070 device_->Start(options, http_client_.get(), network_client_.get(),
71 nullptr /*mdns_client_.get()*/, nullptr /*web_serv_client_.get()*/);
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070072
Vitaly Bukaa0305d32015-07-27 16:08:51 -070073 command_dispatcher_.reset(new DBusCommandDispacher{
Vitaly Bukae8c3bab2015-07-29 16:39:34 -070074 dbus_object_.GetObjectManager(), device_->GetCommands()});
75
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070076 device_->GetState()->AddOnChangedCallback(
Vitaly Buka2b30e7a2015-05-27 09:27:08 -070077 base::Bind(&Manager::OnStateChanged, weak_ptr_factory_.GetWeakPtr()));
Vitaly Bukabf4ba652015-05-14 16:57:23 -070078
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070079 device_->GetConfig()->AddOnChangedCallback(
Vitaly Bukabf4ba652015-05-14 16:57:23 -070080 base::Bind(&Manager::OnConfigChanged, weak_ptr_factory_.GetWeakPtr()));
Vitaly Bukabf4ba652015-05-14 16:57:23 -070081
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070082 device_->GetCloud()->AddOnRegistrationChangedCallback(base::Bind(
Vitaly Bukabf4ba652015-05-14 16:57:23 -070083 &Manager::OnRegistrationChanged, weak_ptr_factory_.GetWeakPtr()));
Vitaly Bukae74fe3c2015-05-13 13:48:59 -070084
Vitaly Buka1d63c9c2015-07-17 14:34:35 -070085 if (device_->GetPrivet()) {
86 device_->GetPrivet()->AddOnWifiSetupChangedCallback(base::Bind(
87 &Manager::UpdateWiFiBootstrapState, weak_ptr_factory_.GetWeakPtr()));
Vitaly Bukae74fe3c2015-05-13 13:48:59 -070088
Vitaly Buka1d63c9c2015-07-17 14:34:35 -070089 device_->GetPrivet()->AddOnPairingChangedCallbacks(
90 base::Bind(&Manager::OnPairingStart, weak_ptr_factory_.GetWeakPtr()),
91 base::Bind(&Manager::OnPairingEnd, weak_ptr_factory_.GetWeakPtr()));
92 } else {
93 UpdateWiFiBootstrapState(weave::WifiSetupState::kDisabled);
94 }
Vitaly Buka84fd6dd2015-06-09 17:22:18 -070095
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080096 dbus_adaptor_.RegisterWithDBusObject(&dbus_object_);
Vitaly Buka84fd6dd2015-06-09 17:22:18 -070097 dbus_object_.RegisterAsync(
98 sequencer->GetHandler("Manager.RegisterAsync() failed.", true));
Vitaly Buka84fd6dd2015-06-09 17:22:18 -070099}
100
101void Manager::Stop() {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700102 device_.reset();
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700103}
104
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700105// TODO(vitalybuka): Remove, it's just duplicate of property.
Alex Vakulenko6c375262015-06-19 11:01:42 -0700106void Manager::CheckDeviceRegistered(
107 DBusMethodResponsePtr<std::string> response) {
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700108 LOG(INFO) << "Received call to Manager.CheckDeviceRegistered()";
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700109 response->Return(dbus_adaptor_.GetDeviceId());
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700110}
111
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700112// TODO(vitalybuka): Remove or rename to leave for testing.
Alex Vakulenko6c375262015-06-19 11:01:42 -0700113void Manager::GetDeviceInfo(DBusMethodResponsePtr<std::string> response) {
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700114 LOG(INFO) << "Received call to Manager.GetDeviceInfo()";
Alex Vakulenko6c375262015-06-19 11:01:42 -0700115 std::shared_ptr<DBusMethodResponse<std::string>> shared_response =
116 std::move(response);
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700117
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700118 device_->GetCloud()->GetDeviceInfo(
Alex Vakulenko6c375262015-06-19 11:01:42 -0700119 base::Bind(&Manager::OnGetDeviceInfoSuccess,
120 weak_ptr_factory_.GetWeakPtr(), shared_response),
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700121 base::Bind(&Manager::OnGetDeviceInfoError, weak_ptr_factory_.GetWeakPtr(),
122 shared_response));
Alex Vakulenko6c375262015-06-19 11:01:42 -0700123}
Alex Vakulenko7c3226e2014-05-07 17:35:24 -0700124
Alex Vakulenko6c375262015-06-19 11:01:42 -0700125void Manager::OnGetDeviceInfoSuccess(
126 const std::shared_ptr<DBusMethodResponse<std::string>>& response,
127 const base::DictionaryValue& device_info) {
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700128 std::string device_info_str;
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700129 base::JSONWriter::WriteWithOptions(
Alex Vakulenko6c375262015-06-19 11:01:42 -0700130 device_info, base::JSONWriter::OPTIONS_PRETTY_PRINT, &device_info_str);
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700131 response->Return(device_info_str);
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700132}
133
Alex Vakulenko6c375262015-06-19 11:01:42 -0700134void Manager::OnGetDeviceInfoError(
135 const std::shared_ptr<DBusMethodResponse<std::string>>& response,
136 const chromeos::Error* error) {
137 response->ReplyWithError(error);
138}
139
140void Manager::RegisterDevice(DBusMethodResponsePtr<std::string> response,
Vitaly Bukacbadabe2015-05-14 23:33:32 -0700141 const std::string& ticket_id) {
Anton Muhin9cc03fd2014-10-16 18:59:57 +0400142 LOG(INFO) << "Received call to Manager.RegisterDevice()";
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700143
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700144 chromeos::ErrorPtr error;
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700145 std::string device_id =
146 device_->GetCloud()->RegisterDevice(ticket_id, &error);
David Zeuthen2101c082015-02-12 15:24:21 -0500147 if (!device_id.empty()) {
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700148 response->Return(device_id);
David Zeuthen2101c082015-02-12 15:24:21 -0500149 return;
150 }
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700151 CHECK(error);
David Zeuthen2101c082015-02-12 15:24:21 -0500152 response->ReplyWithError(error.get());
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700153}
154
Alex Vakulenko6c375262015-06-19 11:01:42 -0700155void Manager::UpdateState(DBusMethodResponsePtr<> response,
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -0800156 const chromeos::VariantDictionary& property_set) {
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700157 chromeos::ErrorPtr error;
Vitaly Bukaa0305d32015-07-27 16:08:51 -0700158 auto properties = DictionaryFromDBusVariantDictionary(property_set, &error);
Vitaly Bukafb2584b2015-07-28 21:39:45 -0700159 if (!properties)
160 response->ReplyWithError(error.get());
161
162 if (!device_->GetState()->SetProperties(*properties, &error))
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700163 response->ReplyWithError(error.get());
164 else
165 response->Return();
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700166}
167
Alex Vakulenkoceab1772015-01-20 10:50:04 -0800168bool Manager::GetState(chromeos::ErrorPtr* error, std::string* state) {
Vitaly Bukacd5e5562015-07-28 15:33:55 -0700169 auto json = device_->GetState()->GetStateValuesAsJson();
170 CHECK(json);
Nathan Bullockf5b91bf2015-04-01 15:32:58 -0400171 base::JSONWriter::WriteWithOptions(
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700172 *json, base::JSONWriter::OPTIONS_PRETTY_PRINT, state);
Alex Vakulenkoceab1772015-01-20 10:50:04 -0800173 return true;
174}
175
Alex Vakulenko6c375262015-06-19 11:01:42 -0700176void Manager::AddCommand(DBusMethodResponsePtr<std::string> response,
Vitaly Bukac03ec2b2015-05-31 23:32:46 -0700177 const std::string& json_command,
178 const std::string& in_user_role) {
Alex Vakulenko4f7778e2014-09-11 16:57:24 -0700179 std::string error_message;
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700180 std::unique_ptr<base::Value> value(
181 base::JSONReader::ReadAndReturnError(json_command, base::JSON_PARSE_RFC,
182 nullptr, &error_message)
183 .release());
Vitaly Bukaa4e8d7f2015-06-09 09:46:53 -0700184 const base::DictionaryValue* command{nullptr};
185 if (!value || !value->GetAsDictionary(&command)) {
186 return response->ReplyWithError(FROM_HERE, chromeos::errors::json::kDomain,
187 chromeos::errors::json::kParseError,
188 error_message);
Alex Vakulenko4f7778e2014-09-11 16:57:24 -0700189 }
Vitaly Bukaa4e8d7f2015-06-09 09:46:53 -0700190
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700191 chromeos::ErrorPtr error;
Vitaly Buka3b086312015-07-09 14:59:23 -0700192 weave::UserRole role;
Vitaly Buka03319c22015-07-17 14:48:30 -0700193 if (!StringToEnum(in_user_role, &role)) {
194 chromeos::Error::AddToPrintf(&error, FROM_HERE, kErrorDomain,
195 "invalid_user_role", "Invalid role: '%s'",
196 in_user_role.c_str());
Vitaly Bukaa4e8d7f2015-06-09 09:46:53 -0700197 return response->ReplyWithError(error.get());
Vitaly Buka03319c22015-07-17 14:48:30 -0700198 }
Vitaly Bukac03ec2b2015-05-31 23:32:46 -0700199
Vitaly Bukaa4e8d7f2015-06-09 09:46:53 -0700200 std::string id;
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700201 if (!device_->GetCommands()->AddCommand(*command, role, &id, &error))
Vitaly Bukaa4e8d7f2015-06-09 09:46:53 -0700202 return response->ReplyWithError(error.get());
Vitaly Bukac03ec2b2015-05-31 23:32:46 -0700203
Vitaly Buka59af7ac2015-03-24 12:42:24 -0700204 response->Return(id);
Alex Vakulenko4f7778e2014-09-11 16:57:24 -0700205}
206
Alex Vakulenko6c375262015-06-19 11:01:42 -0700207void Manager::GetCommand(DBusMethodResponsePtr<std::string> response,
Vitaly Buka5515de02015-03-24 11:39:40 -0700208 const std::string& id) {
Vitaly Bukaba463732015-07-14 19:19:39 -0700209 const weave::Command* command = device_->GetCommands()->FindCommand(id);
Vitaly Buka5515de02015-03-24 11:39:40 -0700210 if (!command) {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700211 response->ReplyWithError(FROM_HERE, kErrorDomain, "unknown_command",
Vitaly Buka5515de02015-03-24 11:39:40 -0700212 "Can't find command with id: " + id);
213 return;
214 }
215 std::string command_str;
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700216 base::JSONWriter::WriteWithOptions(
217 *command->ToJson(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &command_str);
Vitaly Buka5515de02015-03-24 11:39:40 -0700218 response->Return(command_str);
219}
220
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -0800221std::string Manager::TestMethod(const std::string& message) {
Alex Vakulenko35e3bab2014-08-15 11:45:46 -0700222 LOG(INFO) << "Received call to test method: " << message;
223 return message;
Christopher Wiley2ffa0042014-05-05 16:09:16 -0700224}
225
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700226bool Manager::EnableWiFiBootstrapping(
227 chromeos::ErrorPtr* error,
228 const dbus::ObjectPath& in_listener_path,
229 const chromeos::VariantDictionary& in_options) {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700230 chromeos::Error::AddTo(error, FROM_HERE, kErrorDomain, kNotImplemented,
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700231 "Manual WiFi bootstrapping is not implemented");
232 return false;
233}
234
235bool Manager::DisableWiFiBootstrapping(chromeos::ErrorPtr* error) {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700236 chromeos::Error::AddTo(error, FROM_HERE, kErrorDomain, kNotImplemented,
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700237 "Manual WiFi bootstrapping is not implemented");
238 return false;
239}
240
241bool Manager::EnableGCDBootstrapping(
242 chromeos::ErrorPtr* error,
243 const dbus::ObjectPath& in_listener_path,
244 const chromeos::VariantDictionary& in_options) {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700245 chromeos::Error::AddTo(error, FROM_HERE, kErrorDomain, kNotImplemented,
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700246 "Manual GCD bootstrapping is not implemented");
247 return false;
248}
249
250bool Manager::DisableGCDBootstrapping(chromeos::ErrorPtr* error) {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700251 chromeos::Error::AddTo(error, FROM_HERE, kErrorDomain, kNotImplemented,
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700252 "Manual GCD bootstrapping is not implemented");
253 return false;
254}
255
Vitaly Buka760d6322015-04-17 00:41:31 -0700256bool Manager::UpdateDeviceInfo(chromeos::ErrorPtr* error,
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700257 const std::string& name,
258 const std::string& description,
259 const std::string& location) {
260 return device_->GetCloud()->UpdateDeviceInfo(name, description, location,
261 error);
Christopher Wiley2f772932015-02-15 15:42:04 -0800262}
263
Vitaly Buka7cd01972015-05-14 21:25:45 -0700264bool Manager::UpdateServiceConfig(chromeos::ErrorPtr* error,
265 const std::string& client_id,
266 const std::string& client_secret,
267 const std::string& api_key,
268 const std::string& oauth_url,
269 const std::string& service_url) {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700270 return device_->GetCloud()->UpdateServiceConfig(
271 client_id, client_secret, api_key, oauth_url, service_url, error);
Vitaly Buka7cd01972015-05-14 21:25:45 -0700272}
273
Vitaly Buka2b30e7a2015-05-27 09:27:08 -0700274void Manager::OnStateChanged() {
Vitaly Bukacd5e5562015-07-28 15:33:55 -0700275 auto state = device_->GetState()->GetStateValuesAsJson();
Vitaly Buka2b30e7a2015-05-27 09:27:08 -0700276 CHECK(state);
277 std::string json;
278 base::JSONWriter::WriteWithOptions(
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700279 *state, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
Vitaly Buka2b30e7a2015-05-27 09:27:08 -0700280 dbus_adaptor_.SetState(json);
281}
282
Vitaly Buka3b086312015-07-09 14:59:23 -0700283void Manager::OnRegistrationChanged(weave::RegistrationStatus status) {
Vitaly Buka03319c22015-07-17 14:48:30 -0700284 dbus_adaptor_.SetStatus(weave::EnumToString(status));
Vitaly Bukabf4ba652015-05-14 16:57:23 -0700285}
286
Vitaly Buka00b83492015-07-20 00:37:48 -0700287void Manager::OnConfigChanged(const weave::Settings& settings) {
288 dbus_adaptor_.SetDeviceId(settings.device_id);
289 dbus_adaptor_.SetOemName(settings.oem_name);
290 dbus_adaptor_.SetModelName(settings.model_name);
291 dbus_adaptor_.SetModelId(settings.model_id);
292 dbus_adaptor_.SetName(settings.name);
293 dbus_adaptor_.SetDescription(settings.description);
294 dbus_adaptor_.SetLocation(settings.location);
295 dbus_adaptor_.SetAnonymousAccessRole(settings.local_anonymous_access_role);
Vitaly Bukabf4ba652015-05-14 16:57:23 -0700296}
297
Vitaly Buka03319c22015-07-17 14:48:30 -0700298void Manager::UpdateWiFiBootstrapState(weave::WifiSetupState state) {
299 dbus_adaptor_.SetWiFiBootstrapState(weave::EnumToString(state));
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700300}
301
302void Manager::OnPairingStart(const std::string& session_id,
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700303 weave::PairingType pairing_type,
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700304 const std::vector<uint8_t>& code) {
305 // For now, just overwrite the exposed PairInfo with
306 // the most recent pairing attempt.
307 dbus_adaptor_.SetPairingInfo(chromeos::VariantDictionary{
308 {kPairingSessionIdKey, session_id},
Vitaly Buka03319c22015-07-17 14:48:30 -0700309 {kPairingModeKey, weave::EnumToString(pairing_type)},
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700310 {kPairingCodeKey, code},
311 });
312}
313
314void Manager::OnPairingEnd(const std::string& session_id) {
315 auto exposed_pairing_attempt = dbus_adaptor_.GetPairingInfo();
316 auto it = exposed_pairing_attempt.find(kPairingSessionIdKey);
317 if (it == exposed_pairing_attempt.end()) {
318 return;
319 }
320 std::string exposed_session{it->second.TryGet<std::string>()};
321 if (exposed_session == session_id) {
322 dbus_adaptor_.SetPairingInfo(chromeos::VariantDictionary{});
323 }
324}
325
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700326} // namespace buffet