libweave: Remove dependency on libchromeos/chromeos/errors/error_codes.h

Codes moved into libweave.

BUG=brillo:1257
TEST=`FEATURES=test emerge-gizmo libweave`

Change-Id: If564703f1e7d1ba354d0ee991031bbcd71f0d67c
Reviewed-on: https://chromium-review.googlesource.com/293586
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/libweave/libweave.gyp b/libweave/libweave.gyp
index e0287d7..badd394 100644
--- a/libweave/libweave.gyp
+++ b/libweave/libweave.gyp
@@ -46,6 +46,7 @@
         'src/device_manager.cc',
         'src/device_registration_info.cc',
         'src/http_constants.cc',
+        'src/json_error_codes.cc',
         'src/notification/notification_parser.cc',
         'src/notification/pull_channel.cc',
         'src/notification/xml_node.cc',
diff --git a/libweave/src/commands/command_instance.cc b/libweave/src/commands/command_instance.cc
index 2b7128e..de0fdd5 100644
--- a/libweave/src/commands/command_instance.cc
+++ b/libweave/src/commands/command_instance.cc
@@ -6,7 +6,6 @@
 
 #include <base/values.h>
 #include <chromeos/errors/error.h>
-#include <chromeos/errors/error_codes.h>
 #include <weave/enum_to_string.h>
 #include <weave/export.h>
 
@@ -16,6 +15,7 @@
 #include "libweave/src/commands/prop_types.h"
 #include "libweave/src/commands/schema_constants.h"
 #include "libweave/src/commands/schema_utils.h"
+#include "libweave/src/json_error_codes.h"
 
 namespace weave {
 
@@ -147,9 +147,8 @@
   if (json->Get(commands::attributes::kCommand_Parameters, &params_value)) {
     // Make sure the "parameters" property is actually an object.
     if (!params_value->GetAsDictionary(&params)) {
-      chromeos::Error::AddToPrintf(error, FROM_HERE,
-                                   chromeos::errors::json::kDomain,
-                                   chromeos::errors::json::kObjectExpected,
+      chromeos::Error::AddToPrintf(error, FROM_HERE, errors::json::kDomain,
+                                   errors::json::kObjectExpected,
                                    "Property '%s' must be a JSON object",
                                    commands::attributes::kCommand_Parameters);
       return false;
@@ -185,8 +184,8 @@
   // Get the command JSON object from the value.
   const base::DictionaryValue* json = nullptr;
   if (!value->GetAsDictionary(&json)) {
-    chromeos::Error::AddTo(error, FROM_HERE, chromeos::errors::json::kDomain,
-                           chromeos::errors::json::kObjectExpected,
+    chromeos::Error::AddTo(error, FROM_HERE, errors::json::kDomain,
+                           errors::json::kObjectExpected,
                            "Command instance is not a JSON object");
     command_id->clear();
     return instance;
diff --git a/libweave/src/device_registration_info.cc b/libweave/src/device_registration_info.cc
index bc738f6..59f5dde 100644
--- a/libweave/src/device_registration_info.cc
+++ b/libweave/src/device_registration_info.cc
@@ -16,7 +16,6 @@
 #include <base/strings/string_number_conversions.h>
 #include <base/values.h>
 #include <chromeos/bind_lambda.h>
-#include <chromeos/errors/error_codes.h>
 #include <chromeos/key_value_store.h>
 #include <chromeos/strings/string_utils.h>
 #include <chromeos/url_utils.h>
@@ -29,6 +28,7 @@
 #include "libweave/src/commands/command_manager.h"
 #include "libweave/src/commands/schema_constants.h"
 #include "libweave/src/http_constants.h"
+#include "libweave/src/json_error_codes.h"
 #include "libweave/src/notification/xmpp_channel.h"
 #include "libweave/src/states/state_manager.h"
 #include "libweave/src/utils.h"
@@ -168,7 +168,7 @@
           .first;
 
   if (content_type != http::kJson && content_type != http::kPlain) {
-    chromeos::Error::AddTo(error, FROM_HERE, chromeos::errors::json::kDomain,
+    chromeos::Error::AddTo(error, FROM_HERE, errors::json::kDomain,
                            "non_json_content_type",
                            "Unexpected response content type: " + content_type);
     return std::unique_ptr<base::DictionaryValue>();
@@ -179,9 +179,8 @@
   auto value = base::JSONReader::ReadAndReturnError(json, base::JSON_PARSE_RFC,
                                                     nullptr, &error_message);
   if (!value) {
-    chromeos::Error::AddToPrintf(error, FROM_HERE,
-                                 chromeos::errors::json::kDomain,
-                                 chromeos::errors::json::kParseError,
+    chromeos::Error::AddToPrintf(error, FROM_HERE, errors::json::kDomain,
+                                 errors::json::kParseError,
                                  "Error '%s' occurred parsing JSON string '%s'",
                                  error_message.c_str(), json.c_str());
     return std::unique_ptr<base::DictionaryValue>();
@@ -189,8 +188,7 @@
   base::DictionaryValue* dict_value = nullptr;
   if (!value->GetAsDictionary(&dict_value)) {
     chromeos::Error::AddToPrintf(
-        error, FROM_HERE, chromeos::errors::json::kDomain,
-        chromeos::errors::json::kObjectExpected,
+        error, FROM_HERE, errors::json::kDomain, errors::json::kObjectExpected,
         "Response is not a valid JSON object: '%s'", json.c_str());
     return std::unique_ptr<base::DictionaryValue>();
   } else {
diff --git a/libweave/src/json_error_codes.cc b/libweave/src/json_error_codes.cc
new file mode 100644
index 0000000..8b40bf0
--- /dev/null
+++ b/libweave/src/json_error_codes.cc
@@ -0,0 +1,17 @@
+// 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 "libweave/src/json_error_codes.h"
+
+namespace weave {
+namespace errors {
+
+namespace json {
+const char kDomain[] = "json_parser";
+const char kParseError[] = "json_parse_error";
+const char kObjectExpected[] = "json_object_expected";
+}  // namespace json
+
+}  // namespace errors
+}  // namespace weave
diff --git a/libweave/src/json_error_codes.h b/libweave/src/json_error_codes.h
new file mode 100644
index 0000000..193f6b2
--- /dev/null
+++ b/libweave/src/json_error_codes.h
@@ -0,0 +1,23 @@
+// Copyright 2015 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 LIBWEAVE_SRC_JSON_ERROR_CODES_H_
+#define LIBWEAVE_SRC_JSON_ERROR_CODES_H_
+
+namespace weave {
+
+namespace errors {
+
+namespace json {
+extern const char kDomain[];
+
+extern const char kParseError[];
+extern const char kObjectExpected[];
+}  // namespace json
+
+}  // namespace errors
+
+}  // namespace weave
+
+#endif  // LIBWEAVE_SRC_JSON_ERROR_CODES_H_
diff --git a/libweave/src/states/state_manager.cc b/libweave/src/states/state_manager.cc
index 522a2ec..fa8f81e 100644
--- a/libweave/src/states/state_manager.cc
+++ b/libweave/src/states/state_manager.cc
@@ -8,10 +8,10 @@
 #include <base/files/file_path.h>
 #include <base/logging.h>
 #include <base/values.h>
-#include <chromeos/errors/error_codes.h>
 #include <chromeos/key_value_store.h>
 #include <chromeos/strings/string_utils.h>
 
+#include "libweave/src/json_error_codes.h"
 #include "libweave/src/states/error_codes.h"
 #include "libweave/src/states/state_change_queue_interface.h"
 #include "libweave/src/utils.h"
@@ -165,10 +165,10 @@
     }
     const base::DictionaryValue* package_dict = nullptr;
     if (!iter.value().GetAsDictionary(&package_dict)) {
-      chromeos::Error::AddToPrintf(
-          error, FROM_HERE, chromeos::errors::json::kDomain,
-          chromeos::errors::json::kObjectExpected,
-          "State package '%s' must be an object", package_name.c_str());
+      chromeos::Error::AddToPrintf(error, FROM_HERE, errors::json::kDomain,
+                                   errors::json::kObjectExpected,
+                                   "State package '%s' must be an object",
+                                   package_name.c_str());
       return false;
     }
     StatePackage* package = FindOrCreatePackage(package_name);
@@ -235,17 +235,17 @@
     }
     const base::DictionaryValue* package_dict = nullptr;
     if (!iter.value().GetAsDictionary(&package_dict)) {
-      chromeos::Error::AddToPrintf(
-          error, FROM_HERE, chromeos::errors::json::kDomain,
-          chromeos::errors::json::kObjectExpected,
-          "State package '%s' must be an object", package_name.c_str());
+      chromeos::Error::AddToPrintf(error, FROM_HERE, errors::json::kDomain,
+                                   errors::json::kObjectExpected,
+                                   "State package '%s' must be an object",
+                                   package_name.c_str());
       return false;
     }
     StatePackage* package = FindPackage(package_name);
     if (package == nullptr) {
       chromeos::Error::AddToPrintf(
-          error, FROM_HERE, chromeos::errors::json::kDomain,
-          chromeos::errors::json::kObjectExpected,
+          error, FROM_HERE, errors::json::kDomain,
+          errors::json::kObjectExpected,
           "Providing values for undefined state package '%s'",
           package_name.c_str());
       return false;
diff --git a/libweave/src/utils.cc b/libweave/src/utils.cc
index 353ea96..ea31476 100644
--- a/libweave/src/utils.cc
+++ b/libweave/src/utils.cc
@@ -7,7 +7,8 @@
 #include <base/bind_helpers.h>
 #include <base/files/file_util.h>
 #include <base/json/json_reader.h>
-#include <chromeos/errors/error_codes.h>
+
+#include "libweave/src/json_error_codes.h"
 
 namespace weave {
 
@@ -35,7 +36,6 @@
     chromeos::ErrorPtr* error) {
   std::string json_string;
   if (!base::ReadFileToString(json_file_path, &json_string)) {
-    chromeos::errors::system::AddSystemError(error, FROM_HERE, errno);
     chromeos::Error::AddToPrintf(error, FROM_HERE, kErrorDomain, kFileReadError,
                                  "Failed to read file '%s'",
                                  json_file_path.value().c_str());
@@ -52,19 +52,17 @@
   auto value = base::JSONReader::ReadAndReturnError(
       json_string, base::JSON_PARSE_RFC, nullptr, &error_message);
   if (!value) {
-    chromeos::Error::AddToPrintf(
-        error, FROM_HERE, chromeos::errors::json::kDomain,
-        chromeos::errors::json::kParseError,
-        "Error parsing JSON string '%s' (%zu): %s",
-        LimitString(json_string, kMaxStrLen).c_str(), json_string.size(),
-        error_message.c_str());
+    chromeos::Error::AddToPrintf(error, FROM_HERE, errors::json::kDomain,
+                                 errors::json::kParseError,
+                                 "Error parsing JSON string '%s' (%zu): %s",
+                                 LimitString(json_string, kMaxStrLen).c_str(),
+                                 json_string.size(), error_message.c_str());
     return result;
   }
   base::DictionaryValue* dict_value = nullptr;
   if (!value->GetAsDictionary(&dict_value)) {
-    chromeos::Error::AddToPrintf(error, FROM_HERE,
-                                 chromeos::errors::json::kDomain,
-                                 chromeos::errors::json::kObjectExpected,
+    chromeos::Error::AddToPrintf(error, FROM_HERE, errors::json::kDomain,
+                                 errors::json::kObjectExpected,
                                  "JSON string '%s' is not a JSON object",
                                  LimitString(json_string, kMaxStrLen).c_str());
     return result;