Hide UserRole from public interface All commands added using API executed as Owner's commands. BUG:24267885 Change-Id: I296e9503cac07d84664941278ffb56f79f695fb0 Reviewed-on: https://weave-review.googlesource.com/1225 Reviewed-by: Alex Vakulenko <avakulenko@google.com>
diff --git a/libweave/include/weave/commands.h b/libweave/include/weave/commands.h index 68751ac..c77abcb 100644 --- a/libweave/include/weave/commands.h +++ b/libweave/include/weave/commands.h
@@ -14,13 +14,6 @@ namespace weave { -enum class UserRole { - kViewer, - kUser, - kManager, - kOwner, -}; - class Commands { public: using OnCommandCallback = base::Callback<void(Command*)>; @@ -34,7 +27,6 @@ // Adds a new command to the command queue. virtual bool AddCommand(const base::DictionaryValue& command, - UserRole role, std::string* id, ErrorPtr* error) = 0;
diff --git a/libweave/libweave.gypi b/libweave/libweave.gypi index 3229571..bad1412 100644 --- a/libweave/libweave.gypi +++ b/libweave/libweave.gypi
@@ -18,7 +18,6 @@ 'src/commands/prop_values.cc', 'src/commands/schema_constants.cc', 'src/commands/schema_utils.cc', - 'src/commands/user_role.cc', 'src/config.cc', 'src/data_encoding.cc', 'src/device_manager.cc',
diff --git a/libweave/src/commands/command_definition.cc b/libweave/src/commands/command_definition.cc index 78121ac..1deb594 100644 --- a/libweave/src/commands/command_definition.cc +++ b/libweave/src/commands/command_definition.cc
@@ -7,12 +7,27 @@ #include <vector> #include <weave/error.h> +#include <weave/enum_to_string.h> #include "src/commands/schema_constants.h" #include "src/string_utils.h" namespace weave { +namespace { + +const EnumToStringMap<UserRole>::Map kMap[] = { + {UserRole::kViewer, commands::attributes::kCommand_Role_Viewer}, + {UserRole::kUser, commands::attributes::kCommand_Role_User}, + {UserRole::kOwner, commands::attributes::kCommand_Role_Owner}, + {UserRole::kManager, commands::attributes::kCommand_Role_Manager}, +}; +} + +template <> +LIBWEAVE_EXPORT EnumToStringMap<UserRole>::EnumToStringMap() + : EnumToStringMap(kMap) {} + bool CommandDefinition::Visibility::FromString(const std::string& str, ErrorPtr* error) { // This special case is useful for places where we want to make a command
diff --git a/libweave/src/commands/command_definition.h b/libweave/src/commands/command_definition.h index 06d7afd..a6a17f8 100644 --- a/libweave/src/commands/command_definition.h +++ b/libweave/src/commands/command_definition.h
@@ -15,6 +15,13 @@ namespace weave { +enum class UserRole { + kViewer, + kUser, + kManager, + kOwner, +}; + // A simple GCD command definition. This class contains the command category // and a full object schema describing the command parameter types and // constraints. See comments for CommandDefinitions::LoadCommands for the
diff --git a/libweave/src/commands/command_manager.cc b/libweave/src/commands/command_manager.cc index cf2fc2d..bd7d02c 100644 --- a/libweave/src/commands/command_manager.cc +++ b/libweave/src/commands/command_manager.cc
@@ -113,6 +113,12 @@ } bool CommandManager::AddCommand(const base::DictionaryValue& command, + std::string* id, + ErrorPtr* error) { + return AddCommand(command, UserRole::kOwner, id, error); +} + +bool CommandManager::AddCommand(const base::DictionaryValue& command, UserRole role, std::string* id, ErrorPtr* error) {
diff --git a/libweave/src/commands/command_manager.h b/libweave/src/commands/command_manager.h index c982d2d..ea1392c 100644 --- a/libweave/src/commands/command_manager.h +++ b/libweave/src/commands/command_manager.h
@@ -36,7 +36,6 @@ // Commands overrides. bool AddCommand(const base::DictionaryValue& command, - UserRole role, std::string* id, ErrorPtr* error) override; CommandInstance* FindCommand(const std::string& id) override; @@ -91,6 +90,11 @@ CommandDefinition::Visibility visibility, ErrorPtr* error); + bool AddCommand(const base::DictionaryValue& command, + UserRole role, + std::string* id, + ErrorPtr* error); + private: CommandDictionary base_dictionary_; // Base/std command definitions/schemas. CommandDictionary dictionary_; // Command definitions/schemas.
diff --git a/libweave/src/commands/user_role.cc b/libweave/src/commands/user_role.cc deleted file mode 100644 index d45d02b..0000000 --- a/libweave/src/commands/user_role.cc +++ /dev/null
@@ -1,30 +0,0 @@ -// Copyright 2014 The Chromium OS Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <weave/error.h> - -#include <weave/commands.h> -#include <weave/enum_to_string.h> -#include <weave/export.h> - -#include "src/commands/schema_constants.h" - -namespace weave { - -namespace { - -const EnumToStringMap<UserRole>::Map kMap[] = { - {UserRole::kViewer, commands::attributes::kCommand_Role_Viewer}, - {UserRole::kUser, commands::attributes::kCommand_Role_User}, - {UserRole::kOwner, commands::attributes::kCommand_Role_Owner}, - {UserRole::kManager, commands::attributes::kCommand_Role_Manager}, -}; - -} // namespace - -template <> -LIBWEAVE_EXPORT EnumToStringMap<UserRole>::EnumToStringMap() - : EnumToStringMap(kMap) {} - -} // namespace weave