Commit 87e7af86 authored by Dominic Battre's avatar Dominic Battre Committed by Commit Bot

Move serialization of LoggingScope and LogMessage to proper place

This CL resolves an older TODO. With the LogBuffer now living in common/
instead of browser/, it is possible to do the serialization of these two enums
in common/ as well.

TBR=ftirelo@chromium.org

Bug: 928595
Change-Id: Ie9a0f8352b38202b1b87a269256ecf4e6e4421ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1803925
Commit-Queue: Dominic Battré <battre@chromium.org>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697173}
parent f25bed38
......@@ -39,7 +39,6 @@
#include "components/autofill/content/browser/autofill_log_router_factory.h"
#include "components/autofill/content/browser/content_autofill_driver.h"
#include "components/autofill/content/browser/content_autofill_driver_factory.h"
#include "components/autofill/core/browser/autofill_internals_service.h"
#include "components/autofill/core/browser/form_data_importer.h"
#include "components/autofill/core/browser/payments/payments_client.h"
#include "components/autofill/core/browser/ui/payments/card_unmask_prompt_view.h"
......
......@@ -56,8 +56,6 @@ jumbo_static_library("browser") {
"autofill_handler_proxy.h",
"autofill_ie_toolbar_import_win.cc",
"autofill_ie_toolbar_import_win.h",
"autofill_internals_service.cc",
"autofill_internals_service.h",
"autofill_manager.cc",
"autofill_manager.h",
"autofill_manager_test_delegate.h",
......@@ -531,7 +529,6 @@ source_set("unit_tests") {
"autofill_experiments_unittest.cc",
"autofill_external_delegate_unittest.cc",
"autofill_ie_toolbar_import_win_unittest.cc",
"autofill_internals_service_unittest.cc",
"autofill_manager_unittest.cc",
"autofill_merge_unittest.cc",
"autofill_metrics_unittest.cc",
......
......@@ -25,7 +25,6 @@
#include "base/strings/stringprintf.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/autofill/core/browser/autofill_driver.h"
#include "components/autofill/core/browser/autofill_internals_service.h"
#include "components/autofill/core/browser/autofill_metrics.h"
#include "components/autofill/core/browser/form_structure.h"
#include "components/autofill/core/browser/logging/log_manager.h"
......
......@@ -12,7 +12,6 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/autofill_internals_service.h"
#include "components/autofill/core/browser/autofill_metrics.h"
#include "components/autofill/core/browser/logging/log_manager.h"
#include "components/autofill/core/browser/payments/payments_util.h"
......
// Copyright 2019 The Chromium 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 "components/autofill/core/browser/autofill_internals_service.h"
namespace autofill {
LogBuffer& operator<<(LogBuffer& buf, LoggingScope scope) {
if (!buf.active())
return buf;
return buf << Tag{"div"} << Attrib{"scope", LoggingScopeToString(scope)}
<< Attrib{"class", "log-entry"};
}
LogBuffer& operator<<(LogBuffer& buf, LogMessage message) {
if (!buf.active())
return buf;
return buf << Tag{"div"} << Attrib{"message", LogMessageToString(message)}
<< Attrib{"class", "log-message"} << LogMessageValue(message);
}
} // namespace autofill
......@@ -42,7 +42,6 @@
#include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/autofill_external_delegate.h"
#include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/autofill_internals_service.h"
#include "components/autofill/core/browser/autofill_manager_test_delegate.h"
#include "components/autofill/core/browser/autofill_metrics.h"
#include "components/autofill/core/browser/autofill_type.h"
......@@ -68,6 +67,8 @@
#include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_data_validation.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_internals/log_message.h"
#include "components/autofill/core/common/autofill_internals/logging_scope.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/autofill/core/common/autofill_switches.h"
......
......@@ -17,7 +17,6 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/autofill_internals_service.h"
#include "components/autofill/core/browser/form_parsing/address_field.h"
#include "components/autofill/core/browser/form_parsing/autofill_scanner.h"
#include "components/autofill/core/browser/form_parsing/credit_card_field.h"
......
......@@ -77,6 +77,8 @@ jumbo_static_library("common") {
source_set("unit_tests") {
testonly = true
sources = [
"autofill_internals/log_message_unittest.cc",
"autofill_internals/logging_scope_unittest.cc",
"autofill_l10n_util_unittest.cc",
"autofill_prefs_unittest.cc",
"autofill_regexes_unittest.cc",
......
......@@ -5,6 +5,7 @@
#include "components/autofill/core/common/autofill_internals/log_message.h"
#include "base/logging.h"
#include "components/autofill/core/common/logging/log_buffer.h"
namespace autofill {
......@@ -50,4 +51,11 @@ const char* LogMessageValue(LogMessage message) {
return "";
}
LogBuffer& operator<<(LogBuffer& buf, LogMessage message) {
if (!buf.active())
return buf;
return buf << Tag{"div"} << Attrib{"message", LogMessageToString(message)}
<< Attrib{"class", "log-message"} << LogMessageValue(message);
}
} // namespace autofill
......@@ -7,6 +7,8 @@
namespace autofill {
class LogBuffer;
/////////////// Log Messages /////////////
// Generator for log message. If you need to find the call site for a log
......@@ -29,6 +31,8 @@ const char* LogMessageToString(LogMessage message);
// Returns the actual string to be presented to the user for |message|.
const char* LogMessageValue(LogMessage message);
LogBuffer& operator<<(LogBuffer& buf, LogMessage message);
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_INTERNALS_LOG_MESSAGE_H_
......@@ -2,26 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/autofill/core/browser/autofill_internals_service.h"
#include "components/autofill/core/common/autofill_internals/log_message.h"
#include "base/json/json_writer.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest-death-test.h"
#include "components/autofill/core/common/logging/log_buffer.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace autofill {
TEST(AutofillInternalsService, Scope) {
LogBuffer buffer;
buffer << LoggingScope::kContext;
std::string json;
EXPECT_TRUE(base::JSONWriter::Write(buffer.RetrieveResult(), &json));
EXPECT_EQ(R"({"attributes":{"class":"log-entry","scope":"Context"},)"
R"("type":"element","value":"div"})",
json);
}
TEST(AutofillInternalsService, Message) {
TEST(LogMessage, Serialization) {
LogBuffer buffer;
buffer << LogMessage::kParsedForms;
std::string json;
......
......@@ -5,6 +5,7 @@
#include "components/autofill/core/common/autofill_internals/logging_scope.h"
#include "base/logging.h"
#include "components/autofill/core/common/logging/log_buffer.h"
namespace autofill {
......@@ -29,4 +30,11 @@ const char* LoggingScopeToString(LoggingScope scope) {
return "";
}
LogBuffer& operator<<(LogBuffer& buf, LoggingScope scope) {
if (!buf.active())
return buf;
return buf << Tag{"div"} << Attrib{"scope", LoggingScopeToString(scope)}
<< Attrib{"class", "log-entry"};
}
} // namespace autofill
......@@ -7,6 +7,8 @@
namespace autofill {
class LogBuffer;
/////////////// Logging Scopes /////////////
// Generator for source code related to logging scopes. Pass a template T which
......@@ -33,6 +35,8 @@ enum class LoggingScope {
// Returns the enum value of |scope| as a string (without the leading k).
const char* LoggingScopeToString(LoggingScope scope);
LogBuffer& operator<<(LogBuffer& buf, LoggingScope scope);
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_INTERNALS_LOGGING_SCOPE_H_
......@@ -2,23 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_INTERNALS_SERVICE_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_INTERNALS_SERVICE_H_
#include "base/macros.h"
#include "components/autofill/core/browser/logging/log_router.h"
#include "components/autofill/core/common/autofill_internals/log_message.h"
#include "components/autofill/core/common/autofill_internals/logging_scope.h"
#include "base/json/json_writer.h"
#include "components/autofill/core/common/logging/log_buffer.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace autofill {
// TODO(crbug.com/928595) This is a temporary home for these operations.
// Find a properly named file.
LogBuffer& operator<<(LogBuffer& buf, LoggingScope scope);
LogBuffer& operator<<(LogBuffer& buf, LogMessage message);
TEST(LoggingScope, Serialization) {
LogBuffer buffer;
buffer << LoggingScope::kContext;
std::string json;
EXPECT_TRUE(base::JSONWriter::Write(buffer.RetrieveResult(), &json));
EXPECT_EQ(R"({"attributes":{"class":"log-entry","scope":"Context"},)"
R"("type":"element","value":"div"})",
json);
}
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_INTERNALS_SERVICE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment