blob: 86f69887edc7f5d6aa3e999fdd9de064636674c3 [file] [log] [blame]
Christopher Wileya4915c42014-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 Vakulenkob3aac252014-05-07 17:35:24 -07007#include <map>
Alex Vakulenko9ea5a322015-04-17 15:35:34 -07008#include <set>
Alex Vakulenkob3aac252014-05-07 17:35:24 -07009#include <string>
10
Christopher Wileya4915c42014-03-27 14:45:37 -070011#include <base/bind.h>
12#include <base/bind_helpers.h>
Alex Vakulenko665c8852014-09-11 16:57:24 -070013#include <base/json/json_reader.h>
Christopher Wileyb76eb292014-05-05 16:09:16 -070014#include <base/json/json_writer.h>
Christopher Wileycd419662015-02-06 17:51:43 -080015#include <base/time/time.h>
Alex Vakulenkoa8b95bc2014-08-27 11:00:57 -070016#include <chromeos/dbus/async_event_sequencer.h>
17#include <chromeos/dbus/exported_object_manager.h>
18#include <chromeos/errors/error.h>
Garret Kelly9a895382015-05-29 15:56:52 -040019#include <chromeos/http/http_transport.h>
Anton Muhin332df192014-11-22 05:59:14 +040020#include <chromeos/key_value_store.h>
Christopher Wileyb76eb292014-05-05 16:09:16 -070021#include <dbus/bus.h>
Christopher Wiley90016242014-04-01 17:33:29 -070022#include <dbus/object_path.h>
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070023#include <dbus/values_util.h>
Christopher Wileya4915c42014-03-27 14:45:37 -070024
Vitaly Buka72410b22015-05-13 13:48:59 -070025#include "buffet/base_api_handler.h"
Alex Vakulenko665c8852014-09-11 16:57:24 -070026#include "buffet/commands/command_instance.h"
Alex Vakulenkoe03af6d2015-04-20 11:00:54 -070027#include "buffet/commands/schema_constants.h"
Vitaly Buka505c4132015-06-09 17:01:54 -070028#include "buffet/privet/constants.h"
29#include "buffet/privet/security_manager.h"
30#include "buffet/privet/wifi_bootstrap_manager.h"
Alex Vakulenko57123b22014-10-28 13:50:16 -070031#include "buffet/states/state_change_queue.h"
Alex Vakulenko07216fe2014-09-19 15:31:09 -070032#include "buffet/states/state_manager.h"
Christopher Wileye0fdeee2015-02-07 18:29:32 -080033#include "buffet/storage_impls.h"
Christopher Wileya4915c42014-03-27 14:45:37 -070034
Christopher Wiley2d2d92b2014-07-29 14:07:10 -070035using chromeos::dbus_utils::AsyncEventSequencer;
Christopher Wileyb5dd5ea2014-08-11 10:51:20 -070036using chromeos::dbus_utils::ExportedObjectManager;
Christopher Wileya4915c42014-03-27 14:45:37 -070037
38namespace buffet {
39
Alex Vakulenko57123b22014-10-28 13:50:16 -070040namespace {
Vitaly Buka505c4132015-06-09 17:01:54 -070041
Alex Vakulenko57123b22014-10-28 13:50:16 -070042// Max of 100 state update events should be enough in the queue.
43const size_t kMaxStateChangeQueueSize = 100;
Garret Kelly9a895382015-05-29 15:56:52 -040044// The number of seconds each HTTP request will be allowed before timing out.
45const int kRequestTimeoutSeconds = 30;
Vitaly Buka505c4132015-06-09 17:01:54 -070046
47const char kPairingSessionIdKey[] = "sessionId";
48const char kPairingModeKey[] = "mode";
49const char kPairingCodeKey[] = "code";
50
Alex Vakulenko57123b22014-10-28 13:50:16 -070051} // anonymous namespace
52
Alex Vakulenkof2784de2014-08-15 11:49:35 -070053Manager::Manager(const base::WeakPtr<ExportedObjectManager>& object_manager)
54 : dbus_object_(object_manager.get(),
55 object_manager->GetBus(),
Vitaly Buka7ad8ffb2015-03-20 09:46:57 -070056 org::chromium::Buffet::ManagerAdaptor::GetObjectPath()) {
57}
Christopher Wileya4915c42014-03-27 14:45:37 -070058
Vitaly Buka7ad8ffb2015-03-20 09:46:57 -070059Manager::~Manager() {
60}
Alex Vakulenko57123b22014-10-28 13:50:16 -070061
Vitaly Bukaae96cc32015-06-09 17:22:18 -070062void Manager::Start(const Options& options, AsyncEventSequencer* sequencer) {
Alex Vakulenko95110752014-09-03 16:27:21 -070063 command_manager_ =
64 std::make_shared<CommandManager>(dbus_object_.GetObjectManager());
Vitaly Buka5e6ff6c2015-05-11 15:41:33 -070065 command_manager_->AddOnCommandDefChanged(base::Bind(
66 &Manager::OnCommandDefsChanged, weak_ptr_factory_.GetWeakPtr()));
Christopher Wileybb5b8482015-02-12 13:42:16 -080067 command_manager_->Startup(base::FilePath{"/etc/buffet"},
Vitaly Bukaae96cc32015-06-09 17:22:18 -070068 options.test_definitions_path);
Vitaly Buka72410b22015-05-13 13:48:59 -070069 state_change_queue_.reset(new StateChangeQueue(kMaxStateChangeQueueSize));
Alex Vakulenko57123b22014-10-28 13:50:16 -070070 state_manager_ = std::make_shared<StateManager>(state_change_queue_.get());
Vitaly Bukadbb8c352015-05-27 09:27:08 -070071 state_manager_->AddOnChangedCallback(
72 base::Bind(&Manager::OnStateChanged, weak_ptr_factory_.GetWeakPtr()));
Alex Vakulenko07216fe2014-09-19 15:31:09 -070073 state_manager_->Startup();
Vitaly Bukaee7a3af2015-05-14 16:57:23 -070074
Vitaly Bukaae96cc32015-06-09 17:22:18 -070075 std::unique_ptr<BuffetConfig> config{new BuffetConfig{options.state_path}};
Vitaly Bukaee7a3af2015-05-14 16:57:23 -070076 config->AddOnChangedCallback(
77 base::Bind(&Manager::OnConfigChanged, weak_ptr_factory_.GetWeakPtr()));
Vitaly Bukaae96cc32015-06-09 17:22:18 -070078 config->Load(options.config_path);
Vitaly Bukaee7a3af2015-05-14 16:57:23 -070079
Garret Kelly9a895382015-05-29 15:56:52 -040080 auto transport = chromeos::http::Transport::CreateDefault();
81 transport->SetDefaultTimeout(base::TimeDelta::FromSeconds(
82 kRequestTimeoutSeconds));
83
Christopher Wileye0fdeee2015-02-07 18:29:32 -080084 // TODO(avakulenko): Figure out security implications of storing
85 // device info state data unencrypted.
Vitaly Buka72410b22015-05-13 13:48:59 -070086 device_info_.reset(new DeviceRegistrationInfo(
Garret Kelly9a895382015-05-29 15:56:52 -040087 command_manager_, state_manager_, std::move(config), transport,
Vitaly Bukaae96cc32015-06-09 17:22:18 -070088 options.xmpp_enabled));
Vitaly Bukaee7a3af2015-05-14 16:57:23 -070089 device_info_->AddOnRegistrationChangedCallback(base::Bind(
90 &Manager::OnRegistrationChanged, weak_ptr_factory_.GetWeakPtr()));
Vitaly Buka72410b22015-05-13 13:48:59 -070091
Vitaly Buka2f7efdb2015-05-27 16:00:21 -070092 base_api_handler_.reset(new BaseApiHandler{
93 device_info_->AsWeakPtr(), state_manager_, command_manager_});
Vitaly Buka72410b22015-05-13 13:48:59 -070094
Vitaly Bukaee7a3af2015-05-14 16:57:23 -070095 device_info_->Start();
Vitaly Bukaae96cc32015-06-09 17:22:18 -070096
Alex Vakulenko2348e422014-11-21 08:57:57 -080097 dbus_adaptor_.RegisterWithDBusObject(&dbus_object_);
Vitaly Bukaae96cc32015-06-09 17:22:18 -070098 dbus_object_.RegisterAsync(
99 sequencer->GetHandler("Manager.RegisterAsync() failed.", true));
100
101 if (!options.privet.disable_privet)
102 StartPrivet(options.privet, sequencer);
103}
104
105void Manager::StartPrivet(const privetd::Manager::Options& options,
106 AsyncEventSequencer* sequencer) {
107 privet_.reset(new privetd::Manager{});
Vitaly Buka7ab89ff2015-06-09 22:11:40 -0700108 privet_->Start(options, dbus_object_.GetBus(), device_info_.get(),
109 command_manager_.get(), state_manager_.get(), sequencer);
Vitaly Bukaae96cc32015-06-09 17:22:18 -0700110
111 if (privet_->GetWifiBootstrapManager()) {
112 privet_->GetWifiBootstrapManager()->RegisterStateListener(base::Bind(
113 &Manager::UpdateWiFiBootstrapState, weak_ptr_factory_.GetWeakPtr()));
114 } else {
115 UpdateWiFiBootstrapState(privetd::WifiBootstrapManager::kDisabled);
116 }
117
118 privet_->GetSecurityManager()->RegisterPairingListeners(
119 base::Bind(&Manager::OnPairingStart, weak_ptr_factory_.GetWeakPtr()),
120 base::Bind(&Manager::OnPairingEnd, weak_ptr_factory_.GetWeakPtr()));
121 // TODO(wiley) Watch for appropriate state variables from |cloud_delegate|.
122}
123
124void Manager::Stop() {
125 if (privet_)
126 privet_->OnShutdown();
Christopher Wileya4915c42014-03-27 14:45:37 -0700127}
128
Alex Vakulenko2348e422014-11-21 08:57:57 -0800129void Manager::CheckDeviceRegistered(DBusMethodResponse<std::string> response) {
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700130 LOG(INFO) << "Received call to Manager.CheckDeviceRegistered()";
Alex Vakulenko5c7bf012014-10-30 16:28:38 -0700131 chromeos::ErrorPtr error;
Nathan Bullock5e022a32015-04-08 15:13:07 -0400132 bool registered = device_info_->HaveRegistrationCredentials(&error);
Alex Vakulenkob3aac252014-05-07 17:35:24 -0700133 // If it fails due to any reason other than 'device not registered',
134 // treat it as a real error and report it to the caller.
135 if (!registered &&
Alex Vakulenko5c7bf012014-10-30 16:28:38 -0700136 !error->HasError(kErrorDomainGCD, "device_not_registered")) {
137 response->ReplyWithError(error.get());
138 return;
Alex Vakulenkob3aac252014-05-07 17:35:24 -0700139 }
Christopher Wileya4915c42014-03-27 14:45:37 -0700140
Vitaly Bukaee7a3af2015-05-14 16:57:23 -0700141 response->Return(registered ? device_info_->GetConfig().device_id()
142 : std::string());
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700143}
144
Alex Vakulenko2348e422014-11-21 08:57:57 -0800145void Manager::GetDeviceInfo(DBusMethodResponse<std::string> response) {
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700146 LOG(INFO) << "Received call to Manager.GetDeviceInfo()";
147
Alex Vakulenko5c7bf012014-10-30 16:28:38 -0700148 chromeos::ErrorPtr error;
149 auto device_info = device_info_->GetDeviceInfo(&error);
150 if (!device_info) {
151 response->ReplyWithError(error.get());
152 return;
153 }
Alex Vakulenkob3aac252014-05-07 17:35:24 -0700154
Alex Vakulenko5c7bf012014-10-30 16:28:38 -0700155 std::string device_info_str;
Nathan Bullock4b6c0fb2015-04-01 15:32:58 -0400156 base::JSONWriter::WriteWithOptions(device_info.get(),
157 base::JSONWriter::OPTIONS_PRETTY_PRINT, &device_info_str);
Alex Vakulenko5c7bf012014-10-30 16:28:38 -0700158 response->Return(device_info_str);
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700159}
160
Alex Vakulenko2348e422014-11-21 08:57:57 -0800161void Manager::RegisterDevice(DBusMethodResponse<std::string> response,
Vitaly Bukacad2e332015-05-14 23:33:32 -0700162 const std::string& ticket_id) {
Anton Muhinbeb1c5b2014-10-16 18:59:57 +0400163 LOG(INFO) << "Received call to Manager.RegisterDevice()";
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700164
Alex Vakulenko5c7bf012014-10-30 16:28:38 -0700165 chromeos::ErrorPtr error;
Vitaly Bukacad2e332015-05-14 23:33:32 -0700166 std::string device_id = device_info_->RegisterDevice(ticket_id, &error);
David Zeuthen1dbad472015-02-12 15:24:21 -0500167 if (!device_id.empty()) {
Alex Vakulenko5c7bf012014-10-30 16:28:38 -0700168 response->Return(device_id);
David Zeuthen1dbad472015-02-12 15:24:21 -0500169 return;
170 }
171 if (!error) {
172 // TODO(zeuthen): This can be changed to CHECK(error) once
173 // RegisterDevice() has been fixed to set |error| when failing.
Vitaly Buka7ad8ffb2015-03-20 09:46:57 -0700174 chromeos::Error::AddTo(&error, FROM_HERE, kErrorDomainGCD, "internal_error",
David Zeuthen1dbad472015-02-12 15:24:21 -0500175 "device_id empty but error not set");
176 }
177 response->ReplyWithError(error.get());
Christopher Wileya4915c42014-03-27 14:45:37 -0700178}
179
Alex Vakulenko2348e422014-11-21 08:57:57 -0800180void Manager::UpdateState(DBusMethodResponse<> response,
181 const chromeos::VariantDictionary& property_set) {
Alex Vakulenko5c7bf012014-10-30 16:28:38 -0700182 chromeos::ErrorPtr error;
Vitaly Buka247620b2015-05-26 15:42:20 -0700183 if (!state_manager_->SetProperties(property_set, &error))
Alex Vakulenko5c7bf012014-10-30 16:28:38 -0700184 response->ReplyWithError(error.get());
185 else
186 response->Return();
Christopher Wileya4915c42014-03-27 14:45:37 -0700187}
188
Alex Vakulenko61ad4db2015-01-20 10:50:04 -0800189bool Manager::GetState(chromeos::ErrorPtr* error, std::string* state) {
190 auto json = state_manager_->GetStateValuesAsJson(error);
191 if (!json)
192 return false;
Nathan Bullock4b6c0fb2015-04-01 15:32:58 -0400193 base::JSONWriter::WriteWithOptions(
194 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, state);
Alex Vakulenko61ad4db2015-01-20 10:50:04 -0800195 return true;
196}
197
Vitaly Buka64fc5fc2015-03-24 12:42:24 -0700198void Manager::AddCommand(DBusMethodResponse<std::string> response,
Vitaly Bukab2098422015-05-31 23:32:46 -0700199 const std::string& json_command,
200 const std::string& in_user_role) {
Alex Vakulenko665c8852014-09-11 16:57:24 -0700201 std::string error_message;
202 std::unique_ptr<base::Value> value(base::JSONReader::ReadAndReturnError(
203 json_command, base::JSON_PARSE_RFC, nullptr, &error_message));
Vitaly Buka4547afa2015-06-09 09:46:53 -0700204 const base::DictionaryValue* command{nullptr};
205 if (!value || !value->GetAsDictionary(&command)) {
206 return response->ReplyWithError(FROM_HERE, chromeos::errors::json::kDomain,
207 chromeos::errors::json::kParseError,
208 error_message);
Alex Vakulenko665c8852014-09-11 16:57:24 -0700209 }
Vitaly Buka4547afa2015-06-09 09:46:53 -0700210
Alex Vakulenko5c7bf012014-10-30 16:28:38 -0700211 chromeos::ErrorPtr error;
Vitaly Bukab2098422015-05-31 23:32:46 -0700212 UserRole role;
Vitaly Buka4547afa2015-06-09 09:46:53 -0700213 if (!FromString(in_user_role, &role, &error))
214 return response->ReplyWithError(error.get());
Vitaly Bukab2098422015-05-31 23:32:46 -0700215
Vitaly Buka4547afa2015-06-09 09:46:53 -0700216 std::string id;
217 if (!command_manager_->AddCommand(*command, role, &id, &error))
218 return response->ReplyWithError(error.get());
Vitaly Bukab2098422015-05-31 23:32:46 -0700219
Vitaly Buka64fc5fc2015-03-24 12:42:24 -0700220 response->Return(id);
Alex Vakulenko665c8852014-09-11 16:57:24 -0700221}
222
Vitaly Buka3886e8f2015-03-24 11:39:40 -0700223void Manager::GetCommand(DBusMethodResponse<std::string> response,
224 const std::string& id) {
225 const CommandInstance* command = command_manager_->FindCommand(id);
226 if (!command) {
227 response->ReplyWithError(FROM_HERE, kErrorDomainGCD, "unknown_command",
228 "Can't find command with id: " + id);
229 return;
230 }
231 std::string command_str;
Nathan Bullock4b6c0fb2015-04-01 15:32:58 -0400232 base::JSONWriter::WriteWithOptions(command->ToJson().get(),
233 base::JSONWriter::OPTIONS_PRETTY_PRINT, &command_str);
Vitaly Buka3886e8f2015-03-24 11:39:40 -0700234 response->Return(command_str);
235}
236
Alex Vakulenkoe03af6d2015-04-20 11:00:54 -0700237void Manager::SetCommandVisibility(
Alex Vakulenko41f73a92015-04-24 18:09:32 -0700238 std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<>> response,
Alex Vakulenkoe03af6d2015-04-20 11:00:54 -0700239 const std::vector<std::string>& in_names,
240 const std::string& in_visibility) {
241 CommandDefinition::Visibility visibility;
242 chromeos::ErrorPtr error;
243 if (!visibility.FromString(in_visibility, &error)) {
244 response->ReplyWithError(error.get());
245 return;
246 }
247 if (!command_manager_->SetCommandVisibility(in_names, visibility, &error)) {
248 response->ReplyWithError(error.get());
249 return;
250 }
251 response->Return();
252}
253
Alex Vakulenko2348e422014-11-21 08:57:57 -0800254std::string Manager::TestMethod(const std::string& message) {
Alex Vakulenko7a1dc0b2014-08-15 11:45:46 -0700255 LOG(INFO) << "Received call to test method: " << message;
256 return message;
Christopher Wileyb76eb292014-05-05 16:09:16 -0700257}
258
Vitaly Buka505c4132015-06-09 17:01:54 -0700259bool Manager::EnableWiFiBootstrapping(
260 chromeos::ErrorPtr* error,
261 const dbus::ObjectPath& in_listener_path,
262 const chromeos::VariantDictionary& in_options) {
263 chromeos::Error::AddTo(error, FROM_HERE, privetd::errors::kDomain,
264 privetd::errors::kNotImplemented,
265 "Manual WiFi bootstrapping is not implemented");
266 return false;
267}
268
269bool Manager::DisableWiFiBootstrapping(chromeos::ErrorPtr* error) {
270 chromeos::Error::AddTo(error, FROM_HERE, privetd::errors::kDomain,
271 privetd::errors::kNotImplemented,
272 "Manual WiFi bootstrapping is not implemented");
273 return false;
274}
275
276bool Manager::EnableGCDBootstrapping(
277 chromeos::ErrorPtr* error,
278 const dbus::ObjectPath& in_listener_path,
279 const chromeos::VariantDictionary& in_options) {
280 chromeos::Error::AddTo(error, FROM_HERE, privetd::errors::kDomain,
281 privetd::errors::kNotImplemented,
282 "Manual GCD bootstrapping is not implemented");
283 return false;
284}
285
286bool Manager::DisableGCDBootstrapping(chromeos::ErrorPtr* error) {
287 chromeos::Error::AddTo(error, FROM_HERE, privetd::errors::kDomain,
288 privetd::errors::kNotImplemented,
289 "Manual GCD bootstrapping is not implemented");
290 return false;
291}
292
Vitaly Bukafa947062015-04-17 00:41:31 -0700293bool Manager::UpdateDeviceInfo(chromeos::ErrorPtr* error,
294 const std::string& in_name,
295 const std::string& in_description,
296 const std::string& in_location) {
297 return device_info_->UpdateDeviceInfo(in_name, in_description, in_location,
298 error);
Christopher Wileyc900e482015-02-15 15:42:04 -0800299}
300
Vitaly Bukaff81db62015-05-14 21:25:45 -0700301bool Manager::UpdateServiceConfig(chromeos::ErrorPtr* error,
302 const std::string& client_id,
303 const std::string& client_secret,
304 const std::string& api_key,
305 const std::string& oauth_url,
306 const std::string& service_url) {
307 return device_info_->UpdateServiceConfig(client_id, client_secret, api_key,
308 oauth_url, service_url, error);
309}
310
Vitaly Bukaaabadee2015-03-18 23:33:44 -0700311void Manager::OnCommandDefsChanged() {
Alex Vakulenko9ea5a322015-04-17 15:35:34 -0700312 // Limit only to commands that are visible to the local clients.
313 auto commands = command_manager_->GetCommandDictionary().GetCommandsAsJson(
314 [](const buffet::CommandDefinition* def) {
315 return def->GetVisibility().local;
Vitaly Bukadbb8c352015-05-27 09:27:08 -0700316 }, true, nullptr);
Vitaly Bukaaabadee2015-03-18 23:33:44 -0700317 CHECK(commands);
318 std::string json;
Nathan Bullock4b6c0fb2015-04-01 15:32:58 -0400319 base::JSONWriter::WriteWithOptions(commands.get(),
320 base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
Vitaly Bukaaabadee2015-03-18 23:33:44 -0700321 dbus_adaptor_.SetCommandDefs(json);
322}
323
Vitaly Bukadbb8c352015-05-27 09:27:08 -0700324void Manager::OnStateChanged() {
325 auto state = state_manager_->GetStateValuesAsJson(nullptr);
326 CHECK(state);
327 std::string json;
328 base::JSONWriter::WriteWithOptions(
329 state.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
330 dbus_adaptor_.SetState(json);
331}
332
Vitaly Bukaee7a3af2015-05-14 16:57:23 -0700333void Manager::OnRegistrationChanged(RegistrationStatus status) {
334 dbus_adaptor_.SetStatus(StatusToString(status));
335}
336
337void Manager::OnConfigChanged(const BuffetConfig& config) {
338 dbus_adaptor_.SetDeviceId(config.device_id());
339 dbus_adaptor_.SetOemName(config.oem_name());
340 dbus_adaptor_.SetModelName(config.model_name());
341 dbus_adaptor_.SetModelId(config.model_id());
342 dbus_adaptor_.SetName(config.name());
343 dbus_adaptor_.SetDescription(config.description());
344 dbus_adaptor_.SetLocation(config.location());
345 dbus_adaptor_.SetAnonymousAccessRole(config.local_anonymous_access_role());
346}
347
Vitaly Buka505c4132015-06-09 17:01:54 -0700348void Manager::UpdateWiFiBootstrapState(
349 privetd::WifiBootstrapManager::State state) {
350 switch (state) {
351 case privetd::WifiBootstrapManager::kDisabled:
352 dbus_adaptor_.SetWiFiBootstrapState("disabled");
353 break;
354 case privetd::WifiBootstrapManager::kBootstrapping:
355 dbus_adaptor_.SetWiFiBootstrapState("waiting");
356 break;
357 case privetd::WifiBootstrapManager::kMonitoring:
358 dbus_adaptor_.SetWiFiBootstrapState("monitoring");
359 break;
360 case privetd::WifiBootstrapManager::kConnecting:
361 dbus_adaptor_.SetWiFiBootstrapState("connecting");
362 break;
363 }
364}
365
366void Manager::OnPairingStart(const std::string& session_id,
367 privetd::PairingType pairing_type,
368 const std::vector<uint8_t>& code) {
369 // For now, just overwrite the exposed PairInfo with
370 // the most recent pairing attempt.
371 dbus_adaptor_.SetPairingInfo(chromeos::VariantDictionary{
372 {kPairingSessionIdKey, session_id},
373 {kPairingModeKey, PairingTypeToString(pairing_type)},
374 {kPairingCodeKey, code},
375 });
376}
377
378void Manager::OnPairingEnd(const std::string& session_id) {
379 auto exposed_pairing_attempt = dbus_adaptor_.GetPairingInfo();
380 auto it = exposed_pairing_attempt.find(kPairingSessionIdKey);
381 if (it == exposed_pairing_attempt.end()) {
382 return;
383 }
384 std::string exposed_session{it->second.TryGet<std::string>()};
385 if (exposed_session == session_id) {
386 dbus_adaptor_.SetPairingInfo(chromeos::VariantDictionary{});
387 }
388}
389
Christopher Wileya4915c42014-03-27 14:45:37 -0700390} // namespace buffet