platform2: Move Error class from Buffet to libchromeos
Moved buffet::Error class and related facilities to
libchromeos and changed the namespace to 'chromeos::'.
Updated a bunch of code to include the header files
from the new location and referring to the new
namespace.
BUG=chromium:403604
TEST=USE=buffet ./build_packages
FEATURES=test emerge-link libchromeos
USE=buffet FEATURES=test emerge-link platform2
Change-Id: I0b5b37ccd7ee3b7be9467ebfae5d172d9b057cf6
Reviewed-on: https://chromium-review.googlesource.com/212525
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/buffet.gyp b/buffet/buffet.gyp
index 925afd9..6ec8c85 100644
--- a/buffet/buffet.gyp
+++ b/buffet/buffet.gyp
@@ -31,8 +31,6 @@
'dbus_constants.cc',
'dbus_utils.cc',
'device_registration_info.cc',
- 'error.cc',
- 'error_codes.cc',
'http_request.cc',
'http_connection_curl.cc',
'http_transport_curl.cc',
@@ -90,7 +88,6 @@
'commands/unittest_utils.cc',
'data_encoding_unittest.cc',
'device_registration_info_unittest.cc',
- 'error_unittest.cc',
'http_connection_fake.cc',
'http_transport_fake.cc',
'http_utils_unittest.cc',
diff --git a/buffet/commands/command_dictionary.cc b/buffet/commands/command_dictionary.cc
index e011a23..64f47c1 100644
--- a/buffet/commands/command_dictionary.cc
+++ b/buffet/commands/command_dictionary.cc
@@ -25,7 +25,7 @@
bool CommandDictionary::LoadCommands(const base::DictionaryValue& json,
const std::string& category,
const CommandDictionary* base_commands,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
std::map<std::string, std::shared_ptr<const CommandDefinition>> new_defs;
// |json| contains a list of nested objects with the following structure:
@@ -36,10 +36,10 @@
std::string package_name = package_iter.key();
const base::DictionaryValue* package_value = nullptr;
if (!package_iter.value().GetAsDictionary(&package_value)) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kTypeMismatch,
- "Expecting an object for package '%s'",
- package_name.c_str());
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kTypeMismatch,
+ "Expecting an object for package '%s'",
+ package_name.c_str());
return false;
}
// Iterate over command definitions within the current package.
@@ -47,18 +47,19 @@
while (!command_iter.IsAtEnd()) {
std::string command_name = command_iter.key();
if (command_name.empty()) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kInvalidCommandName,
- "Unnamed command encountered in package '%s'",
- package_name.c_str());
+ chromeos::Error::AddToPrintf(
+ error, errors::commands::kDomain,
+ errors::commands::kInvalidCommandName,
+ "Unnamed command encountered in package '%s'",
+ package_name.c_str());
return false;
}
const base::DictionaryValue* command_value = nullptr;
if (!command_iter.value().GetAsDictionary(&command_value)) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kTypeMismatch,
- "Expecting an object for command '%s'",
- command_name.c_str());
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kTypeMismatch,
+ "Expecting an object for command '%s'",
+ command_name.c_str());
return false;
}
// Construct the compound command name as "pkg_name.cmd_name".
@@ -69,11 +70,12 @@
const base::DictionaryValue* command_schema_def = nullptr;
if (!command_value->GetDictionaryWithoutPathExpansion(
commands::attributes::kCommand_Parameters, &command_schema_def)) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kPropertyMissing,
- "Command definition '%s' is missing property '%s'",
- full_command_name.c_str(),
- commands::attributes::kCommand_Parameters);
+ chromeos::Error::AddToPrintf(
+ error, errors::commands::kDomain,
+ errors::commands::kPropertyMissing,
+ "Command definition '%s' is missing property '%s'",
+ full_command_name.c_str(),
+ commands::attributes::kCommand_Parameters);
return false;
}
@@ -90,11 +92,12 @@
// this rule here.
if (!base_def) {
if (command_name.front() != '_') {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kInvalidCommandName,
- "The name of custom command '%s' in package '%s'"
- " must start with '_'",
- command_name.c_str(), package_name.c_str());
+ chromeos::Error::AddToPrintf(
+ error, errors::commands::kDomain,
+ errors::commands::kInvalidCommandName,
+ "The name of custom command '%s' in package '%s'"
+ " must start with '_'",
+ command_name.c_str(), package_name.c_str());
return false;
}
}
@@ -102,10 +105,10 @@
auto command_schema = std::make_shared<ObjectSchema>();
if (!command_schema->FromJson(command_schema_def, base_def, error)) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kInvalidObjectSchema,
- "Invalid definition for command '%s'",
- full_command_name.c_str());
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kInvalidObjectSchema,
+ "Invalid definition for command '%s'",
+ full_command_name.c_str());
return false;
}
auto command_def = std::make_shared<CommandDefinition>(category,
@@ -124,12 +127,12 @@
for (const auto& pair : new_defs) {
auto iter = definitions_.find(pair.first);
if (iter != definitions_.end()) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kDuplicateCommandDef,
- "Definition for command '%s' overrides an earlier "
- "definition in category '%s'",
- pair.first.c_str(),
- iter->second->GetCategory().c_str());
+ chromeos::Error::AddToPrintf(
+ error, errors::commands::kDomain,
+ errors::commands::kDuplicateCommandDef,
+ "Definition for command '%s' overrides an earlier "
+ "definition in category '%s'",
+ pair.first.c_str(), iter->second->GetCategory().c_str());
return false;
}
}
@@ -146,7 +149,7 @@
}
std::unique_ptr<base::DictionaryValue> CommandDictionary::GetCommandsAsJson(
- bool full_schema, ErrorPtr* error) const {
+ bool full_schema, chromeos::ErrorPtr* error) const {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
for (const auto& pair : definitions_) {
std::unique_ptr<base::DictionaryValue> definition =
diff --git a/buffet/commands/command_dictionary.h b/buffet/commands/command_dictionary.h
index b656684..10a4f9d 100644
--- a/buffet/commands/command_dictionary.h
+++ b/buffet/commands/command_dictionary.h
@@ -11,8 +11,7 @@
#include <vector>
#include <base/basictypes.h>
-
-#include "buffet/error.h"
+#include <chromeos/error.h>
namespace base {
class Value;
@@ -53,14 +52,15 @@
// when provided.
bool LoadCommands(const base::DictionaryValue& json,
const std::string& category,
- const CommandDictionary* base_commands, ErrorPtr* error);
+ const CommandDictionary* base_commands,
+ chromeos::ErrorPtr* error);
// Converts all the command definitions to a JSON object for CDD/Device
// draft. |full_schema| specifies whether full command definitions must
// be generated (true) for CDD or only overrides from the base schema (false).
// Returns empty unique_ptr in case of an error and fills in the additional
// error details in |error|.
std::unique_ptr<base::DictionaryValue> GetCommandsAsJson(
- bool full_schema, ErrorPtr* error) const;
+ bool full_schema, chromeos::ErrorPtr* error) const;
// Returns the number of command definitions in the dictionary.
size_t GetSize() const { return definitions_.size(); }
// Checks if the dictionary has no command definitions.
diff --git a/buffet/commands/command_dictionary_unittest.cc b/buffet/commands/command_dictionary_unittest.cc
index 30d185f..d4c4ab1 100644
--- a/buffet/commands/command_dictionary_unittest.cc
+++ b/buffet/commands/command_dictionary_unittest.cc
@@ -53,7 +53,7 @@
TEST(CommandDictionary, LoadCommands_Failures) {
buffet::CommandDictionary dict;
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
// Command definition missing 'parameters' property.
auto json = CreateDictionaryValue("{'robot':{'jump':{}}}");
@@ -97,7 +97,7 @@
TEST(CommandDictionary, LoadCommands_RedefineInDifferentCategory) {
// Redefine commands in different category.
buffet::CommandDictionary dict;
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
auto json = CreateDictionaryValue("{'robot':{'jump':{'parameters':{}}}}");
dict.LoadCommands(*json, "category1", nullptr, &error);
EXPECT_FALSE(dict.LoadCommands(*json, "category2", nullptr, &error));
@@ -111,7 +111,7 @@
// Custom command must start with '_'.
buffet::CommandDictionary base_dict;
buffet::CommandDictionary dict;
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
auto json = CreateDictionaryValue(R"({
'base': {
'reboot': {
@@ -137,7 +137,7 @@
// Redefine commands parameter type.
buffet::CommandDictionary base_dict;
buffet::CommandDictionary dict;
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
auto json = CreateDictionaryValue(R"({
'base': {
'reboot': {
diff --git a/buffet/commands/command_instance.cc b/buffet/commands/command_instance.cc
index 1e667fe..04b08ab 100644
--- a/buffet/commands/command_instance.cc
+++ b/buffet/commands/command_instance.cc
@@ -5,12 +5,13 @@
#include "buffet/commands/command_instance.h"
#include <base/values.h>
+#include <chromeos/error.h>
+#include <chromeos/error_codes.h>
#include "buffet/commands/command_definition.h"
#include "buffet/commands/command_dictionary.h"
#include "buffet/commands/schema_constants.h"
#include "buffet/commands/schema_utils.h"
-#include "buffet/error_codes.h"
namespace buffet {
@@ -40,7 +41,7 @@
bool GetCommandParameters(const base::DictionaryValue* json,
const CommandDefinition* command_def,
native_types::Object* parameters,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
// Get the command parameters from 'parameters' property.
base::DictionaryValue no_params; // Placeholder when no params are specified.
const base::DictionaryValue* params = nullptr;
@@ -49,10 +50,10 @@
¶ms_value)) {
// Make sure the "parameters" property is actually an object.
if (!params_value->GetAsDictionary(¶ms)) {
- Error::AddToPrintf(error, errors::json::kDomain,
- errors::json::kObjectExpected,
- "Property '%s' must be a JSON object",
- commands::attributes::kCommand_Parameters);
+ chromeos::Error::AddToPrintf(error, chromeos::errors::json::kDomain,
+ chromeos::errors::json::kObjectExpected,
+ "Property '%s' must be a JSON object",
+ commands::attributes::kCommand_Parameters);
return false;
}
} else {
@@ -74,13 +75,14 @@
std::unique_ptr<const CommandInstance> CommandInstance::FromJson(
const base::Value* value,
const CommandDictionary& dictionary,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
std::unique_ptr<const CommandInstance> instance;
// Get the command JSON object from the value.
const base::DictionaryValue* json = nullptr;
if (!value->GetAsDictionary(&json)) {
- Error::AddTo(error, errors::json::kDomain, errors::json::kObjectExpected,
- "Command instance is not a JSON object");
+ chromeos::Error::AddTo(error, chromeos::errors::json::kDomain,
+ chromeos::errors::json::kObjectExpected,
+ "Command instance is not a JSON object");
return instance;
}
@@ -88,25 +90,27 @@
std::string command_name;
if (!json->GetStringWithoutPathExpansion(commands::attributes::kCommand_Name,
&command_name)) {
- Error::AddTo(error, errors::commands::kDomain,
- errors::commands::kPropertyMissing,
- "Command name is missing");
+ chromeos::Error::AddTo(error, errors::commands::kDomain,
+ errors::commands::kPropertyMissing,
+ "Command name is missing");
return instance;
}
// Make sure we know how to handle the command with this name.
const CommandDefinition* command_def = dictionary.FindCommand(command_name);
if (!command_def) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kInvalidCommandName,
- "Unknown command received: %s", command_name.c_str());
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kInvalidCommandName,
+ "Unknown command received: %s",
+ command_name.c_str());
return instance;
}
native_types::Object parameters;
if (!GetCommandParameters(json, command_def, ¶meters, error)) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kCommandFailed,
- "Failed to validate command '%s'", command_name.c_str());
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kCommandFailed,
+ "Failed to validate command '%s'",
+ command_name.c_str());
return instance;
}
diff --git a/buffet/commands/command_instance.h b/buffet/commands/command_instance.h
index f5d259d..a901380 100644
--- a/buffet/commands/command_instance.h
+++ b/buffet/commands/command_instance.h
@@ -10,10 +10,10 @@
#include <string>
#include <base/basictypes.h>
+#include <chromeos/error.h>
#include "buffet/commands/prop_values.h"
#include "buffet/commands/schema_utils.h"
-#include "buffet/error.h"
namespace base {
class Value;
@@ -49,7 +49,7 @@
static std::unique_ptr<const CommandInstance> FromJson(
const base::Value* value,
const CommandDictionary& dictionary,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
private:
// Full command name as "<package_name>.<command_name>".
diff --git a/buffet/commands/command_instance_unittest.cc b/buffet/commands/command_instance_unittest.cc
index 3f81016..ace0738 100644
--- a/buffet/commands/command_instance_unittest.cc
+++ b/buffet/commands/command_instance_unittest.cc
@@ -104,7 +104,7 @@
TEST_F(CommandInstanceTest, FromJson_NotObject) {
auto json = CreateValue("'string'");
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
auto instance = buffet::CommandInstance::FromJson(json.get(), dict_, &error);
EXPECT_EQ(nullptr, instance.get());
EXPECT_EQ("json_object_expected", error->GetCode());
@@ -113,7 +113,7 @@
TEST_F(CommandInstanceTest, FromJson_NameMissing) {
auto json = CreateDictionaryValue("{'param': 'value'}");
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
auto instance = buffet::CommandInstance::FromJson(json.get(), dict_, &error);
EXPECT_EQ(nullptr, instance.get());
EXPECT_EQ("parameter_missing", error->GetCode());
@@ -122,7 +122,7 @@
TEST_F(CommandInstanceTest, FromJson_UnknownCommand) {
auto json = CreateDictionaryValue("{'name': 'robot.scream'}");
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
auto instance = buffet::CommandInstance::FromJson(json.get(), dict_, &error);
EXPECT_EQ(nullptr, instance.get());
EXPECT_EQ("invalid_command_name", error->GetCode());
@@ -134,7 +134,7 @@
'name': 'robot.speak',
'parameters': 'hello'
})");
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
auto instance = buffet::CommandInstance::FromJson(json.get(), dict_, &error);
EXPECT_EQ(nullptr, instance.get());
auto inner = error->GetInnerError();
@@ -152,7 +152,7 @@
'volume': 20
}
})");
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
auto instance = buffet::CommandInstance::FromJson(json.get(), dict_, &error);
EXPECT_EQ(nullptr, instance.get());
auto first = error->GetFirstError();
diff --git a/buffet/commands/command_manager.cc b/buffet/commands/command_manager.cc
index 8c54e51..6ba498e 100644
--- a/buffet/commands/command_manager.cc
+++ b/buffet/commands/command_manager.cc
@@ -8,9 +8,10 @@
#include <base/files/file_enumerator.h>
#include <base/json/json_reader.h>
#include <base/values.h>
+#include <chromeos/error.h>
+#include <chromeos/error_codes.h>
#include "buffet/commands/schema_constants.h"
-#include "buffet/error_codes.h"
namespace buffet {
@@ -19,12 +20,12 @@
}
bool CommandManager::LoadBaseCommands(const base::DictionaryValue& json,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
return base_dictionary_.LoadCommands(json, "", nullptr, error);
}
bool CommandManager::LoadBaseCommands(const base::FilePath& json_file_path,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
std::unique_ptr<const base::DictionaryValue> json = LoadJsonDict(
json_file_path, error);
if (!json)
@@ -34,12 +35,12 @@
bool CommandManager::LoadCommands(const base::DictionaryValue& json,
const std::string& category,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
return dictionary_.LoadCommands(json, category, &base_dictionary_, error);
}
bool CommandManager::LoadCommands(const base::FilePath& json_file_path,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
std::unique_ptr<const base::DictionaryValue> json = LoadJsonDict(
json_file_path, error);
if (!json)
@@ -71,31 +72,33 @@
}
std::unique_ptr<const base::DictionaryValue> CommandManager::LoadJsonDict(
- const base::FilePath& json_file_path, ErrorPtr* error) {
+ const base::FilePath& json_file_path, chromeos::ErrorPtr* error) {
std::string json_string;
if (!base::ReadFileToString(json_file_path, &json_string)) {
- Error::AddToPrintf(error, errors::file_system::kDomain,
- errors::file_system::kFileReadError,
- "Failed to read file '%s'",
- json_file_path.value().c_str());
+ chromeos::Error::AddToPrintf(error, chromeos::errors::file_system::kDomain,
+ chromeos::errors::file_system::kFileReadError,
+ "Failed to read file '%s'",
+ json_file_path.value().c_str());
return std::unique_ptr<const base::DictionaryValue>();
}
std::string error_message;
base::Value* value = base::JSONReader::ReadAndReturnError(
json_string, base::JSON_PARSE_RFC, nullptr, &error_message);
if (!value) {
- Error::AddToPrintf(error, errors::json::kDomain, errors::json::kParseError,
- "Error parsing content of JSON file '%s': %s",
- json_file_path.value().c_str(), error_message.c_str());
+ chromeos::Error::AddToPrintf(error, chromeos::errors::json::kDomain,
+ chromeos::errors::json::kParseError,
+ "Error parsing content of JSON file '%s': %s",
+ json_file_path.value().c_str(),
+ error_message.c_str());
return std::unique_ptr<const base::DictionaryValue>();
}
const base::DictionaryValue* dict_value = nullptr;
if (!value->GetAsDictionary(&dict_value)) {
delete value;
- Error::AddToPrintf(error, errors::json::kDomain,
- errors::json::kObjectExpected,
- "Content of file '%s' is not a JSON object",
- json_file_path.value().c_str());
+ chromeos::Error::AddToPrintf(error, chromeos::errors::json::kDomain,
+ chromeos::errors::json::kObjectExpected,
+ "Content of file '%s' is not a JSON object",
+ json_file_path.value().c_str());
return std::unique_ptr<const base::DictionaryValue>();
}
return std::unique_ptr<const base::DictionaryValue>(dict_value);
diff --git a/buffet/commands/command_manager.h b/buffet/commands/command_manager.h
index 1199892..d3f9a34 100644
--- a/buffet/commands/command_manager.h
+++ b/buffet/commands/command_manager.h
@@ -32,25 +32,26 @@
// On success, returns true. Otherwise, |error| contains additional
// error information.
bool LoadBaseCommands(const base::DictionaryValue& json,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
// Same as the overload above, but takes a path to a json file to read
// the base command definitions from.
bool LoadBaseCommands(const base::FilePath& json_file_path,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
// Loads device command schema for particular category.
// See CommandDictionary::LoadCommands for detailed description of the
// parameters.
bool LoadCommands(const base::DictionaryValue& json,
- const std::string& category, ErrorPtr* error);
+ const std::string& category,
+ chromeos::ErrorPtr* error);
// Same as the overload above, but takes a path to a json file to read
// the base command definitions from. Also, the command category is
// derived from file name (without extension). So, if the path points to
// "power_manager.json", the command category used will be "power_manager".
bool LoadCommands(const base::FilePath& json_file_path,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
// Startup method to be called by buffet daemon at startup.
// Initializes the object and loads the standard GCD command
@@ -63,7 +64,7 @@
// an object/dictionary. In case of error, returns empty unique ptr and fills
// in error details in |error|.
std::unique_ptr<const base::DictionaryValue> LoadJsonDict(
- const base::FilePath& json_file_path, ErrorPtr* error);
+ const base::FilePath& json_file_path, chromeos::ErrorPtr* error);
CommandDictionary base_dictionary_; // Base/std command definitions/schemas.
CommandDictionary dictionary_; // Command definitions/schemas.
diff --git a/buffet/commands/object_schema.cc b/buffet/commands/object_schema.cc
index 82d1e6e..b71b467 100644
--- a/buffet/commands/object_schema.cc
+++ b/buffet/commands/object_schema.cc
@@ -27,7 +27,7 @@
}
std::unique_ptr<base::DictionaryValue> ObjectSchema::ToJson(
- bool full_schema, ErrorPtr* error) const {
+ bool full_schema, chromeos::ErrorPtr* error) const {
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue);
for (const auto& pair : properties_) {
auto PropDef = pair.second->ToJson(full_schema, error);
@@ -40,7 +40,7 @@
bool ObjectSchema::FromJson(const base::DictionaryValue* value,
const ObjectSchema* object_schema,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
Properties properties;
base::DictionaryValue::Iterator iter(*value);
while (!iter.IsAtEnd()) {
@@ -58,26 +58,26 @@
static std::unique_ptr<PropType> CreatePropType(const std::string& type_name,
const std::string& prop_name,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
std::unique_ptr<PropType> prop;
ValueType type;
if (PropType::GetTypeFromTypeString(type_name, &type))
prop = PropType::Create(type);
if (!prop) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kUnknownType,
- "Unknown type %s for parameter %s",
- type_name.c_str(), prop_name.c_str());
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kUnknownType,
+ "Unknown type %s for parameter %s",
+ type_name.c_str(), prop_name.c_str());
}
return prop;
}
static bool ErrorInvalidTypeInfo(const std::string& prop_name,
- ErrorPtr* error) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kNoTypeInfo,
- "Unable to determine parameter type for %s",
- prop_name.c_str());
+ chromeos::ErrorPtr* error) {
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kNoTypeInfo,
+ "Unable to determine parameter type for %s",
+ prop_name.c_str());
return false;
}
@@ -85,7 +85,7 @@
const base::Value& value,
const PropType* base_schema,
Properties* properties,
- ErrorPtr* error) const {
+ chromeos::ErrorPtr* error) const {
if (value.IsType(base::Value::TYPE_STRING)) {
// A string value is a short-hand object specification and provides
// the parameter type.
@@ -100,9 +100,10 @@
return PropFromJsonObject(prop_name, value, base_schema, properties,
error);
}
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kInvalidPropDef,
- "Invalid parameter definition for %s", prop_name.c_str());
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kInvalidPropDef,
+ "Invalid parameter definition for %s",
+ prop_name.c_str());
return false;
}
@@ -110,7 +111,7 @@
const base::Value& value,
const PropType* base_schema,
Properties* properties,
- ErrorPtr* error) const {
+ chromeos::ErrorPtr* error) const {
std::string type_name;
CHECK(value.GetAsString(&type_name)) << "Unable to get string value";
std::unique_ptr<PropType> prop = CreatePropType(type_name, prop_name, error);
@@ -118,10 +119,10 @@
return false;
base::DictionaryValue empty;
if (!prop->FromJson(&empty, base_schema, error)) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kInvalidPropDef,
- "Error in definition of property '%s'",
- prop_name.c_str());
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kInvalidPropDef,
+ "Error in definition of property '%s'",
+ prop_name.c_str());
return false;
}
properties->insert(std::make_pair(prop_name, std::move(prop)));
@@ -165,7 +166,7 @@
const base::Value& value,
const PropType* base_schema,
Properties* properties,
- ErrorPtr* error) const {
+ chromeos::ErrorPtr* error) const {
const base::ListValue* list = nullptr;
CHECK(value.GetAsList(&list)) << "Unable to get array value";
std::string type_name = DetectArrayType(list, base_schema);
@@ -178,10 +179,10 @@
array_object.SetWithoutPathExpansion(commands::attributes::kOneOf_Enum,
list->DeepCopy());
if (!prop->FromJson(&array_object, base_schema, error)) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kInvalidPropDef,
- "Error in definition of property '%s'",
- prop_name.c_str());
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kInvalidPropDef,
+ "Error in definition of property '%s'",
+ prop_name.c_str());
return false;
}
properties->insert(std::make_pair(prop_name, std::move(prop)));
@@ -242,7 +243,7 @@
const base::Value& value,
const PropType* base_schema,
Properties* properties,
- ErrorPtr* error) const {
+ chromeos::ErrorPtr* error) const {
const base::DictionaryValue* dict = nullptr;
CHECK(value.GetAsDictionary(&dict)) << "Unable to get dictionary value";
std::string type_name;
@@ -261,10 +262,10 @@
if (!prop)
return false;
if (!prop->FromJson(dict, base_schema, error)) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kInvalidPropDef,
- "Error in definition of property '%s'",
- prop_name.c_str());
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kInvalidPropDef,
+ "Error in definition of property '%s'",
+ prop_name.c_str());
return false;
}
properties->insert(std::make_pair(prop_name, std::move(prop)));
diff --git a/buffet/commands/object_schema.h b/buffet/commands/object_schema.h
index d6f5069..d133b1a 100644
--- a/buffet/commands/object_schema.h
+++ b/buffet/commands/object_schema.h
@@ -9,7 +9,7 @@
#include <memory>
#include <string>
-#include "buffet/error.h"
+#include <chromeos/error.h>
namespace base {
class Value;
@@ -58,37 +58,40 @@
// Saves the object schema to JSON. When |full_schema| is set to true,
// then all properties and constraints are saved, otherwise, only
// the overridden (not inherited) ones are saved.
- std::unique_ptr<base::DictionaryValue> ToJson(bool full_schema,
- ErrorPtr* error) const;
+ std::unique_ptr<base::DictionaryValue> ToJson(
+ bool full_schema, chromeos::ErrorPtr* error) const;
// Loads the object schema from JSON. If |object_schema| is not nullptr, it is
// used as a base schema to inherit omitted properties and constraints from.
bool FromJson(const base::DictionaryValue* value,
- const ObjectSchema* object_schema, ErrorPtr* error);
+ const ObjectSchema* object_schema, chromeos::ErrorPtr* error);
private:
// Internal helper method to load individual parameter type definitions.
bool PropFromJson(const std::string& prop_name,
const base::Value& value,
const PropType* base_schema,
- Properties* properties, ErrorPtr* error) const;
+ Properties* properties, chromeos::ErrorPtr* error) const;
// Helper function in case the parameter is defined as JSON string like this:
// "prop":"..."
bool PropFromJsonString(const std::string& prop_name,
const base::Value& value,
const PropType* base_schema,
- Properties* properties, ErrorPtr* error) const;
+ Properties* properties,
+ chromeos::ErrorPtr* error) const;
// Helper function in case the parameter is defined as JSON array like this:
// "prop":[...]
bool PropFromJsonArray(const std::string& prop_name,
const base::Value& value,
const PropType* base_schema,
- Properties* properties, ErrorPtr* error) const;
+ Properties* properties,
+ chromeos::ErrorPtr* error) const;
// Helper function in case the parameter is defined as JSON object like this:
// "prop":{...}
bool PropFromJsonObject(const std::string& prop_name,
const base::Value& value,
const PropType* base_schema,
- Properties* properties, ErrorPtr* error) const;
+ Properties* properties,
+ chromeos::ErrorPtr* error) const;
// Internal parameter type definition map.
Properties properties_;
diff --git a/buffet/commands/object_schema_unittest.cc b/buffet/commands/object_schema_unittest.cc
index 6921b56..e2e32e1 100644
--- a/buffet/commands/object_schema_unittest.cc
+++ b/buffet/commands/object_schema_unittest.cc
@@ -95,7 +95,7 @@
TEST(CommandSchema, IntPropType_Validate) {
buffet::IntPropType prop;
prop.AddMinMaxConstraint(2, 4);
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
EXPECT_FALSE(prop.ValidateValue(CreateValue("-1").get(), &error));
EXPECT_EQ("out_of_range", error->GetCode());
error.reset();
@@ -172,7 +172,7 @@
buffet::BooleanPropType prop;
prop.FromJson(CreateDictionaryValue("{'enum':[true]}").get(), &prop,
nullptr);
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
EXPECT_FALSE(prop.ValidateValue(CreateValue("false").get(), &error));
EXPECT_EQ("out_of_range", error->GetCode());
error.reset();
@@ -262,7 +262,7 @@
TEST(CommandSchema, DoublePropType_Validate) {
buffet::DoublePropType prop;
prop.AddMinMaxConstraint(-1.2, 1.3);
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
EXPECT_FALSE(prop.ValidateValue(CreateValue("-2").get(), &error));
EXPECT_EQ("out_of_range", error->GetCode());
error.reset();
@@ -359,7 +359,7 @@
TEST(CommandSchema, StringPropType_Validate) {
buffet::StringPropType prop;
prop.AddLengthConstraint(1, 3);
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
EXPECT_FALSE(prop.ValidateValue(CreateValue("''").get(), &error));
EXPECT_EQ("out_of_range", error->GetCode());
error.reset();
@@ -450,7 +450,7 @@
"{'properties':{'expires':'integer',"
"'password':{'maxLength':100,'minLength':6}}}").get(), nullptr,
nullptr);
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
EXPECT_TRUE(prop.ValidateValue(CreateValue(
"{'expires':10,'password':'abcdef'}").get(), &error));
error.reset();
@@ -486,7 +486,7 @@
"{'properties':{'width':'integer','height':'integer'},"
"'enum':[{'width':10,'height':20},{'width':100,'height':200}]}").get(),
nullptr, nullptr));
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
EXPECT_TRUE(prop.ValidateValue(CreateValue(
"{'height':20,'width':10}").get(), &error));
error.reset();
@@ -790,7 +790,7 @@
TEST(CommandSchema, ObjectSchema_FromJson_BaseSchema_Failures) {
buffet::ObjectSchema schema;
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
const char* schema_str = "{"
"'param1':{}"
"}";
diff --git a/buffet/commands/prop_constraints.cc b/buffet/commands/prop_constraints.cc
index 97b524d..210b254 100644
--- a/buffet/commands/prop_constraints.cc
+++ b/buffet/commands/prop_constraints.cc
@@ -12,37 +12,42 @@
// Constraint ----------------------------------------------------------------
Constraint::~Constraint() {}
-bool Constraint::ReportErrorLessThan(
- ErrorPtr* error, const std::string& val, const std::string& limit) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kOutOfRange,
- "Value %s is out of range. It must not be less than %s",
- val.c_str(), limit.c_str());
+bool Constraint::ReportErrorLessThan(chromeos::ErrorPtr* error,
+ const std::string& val,
+ const std::string& limit) {
+ chromeos::Error::AddToPrintf(
+ error, errors::commands::kDomain,
+ errors::commands::kOutOfRange,
+ "Value %s is out of range. It must not be less than %s",
+ val.c_str(), limit.c_str());
return false;
}
-bool Constraint::ReportErrorGreaterThan(
- ErrorPtr* error, const std::string& val, const std::string& limit) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kOutOfRange,
- "Value %s is out of range. It must not be greater than %s",
- val.c_str(), limit.c_str());
+bool Constraint::ReportErrorGreaterThan(chromeos::ErrorPtr* error,
+ const std::string& val,
+ const std::string& limit) {
+ chromeos::Error::AddToPrintf(
+ error, errors::commands::kDomain,
+ errors::commands::kOutOfRange,
+ "Value %s is out of range. It must not be greater than %s",
+ val.c_str(), limit.c_str());
return false;
}
-bool Constraint::ReportErrorNotOneOf(
- ErrorPtr* error, const std::string& val,
- const std::vector<std::string>& values) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kOutOfRange,
- "Value %s is invalid. Expected one of [%s]",
- val.c_str(), string_utils::Join(',', values).c_str());
+bool Constraint::ReportErrorNotOneOf(chromeos::ErrorPtr* error,
+ const std::string& val,
+ const std::vector<std::string>& values) {
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kOutOfRange,
+ "Value %s is invalid. Expected one of [%s]",
+ val.c_str(),
+ string_utils::Join(',', values).c_str());
return false;
}
bool Constraint::AddToJsonDict(base::DictionaryValue* dict,
bool overridden_only,
- ErrorPtr* error) const {
+ chromeos::ErrorPtr* error) const {
if (!overridden_only || HasOverriddenAttributes()) {
auto value = ToJson(error);
if (!value)
@@ -62,7 +67,7 @@
}
std::unique_ptr<base::Value> ConstraintStringLength::ToJson(
- ErrorPtr* error) const {
+ chromeos::ErrorPtr* error) const {
return TypedValueToJson(limit_.value, error);
}
@@ -73,20 +78,21 @@
: ConstraintStringLength(limit) {}
bool ConstraintStringLengthMin::Validate(const PropValue& value,
- ErrorPtr* error) const {
+ chromeos::ErrorPtr* error) const {
CHECK(value.GetString()) << "Expecting a string value for this constraint";
const std::string& str = value.GetString()->GetValue();
int length = static_cast<int>(str.size());
if (length < limit_.value) {
if (limit_.value == 1) {
- Error::AddTo(error, errors::commands::kDomain,
- errors::commands::kOutOfRange, "String must not be empty");
+ chromeos::Error::AddTo(error, errors::commands::kDomain,
+ errors::commands::kOutOfRange,
+ "String must not be empty");
} else {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kOutOfRange,
- "String must be at least %d characters long, "
- "actual length of string '%s' is %d", limit_.value,
- str.c_str(), length);
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kOutOfRange,
+ "String must be at least %d characters long,"
+ " actual length of string '%s' is %d",
+ limit_.value, str.c_str(), length);
}
return false;
}
@@ -105,16 +111,16 @@
: ConstraintStringLength(limit) {}
bool ConstraintStringLengthMax::Validate(const PropValue& value,
- ErrorPtr* error) const {
+ chromeos::ErrorPtr* error) const {
CHECK(value.GetString()) << "Expecting a string value for this constraint";
const std::string& str = value.GetString()->GetValue();
int length = static_cast<int>(str.size());
if (length > limit_.value) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kOutOfRange,
- "String must be no more than %d character(s) long, "
- "actual length of string '%s' is %d", limit_.value,
- str.c_str(), length);
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kOutOfRange,
+ "String must be no more than %d character(s) "
+ "long, actual length of string '%s' is %d",
+ limit_.value, str.c_str(), length);
return false;
}
return true;
diff --git a/buffet/commands/prop_constraints.h b/buffet/commands/prop_constraints.h
index cd35d65..3aa6e8e 100644
--- a/buffet/commands/prop_constraints.h
+++ b/buffet/commands/prop_constraints.h
@@ -11,11 +11,11 @@
#include <base/basictypes.h>
#include <base/values.h>
+#include <chromeos/error.h>
#include "buffet/commands/prop_values.h"
#include "buffet/commands/schema_constants.h"
#include "buffet/commands/schema_utils.h"
-#include "buffet/error.h"
#include "buffet/string_utils.h"
namespace buffet {
@@ -46,7 +46,8 @@
// Validates a parameter against the constraint. Returns true if parameter
// value satisfies the constraint, otherwise fills the optional |error| with
// the details for the failure.
- virtual bool Validate(const PropValue& value, ErrorPtr* error) const = 0;
+ virtual bool Validate(const PropValue& value,
+ chromeos::ErrorPtr* error) const = 0;
// Makes a copy of the constraint object, marking all the attributes
// as inherited from the original definition.
virtual std::shared_ptr<Constraint> CloneAsInherited() const = 0;
@@ -54,13 +55,14 @@
// the object schema. If |overridden_only| is set to true, then the
// inherited constraints will not be added to the schema object.
virtual bool AddToJsonDict(base::DictionaryValue* dict, bool overridden_only,
- ErrorPtr* error) const;
+ chromeos::ErrorPtr* error) const;
// Saves the value of constraint to JSON value. E.g., if the numeric
// constraint was defined as {"minimum":20} this will create a JSON value
// of 20. The current design implies that each constraint has one value
// only. If this assumption changes, this interface needs to be updated
// accordingly.
- virtual std::unique_ptr<base::Value> ToJson(ErrorPtr* error) const = 0;
+ virtual std::unique_ptr<base::Value> ToJson(
+ chromeos::ErrorPtr* error) const = 0;
// Overloaded by the concrete class implementation, it should return the
// JSON object property name to store the constraint's value as.
// E.g., if the numeric constraint was defined as {"minimum":20} this
@@ -73,12 +75,15 @@
// Since these functions could be used by constraint objects for various
// data types, the values used in validation are expected to be
// send as strings already.
- static bool ReportErrorLessThan(ErrorPtr* error, const std::string& val,
+ static bool ReportErrorLessThan(chromeos::ErrorPtr* error,
+ const std::string& val,
const std::string& limit);
- static bool ReportErrorGreaterThan(ErrorPtr* error, const std::string& val,
+ static bool ReportErrorGreaterThan(chromeos::ErrorPtr* error,
+ const std::string& val,
const std::string& limit);
- static bool ReportErrorNotOneOf(ErrorPtr* error, const std::string& val,
+ static bool ReportErrorNotOneOf(chromeos::ErrorPtr* error,
+ const std::string& val,
const std::vector<std::string>& values);
private:
@@ -101,7 +106,8 @@
}
// Implementation of Constraint::ToJson().
- std::unique_ptr<base::Value> ToJson(ErrorPtr* error) const override {
+ std::unique_ptr<base::Value> ToJson(
+ chromeos::ErrorPtr* error) const override {
return TypedValueToJson(limit_.value, error);
}
@@ -127,7 +133,8 @@
ConstraintType GetType() const { return ConstraintType::Min; }
// Implementation of Constraint::Validate().
- bool Validate(const PropValue& value, ErrorPtr* error) const override {
+ bool Validate(const PropValue& value,
+ chromeos::ErrorPtr* error) const override {
T v = value.GetValueAsAny().Get<T>();
if (v < this->limit_.value)
return this->ReportErrorLessThan(
@@ -163,7 +170,8 @@
ConstraintType GetType() const { return ConstraintType::Max; }
// Implementation of Constraint::Validate().
- bool Validate(const PropValue& value, ErrorPtr* error) const override {
+ bool Validate(const PropValue& value,
+ chromeos::ErrorPtr* error) const override {
T v = value.GetValueAsAny().Get<T>();
if (v > this->limit_.value)
return this->ReportErrorGreaterThan(
@@ -196,7 +204,7 @@
// Implementation of Constraint::HasOverriddenAttributes().
bool HasOverriddenAttributes() const override;
// Implementation of Constraint::ToJson().
- std::unique_ptr<base::Value> ToJson(ErrorPtr* error) const override;
+ std::unique_ptr<base::Value> ToJson(chromeos::ErrorPtr* error) const override;
// Stores the upper/lower value limit for string length constraint.
// |limit_.is_inherited| indicates whether the constraint is inherited
@@ -217,7 +225,8 @@
return ConstraintType::StringLengthMin;
}
// Implementation of Constraint::Validate().
- bool Validate(const PropValue& value, ErrorPtr* error) const override;
+ bool Validate(const PropValue& value,
+ chromeos::ErrorPtr* error) const override;
// Implementation of Constraint::CloneAsInherited().
std::shared_ptr<Constraint> CloneAsInherited() const override;
// Implementation of Constraint::GetDictKey().
@@ -238,7 +247,8 @@
return ConstraintType::StringLengthMax;
}
// Implementation of Constraint::Validate().
- bool Validate(const PropValue& value, ErrorPtr* error) const override;
+ bool Validate(const PropValue& value,
+ chromeos::ErrorPtr* error) const override;
// Implementation of Constraint::CloneAsInherited().
std::shared_ptr<Constraint> CloneAsInherited() const override;
// Implementation of Constraint::GetDictKey().
@@ -270,7 +280,8 @@
}
// Implementation of Constraint::Validate().
- bool Validate(const PropValue& value, ErrorPtr* error) const override {
+ bool Validate(const PropValue& value,
+ chromeos::ErrorPtr* error) const override {
using string_utils::ToString;
T v = value.GetValueAsAny().Get<T>();
for (const auto& item : set_.value) {
@@ -291,7 +302,8 @@
}
// Implementation of Constraint::ToJson().
- std::unique_ptr<base::Value> ToJson(ErrorPtr* error) const override {
+ std::unique_ptr<base::Value> ToJson(
+ chromeos::ErrorPtr* error) const override {
return TypedValueToJson(set_.value, error);
}
diff --git a/buffet/commands/prop_types.cc b/buffet/commands/prop_types.cc
index f32ff2c..a3d7d6c 100644
--- a/buffet/commands/prop_types.cc
+++ b/buffet/commands/prop_types.cc
@@ -39,7 +39,7 @@
}
std::unique_ptr<base::Value> PropType::ToJson(bool full_schema,
- ErrorPtr* error) const {
+ chromeos::ErrorPtr* error) const {
if (!full_schema && !HasOverriddenAttributes()) {
if (based_on_schema_)
return std::unique_ptr<base::Value>(new base::DictionaryValue);
@@ -82,13 +82,14 @@
}
bool PropType::FromJson(const base::DictionaryValue* value,
- const PropType* base_schema, ErrorPtr* error) {
+ const PropType* base_schema,
+ chromeos::ErrorPtr* error) {
if (base_schema && base_schema->GetType() != GetType()) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kPropTypeChanged,
- "Redefining a property of type %s as %s",
- base_schema->GetTypeAsString().c_str(),
- GetTypeAsString().c_str());
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kPropTypeChanged,
+ "Redefining a property of type %s as %s",
+ base_schema->GetTypeAsString().c_str(),
+ GetTypeAsString().c_str());
return false;
}
based_on_schema_ = (base_schema != nullptr);
@@ -111,9 +112,9 @@
while (!iter.IsAtEnd()) {
std::string key = iter.key();
if (processed_keys.find(key) == processed_keys.end()) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kUnknownProperty,
- "Unexpected property '%s'", key.c_str());
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kUnknownProperty,
+ "Unexpected property '%s'", key.c_str());
return false;
}
iter.Advance();
@@ -141,14 +142,15 @@
return p != constraints_.end() ? p->second.get() : nullptr;
}
-bool PropType::ValidateValue(const base::Value* value, ErrorPtr* error) const {
+bool PropType::ValidateValue(const base::Value* value,
+ chromeos::ErrorPtr* error) const {
std::shared_ptr<PropValue> val = CreateValue();
CHECK(val) << "Failed to create value object";
return val->FromJson(value, error) && ValidateConstraints(*val, error);
}
bool PropType::ValidateConstraints(const PropValue& value,
- ErrorPtr* error) const {
+ chromeos::ErrorPtr* error) const {
for (const auto& pair : constraints_) {
if (!pair.second->Validate(value, error))
return false;
@@ -211,12 +213,13 @@
template<typename T>
static std::shared_ptr<Constraint> LoadOneOfConstraint(
const base::DictionaryValue* value, const ObjectSchema* object_schema,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
const base::ListValue* list = nullptr;
if (!value->GetListWithoutPathExpansion(commands::attributes::kOneOf_Enum,
&list)) {
- Error::AddTo(error, errors::commands::kDomain,
- errors::commands::kTypeMismatch, "Expecting an array");
+ chromeos::Error::AddTo(error, errors::commands::kDomain,
+ errors::commands::kTypeMismatch,
+ "Expecting an array");
return std::shared_ptr<Constraint>();
}
std::vector<T> set;
@@ -234,7 +237,7 @@
template<class ConstraintClass, typename T>
static std::shared_ptr<Constraint> LoadMinMaxConstraint(
const char* dict_key, const base::DictionaryValue* value,
- const ObjectSchema* object_schema, ErrorPtr* error) {
+ const ObjectSchema* object_schema, chromeos::ErrorPtr* error) {
InheritableAttribute<T> limit;
const base::Value* src_val = nullptr;
@@ -251,7 +254,7 @@
template<class Derived, class Value, typename T>
bool PropTypeBase<Derived, Value, T>::ConstraintsFromJson(
const base::DictionaryValue* value, std::set<std::string>* processed_keys,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
if (!PropType::ConstraintsFromJson(value, processed_keys, error))
return false;
@@ -274,7 +277,7 @@
template<class Derived, class Value, typename T>
bool NumericPropTypeBase<Derived, Value, T>::ConstraintsFromJson(
const base::DictionaryValue* value, std::set<std::string>* processed_keys,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
if (!_Base::ConstraintsFromJson(value, processed_keys, error))
return false;
@@ -311,7 +314,7 @@
bool StringPropType::ConstraintsFromJson(
const base::DictionaryValue* value, std::set<std::string>* processed_keys,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
if (!_Base::ConstraintsFromJson(value, processed_keys, error))
return false;
@@ -372,8 +375,8 @@
!object_schema_.is_inherited;
}
-std::unique_ptr<base::Value> ObjectPropType::ToJson(bool full_schema,
- ErrorPtr* error) const {
+std::unique_ptr<base::Value> ObjectPropType::ToJson(
+ bool full_schema, chromeos::ErrorPtr* error) const {
std::unique_ptr<base::Value> value = PropType::ToJson(full_schema, error);
if (value) {
base::DictionaryValue* dict = nullptr;
@@ -393,7 +396,7 @@
bool ObjectPropType::ObjectSchemaFromJson(
const base::DictionaryValue* value, const PropType* base_schema,
- std::set<std::string>* processed_keys, ErrorPtr* error) {
+ std::set<std::string>* processed_keys, chromeos::ErrorPtr* error) {
if (!_Base::ObjectSchemaFromJson(value, base_schema, processed_keys, error))
return false;
@@ -408,9 +411,9 @@
processed_keys->insert(kObject_Properties);
auto object_schema = std::make_shared<ObjectSchema>();
if (!object_schema->FromJson(props, base_object_schema.get(), error)) {
- Error::AddTo(error, errors::commands::kDomain,
- errors::commands::kInvalidObjectSchema,
- "Error parsing object property schema");
+ chromeos::Error::AddTo(error, errors::commands::kDomain,
+ errors::commands::kInvalidObjectSchema,
+ "Error parsing object property schema");
return false;
}
object_schema_.value = object_schema;
@@ -419,10 +422,11 @@
object_schema_.value = base_object_schema;
object_schema_.is_inherited = true;
} else {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kInvalidObjectSchema,
- "Object type definition must include the object schema "
- "('%s' field not found)", kObject_Properties);
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kInvalidObjectSchema,
+ "Object type definition must include the "
+ "object schema ('%s' field not found)",
+ kObject_Properties);
return false;
}
diff --git a/buffet/commands/prop_types.h b/buffet/commands/prop_types.h
index f7cd5a1..7f2b2e6 100644
--- a/buffet/commands/prop_types.h
+++ b/buffet/commands/prop_types.h
@@ -13,9 +13,10 @@
#include <utility>
#include <vector>
+#include <chromeos/error.h>
+
#include "buffet/commands/prop_constraints.h"
#include "buffet/commands/prop_values.h"
-#include "buffet/error.h"
namespace buffet {
@@ -90,7 +91,7 @@
// If it fails, returns "nullptr" and fills in the |error| with additional
// error information.
virtual std::unique_ptr<base::Value> ToJson(bool full_schema,
- ErrorPtr* error) const;
+ chromeos::ErrorPtr* error) const;
// Parses an JSON parameter type definition. Optional |base_schema| may
// specify the base schema type definition this type should be based upon.
// If not specified (nullptr), the parameter type is assumed to be a full
@@ -98,18 +99,18 @@
// Returns true on success, otherwise fills in the |error| with additional
// error information.
virtual bool FromJson(const base::DictionaryValue* value,
- const PropType* base_schema, ErrorPtr* error);
+ const PropType* base_schema, chromeos::ErrorPtr* error);
// Helper function to load object schema from JSON.
virtual bool ObjectSchemaFromJson(const base::DictionaryValue* value,
const PropType* base_schema,
std::set<std::string>* processed_keys,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
return true;
}
// Helper function to load type-specific constraints from JSON.
virtual bool ConstraintsFromJson(const base::DictionaryValue* value,
std::set<std::string>* processed_keys,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
return true;
}
@@ -118,7 +119,7 @@
// Returns false if the |value| does not meet the requirements of the type
// definition and returns additional information about the failure via
// the |error| parameter.
- bool ValidateValue(const base::Value* value, ErrorPtr* error) const;
+ bool ValidateValue(const base::Value* value, chromeos::ErrorPtr* error) const;
// Additional helper static methods to help with converting a type enum
// value into a string and back.
@@ -153,7 +154,8 @@
}
// Validates the given value against all the constraints.
- bool ValidateConstraints(const PropValue& value, ErrorPtr* error) const;
+ bool ValidateConstraints(const PropValue& value,
+ chromeos::ErrorPtr* error) const;
protected:
// Specifies if this parameter definition is derived from a base
@@ -188,7 +190,7 @@
}
bool ConstraintsFromJson(const base::DictionaryValue* value,
std::set<std::string>* processed_keys,
- ErrorPtr* error) override;
+ chromeos::ErrorPtr* error) override;
// Helper method to obtain a vector of OneOf constraint values.
std::vector<T> GetOneOfValues() const {
@@ -205,7 +207,7 @@
using _Base = PropTypeBase<Derived, Value, T>;
bool ConstraintsFromJson(const base::DictionaryValue* value,
std::set<std::string>* processed_keys,
- ErrorPtr* error) override;
+ chromeos::ErrorPtr* error) override;
// Helper method to set and obtain a min/max constraint values.
// Used mostly for unit testing.
@@ -255,7 +257,7 @@
bool ConstraintsFromJson(const base::DictionaryValue* value,
std::set<std::string>* processed_keys,
- ErrorPtr* error) override;
+ chromeos::ErrorPtr* error) override;
// Helper methods to add and inspect simple constraints.
// Used mostly for unit testing.
@@ -287,11 +289,11 @@
ObjectPropType const* GetObject() const override { return this; }
std::unique_ptr<base::Value> ToJson(bool full_schema,
- ErrorPtr* error) const override;
+ chromeos::ErrorPtr* error) const override;
bool ObjectSchemaFromJson(const base::DictionaryValue* value,
const PropType* base_schema,
std::set<std::string>* processed_keys,
- ErrorPtr* error) override;
+ chromeos::ErrorPtr* error) override;
std::shared_ptr<const ObjectSchema> GetObjectSchema() const override {
return object_schema_.value;
diff --git a/buffet/commands/prop_values.h b/buffet/commands/prop_values.h
index b408f0d..f568dd8 100644
--- a/buffet/commands/prop_values.h
+++ b/buffet/commands/prop_values.h
@@ -9,9 +9,10 @@
#include <memory>
#include <string>
+#include <chromeos/error.h>
+
#include "buffet/any.h"
#include "buffet/commands/schema_utils.h"
-#include "buffet/error.h"
namespace base {
class Value;
@@ -93,12 +94,13 @@
// Saves the value as a JSON object.
// If it fails, returns nullptr value and fills in the details for the
// failure in the |error| parameter.
- virtual std::unique_ptr<base::Value> ToJson(ErrorPtr* error) const = 0;
+ virtual std::unique_ptr<base::Value> ToJson(
+ chromeos::ErrorPtr* error) const = 0;
// Parses a value from JSON.
// If it fails, it returns false and provides additional information
// via the |error| parameter.
virtual bool FromJson(const base::Value* value,
- ErrorPtr* error) = 0;
+ chromeos::ErrorPtr* error) = 0;
// Returns the contained C++ value as Any.
virtual Any GetValueAsAny() const = 0;
@@ -129,12 +131,12 @@
return std::make_shared<Derived>(*static_cast<const Derived*>(this));
}
- std::unique_ptr<base::Value> ToJson(ErrorPtr* error) const override {
+ std::unique_ptr<base::Value> ToJson(
+ chromeos::ErrorPtr* error) const override {
return TypedValueToJson(value_, error);
}
- bool FromJson(const base::Value* value,
- ErrorPtr* error) override {
+ bool FromJson(const base::Value* value, chromeos::ErrorPtr* error) override {
return TypedValueFromJson(value, GetPropType()->GetObjectSchemaPtr(),
&value_, error);
}
diff --git a/buffet/commands/schema_utils.cc b/buffet/commands/schema_utils.cc
index cef5030..08b00cb 100644
--- a/buffet/commands/schema_utils.cc
+++ b/buffet/commands/schema_utils.cc
@@ -19,54 +19,58 @@
// Helper function to report "type mismatch" errors when parsing JSON.
void ReportJsonTypeMismatch(const base::Value* value_in,
const std::string& expected_type,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
std::string value_as_string;
base::JSONWriter::Write(value_in, &value_as_string);
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kTypeMismatch,
- "Unable to convert value %s into %s",
- value_as_string.c_str(), expected_type.c_str());
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kTypeMismatch,
+ "Unable to convert value %s into %s",
+ value_as_string.c_str(), expected_type.c_str());
}
// Template version of ReportJsonTypeMismatch that deduces the type of expected
// data from the value_out parameter passed to particular overload of
// TypedValueFromJson() function. Always returns false.
template<typename T>
-bool ReportUnexpectedJson(const base::Value* value_in, T*, ErrorPtr* error) {
+bool ReportUnexpectedJson(const base::Value* value_in, T*,
+ chromeos::ErrorPtr* error) {
ReportJsonTypeMismatch(value_in,
PropType::GetTypeStringFromType(GetValueType<T>()),
error);
return false;
}
-bool ErrorMissingProperty(ErrorPtr* error, const char* param_name) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kPropertyMissing,
- "Required parameter missing: %s", param_name);
+bool ErrorMissingProperty(chromeos::ErrorPtr* error, const char* param_name) {
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kPropertyMissing,
+ "Required parameter missing: %s", param_name);
return false;
}
} // namespace
// Specializations of TypedValueToJson<T>() for supported C++ types.
-std::unique_ptr<base::Value> TypedValueToJson(bool value, ErrorPtr* error) {
+std::unique_ptr<base::Value> TypedValueToJson(bool value,
+ chromeos::ErrorPtr* error) {
return std::unique_ptr<base::Value>(base::Value::CreateBooleanValue(value));
}
-std::unique_ptr<base::Value> TypedValueToJson(int value, ErrorPtr* error) {
+std::unique_ptr<base::Value> TypedValueToJson(int value,
+ chromeos::ErrorPtr* error) {
return std::unique_ptr<base::Value>(base::Value::CreateIntegerValue(value));
}
-std::unique_ptr<base::Value> TypedValueToJson(double value, ErrorPtr* error) {
+std::unique_ptr<base::Value> TypedValueToJson(double value,
+ chromeos::ErrorPtr* error) {
return std::unique_ptr<base::Value>(base::Value::CreateDoubleValue(value));
}
std::unique_ptr<base::Value> TypedValueToJson(const std::string& value,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
return std::unique_ptr<base::Value>(base::Value::CreateStringValue(value));
}
std::unique_ptr<base::Value> TypedValueToJson(const native_types::Object& value,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
for (const auto& pair : value) {
auto prop_value = pair.second->ToJson(error);
@@ -79,35 +83,36 @@
bool TypedValueFromJson(const base::Value* value_in,
const ObjectSchema* object_schema,
- bool* value_out, ErrorPtr* error) {
+ bool* value_out, chromeos::ErrorPtr* error) {
return value_in->GetAsBoolean(value_out) ||
ReportUnexpectedJson(value_in, value_out, error);
}
bool TypedValueFromJson(const base::Value* value_in,
const ObjectSchema* object_schema,
- int* value_out, ErrorPtr* error) {
+ int* value_out, chromeos::ErrorPtr* error) {
return value_in->GetAsInteger(value_out) ||
ReportUnexpectedJson(value_in, value_out, error);
}
bool TypedValueFromJson(const base::Value* value_in,
const ObjectSchema* object_schema,
- double* value_out, ErrorPtr* error) {
+ double* value_out, chromeos::ErrorPtr* error) {
return value_in->GetAsDouble(value_out) ||
ReportUnexpectedJson(value_in, value_out, error);
}
bool TypedValueFromJson(const base::Value* value_in,
const ObjectSchema* object_schema,
- std::string* value_out, ErrorPtr* error) {
+ std::string* value_out, chromeos::ErrorPtr* error) {
return value_in->GetAsString(value_out) ||
ReportUnexpectedJson(value_in, value_out, error);
}
bool TypedValueFromJson(const base::Value* value_in,
const ObjectSchema* object_schema,
- native_types::Object* value_out, ErrorPtr* error) {
+ native_types::Object* value_out,
+ chromeos::ErrorPtr* error) {
const base::DictionaryValue* dict = nullptr;
if (!value_in->GetAsDictionary(&dict))
return ReportUnexpectedJson(value_in, value_out, error);
@@ -142,9 +147,9 @@
std::string key = iter.key();
if (keys_processed.find(key) == keys_processed.end() &&
!object_schema->GetExtraPropertiesAllowed()) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kUnknownProperty,
- "Unrecognized parameter '%s'", key.c_str());
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kUnknownProperty,
+ "Unrecognized parameter '%s'", key.c_str());
return false;
}
iter.Advance();
@@ -155,10 +160,10 @@
const PropType* prop_type = pair.second->GetPropType();
CHECK(prop_type) << "Value property type must be available";
if (!prop_type->ValidateConstraints(*pair.second, error)) {
- Error::AddToPrintf(error, errors::commands::kDomain,
- errors::commands::kInvalidPropValue,
- "Invalid parameter value for property '%s'",
- pair.first.c_str());
+ chromeos::Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kInvalidPropValue,
+ "Invalid parameter value for property '%s'",
+ pair.first.c_str());
return false;
}
}
diff --git a/buffet/commands/schema_utils.h b/buffet/commands/schema_utils.h
index 0f89e27..16627af 100644
--- a/buffet/commands/schema_utils.h
+++ b/buffet/commands/schema_utils.h
@@ -13,8 +13,7 @@
#include <vector>
#include <base/values.h>
-
-#include <buffet/error.h>
+#include <chromeos/error.h>
namespace buffet {
@@ -48,16 +47,19 @@
// A bunch of helper function to create base::Value for specific C++ classes,
// including vectors of types. These are used in template classes below
// to simplify specialization logic.
-std::unique_ptr<base::Value> TypedValueToJson(bool value, ErrorPtr* error);
-std::unique_ptr<base::Value> TypedValueToJson(int value, ErrorPtr* error);
-std::unique_ptr<base::Value> TypedValueToJson(double value, ErrorPtr* error);
+std::unique_ptr<base::Value> TypedValueToJson(bool value,
+ chromeos::ErrorPtr* error);
+std::unique_ptr<base::Value> TypedValueToJson(int value,
+ chromeos::ErrorPtr* error);
+std::unique_ptr<base::Value> TypedValueToJson(double value,
+ chromeos::ErrorPtr* error);
std::unique_ptr<base::Value> TypedValueToJson(const std::string& value,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
std::unique_ptr<base::Value> TypedValueToJson(const native_types::Object& value,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
template<typename T>
std::unique_ptr<base::Value> TypedValueToJson(const std::vector<T>& values,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
std::unique_ptr<base::ListValue> list(new base::ListValue);
for (const auto& v : values) {
auto json = TypedValueToJson(v, error);
@@ -73,19 +75,20 @@
// Also used in template classes below to simplify specialization logic.
bool TypedValueFromJson(const base::Value* value_in,
const ObjectSchema* object_schema,
- bool* value_out, ErrorPtr* error);
+ bool* value_out, chromeos::ErrorPtr* error);
bool TypedValueFromJson(const base::Value* value_in,
const ObjectSchema* object_schema,
- int* value_out, ErrorPtr* error);
+ int* value_out, chromeos::ErrorPtr* error);
bool TypedValueFromJson(const base::Value* value_in,
const ObjectSchema* object_schema,
- double* value_out, ErrorPtr* error);
+ double* value_out, chromeos::ErrorPtr* error);
bool TypedValueFromJson(const base::Value* value_in,
const ObjectSchema* object_schema,
- std::string* value_out, ErrorPtr* error);
+ std::string* value_out, chromeos::ErrorPtr* error);
bool TypedValueFromJson(const base::Value* value_in,
const ObjectSchema* object_schema,
- native_types::Object* value_out, ErrorPtr* error);
+ native_types::Object* value_out,
+ chromeos::ErrorPtr* error);
bool operator==(const native_types::Object& obj1,
const native_types::Object& obj2);
diff --git a/buffet/commands/schema_utils_unittest.cc b/buffet/commands/schema_utils_unittest.cc
index e20532d..1a92d7f 100644
--- a/buffet/commands/schema_utils_unittest.cc
+++ b/buffet/commands/schema_utils_unittest.cc
@@ -73,7 +73,7 @@
&value, nullptr));
EXPECT_FALSE(value);
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
EXPECT_FALSE(buffet::TypedValueFromJson(CreateValue("0").get(), nullptr,
&value, &error));
EXPECT_EQ("type_mismatch", error->GetCode());
@@ -95,7 +95,7 @@
&value, nullptr));
EXPECT_EQ(-1234, value);
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
EXPECT_FALSE(buffet::TypedValueFromJson(CreateValue("'abc'").get(), nullptr,
&value, &error));
EXPECT_EQ("type_mismatch", error->GetCode());
@@ -123,7 +123,7 @@
nullptr, &value, nullptr));
EXPECT_EQ(-123.0, value);
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
EXPECT_FALSE(buffet::TypedValueFromJson(CreateValue("'abc'").get(), nullptr,
&value, &error));
EXPECT_EQ("type_mismatch", error->GetCode());
@@ -145,7 +145,7 @@
&value, nullptr));
EXPECT_EQ("abc", value);
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
EXPECT_FALSE(buffet::TypedValueFromJson(CreateValue("12").get(), nullptr,
&value, &error));
EXPECT_EQ("type_mismatch", error->GetCode());
@@ -172,7 +172,7 @@
name_prop->CreateValue(std::string("Bob"))));
EXPECT_EQ(value2, value);
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
EXPECT_FALSE(buffet::TypedValueFromJson(CreateValue("'abc'").get(), nullptr,
&value, &error));
EXPECT_EQ("type_mismatch", error->GetCode());
diff --git a/buffet/dbus_utils.cc b/buffet/dbus_utils.cc
index 099abc1..ecb2f74 100644
--- a/buffet/dbus_utils.cc
+++ b/buffet/dbus_utils.cc
@@ -32,7 +32,7 @@
} // namespace
scoped_ptr<dbus::Response> GetDBusError(dbus::MethodCall* method_call,
- const Error* error) {
+ const chromeos::Error* error) {
std::string message;
while (error) {
// Format error string as "domain/code:message".
diff --git a/buffet/dbus_utils.h b/buffet/dbus_utils.h
index ed4a76c..9a2851c 100644
--- a/buffet/dbus_utils.h
+++ b/buffet/dbus_utils.h
@@ -6,17 +6,16 @@
#define BUFFET_DBUS_UTILS_H_
#include <base/memory/scoped_ptr.h>
+#include <chromeos/error.h>
#include <dbus/exported_object.h>
#include <dbus/message.h>
-#include "buffet/error.h"
-
namespace buffet {
namespace dbus_utils {
scoped_ptr<dbus::Response> GetDBusError(dbus::MethodCall* method_call,
- const Error* error);
+ const chromeos::Error* error);
dbus::ExportedObject::MethodCallCallback GetExportableDBusMethod(
base::Callback<scoped_ptr<dbus::Response>(dbus::MethodCall*)> handler);
diff --git a/buffet/device_registration_info.cc b/buffet/device_registration_info.cc
index 6c21429..c6aef06 100644
--- a/buffet/device_registration_info.cc
+++ b/buffet/device_registration_info.cc
@@ -72,7 +72,7 @@
}
std::unique_ptr<base::DictionaryValue> ParseOAuthResponse(
- const buffet::http::Response* response, buffet::ErrorPtr* error) {
+ const buffet::http::Response* response, chromeos::ErrorPtr* error) {
int code = 0;
auto resp = buffet::http::ParseJsonResponse(response, &code, error);
if (resp && code >= buffet::http::status_code::BadRequest) {
@@ -80,11 +80,11 @@
std::string error_code, error_message;
if (resp->GetString("error", &error_code) &&
resp->GetString("error_description", &error_message)) {
- buffet::Error::AddTo(error, buffet::kErrorDomainOAuth2, error_code,
- error_message);
+ chromeos::Error::AddTo(error, buffet::kErrorDomainOAuth2, error_code,
+ error_message);
} else {
- buffet::Error::AddTo(error, buffet::kErrorDomainOAuth2,
- "unexpected_response", "Unexpected OAuth error");
+ chromeos::Error::AddTo(error, buffet::kErrorDomainOAuth2,
+ "unexpected_response", "Unexpected OAuth error");
}
}
return std::unique_ptr<base::DictionaryValue>();
@@ -92,12 +92,13 @@
return resp;
}
-inline void SetUnexpectedError(buffet::ErrorPtr* error) {
- buffet::Error::AddTo(error, buffet::kErrorDomainGCD, "unexpected_response",
- "Unexpected GCD error");
+inline void SetUnexpectedError(chromeos::ErrorPtr* error) {
+ chromeos::Error::AddTo(error, buffet::kErrorDomainGCD, "unexpected_response",
+ "Unexpected GCD error");
}
-void ParseGCDError(const base::DictionaryValue* json, buffet::ErrorPtr* error) {
+void ParseGCDError(const base::DictionaryValue* json,
+ chromeos::ErrorPtr* error) {
if (!error)
return;
@@ -120,8 +121,8 @@
std::string error_code, error_message;
if (error_object->GetString("reason", &error_code) &&
error_object->GetString("message", &error_message)) {
- buffet::Error::AddTo(error, buffet::kErrorDomainGCDServer,
- error_code, error_message);
+ chromeos::Error::AddTo(error, buffet::kErrorDomainGCDServer,
+ error_code, error_message);
} else {
SetUnexpectedError(error);
}
@@ -181,7 +182,7 @@
return BuildURL(oauth_url_, {subpath}, params);
}
-std::string DeviceRegistrationInfo::GetDeviceId(ErrorPtr* error) {
+std::string DeviceRegistrationInfo::GetDeviceId(chromeos::ErrorPtr* error) {
return CheckRegistration(error) ? device_id_ : std::string();
}
@@ -242,14 +243,14 @@
return storage_->Save(&dict);
}
-bool DeviceRegistrationInfo::CheckRegistration(ErrorPtr* error) {
+bool DeviceRegistrationInfo::CheckRegistration(chromeos::ErrorPtr* error) {
LOG(INFO) << "Checking device registration record.";
if (refresh_token_.empty() ||
device_id_.empty() ||
device_robot_account_.empty()) {
LOG(INFO) << "No valid device registration record found.";
- Error::AddTo(error, kErrorDomainGCD, "device_not_registered",
- "No valid device registration record found");
+ chromeos::Error::AddTo(error, kErrorDomainGCD, "device_not_registered",
+ "No valid device registration record found");
return false;
}
@@ -257,7 +258,8 @@
return ValidateAndRefreshAccessToken(error);
}
-bool DeviceRegistrationInfo::ValidateAndRefreshAccessToken(ErrorPtr* error) {
+bool DeviceRegistrationInfo::ValidateAndRefreshAccessToken(
+ chromeos::ErrorPtr* error) {
LOG(INFO) << "Checking access token expiration.";
if (!access_token_.empty() &&
!access_token_expiration_.is_null() &&
@@ -285,8 +287,9 @@
access_token_.empty() ||
expires_in <= 0) {
LOG(ERROR) << "Access token unavailable.";
- Error::AddTo(error, kErrorDomainOAuth2, "unexpected_server_response",
- "Access token unavailable");
+ chromeos::Error::AddTo(error, kErrorDomainOAuth2,
+ "unexpected_server_response",
+ "Access token unavailable");
return false;
}
@@ -299,7 +302,7 @@
}
std::unique_ptr<base::Value> DeviceRegistrationInfo::GetDeviceInfo(
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
if (!CheckRegistration(error))
return std::unique_ptr<base::Value>();
@@ -321,18 +324,19 @@
bool CheckParam(const std::string& param_name,
const std::string& param_value,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
if (!param_value.empty())
return true;
- Error::AddToPrintf(error, kErrorDomainBuffet, "missing_parameter",
- "Parameter %s not specified", param_name.c_str());
+ chromeos::Error::AddToPrintf(error, kErrorDomainBuffet, "missing_parameter",
+ "Parameter %s not specified",
+ param_name.c_str());
return false;
}
std::string DeviceRegistrationInfo::StartRegistration(
const std::map<std::string, std::shared_ptr<base::Value>>& params,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
GetParamValue(params, storage_keys::kClientId, &client_id_);
GetParamValue(params, storage_keys::kClientSecret, &client_secret_);
GetParamValue(params, storage_keys::kApiKey, &api_key_);
@@ -378,8 +382,8 @@
return std::string();
if (!resp_json->GetString("id", &ticket_id_)) {
- Error::AddTo(error, kErrorDomainGCD, "unexpected_response",
- "Device ID missing");
+ chromeos::Error::AddTo(error, kErrorDomainGCD, "unexpected_response",
+ "Device ID missing");
return std::string();
}
@@ -400,11 +404,12 @@
}
bool DeviceRegistrationInfo::FinishRegistration(
- const std::string& user_auth_code, ErrorPtr* error) {
+ const std::string& user_auth_code, chromeos::ErrorPtr* error) {
if (ticket_id_.empty()) {
LOG(ERROR) << "Finish registration without ticket ID";
- Error::AddTo(error, kErrorDomainBuffet, "registration_not_started",
- "Device registration not started");
+ chromeos::Error::AddTo(error, kErrorDomainBuffet,
+ "registration_not_started",
+ "Device registration not started");
return false;
}
@@ -429,8 +434,8 @@
std::string token_type;
if (!json_resp->GetString("access_token", &user_access_token) ||
!json_resp->GetString("token_type", &token_type)) {
- Error::AddTo(error, kErrorDomainOAuth2, "unexpected_response",
- "User access_token is missing in response");
+ chromeos::Error::AddTo(error, kErrorDomainOAuth2, "unexpected_response",
+ "User access_token is missing in response");
return false;
}
@@ -461,8 +466,8 @@
if (!json_resp->GetString("robotAccountEmail", &device_robot_account_) ||
!json_resp->GetString("robotAccountAuthorizationCode", &auth_code) ||
!json_resp->GetString("deviceDraft.id", &device_id_)) {
- Error::AddTo(error, kErrorDomainGCD, "unexpected_response",
- "Device account missing in response");
+ chromeos::Error::AddTo(error, kErrorDomainGCD, "unexpected_response",
+ "Device account missing in response");
return false;
}
@@ -487,8 +492,8 @@
access_token_.empty() ||
refresh_token_.empty() ||
expires_in <= 0) {
- Error::AddTo(error, kErrorDomainGCD, "unexpected_response",
- "Device access_token missing in response");
+ chromeos::Error::AddTo(error, kErrorDomainGCD, "unexpected_response",
+ "Device access_token missing in response");
return false;
}
diff --git a/buffet/device_registration_info.h b/buffet/device_registration_info.h
index 49408da..df23e36 100644
--- a/buffet/device_registration_info.h
+++ b/buffet/device_registration_info.h
@@ -12,9 +12,9 @@
#include <base/basictypes.h>
#include <base/time/time.h>
+#include <chromeos/error.h>
#include "buffet/data_encoding.h"
-#include "buffet/error.h"
#include "buffet/http_transport.h"
#include "buffet/storage_interface.h"
@@ -78,18 +78,18 @@
const data_encoding::WebParamList& params = {}) const;
// Returns the registered device ID (GUID) or empty string if failed
- std::string GetDeviceId(ErrorPtr* error);
+ std::string GetDeviceId(chromeos::ErrorPtr* error);
// Loads the device registration information from cache.
bool Load();
// Checks for the valid device registration as well as refreshes
// the device access token, if available.
- bool CheckRegistration(ErrorPtr* error);
+ bool CheckRegistration(chromeos::ErrorPtr* error);
// Gets the full device description JSON object, or nullptr if
// the device is not registered or communication failure.
- std::unique_ptr<base::Value> GetDeviceInfo(ErrorPtr* error);
+ std::unique_ptr<base::Value> GetDeviceInfo(chromeos::ErrorPtr* error);
// Starts device registration procedure. |params| are a list of
// key-value pairs of device information, such as client_id, client_secret,
@@ -97,21 +97,21 @@
// is used when possible. Returns a device claim ID on success.
std::string StartRegistration(
const std::map<std::string, std::shared_ptr<base::Value>>& params,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
// Finalizes the device registration. If |user_auth_code| is provided, then
// the device record is populated with user email on user's behalf. Otherwise
// the user is responsible to issue a PATCH request to provide a valid
// email address before calling FinishRegistration.
bool FinishRegistration(const std::string& user_auth_code,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
private:
// Saves the device registration to cache.
bool Save() const;
// Makes sure the access token is available and up-to-date.
- bool ValidateAndRefreshAccessToken(ErrorPtr* error);
+ bool ValidateAndRefreshAccessToken(chromeos::ErrorPtr* error);
// Persistent data. Some of default values for testing purposes are used.
// TODO(avakulenko): remove these default values in the future.
diff --git a/buffet/error.cc b/buffet/error.cc
deleted file mode 100644
index db5543d..0000000
--- a/buffet/error.cc
+++ /dev/null
@@ -1,80 +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 "buffet/error.h"
-
-#include <base/logging.h>
-#include <base/strings/stringprintf.h>
-
-using buffet::Error;
-using buffet::ErrorPtr;
-
-ErrorPtr Error::Create(const std::string& domain,
- const std::string& code,
- const std::string& message) {
- return Create(domain, code, message, ErrorPtr());
-}
-
-ErrorPtr Error::Create(const std::string& domain,
- const std::string& code,
- const std::string& message,
- ErrorPtr inner_error) {
- LOG(ERROR) << "Error::Create: Domain=" << domain
- << ", Code=" << code << ", Message=" << message;
- return ErrorPtr(new Error(domain, code, message, std::move(inner_error)));
-}
-
-void Error::AddTo(ErrorPtr* error, const std::string& domain,
- const std::string& code, const std::string& message) {
- if (error) {
- *error = Create(domain, code, message, std::move(*error));
- } else {
- // Create already logs the error, but if |error| is nullptr,
- // we still want to log the error...
- LOG(ERROR) << "Error::Create: Domain=" << domain
- << ", Code=" << code << ", Message=" << message;
- }
-}
-
-void Error::AddToPrintf(ErrorPtr* error, const std::string& domain,
- const std::string& code, const char* format, ...) {
- va_list ap;
- va_start(ap, format);
- std::string message = base::StringPrintV(format, ap);
- va_end(ap);
- AddTo(error, domain, code, message);
-}
-
-bool Error::HasDomain(const std::string& domain) const {
- const Error* err = this;
- while (err) {
- if (err->GetDomain() == domain)
- return true;
- err = err->GetInnerError();
- }
- return false;
-}
-
-bool Error::HasError(const std::string& domain, const std::string& code) const {
- const Error* err = this;
- while (err) {
- if (err->GetDomain() == domain && err->GetCode() == code)
- return true;
- err = err->GetInnerError();
- }
- return false;
-}
-
-const Error* Error::GetFirstError() const {
- const Error* err = this;
- while (err->GetInnerError())
- err = err->GetInnerError();
- return err;
-}
-
-Error::Error(const std::string& domain, const std::string& code,
- const std::string& message, ErrorPtr inner_error) :
- domain_(domain), code_(code), message_(message),
- inner_error_(std::move(inner_error)) {
-}
diff --git a/buffet/error.h b/buffet/error.h
deleted file mode 100644
index 4e90c2b..0000000
--- a/buffet/error.h
+++ /dev/null
@@ -1,80 +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.
-
-#ifndef BUFFET_ERROR_H_
-#define BUFFET_ERROR_H_
-
-#include <memory>
-#include <string>
-
-#include <base/basictypes.h>
-
-namespace buffet {
-
-class Error; // Forward declaration.
-
-typedef std::unique_ptr<Error> ErrorPtr;
-
-class Error {
- public:
- virtual ~Error() = default;
-
- // Creates an instance of Error class.
- static ErrorPtr Create(const std::string& domain, const std::string& code,
- const std::string& message);
- static ErrorPtr Create(const std::string& domain, const std::string& code,
- const std::string& message, ErrorPtr inner_error);
- // If |error| is not nullptr, creates another instance of Error class,
- // initializes it with specified arguments and adds it to the head of
- // the error chain pointed to by |error|.
- static void AddTo(ErrorPtr* error, const std::string& domain,
- const std::string& code, const std::string& message);
- // Same as the Error::AddTo above, but allows to pass in a printf-like
- // format string and optional parameters to format the error message.
- static void AddToPrintf(ErrorPtr* error, const std::string& domain,
- const std::string& code,
- const char* format, ...) PRINTF_FORMAT(4, 5);
-
- // Returns the error domain, code and message
- const std::string& GetDomain() const { return domain_; }
- const std::string& GetCode() const { return code_; }
- const std::string& GetMessage() const { return message_; }
-
- // Checks if this or any of the inner error in the chain has the specified
- // error domain.
- bool HasDomain(const std::string& domain) const;
- // Checks if this or any of the inner error in the chain matches the specified
- // error domain and code.
- bool HasError(const std::string& domain, const std::string& code) const;
-
- // Gets a pointer to the inner error, if present. Returns nullptr otherwise.
- const Error* GetInnerError() const { return inner_error_.get(); }
-
- // Gets a pointer to the first error occurred.
- // Returns itself if no inner error are available.
- const Error* GetFirstError() const;
-
- protected:
- // Constructor is protected since this object is supposed to be
- // created via the Create factory methods.
- Error(const std::string& domain, const std::string& code,
- const std::string& message, ErrorPtr inner_error);
-
- // Error domain. The domain defines the scopes for error codes.
- // Two errors with the same code but different domains are different errors.
- std::string domain_;
- // Error code. A unique error code identifier within the given domain.
- std::string code_;
- // Human-readable error message.
- std::string message_;
- // Pointer to inner error, if any. This forms a chain of errors.
- ErrorPtr inner_error_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(Error);
-};
-
-} // namespace buffet
-
-#endif // BUFFET_ERROR_H_
diff --git a/buffet/error_codes.cc b/buffet/error_codes.cc
deleted file mode 100644
index bf51efc..0000000
--- a/buffet/error_codes.cc
+++ /dev/null
@@ -1,22 +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 "buffet/error_codes.h"
-
-namespace buffet {
-namespace errors {
-
-namespace json {
-const char kDomain[] = "json_parser";
-const char kParseError[] = "json_parse_error";
-const char kObjectExpected[] = "json_object_expected";
-} // namespace json
-
-namespace file_system {
-const char kDomain[] = "file_system";
-const char kFileReadError[] = "file_read_error";
-} // namespace file_system
-
-} // namespace errors
-} // namespace buffet
diff --git a/buffet/error_codes.h b/buffet/error_codes.h
deleted file mode 100644
index e2f5961..0000000
--- a/buffet/error_codes.h
+++ /dev/null
@@ -1,25 +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.
-
-#ifndef BUFFET_ERROR_CODES_H_
-#define BUFFET_ERROR_CODES_H_
-
-namespace buffet {
-namespace errors {
-
-namespace json {
-extern const char kDomain[];
-extern const char kParseError[];
-extern const char kObjectExpected[];
-} // namespace json
-
-namespace file_system {
-extern const char kDomain[];
-extern const char kFileReadError[];
-} // namespace file_system
-
-} // namespace errors
-} // namespace buffet
-
-#endif // BUFFET_ERROR_CODES_H_
diff --git a/buffet/error_unittest.cc b/buffet/error_unittest.cc
deleted file mode 100644
index 5db0012..0000000
--- a/buffet/error_unittest.cc
+++ /dev/null
@@ -1,56 +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 <base/files/file_path.h>
-#include <gtest/gtest.h>
-
-#include "buffet/error.h"
-
-using buffet::Error;
-
-namespace {
-
-buffet::ErrorPtr GenerateNetworkError() {
- return Error::Create("network", "not_found", "Resource not found");
-}
-
-buffet::ErrorPtr GenerateHttpError() {
- auto inner = GenerateNetworkError();
- return Error::Create("HTTP", "404", "Not found", std::move(inner));
-}
-
-} // namespace
-
-TEST(Error, Single) {
- auto err = GenerateNetworkError();
- EXPECT_EQ("network", err->GetDomain());
- EXPECT_EQ("not_found", err->GetCode());
- EXPECT_EQ("Resource not found", err->GetMessage());
- EXPECT_EQ(nullptr, err->GetInnerError());
- EXPECT_TRUE(err->HasDomain("network"));
- EXPECT_FALSE(err->HasDomain("HTTP"));
- EXPECT_FALSE(err->HasDomain("foo"));
- EXPECT_TRUE(err->HasError("network", "not_found"));
- EXPECT_FALSE(err->HasError("network", "404"));
- EXPECT_FALSE(err->HasError("HTTP", "404"));
- EXPECT_FALSE(err->HasError("HTTP", "not_found"));
- EXPECT_FALSE(err->HasError("foo", "bar"));
-}
-
-TEST(Error, Nested) {
- auto err = GenerateHttpError();
- EXPECT_EQ("HTTP", err->GetDomain());
- EXPECT_EQ("404", err->GetCode());
- EXPECT_EQ("Not found", err->GetMessage());
- EXPECT_NE(nullptr, err->GetInnerError());
- EXPECT_EQ("network", err->GetInnerError()->GetDomain());
- EXPECT_TRUE(err->HasDomain("network"));
- EXPECT_TRUE(err->HasDomain("HTTP"));
- EXPECT_FALSE(err->HasDomain("foo"));
- EXPECT_TRUE(err->HasError("network", "not_found"));
- EXPECT_FALSE(err->HasError("network", "404"));
- EXPECT_TRUE(err->HasError("HTTP", "404"));
- EXPECT_FALSE(err->HasError("HTTP", "not_found"));
- EXPECT_FALSE(err->HasError("foo", "bar"));
-}
diff --git a/buffet/http_connection.h b/buffet/http_connection.h
index ab67905..893b992 100644
--- a/buffet/http_connection.h
+++ b/buffet/http_connection.h
@@ -9,8 +9,8 @@
#include <vector>
#include <base/basictypes.h>
+#include <chromeos/error.h>
-#include "buffet/error.h"
#include "buffet/http_transport.h"
namespace buffet {
@@ -36,14 +36,15 @@
// Called by http::Request to initiate the connection with the server.
// This normally opens the socket and sends the request headers.
- virtual bool SendHeaders(const HeaderList& headers, ErrorPtr* error) = 0;
+ virtual bool SendHeaders(const HeaderList& headers,
+ chromeos::ErrorPtr* error) = 0;
// If needed, this function can be called to send the request body data.
// This function can be called repeatedly until all data is sent.
virtual bool WriteRequestData(const void* data, size_t size,
- ErrorPtr* error) = 0;
+ chromeos::ErrorPtr* error) = 0;
// This function is called when all the data is sent off and it's time
// to receive the response data.
- virtual bool FinishRequest(ErrorPtr* error) = 0;
+ virtual bool FinishRequest(chromeos::ErrorPtr* error) = 0;
// Returns the HTTP status code (e.g. 200 for success).
virtual int GetResponseStatusCode() const = 0;
@@ -65,8 +66,10 @@
// |buffer_size| is the size of the buffer (amount of data to read).
// |read_size| is the amount of data actually read, which could be less than
// the size requested or 0 if there is no more data available.
- virtual bool ReadResponseData(void* data, size_t buffer_size,
- size_t* size_read, ErrorPtr* error) = 0;
+ virtual bool ReadResponseData(void* data,
+ size_t buffer_size,
+ size_t* size_read,
+ chromeos::ErrorPtr* error) = 0;
protected:
// |transport_| is mainly used to keep the object alive as long as the
diff --git a/buffet/http_connection_curl.cc b/buffet/http_connection_curl.cc
index ebdd3cc..3b2d0a8 100644
--- a/buffet/http_connection_curl.cc
+++ b/buffet/http_connection_curl.cc
@@ -56,13 +56,14 @@
VLOG(1) << "curl::Connection destroyed";
}
-bool Connection::SendHeaders(const HeaderList& headers, ErrorPtr* error) {
+bool Connection::SendHeaders(const HeaderList& headers,
+ chromeos::ErrorPtr* error) {
headers_.insert(headers.begin(), headers.end());
return true;
}
bool Connection::WriteRequestData(const void* data, size_t size,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
if (size > 0) {
auto data_ptr = reinterpret_cast<const unsigned char*>(data);
request_data_.insert(request_data_.end(), data_ptr, data_ptr + size);
@@ -70,7 +71,7 @@
return true;
}
-bool Connection::FinishRequest(ErrorPtr* error) {
+bool Connection::FinishRequest(chromeos::ErrorPtr* error) {
if (VLOG_IS_ON(3)) {
curl_easy_setopt(curl_handle_, CURLOPT_DEBUGFUNCTION, curl_trace);
curl_easy_setopt(curl_handle_, CURLOPT_VERBOSE, 1L);
@@ -121,8 +122,9 @@
if (header_list)
curl_slist_free_all(header_list);
if (ret != CURLE_OK) {
- Error::AddTo(error, http::curl::kErrorDomain, string_utils::ToString(ret),
- curl_easy_strerror(ret));
+ chromeos::Error::AddTo(error, http::curl::kErrorDomain,
+ string_utils::ToString(ret),
+ curl_easy_strerror(ret));
} else {
LOG(INFO) << "Response: " << GetResponseStatusCode() << " ("
<< GetResponseStatusText() << ")";
@@ -157,8 +159,10 @@
return response_data_.size();
}
-bool Connection::ReadResponseData(void* data, size_t buffer_size,
- size_t* size_read, ErrorPtr* error) {
+bool Connection::ReadResponseData(void* data,
+ size_t buffer_size,
+ size_t* size_read,
+ chromeos::ErrorPtr* error) {
size_t size_to_read = response_data_.size() - response_data_ptr_;
if (size_to_read > buffer_size)
size_to_read = buffer_size;
diff --git a/buffet/http_connection_curl.h b/buffet/http_connection_curl.h
index 0460bcf..67d7eac 100644
--- a/buffet/http_connection_curl.h
+++ b/buffet/http_connection_curl.h
@@ -27,10 +27,11 @@
// Overrides from http::Connection.
// See http_connection.h for description of these methods.
- bool SendHeaders(const HeaderList& headers, ErrorPtr* error) override;
+ bool SendHeaders(const HeaderList& headers,
+ chromeos::ErrorPtr* error) override;
bool WriteRequestData(const void* data, size_t size,
- ErrorPtr* error) override;
- bool FinishRequest(ErrorPtr* error) override;
+ chromeos::ErrorPtr* error) override;
+ bool FinishRequest(chromeos::ErrorPtr* error) override;
int GetResponseStatusCode() const override;
std::string GetResponseStatusText() const override;
@@ -38,7 +39,7 @@
std::string GetResponseHeader(const std::string& header_name) const override;
uint64_t GetResponseDataSize() const override;
bool ReadResponseData(void* data, size_t buffer_size,
- size_t* size_read, ErrorPtr* error) override;
+ size_t* size_read, chromeos::ErrorPtr* error) override;
protected:
// Write data callback. Used by CURL when receiving response data.
diff --git a/buffet/http_connection_fake.cc b/buffet/http_connection_fake.cc
index 383f6d4..d57786a 100644
--- a/buffet/http_connection_fake.cc
+++ b/buffet/http_connection_fake.cc
@@ -24,18 +24,19 @@
VLOG(1) << "fake::Connection destroyed";
}
-bool Connection::SendHeaders(const HeaderList& headers, ErrorPtr* error) {
+bool Connection::SendHeaders(const HeaderList& headers,
+ chromeos::ErrorPtr* error) {
request_.AddHeaders(headers);
return true;
}
bool Connection::WriteRequestData(const void* data, size_t size,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
request_.AddData(data, size);
return true;
}
-bool Connection::FinishRequest(ErrorPtr* error) {
+bool Connection::FinishRequest(chromeos::ErrorPtr* error) {
request_.AddHeaders({{request_header::kContentLength,
string_utils::ToString(request_.GetData().size())}});
fake::Transport* transport = static_cast<fake::Transport*>(transport_.get());
@@ -76,8 +77,10 @@
response_.GetData().size() : 0;
}
-bool Connection::ReadResponseData(void* data, size_t buffer_size,
- size_t* size_read, ErrorPtr* error) {
+bool Connection::ReadResponseData(void* data,
+ size_t buffer_size,
+ size_t* size_read,
+ chromeos::ErrorPtr* error) {
size_t size_to_read = GetResponseDataSize() - response_data_ptr_;
if (size_to_read > buffer_size)
size_to_read = buffer_size;
diff --git a/buffet/http_connection_fake.h b/buffet/http_connection_fake.h
index 788d551..513228a 100644
--- a/buffet/http_connection_fake.h
+++ b/buffet/http_connection_fake.h
@@ -27,10 +27,11 @@
// Overrides from http::Connection.
// See http_connection.h for description of these methods.
- bool SendHeaders(const HeaderList& headers, ErrorPtr* error) override;
+ bool SendHeaders(const HeaderList& headers,
+ chromeos::ErrorPtr* error) override;
bool WriteRequestData(const void* data, size_t size,
- ErrorPtr* error) override;
- bool FinishRequest(ErrorPtr* error) override;
+ chromeos::ErrorPtr* error) override;
+ bool FinishRequest(chromeos::ErrorPtr* error) override;
int GetResponseStatusCode() const override;
std::string GetResponseStatusText() const override;
@@ -38,7 +39,7 @@
std::string GetResponseHeader(const std::string& header_name) const override;
uint64_t GetResponseDataSize() const override;
bool ReadResponseData(void* data, size_t buffer_size,
- size_t* size_read, ErrorPtr* error) override;
+ size_t* size_read, chromeos::ErrorPtr* error) override;
private:
// Request and response objects passed to the user-provided request handler
diff --git a/buffet/http_request.cc b/buffet/http_request.cc
index c08e797..a9fa439 100644
--- a/buffet/http_request.cc
+++ b/buffet/http_request.cc
@@ -127,7 +127,7 @@
ranges_.emplace_back(from_byte, to_byte);
}
-std::unique_ptr<Response> Request::GetResponse(ErrorPtr* error) {
+std::unique_ptr<Response> Request::GetResponse(chromeos::ErrorPtr* error) {
if (!SendRequestIfNeeded(error) || !connection_->FinishRequest(error))
return std::unique_ptr<Response>();
std::unique_ptr<Response> response(new Response(std::move(connection_)));
@@ -159,7 +159,9 @@
headers_.insert(headers.begin(), headers.end());
}
-bool Request::AddRequestBody(const void* data, size_t size, ErrorPtr* error) {
+bool Request::AddRequestBody(const void* data,
+ size_t size,
+ chromeos::ErrorPtr* error) {
if (!SendRequestIfNeeded(error))
return false;
return connection_->WriteRequestData(data, size, error);
@@ -181,7 +183,7 @@
return user_agent_;
}
-bool Request::SendRequestIfNeeded(ErrorPtr* error) {
+bool Request::SendRequestIfNeeded(chromeos::ErrorPtr* error) {
if (transport_) {
if (!connection_) {
http::HeaderList headers = MapToVector(headers_);
@@ -221,8 +223,9 @@
if (connection_)
return true;
} else {
- Error::AddTo(error, http::curl::kErrorDomain,
- "request_already_received", "HTTP response already received");
+ chromeos::Error::AddTo(error, http::curl::kErrorDomain,
+ "request_already_received",
+ "HTTP response already received");
}
return false;
}
diff --git a/buffet/http_request.h b/buffet/http_request.h
index 9bb436e..d9e73a4 100644
--- a/buffet/http_request.h
+++ b/buffet/http_request.h
@@ -13,8 +13,8 @@
#include <vector>
#include <base/basictypes.h>
+#include <chromeos/error.h>
-#include "buffet/error.h"
#include "buffet/http_connection.h"
#include "buffet/http_transport.h"
@@ -235,7 +235,7 @@
void RemoveHeader(const char* header);
// Adds a request body. This is not to be used with GET method
- bool AddRequestBody(const void* data, size_t size, ErrorPtr* error);
+ bool AddRequestBody(const void* data, size_t size, chromeos::ErrorPtr* error);
// Makes a request for a subrange of data. Specifies a partial range with
// either from beginning of the data to the specified offset (if |bytes| is
@@ -264,11 +264,11 @@
// In case the server couldn't be reached for whatever reason, returns
// empty unique_ptr (null). In such a case, the additional error information
// can be returned through the optional supplied |error| parameter.
- std::unique_ptr<Response> GetResponse(ErrorPtr* error);
+ std::unique_ptr<Response> GetResponse(chromeos::ErrorPtr* error);
private:
// Helper function to create an http::Connection and send off request headers.
- bool SendRequestIfNeeded(ErrorPtr* error);
+ bool SendRequestIfNeeded(chromeos::ErrorPtr* error);
// Implementation that provides particular HTTP transport.
std::shared_ptr<Transport> transport_;
diff --git a/buffet/http_transport.h b/buffet/http_transport.h
index e26ee77..15b0bd6 100644
--- a/buffet/http_transport.h
+++ b/buffet/http_transport.h
@@ -11,8 +11,7 @@
#include <vector>
#include <base/basictypes.h>
-
-#include "buffet/error.h"
+#include <chromeos/error.h>
namespace buffet {
namespace http {
@@ -42,7 +41,7 @@
const HeaderList& headers,
const std::string& user_agent,
const std::string& referer,
- ErrorPtr* error) = 0;
+ chromeos::ErrorPtr* error) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(Transport);
diff --git a/buffet/http_transport_curl.cc b/buffet/http_transport_curl.cc
index 7ef914b..d5a30fe 100644
--- a/buffet/http_transport_curl.cc
+++ b/buffet/http_transport_curl.cc
@@ -30,12 +30,12 @@
const HeaderList& headers,
const std::string& user_agent,
const std::string& referer,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
CURL* curl_handle = curl_easy_init();
if (!curl_handle) {
LOG(ERROR) << "Failed to initialize CURL";
- Error::AddTo(error, http::curl::kErrorDomain, "curl_init_failed",
- "Failed to initialize CURL");
+ chromeos::Error::AddTo(error, http::curl::kErrorDomain, "curl_init_failed",
+ "Failed to initialize CURL");
return std::unique_ptr<http::Connection>();
}
diff --git a/buffet/http_transport_curl.h b/buffet/http_transport_curl.h
index 740adf7..17b6acc 100644
--- a/buffet/http_transport_curl.h
+++ b/buffet/http_transport_curl.h
@@ -34,7 +34,7 @@
const HeaderList& headers,
const std::string& user_agent,
const std::string& referer,
- ErrorPtr* error) override;
+ chromeos::ErrorPtr* error) override;
private:
DISALLOW_COPY_AND_ASSIGN(Transport);
diff --git a/buffet/http_transport_fake.cc b/buffet/http_transport_fake.cc
index 471de11..2c59cb3 100644
--- a/buffet/http_transport_fake.cc
+++ b/buffet/http_transport_fake.cc
@@ -39,7 +39,7 @@
const HeaderList& headers,
const std::string& user_agent,
const std::string& referer,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
HeaderList headers_copy = headers;
if (!user_agent.empty()) {
headers_copy.push_back(std::make_pair(http::request_header::kUserAgent,
diff --git a/buffet/http_transport_fake.h b/buffet/http_transport_fake.h
index 71acd3e..1e58c65 100644
--- a/buffet/http_transport_fake.h
+++ b/buffet/http_transport_fake.h
@@ -72,7 +72,7 @@
const HeaderList& headers,
const std::string& user_agent,
const std::string& referer,
- ErrorPtr* error) override;
+ chromeos::ErrorPtr* error) override;
private:
// A list of user-supplied request handlers.
diff --git a/buffet/http_utils.cc b/buffet/http_utils.cc
index 3924505..6111aa0 100644
--- a/buffet/http_utils.cc
+++ b/buffet/http_utils.cc
@@ -9,9 +9,9 @@
#include <base/json/json_reader.h>
#include <base/json/json_writer.h>
#include <base/values.h>
+#include <chromeos/error_codes.h>
#include "buffet/data_encoding.h"
-#include "buffet/error_codes.h"
#include "buffet/mime_utils.h"
namespace buffet {
@@ -20,7 +20,7 @@
std::unique_ptr<Response> Get(const std::string& url,
const HeaderList& headers,
std::shared_ptr<Transport> transport,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
return SendRequest(request_type::kGet, url, nullptr, 0, nullptr,
headers, transport, error);
}
@@ -28,14 +28,14 @@
std::string GetAsString(const std::string& url,
const HeaderList& headers,
std::shared_ptr<Transport> transport,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
auto resp = Get(url, headers, transport, error);
return resp ? resp->GetDataAsString() : std::string();
}
std::unique_ptr<Response> Head(const std::string& url,
std::shared_ptr<Transport> transport,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
Request request(url, request_type::kHead, transport);
return request.GetResponse(error);
}
@@ -45,7 +45,7 @@
const char* mime_type,
const HeaderList& headers,
std::shared_ptr<Transport> transport,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
if (mime_type == nullptr) {
mime_type = mime::application::kWwwFormUrlEncoded;
}
@@ -61,7 +61,7 @@
const char* mime_type,
const HeaderList& headers,
std::shared_ptr<Transport> transport,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
Request request(url, method, transport);
request.AddHeaders(headers);
if (data_size > 0) {
@@ -79,7 +79,7 @@
size_t data_size, const char* mime_type,
const HeaderList& headers,
std::shared_ptr<Transport> transport,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
return SendRequest(request_type::kPost, url,
data, data_size, mime_type, headers, transport, error);
}
@@ -88,7 +88,7 @@
const FormFieldList& data,
const HeaderList& headers,
std::shared_ptr<Transport> transport,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
std::string encoded_data = data_encoding::WebParamsEncode(data);
return PostBinary(url, encoded_data.c_str(), encoded_data.size(),
mime::application::kWwwFormUrlEncoded,
@@ -100,7 +100,7 @@
const base::Value* json,
const HeaderList& headers,
std::shared_ptr<Transport> transport,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
std::string data;
if (json)
base::JSONWriter::Write(json, &data);
@@ -115,7 +115,7 @@
const base::Value* json,
const HeaderList& headers,
std::shared_ptr<Transport> transport,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
std::string data;
if (json)
base::JSONWriter::Write(json, &data);
@@ -127,7 +127,7 @@
}
std::unique_ptr<base::DictionaryValue> ParseJsonResponse(
- const Response* response, int* status_code, ErrorPtr* error) {
+ const Response* response, int* status_code, chromeos::ErrorPtr* error) {
if (!response)
return std::unique_ptr<base::DictionaryValue>();
@@ -139,8 +139,9 @@
auto content_type = mime::RemoveParameters(response->GetContentType());
if (content_type != mime::application::kJson &&
content_type != mime::text::kPlain) {
- Error::AddTo(error, errors::json::kDomain, "non_json_content_type",
- "Unexpected response content type: " + content_type);
+ chromeos::Error::AddTo(error, chromeos::errors::json::kDomain,
+ "non_json_content_type",
+ "Unexpected response content type: " + content_type);
return std::unique_ptr<base::DictionaryValue>();
}
@@ -149,15 +150,16 @@
base::Value* value = base::JSONReader::ReadAndReturnError(
json, base::JSON_PARSE_RFC, nullptr, &error_message);
if (!value) {
- Error::AddTo(error, errors::json::kDomain, errors::json::kParseError,
- error_message);
+ chromeos::Error::AddTo(error, chromeos::errors::json::kDomain,
+ chromeos::errors::json::kParseError, error_message);
return std::unique_ptr<base::DictionaryValue>();
}
base::DictionaryValue* dict_value = nullptr;
if (!value->GetAsDictionary(&dict_value)) {
delete value;
- Error::AddTo(error, errors::json::kDomain, errors::json::kObjectExpected,
- "Response is not a valid JSON object");
+ chromeos::Error::AddTo(error, chromeos::errors::json::kDomain,
+ chromeos::errors::json::kObjectExpected,
+ "Response is not a valid JSON object");
return std::unique_ptr<base::DictionaryValue>();
}
return std::unique_ptr<base::DictionaryValue>(dict_value);
diff --git a/buffet/http_utils.h b/buffet/http_utils.h
index 87b9b3a..938905d 100644
--- a/buffet/http_utils.h
+++ b/buffet/http_utils.h
@@ -5,13 +5,14 @@
#ifndef BUFFET_HTTP_UTILS_H_
#define BUFFET_HTTP_UTILS_H_
-#include "buffet/error.h"
-#include "buffet/http_request.h"
-
#include <string>
#include <utility>
#include <vector>
+#include <chromeos/error.h>
+
+#include "buffet/http_request.h"
+
namespace base {
class Value;
class DictionaryValue;
@@ -38,15 +39,15 @@
const char* method, const std::string& url,
const void* data, size_t data_size, const char* mime_type,
const HeaderList& headers, std::shared_ptr<Transport> transport,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
// Performs a simple GET request and returns the data as a string.
std::string GetAsString(const std::string& url, const HeaderList& headers,
std::shared_ptr<Transport> transport,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
inline std::string GetAsString(const std::string& url,
std::shared_ptr<Transport> transport,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
return GetAsString(url, HeaderList(), transport, error);
}
@@ -56,10 +57,10 @@
std::unique_ptr<Response> Get(const std::string& url,
const HeaderList& headers,
std::shared_ptr<Transport> transport,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
inline std::unique_ptr<Response> Get(
const std::string& url, std::shared_ptr<Transport> transport,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
return Get(url, HeaderList(), transport, error);
}
@@ -68,7 +69,7 @@
// the returned Response object.
std::unique_ptr<Response> Head(const std::string& url,
std::shared_ptr<Transport> transport,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
// Performs a POST request with binary data. Success status, returned data
// and additional information (such as returned HTTP headers) can be obtained
@@ -80,19 +81,19 @@
const char* mime_type,
const HeaderList& headers,
std::shared_ptr<Transport> transport,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
inline std::unique_ptr<Response> PostBinary(
const std::string& url, const void* data, size_t data_size,
const char* mime_type, std::shared_ptr<Transport> transport,
- ErrorPtr* error) {
+ chromeos::ErrorPtr* error) {
return PostBinary(url, data, data_size, mime_type, HeaderList(), transport,
error);
}
inline std::unique_ptr<Response> PostBinary(
const std::string& url, const void* data, size_t data_size,
- std::shared_ptr<Transport> transport, ErrorPtr* error) {
+ std::shared_ptr<Transport> transport, chromeos::ErrorPtr* error) {
return PostBinary(url, data, data_size, nullptr, transport, error);
}
@@ -106,17 +107,17 @@
const char* mime_type,
const HeaderList& headers,
std::shared_ptr<Transport> transport,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
inline std::unique_ptr<Response> PostText(
const std::string& url, const char* data, const char* mime_type,
- std::shared_ptr<Transport> transport, ErrorPtr* error) {
+ std::shared_ptr<Transport> transport, chromeos::ErrorPtr* error) {
return PostText(url, data, mime_type, HeaderList(), transport, error);
}
inline std::unique_ptr<Response> PostText(
const std::string& url, const char* data,
- std::shared_ptr<Transport> transport, ErrorPtr* error) {
+ std::shared_ptr<Transport> transport, chromeos::ErrorPtr* error) {
return PostText(url, data, nullptr, transport, error);
}
@@ -127,11 +128,11 @@
std::unique_ptr<Response> PostFormData(
const std::string& url, const FormFieldList& data,
const HeaderList& headers, std::shared_ptr<Transport> transport,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
inline std::unique_ptr<Response> PostFormData(
const std::string& url, const FormFieldList& data,
- std::shared_ptr<Transport> transport, ErrorPtr* error) {
+ std::shared_ptr<Transport> transport, chromeos::ErrorPtr* error) {
return PostFormData(url, data, HeaderList(), transport, error);
}
@@ -143,11 +144,11 @@
const base::Value* json,
const HeaderList& headers,
std::shared_ptr<Transport> transport,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
inline std::unique_ptr<Response> PostJson(
const std::string& url, const base::Value* json,
- std::shared_ptr<Transport> transport, ErrorPtr* error) {
+ std::shared_ptr<Transport> transport, chromeos::ErrorPtr* error) {
return PostJson(url, json, HeaderList(), transport, error);
}
@@ -159,11 +160,11 @@
const base::Value* json,
const HeaderList& headers,
std::shared_ptr<Transport> transport,
- ErrorPtr* error);
+ chromeos::ErrorPtr* error);
inline std::unique_ptr<Response> PatchJson(
const std::string& url, const base::Value* json,
- std::shared_ptr<Transport> transport, ErrorPtr* error) {
+ std::shared_ptr<Transport> transport, chromeos::ErrorPtr* error) {
return PatchJson(url, json, HeaderList(), transport, error);
}
@@ -171,7 +172,7 @@
// Returns null if failed. Optional |error| can be passed in to
// get the extended error information as to why the parse failed.
std::unique_ptr<base::DictionaryValue> ParseJsonResponse(
- const Response* response, int* status_code, ErrorPtr* error);
+ const Response* response, int* status_code, chromeos::ErrorPtr* error);
} // namespace http
} // namespace buffet
diff --git a/buffet/manager.cc b/buffet/manager.cc
index 6f7928e..a039ae8 100644
--- a/buffet/manager.cc
+++ b/buffet/manager.cc
@@ -12,6 +12,7 @@
#include <base/json/json_writer.h>
#include <chromeos/async_event_sequencer.h>
#include <chromeos/dbus_utils.h>
+#include <chromeos/error.h>
#include <chromeos/exported_object_manager.h>
#include <dbus/bus.h>
#include <dbus/object_path.h>
@@ -20,7 +21,6 @@
#include "buffet/commands/command_manager.h"
#include "buffet/dbus_constants.h"
#include "buffet/dbus_utils.h"
-#include "buffet/error.h"
using chromeos::dbus_utils::AsyncEventSequencer;
using chromeos::dbus_utils::GetBadArgsError;
@@ -147,7 +147,7 @@
LOG(INFO) << "Received call to Manager.CheckDeviceRegistered()";
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
bool registered = device_info_->CheckRegistration(&error);
// If it fails due to any reason other than 'device not registered',
// treat it as a real error and report it to the caller.
@@ -182,7 +182,7 @@
LOG(INFO) << "Received call to Manager.GetDeviceInfo()";
std::string device_info_str;
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
auto device_info = device_info_->GetDeviceInfo(&error);
if (!device_info)
return GetDBusError(method_call, error.get());
@@ -227,7 +227,7 @@
LOG(INFO) << "Received call to Manager.StartRegisterDevice()";
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
std::string id = device_info_->StartRegistration(params, &error);
if (id.empty())
return GetDBusError(method_call, error.get());
@@ -258,7 +258,7 @@
}
LOG(INFO) << "Received call to Manager.FinishRegisterDevice()";
- buffet::ErrorPtr error;
+ chromeos::ErrorPtr error;
if (!device_info_->FinishRegistration(user_auth_code, &error))
return GetDBusError(method_call, error.get());