buffet: Change shared ownership of types/values to exclusive
In order to support array types in Buffet's type system, PropValue
must maintain a strong reference to the underlying PropType since
the array elements will have their own type reference and the current
implementation of using raw pointer for this isn't going to work.
In order to resolve this I had to make a lot of changes to the object
ownership inside Buffet's type system. I made it possible for both
PropType and PropValue to make a deep copy of itself using their
Clone() methods. Because of this now it is possible to have exclusive
ownership of objects and I got rid of most of shared pointer usage in
ObjectSchema, PropType and PropValue.
BUG=brillo:107
TEST=`FEATURES=test emerge-link buffet`
Change-Id: I02de455dfd40d4833041b63cbb80bcb00293b5a9
Reviewed-on: https://chromium-review.googlesource.com/261336
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/command_dictionary.h b/buffet/commands/command_dictionary.h
index d051c62..414d79a 100644
--- a/buffet/commands/command_dictionary.h
+++ b/buffet/commands/command_dictionary.h
@@ -13,6 +13,8 @@
#include <base/macros.h>
#include <chromeos/errors/error.h>
+#include "buffet/commands/command_definition.h"
+
namespace base {
class Value;
class DictionaryValue;
@@ -20,7 +22,6 @@
namespace buffet {
-class CommandDefinition;
class ObjectSchema;
// CommandDictionary is a wrapper around a map of command name and the
@@ -69,20 +70,19 @@
// Remove all the command definitions from the dictionary.
void Clear();
// Finds a definition for the given command.
- std::shared_ptr<const CommandDefinition> FindCommand(
- const std::string& command_name) const;
+ const CommandDefinition* FindCommand(const std::string& command_name) const;
private:
- std::shared_ptr<ObjectSchema> BuildObjectSchema(
+ using CommandMap =
+ std::map<std::string, std::unique_ptr<const CommandDefinition>>;
+
+ std::unique_ptr<ObjectSchema> BuildObjectSchema(
const base::DictionaryValue* command_def_json,
const char* property_name,
const ObjectSchema* base_def,
const std::string& command_name,
chromeos::ErrorPtr* error);
- using CommandMap = std::map<std::string,
- std::shared_ptr<const CommandDefinition>>;
-
CommandMap definitions_; // List of all available command definitions.
DISALLOW_COPY_AND_ASSIGN(CommandDictionary);
};