Christopher Wiley | a4915c4 | 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 | #include "buffet/manager.h" |
| 6 | |
Alex Vakulenko | b3aac25 | 2014-05-07 17:35:24 -0700 | [diff] [blame] | 7 | #include <map> |
Alex Vakulenko | 9ea5a32 | 2015-04-17 15:35:34 -0700 | [diff] [blame] | 8 | #include <set> |
Alex Vakulenko | b3aac25 | 2014-05-07 17:35:24 -0700 | [diff] [blame] | 9 | #include <string> |
| 10 | |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 11 | #include <base/bind.h> |
| 12 | #include <base/bind_helpers.h> |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 13 | #include <base/json/json_reader.h> |
Christopher Wiley | b76eb29 | 2014-05-05 16:09:16 -0700 | [diff] [blame] | 14 | #include <base/json/json_writer.h> |
Christopher Wiley | cd41966 | 2015-02-06 17:51:43 -0800 | [diff] [blame] | 15 | #include <base/time/time.h> |
Alex Vakulenko | a8b95bc | 2014-08-27 11:00:57 -0700 | [diff] [blame] | 16 | #include <chromeos/dbus/async_event_sequencer.h> |
| 17 | #include <chromeos/dbus/exported_object_manager.h> |
| 18 | #include <chromeos/errors/error.h> |
Anton Muhin | 332df19 | 2014-11-22 05:59:14 +0400 | [diff] [blame] | 19 | #include <chromeos/key_value_store.h> |
Christopher Wiley | b76eb29 | 2014-05-05 16:09:16 -0700 | [diff] [blame] | 20 | #include <dbus/bus.h> |
Christopher Wiley | 9001624 | 2014-04-01 17:33:29 -0700 | [diff] [blame] | 21 | #include <dbus/object_path.h> |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 22 | #include <dbus/values_util.h> |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 23 | |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 24 | #include "buffet/commands/command_instance.h" |
Alex Vakulenko | e03af6d | 2015-04-20 11:00:54 -0700 | [diff] [blame] | 25 | #include "buffet/commands/schema_constants.h" |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 26 | #include "buffet/states/state_change_queue.h" |
Alex Vakulenko | 07216fe | 2014-09-19 15:31:09 -0700 | [diff] [blame] | 27 | #include "buffet/states/state_manager.h" |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 28 | #include "buffet/storage_impls.h" |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 29 | |
Christopher Wiley | 2d2d92b | 2014-07-29 14:07:10 -0700 | [diff] [blame] | 30 | using chromeos::dbus_utils::AsyncEventSequencer; |
Christopher Wiley | b5dd5ea | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 31 | using chromeos::dbus_utils::ExportedObjectManager; |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 32 | |
| 33 | namespace buffet { |
| 34 | |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 35 | namespace { |
| 36 | // Max of 100 state update events should be enough in the queue. |
| 37 | const size_t kMaxStateChangeQueueSize = 100; |
| 38 | } // anonymous namespace |
| 39 | |
Alex Vakulenko | f2784de | 2014-08-15 11:49:35 -0700 | [diff] [blame] | 40 | Manager::Manager(const base::WeakPtr<ExportedObjectManager>& object_manager) |
| 41 | : dbus_object_(object_manager.get(), |
| 42 | object_manager->GetBus(), |
Vitaly Buka | 7ad8ffb | 2015-03-20 09:46:57 -0700 | [diff] [blame] | 43 | org::chromium::Buffet::ManagerAdaptor::GetObjectPath()) { |
| 44 | } |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 45 | |
Vitaly Buka | 7ad8ffb | 2015-03-20 09:46:57 -0700 | [diff] [blame] | 46 | Manager::~Manager() { |
| 47 | } |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 48 | |
Vitaly Buka | 76e7059 | 2015-04-16 11:39:02 -0700 | [diff] [blame] | 49 | void Manager::Start(const base::FilePath& config_path, |
| 50 | const base::FilePath& state_path, |
| 51 | const base::FilePath& test_definitions_path, |
| 52 | bool xmpp_enabled, |
| 53 | const AsyncEventSequencer::CompletionAction& cb) { |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 54 | command_manager_ = |
| 55 | std::make_shared<CommandManager>(dbus_object_.GetObjectManager()); |
Alex Vakulenko | 9ea5a32 | 2015-04-17 15:35:34 -0700 | [diff] [blame] | 56 | command_changed_callback_token_ = command_manager_->AddOnCommandDefChanged( |
Vitaly Buka | aabadee | 2015-03-18 23:33:44 -0700 | [diff] [blame] | 57 | base::Bind(&Manager::OnCommandDefsChanged, base::Unretained(this))); |
Christopher Wiley | bb5b848 | 2015-02-12 13:42:16 -0800 | [diff] [blame] | 58 | command_manager_->Startup(base::FilePath{"/etc/buffet"}, |
| 59 | test_definitions_path); |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 60 | state_change_queue_ = std::unique_ptr<StateChangeQueue>( |
| 61 | new StateChangeQueue(kMaxStateChangeQueueSize)); |
| 62 | state_manager_ = std::make_shared<StateManager>(state_change_queue_.get()); |
Alex Vakulenko | 07216fe | 2014-09-19 15:31:09 -0700 | [diff] [blame] | 63 | state_manager_->Startup(); |
Christopher Wiley | 583d64b | 2015-03-24 14:30:17 -0700 | [diff] [blame] | 64 | std::unique_ptr<BuffetConfig> config{new BuffetConfig}; |
| 65 | config->Load(config_path); |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 66 | std::unique_ptr<FileStorage> state_store{new FileStorage{state_path}}; |
Christopher Wiley | e0fdeee | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 67 | // TODO(avakulenko): Figure out security implications of storing |
| 68 | // device info state data unencrypted. |
Alex Vakulenko | 1f30a62 | 2014-07-23 11:13:15 -0700 | [diff] [blame] | 69 | device_info_ = std::unique_ptr<DeviceRegistrationInfo>( |
Christopher Wiley | c900e48 | 2015-02-15 15:42:04 -0800 | [diff] [blame] | 70 | new DeviceRegistrationInfo( |
| 71 | command_manager_, |
| 72 | state_manager_, |
Christopher Wiley | 583d64b | 2015-03-24 14:30:17 -0700 | [diff] [blame] | 73 | std::move(config), |
Christopher Wiley | c900e48 | 2015-02-15 15:42:04 -0800 | [diff] [blame] | 74 | chromeos::http::Transport::CreateDefault(), |
| 75 | std::move(state_store), |
Christopher Wiley | d732bd0 | 2015-04-07 11:11:18 -0700 | [diff] [blame] | 76 | xmpp_enabled, |
Vitaly Buka | fa94706 | 2015-04-17 00:41:31 -0700 | [diff] [blame] | 77 | &dbus_adaptor_)); |
Vitaly Buka | b055f15 | 2015-03-12 13:41:43 -0700 | [diff] [blame] | 78 | device_info_->Load(); |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 79 | dbus_adaptor_.RegisterWithDBusObject(&dbus_object_); |
| 80 | dbus_object_.RegisterAsync(cb); |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 83 | void Manager::CheckDeviceRegistered(DBusMethodResponse<std::string> response) { |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 84 | LOG(INFO) << "Received call to Manager.CheckDeviceRegistered()"; |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 85 | chromeos::ErrorPtr error; |
Nathan Bullock | 5e022a3 | 2015-04-08 15:13:07 -0400 | [diff] [blame] | 86 | bool registered = device_info_->HaveRegistrationCredentials(&error); |
Alex Vakulenko | b3aac25 | 2014-05-07 17:35:24 -0700 | [diff] [blame] | 87 | // If it fails due to any reason other than 'device not registered', |
| 88 | // treat it as a real error and report it to the caller. |
| 89 | if (!registered && |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 90 | !error->HasError(kErrorDomainGCD, "device_not_registered")) { |
| 91 | response->ReplyWithError(error.get()); |
| 92 | return; |
Alex Vakulenko | b3aac25 | 2014-05-07 17:35:24 -0700 | [diff] [blame] | 93 | } |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 94 | |
Vitaly Buka | 620bd7e | 2015-03-16 01:07:01 -0700 | [diff] [blame] | 95 | response->Return(registered ? device_info_->GetDeviceId() : std::string()); |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 98 | void Manager::GetDeviceInfo(DBusMethodResponse<std::string> response) { |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 99 | LOG(INFO) << "Received call to Manager.GetDeviceInfo()"; |
| 100 | |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 101 | chromeos::ErrorPtr error; |
| 102 | auto device_info = device_info_->GetDeviceInfo(&error); |
| 103 | if (!device_info) { |
| 104 | response->ReplyWithError(error.get()); |
| 105 | return; |
| 106 | } |
Alex Vakulenko | b3aac25 | 2014-05-07 17:35:24 -0700 | [diff] [blame] | 107 | |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 108 | std::string device_info_str; |
Nathan Bullock | 4b6c0fb | 2015-04-01 15:32:58 -0400 | [diff] [blame] | 109 | base::JSONWriter::WriteWithOptions(device_info.get(), |
| 110 | base::JSONWriter::OPTIONS_PRETTY_PRINT, &device_info_str); |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 111 | response->Return(device_info_str); |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 114 | void Manager::RegisterDevice(DBusMethodResponse<std::string> response, |
| 115 | const chromeos::VariantDictionary& params) { |
Anton Muhin | beb1c5b | 2014-10-16 18:59:57 +0400 | [diff] [blame] | 116 | LOG(INFO) << "Received call to Manager.RegisterDevice()"; |
Alex Vakulenko | 3cb466c | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 117 | |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 118 | chromeos::ErrorPtr error; |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 119 | std::map<std::string, std::string> str_params; |
| 120 | for (const auto& pair : params) { |
| 121 | if (!pair.second.IsTypeCompatible<std::string>()) { |
| 122 | response->ReplyWithError(FROM_HERE, chromeos::errors::dbus::kDomain, |
| 123 | DBUS_ERROR_INVALID_ARGS, |
| 124 | "String value expected"); |
| 125 | return; |
| 126 | } |
Vitaly Buka | 7ad8ffb | 2015-03-20 09:46:57 -0700 | [diff] [blame] | 127 | str_params.emplace_hint(str_params.end(), pair.first, |
| 128 | pair.second.Get<std::string>()); |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 129 | } |
| 130 | std::string device_id = device_info_->RegisterDevice(str_params, &error); |
David Zeuthen | 1dbad47 | 2015-02-12 15:24:21 -0500 | [diff] [blame] | 131 | if (!device_id.empty()) { |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 132 | response->Return(device_id); |
David Zeuthen | 1dbad47 | 2015-02-12 15:24:21 -0500 | [diff] [blame] | 133 | return; |
| 134 | } |
| 135 | if (!error) { |
| 136 | // TODO(zeuthen): This can be changed to CHECK(error) once |
| 137 | // RegisterDevice() has been fixed to set |error| when failing. |
Vitaly Buka | 7ad8ffb | 2015-03-20 09:46:57 -0700 | [diff] [blame] | 138 | chromeos::Error::AddTo(&error, FROM_HERE, kErrorDomainGCD, "internal_error", |
David Zeuthen | 1dbad47 | 2015-02-12 15:24:21 -0500 | [diff] [blame] | 139 | "device_id empty but error not set"); |
| 140 | } |
| 141 | response->ReplyWithError(error.get()); |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 144 | void Manager::UpdateState(DBusMethodResponse<> response, |
| 145 | const chromeos::VariantDictionary& property_set) { |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 146 | chromeos::ErrorPtr error; |
Alex Vakulenko | ff73cf2 | 2014-10-29 09:53:52 -0700 | [diff] [blame] | 147 | base::Time timestamp = base::Time::Now(); |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 148 | bool all_success = true; |
Alex Vakulenko | ff73cf2 | 2014-10-29 09:53:52 -0700 | [diff] [blame] | 149 | for (const auto& pair : property_set) { |
Vitaly Buka | 7ad8ffb | 2015-03-20 09:46:57 -0700 | [diff] [blame] | 150 | if (!state_manager_->SetPropertyValue(pair.first, pair.second, timestamp, |
| 151 | &error)) { |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 152 | // Remember that an error occurred but keep going and update the rest of |
| 153 | // the properties if possible. |
| 154 | all_success = false; |
| 155 | } |
Alex Vakulenko | ff73cf2 | 2014-10-29 09:53:52 -0700 | [diff] [blame] | 156 | } |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 157 | if (!all_success) |
| 158 | response->ReplyWithError(error.get()); |
| 159 | else |
| 160 | response->Return(); |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Alex Vakulenko | 61ad4db | 2015-01-20 10:50:04 -0800 | [diff] [blame] | 163 | bool Manager::GetState(chromeos::ErrorPtr* error, std::string* state) { |
| 164 | auto json = state_manager_->GetStateValuesAsJson(error); |
| 165 | if (!json) |
| 166 | return false; |
Nathan Bullock | 4b6c0fb | 2015-04-01 15:32:58 -0400 | [diff] [blame] | 167 | base::JSONWriter::WriteWithOptions( |
| 168 | json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, state); |
Alex Vakulenko | 61ad4db | 2015-01-20 10:50:04 -0800 | [diff] [blame] | 169 | return true; |
| 170 | } |
| 171 | |
Vitaly Buka | 64fc5fc | 2015-03-24 12:42:24 -0700 | [diff] [blame] | 172 | void Manager::AddCommand(DBusMethodResponse<std::string> response, |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 173 | const std::string& json_command) { |
Anton Muhin | 5191e81 | 2014-10-30 17:49:48 +0400 | [diff] [blame] | 174 | static int next_id = 0; |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 175 | std::string error_message; |
| 176 | std::unique_ptr<base::Value> value(base::JSONReader::ReadAndReturnError( |
| 177 | json_command, base::JSON_PARSE_RFC, nullptr, &error_message)); |
| 178 | if (!value) { |
Alex Vakulenko | ac8037d | 2014-11-11 11:42:05 -0800 | [diff] [blame] | 179 | response->ReplyWithError(FROM_HERE, chromeos::errors::json::kDomain, |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 180 | chromeos::errors::json::kParseError, |
| 181 | error_message); |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 182 | return; |
| 183 | } |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 184 | chromeos::ErrorPtr error; |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 185 | auto command_instance = buffet::CommandInstance::FromJson( |
Alex Vakulenko | f784e21 | 2015-04-20 12:33:52 -0700 | [diff] [blame] | 186 | value.get(), commands::attributes::kCommand_Visibility_Local, |
| 187 | command_manager_->GetCommandDictionary(), &error); |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 188 | if (!command_instance) { |
| 189 | response->ReplyWithError(error.get()); |
| 190 | return; |
| 191 | } |
Vitaly Buka | 64fc5fc | 2015-03-24 12:42:24 -0700 | [diff] [blame] | 192 | std::string id = std::to_string(++next_id); |
| 193 | command_instance->SetID(id); |
Alex Vakulenko | 5c7bf01 | 2014-10-30 16:28:38 -0700 | [diff] [blame] | 194 | command_manager_->AddCommand(std::move(command_instance)); |
Vitaly Buka | 64fc5fc | 2015-03-24 12:42:24 -0700 | [diff] [blame] | 195 | response->Return(id); |
Alex Vakulenko | 665c885 | 2014-09-11 16:57:24 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Vitaly Buka | 3886e8f | 2015-03-24 11:39:40 -0700 | [diff] [blame] | 198 | void Manager::GetCommand(DBusMethodResponse<std::string> response, |
| 199 | const std::string& id) { |
| 200 | const CommandInstance* command = command_manager_->FindCommand(id); |
| 201 | if (!command) { |
| 202 | response->ReplyWithError(FROM_HERE, kErrorDomainGCD, "unknown_command", |
| 203 | "Can't find command with id: " + id); |
| 204 | return; |
| 205 | } |
| 206 | std::string command_str; |
Nathan Bullock | 4b6c0fb | 2015-04-01 15:32:58 -0400 | [diff] [blame] | 207 | base::JSONWriter::WriteWithOptions(command->ToJson().get(), |
| 208 | base::JSONWriter::OPTIONS_PRETTY_PRINT, &command_str); |
Vitaly Buka | 3886e8f | 2015-03-24 11:39:40 -0700 | [diff] [blame] | 209 | response->Return(command_str); |
| 210 | } |
| 211 | |
Alex Vakulenko | e03af6d | 2015-04-20 11:00:54 -0700 | [diff] [blame] | 212 | void Manager::SetCommandVisibility( |
Alex Vakulenko | 41f73a9 | 2015-04-24 18:09:32 -0700 | [diff] [blame] | 213 | std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<>> response, |
Alex Vakulenko | e03af6d | 2015-04-20 11:00:54 -0700 | [diff] [blame] | 214 | const std::vector<std::string>& in_names, |
| 215 | const std::string& in_visibility) { |
| 216 | CommandDefinition::Visibility visibility; |
| 217 | chromeos::ErrorPtr error; |
| 218 | if (!visibility.FromString(in_visibility, &error)) { |
| 219 | response->ReplyWithError(error.get()); |
| 220 | return; |
| 221 | } |
| 222 | if (!command_manager_->SetCommandVisibility(in_names, visibility, &error)) { |
| 223 | response->ReplyWithError(error.get()); |
| 224 | return; |
| 225 | } |
| 226 | response->Return(); |
| 227 | } |
| 228 | |
Alex Vakulenko | 2348e42 | 2014-11-21 08:57:57 -0800 | [diff] [blame] | 229 | std::string Manager::TestMethod(const std::string& message) { |
Alex Vakulenko | 7a1dc0b | 2014-08-15 11:45:46 -0700 | [diff] [blame] | 230 | LOG(INFO) << "Received call to test method: " << message; |
| 231 | return message; |
Christopher Wiley | b76eb29 | 2014-05-05 16:09:16 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Vitaly Buka | fa94706 | 2015-04-17 00:41:31 -0700 | [diff] [blame] | 234 | bool Manager::UpdateDeviceInfo(chromeos::ErrorPtr* error, |
| 235 | const std::string& in_name, |
| 236 | const std::string& in_description, |
| 237 | const std::string& in_location) { |
| 238 | return device_info_->UpdateDeviceInfo(in_name, in_description, in_location, |
| 239 | error); |
Christopher Wiley | c900e48 | 2015-02-15 15:42:04 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Vitaly Buka | aabadee | 2015-03-18 23:33:44 -0700 | [diff] [blame] | 242 | void Manager::OnCommandDefsChanged() { |
| 243 | chromeos::ErrorPtr error; |
Alex Vakulenko | 9ea5a32 | 2015-04-17 15:35:34 -0700 | [diff] [blame] | 244 | // Limit only to commands that are visible to the local clients. |
| 245 | auto commands = command_manager_->GetCommandDictionary().GetCommandsAsJson( |
| 246 | [](const buffet::CommandDefinition* def) { |
| 247 | return def->GetVisibility().local; |
| 248 | }, true, &error); |
Vitaly Buka | aabadee | 2015-03-18 23:33:44 -0700 | [diff] [blame] | 249 | CHECK(commands); |
| 250 | std::string json; |
Nathan Bullock | 4b6c0fb | 2015-04-01 15:32:58 -0400 | [diff] [blame] | 251 | base::JSONWriter::WriteWithOptions(commands.get(), |
| 252 | base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); |
Vitaly Buka | aabadee | 2015-03-18 23:33:44 -0700 | [diff] [blame] | 253 | dbus_adaptor_.SetCommandDefs(json); |
| 254 | } |
| 255 | |
Christopher Wiley | a4915c4 | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 256 | } // namespace buffet |