buffet: Add command_def filtering by command visibility
When updating cloud or local client with the device's CDD make sure
to send only the command definitions that are available to particular
client (local vs cloud).
Also made it possible to subscribe to command definition change notifications
for more than one listener (using base::CallbackList) so that both the local
and cloud adapters can notify the respective clients about command visibility
changes (the actual API to change the command visibility is coming in a
follow-up CL).
BUG=brillo:797
TEST=`FEATURES=test emerge-link buffet`
Change-Id: I6bec36633ababcb534012abad2c37a3502d8faf4
Reviewed-on: https://chromium-review.googlesource.com/266209
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/device_registration_info.h b/buffet/device_registration_info.h
index e3a4b80..f153cda 100644
--- a/buffet/device_registration_info.h
+++ b/buffet/device_registration_info.h
@@ -21,6 +21,7 @@
#include <chromeos/http/http_transport.h>
#include "buffet/buffet_config.h"
+#include "buffet/commands/command_manager.h"
#include "buffet/registration_status.h"
#include "buffet/storage_interface.h"
#include "buffet/xmpp/xmpp_client.h"
@@ -43,7 +44,6 @@
namespace buffet {
-class CommandManager;
class StateManager;
extern const char kErrorDomainOAuth2[];
@@ -215,7 +215,7 @@
void PublishStateUpdates();
- // Builds Cloud API devices collection REST resouce which matches
+ // Builds Cloud API devices collection REST resource which matches
// current state of the device including command definitions
// for all supported commands and current device state.
std::unique_ptr<base::DictionaryValue> BuildDeviceResource(
@@ -225,6 +225,9 @@
void SetDeviceId(const std::string& device_id);
void OnConfigChanged();
+ // Callback called when command definitions are changed to re-publish new CDD.
+ void OnCommandDefsChanged();
+
// Data that is cached here, persisted in the state store.
std::string refresh_token_;
std::string device_id_;
@@ -243,6 +246,10 @@
// Device state manager.
std::shared_ptr<StateManager> state_manager_;
+ // Token given by Command Manager to track the registered Command Definition
+ // change callback.
+ CommandManager::CallbackToken command_changed_callback_token_;
+
std::unique_ptr<BuffetConfig> config_;
const bool xmpp_enabled_;