blob: 9fa54cdb2508b9210d54fc9eaec4bd1f9d1680a4 [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>
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070025
Vitaly Buka03319c22015-07-17 14:48:30 -070026#include "weave/enum_to_string.h"
27
Christopher Wiley68c07cc2014-07-29 14:07:10 -070028using chromeos::dbus_utils::AsyncEventSequencer;
Christopher Wiley1aa980e2014-08-11 10:51:20 -070029using chromeos::dbus_utils::ExportedObjectManager;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070030
31namespace buffet {
32
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070033namespace {
Vitaly Buka7b3ba792015-06-09 17:01:54 -070034
Vitaly Buka7b3ba792015-06-09 17:01:54 -070035const char kPairingSessionIdKey[] = "sessionId";
36const char kPairingModeKey[] = "mode";
37const char kPairingCodeKey[] = "code";
38
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070039const char kErrorDomain[] = "buffet";
40const char kNotImplemented[] = "notImplemented";
41
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070042} // anonymous namespace
43
Alex Vakulenkob6351532014-08-15 11:49:35 -070044Manager::Manager(const base::WeakPtr<ExportedObjectManager>& object_manager)
45 : dbus_object_(object_manager.get(),
46 object_manager->GetBus(),
Vitaly Buka91cc7152015-03-20 09:46:57 -070047 org::chromium::Buffet::ManagerAdaptor::GetObjectPath()) {
48}
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070049
Vitaly Buka91cc7152015-03-20 09:46:57 -070050Manager::~Manager() {
51}
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070052
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070053void Manager::Start(const weave::Device::Options& options,
54 AsyncEventSequencer* sequencer) {
55 device_ = weave::Device::Create();
56 device_->Start(options, &dbus_object_, sequencer);
57
58 device_->GetCommands()->AddOnCommandDefChanged(base::Bind(
Vitaly Bukae43871f2015-05-11 15:41:33 -070059 &Manager::OnCommandDefsChanged, weak_ptr_factory_.GetWeakPtr()));
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070060
61 device_->GetState()->AddOnChangedCallback(
Vitaly Buka2b30e7a2015-05-27 09:27:08 -070062 base::Bind(&Manager::OnStateChanged, weak_ptr_factory_.GetWeakPtr()));
Vitaly Bukabf4ba652015-05-14 16:57:23 -070063
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070064 device_->GetConfig()->AddOnChangedCallback(
Vitaly Bukabf4ba652015-05-14 16:57:23 -070065 base::Bind(&Manager::OnConfigChanged, weak_ptr_factory_.GetWeakPtr()));
Vitaly Bukabf4ba652015-05-14 16:57:23 -070066
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070067 device_->GetCloud()->AddOnRegistrationChangedCallback(base::Bind(
Vitaly Bukabf4ba652015-05-14 16:57:23 -070068 &Manager::OnRegistrationChanged, weak_ptr_factory_.GetWeakPtr()));
Vitaly Bukae74fe3c2015-05-13 13:48:59 -070069
Vitaly Buka1d63c9c2015-07-17 14:34:35 -070070 if (device_->GetPrivet()) {
71 device_->GetPrivet()->AddOnWifiSetupChangedCallback(base::Bind(
72 &Manager::UpdateWiFiBootstrapState, weak_ptr_factory_.GetWeakPtr()));
Vitaly Bukae74fe3c2015-05-13 13:48:59 -070073
Vitaly Buka1d63c9c2015-07-17 14:34:35 -070074 device_->GetPrivet()->AddOnPairingChangedCallbacks(
75 base::Bind(&Manager::OnPairingStart, weak_ptr_factory_.GetWeakPtr()),
76 base::Bind(&Manager::OnPairingEnd, weak_ptr_factory_.GetWeakPtr()));
77 } else {
78 UpdateWiFiBootstrapState(weave::WifiSetupState::kDisabled);
79 }
Vitaly Buka84fd6dd2015-06-09 17:22:18 -070080
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -080081 dbus_adaptor_.RegisterWithDBusObject(&dbus_object_);
Vitaly Buka84fd6dd2015-06-09 17:22:18 -070082 dbus_object_.RegisterAsync(
83 sequencer->GetHandler("Manager.RegisterAsync() failed.", true));
Vitaly Buka84fd6dd2015-06-09 17:22:18 -070084}
85
86void Manager::Stop() {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070087 device_.reset();
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070088}
89
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070090// TODO(vitalybuka): Remove, it's just duplicate of property.
Alex Vakulenko6c375262015-06-19 11:01:42 -070091void Manager::CheckDeviceRegistered(
92 DBusMethodResponsePtr<std::string> response) {
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070093 LOG(INFO) << "Received call to Manager.CheckDeviceRegistered()";
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070094 response->Return(dbus_adaptor_.GetDeviceId());
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070095}
96
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070097// TODO(vitalybuka): Remove or rename to leave for testing.
Alex Vakulenko6c375262015-06-19 11:01:42 -070098void Manager::GetDeviceInfo(DBusMethodResponsePtr<std::string> response) {
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070099 LOG(INFO) << "Received call to Manager.GetDeviceInfo()";
Alex Vakulenko6c375262015-06-19 11:01:42 -0700100 std::shared_ptr<DBusMethodResponse<std::string>> shared_response =
101 std::move(response);
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700102
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700103 device_->GetCloud()->GetDeviceInfo(
Alex Vakulenko6c375262015-06-19 11:01:42 -0700104 base::Bind(&Manager::OnGetDeviceInfoSuccess,
105 weak_ptr_factory_.GetWeakPtr(), shared_response),
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700106 base::Bind(&Manager::OnGetDeviceInfoError, weak_ptr_factory_.GetWeakPtr(),
107 shared_response));
Alex Vakulenko6c375262015-06-19 11:01:42 -0700108}
Alex Vakulenko7c3226e2014-05-07 17:35:24 -0700109
Alex Vakulenko6c375262015-06-19 11:01:42 -0700110void Manager::OnGetDeviceInfoSuccess(
111 const std::shared_ptr<DBusMethodResponse<std::string>>& response,
112 const base::DictionaryValue& device_info) {
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700113 std::string device_info_str;
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700114 base::JSONWriter::WriteWithOptions(
Alex Vakulenko6c375262015-06-19 11:01:42 -0700115 device_info, base::JSONWriter::OPTIONS_PRETTY_PRINT, &device_info_str);
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700116 response->Return(device_info_str);
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700117}
118
Alex Vakulenko6c375262015-06-19 11:01:42 -0700119void Manager::OnGetDeviceInfoError(
120 const std::shared_ptr<DBusMethodResponse<std::string>>& response,
121 const chromeos::Error* error) {
122 response->ReplyWithError(error);
123}
124
125void Manager::RegisterDevice(DBusMethodResponsePtr<std::string> response,
Vitaly Bukacbadabe2015-05-14 23:33:32 -0700126 const std::string& ticket_id) {
Anton Muhin9cc03fd2014-10-16 18:59:57 +0400127 LOG(INFO) << "Received call to Manager.RegisterDevice()";
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700128
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700129 chromeos::ErrorPtr error;
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700130 std::string device_id =
131 device_->GetCloud()->RegisterDevice(ticket_id, &error);
David Zeuthen2101c082015-02-12 15:24:21 -0500132 if (!device_id.empty()) {
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700133 response->Return(device_id);
David Zeuthen2101c082015-02-12 15:24:21 -0500134 return;
135 }
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700136 CHECK(error);
David Zeuthen2101c082015-02-12 15:24:21 -0500137 response->ReplyWithError(error.get());
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700138}
139
Alex Vakulenko6c375262015-06-19 11:01:42 -0700140void Manager::UpdateState(DBusMethodResponsePtr<> response,
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -0800141 const chromeos::VariantDictionary& property_set) {
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700142 chromeos::ErrorPtr error;
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700143 if (!device_->GetState()->SetProperties(property_set, &error))
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700144 response->ReplyWithError(error.get());
145 else
146 response->Return();
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700147}
148
Alex Vakulenkoceab1772015-01-20 10:50:04 -0800149bool Manager::GetState(chromeos::ErrorPtr* error, std::string* state) {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700150 auto json = device_->GetState()->GetStateValuesAsJson(error);
Alex Vakulenkoceab1772015-01-20 10:50:04 -0800151 if (!json)
152 return false;
Nathan Bullockf5b91bf2015-04-01 15:32:58 -0400153 base::JSONWriter::WriteWithOptions(
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700154 *json, base::JSONWriter::OPTIONS_PRETTY_PRINT, state);
Alex Vakulenkoceab1772015-01-20 10:50:04 -0800155 return true;
156}
157
Alex Vakulenko6c375262015-06-19 11:01:42 -0700158void Manager::AddCommand(DBusMethodResponsePtr<std::string> response,
Vitaly Bukac03ec2b2015-05-31 23:32:46 -0700159 const std::string& json_command,
160 const std::string& in_user_role) {
Alex Vakulenko4f7778e2014-09-11 16:57:24 -0700161 std::string error_message;
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700162 std::unique_ptr<base::Value> value(
163 base::JSONReader::ReadAndReturnError(json_command, base::JSON_PARSE_RFC,
164 nullptr, &error_message)
165 .release());
Vitaly Bukaa4e8d7f2015-06-09 09:46:53 -0700166 const base::DictionaryValue* command{nullptr};
167 if (!value || !value->GetAsDictionary(&command)) {
168 return response->ReplyWithError(FROM_HERE, chromeos::errors::json::kDomain,
169 chromeos::errors::json::kParseError,
170 error_message);
Alex Vakulenko4f7778e2014-09-11 16:57:24 -0700171 }
Vitaly Bukaa4e8d7f2015-06-09 09:46:53 -0700172
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700173 chromeos::ErrorPtr error;
Vitaly Buka3b086312015-07-09 14:59:23 -0700174 weave::UserRole role;
Vitaly Buka03319c22015-07-17 14:48:30 -0700175 if (!StringToEnum(in_user_role, &role)) {
176 chromeos::Error::AddToPrintf(&error, FROM_HERE, kErrorDomain,
177 "invalid_user_role", "Invalid role: '%s'",
178 in_user_role.c_str());
Vitaly Bukaa4e8d7f2015-06-09 09:46:53 -0700179 return response->ReplyWithError(error.get());
Vitaly Buka03319c22015-07-17 14:48:30 -0700180 }
Vitaly Bukac03ec2b2015-05-31 23:32:46 -0700181
Vitaly Bukaa4e8d7f2015-06-09 09:46:53 -0700182 std::string id;
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700183 if (!device_->GetCommands()->AddCommand(*command, role, &id, &error))
Vitaly Bukaa4e8d7f2015-06-09 09:46:53 -0700184 return response->ReplyWithError(error.get());
Vitaly Bukac03ec2b2015-05-31 23:32:46 -0700185
Vitaly Buka59af7ac2015-03-24 12:42:24 -0700186 response->Return(id);
Alex Vakulenko4f7778e2014-09-11 16:57:24 -0700187}
188
Alex Vakulenko6c375262015-06-19 11:01:42 -0700189void Manager::GetCommand(DBusMethodResponsePtr<std::string> response,
Vitaly Buka5515de02015-03-24 11:39:40 -0700190 const std::string& id) {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700191 const weave::CommandInstance* command =
192 device_->GetCommands()->FindCommand(id);
Vitaly Buka5515de02015-03-24 11:39:40 -0700193 if (!command) {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700194 response->ReplyWithError(FROM_HERE, kErrorDomain, "unknown_command",
Vitaly Buka5515de02015-03-24 11:39:40 -0700195 "Can't find command with id: " + id);
196 return;
197 }
198 std::string command_str;
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700199 base::JSONWriter::WriteWithOptions(
200 *command->ToJson(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &command_str);
Vitaly Buka5515de02015-03-24 11:39:40 -0700201 response->Return(command_str);
202}
203
Alex Vakulenko6c375262015-06-19 11:01:42 -0700204void Manager::SetCommandVisibility(DBusMethodResponsePtr<> response,
205 const std::vector<std::string>& in_names,
206 const std::string& in_visibility) {
Vitaly Buka3b086312015-07-09 14:59:23 -0700207 weave::CommandDefinition::Visibility visibility;
Alex Vakulenkoacec6aa2015-04-20 11:00:54 -0700208 chromeos::ErrorPtr error;
209 if (!visibility.FromString(in_visibility, &error)) {
210 response->ReplyWithError(error.get());
211 return;
212 }
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700213 if (!device_->GetCommands()->SetCommandVisibility(in_names, visibility,
214 &error)) {
Alex Vakulenkoacec6aa2015-04-20 11:00:54 -0700215 response->ReplyWithError(error.get());
216 return;
217 }
218 response->Return();
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 Buka1fa69012015-03-18 23:33:44 -0700274void Manager::OnCommandDefsChanged() {
Alex Vakulenkoec41a0c2015-04-17 15:35:34 -0700275 // Limit only to commands that are visible to the local clients.
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700276 auto commands =
277 device_->GetCommands()->GetCommandDictionary().GetCommandsAsJson(
278 [](const weave::CommandDefinition* def) {
279 return def->GetVisibility().local;
280 },
281 true, nullptr);
Vitaly Buka1fa69012015-03-18 23:33:44 -0700282 CHECK(commands);
283 std::string json;
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700284 base::JSONWriter::WriteWithOptions(
285 *commands, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
Vitaly Buka1fa69012015-03-18 23:33:44 -0700286 dbus_adaptor_.SetCommandDefs(json);
287}
288
Vitaly Buka2b30e7a2015-05-27 09:27:08 -0700289void Manager::OnStateChanged() {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700290 auto state = device_->GetState()->GetStateValuesAsJson(nullptr);
Vitaly Buka2b30e7a2015-05-27 09:27:08 -0700291 CHECK(state);
292 std::string json;
293 base::JSONWriter::WriteWithOptions(
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700294 *state, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
Vitaly Buka2b30e7a2015-05-27 09:27:08 -0700295 dbus_adaptor_.SetState(json);
296}
297
Vitaly Buka3b086312015-07-09 14:59:23 -0700298void Manager::OnRegistrationChanged(weave::RegistrationStatus status) {
Vitaly Buka03319c22015-07-17 14:48:30 -0700299 dbus_adaptor_.SetStatus(weave::EnumToString(status));
Vitaly Bukabf4ba652015-05-14 16:57:23 -0700300}
301
Vitaly Buka3b086312015-07-09 14:59:23 -0700302void Manager::OnConfigChanged(const weave::BuffetConfig& config) {
Vitaly Bukabf4ba652015-05-14 16:57:23 -0700303 dbus_adaptor_.SetDeviceId(config.device_id());
304 dbus_adaptor_.SetOemName(config.oem_name());
305 dbus_adaptor_.SetModelName(config.model_name());
306 dbus_adaptor_.SetModelId(config.model_id());
307 dbus_adaptor_.SetName(config.name());
308 dbus_adaptor_.SetDescription(config.description());
309 dbus_adaptor_.SetLocation(config.location());
310 dbus_adaptor_.SetAnonymousAccessRole(config.local_anonymous_access_role());
311}
312
Vitaly Buka03319c22015-07-17 14:48:30 -0700313void Manager::UpdateWiFiBootstrapState(weave::WifiSetupState state) {
314 dbus_adaptor_.SetWiFiBootstrapState(weave::EnumToString(state));
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700315}
316
317void Manager::OnPairingStart(const std::string& session_id,
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700318 weave::PairingType pairing_type,
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700319 const std::vector<uint8_t>& code) {
320 // For now, just overwrite the exposed PairInfo with
321 // the most recent pairing attempt.
322 dbus_adaptor_.SetPairingInfo(chromeos::VariantDictionary{
323 {kPairingSessionIdKey, session_id},
Vitaly Buka03319c22015-07-17 14:48:30 -0700324 {kPairingModeKey, weave::EnumToString(pairing_type)},
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700325 {kPairingCodeKey, code},
326 });
327}
328
329void Manager::OnPairingEnd(const std::string& session_id) {
330 auto exposed_pairing_attempt = dbus_adaptor_.GetPairingInfo();
331 auto it = exposed_pairing_attempt.find(kPairingSessionIdKey);
332 if (it == exposed_pairing_attempt.end()) {
333 return;
334 }
335 std::string exposed_session{it->second.TryGet<std::string>()};
336 if (exposed_session == session_id) {
337 dbus_adaptor_.SetPairingInfo(chromeos::VariantDictionary{});
338 }
339}
340
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700341} // namespace buffet