Commit 1e9060c2 authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Added DVLOGs to web_controller.

To provide human-readable status messages, several enums now support the output operator <<. String representations of enums are only compiled into debug builds. The same is true for logging string representations of selectors, because they might contain sensitive data.

Bug: 806868
Change-Id: I09de68f93a612cd4060761e8171b0bcd959df942
Reviewed-on: https://chromium-review.googlesource.com/c/1455901
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarStephane Zermatten <szermatt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630716}
parent e2d80b38
...@@ -196,7 +196,7 @@ void Controller::EnterState(AutofillAssistantState state) { ...@@ -196,7 +196,7 @@ void Controller::EnterState(AutofillAssistantState state) {
return; return;
DCHECK_NE(state_, AutofillAssistantState::STOPPED) DCHECK_NE(state_, AutofillAssistantState::STOPPED)
<< "Unexpected transition from STOPPED to " << static_cast<int>(state); << "Unexpected transition from " << state_ << " to " << state;
state_ = state; state_ = state;
GetUiController()->OnStateChanged(state); GetUiController()->OnStateChanged(state);
...@@ -540,8 +540,8 @@ void Controller::GetTouchableArea(std::vector<RectF>* area) const { ...@@ -540,8 +540,8 @@ void Controller::GetTouchableArea(std::vector<RectF>* area) const {
void Controller::OnFatalError(const std::string& error_message, void Controller::OnFatalError(const std::string& error_message,
Metrics::DropOutReason reason) { Metrics::DropOutReason reason) {
LOG(ERROR) << "Autofill Assistant has encountered an error and is shutting " LOG(ERROR) << "Autofill Assistant has encountered an error and is shutting "
"down. Reason: " "down, reason="
<< static_cast<int>(reason); << reason;
if (state_ == AutofillAssistantState::STOPPED) if (state_ == AutofillAssistantState::STOPPED)
return; return;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_METRICS_H_ #ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_METRICS_H_
#define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_METRICS_H_ #define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_METRICS_H_
#include <ostream>
namespace autofill_assistant { namespace autofill_assistant {
// A class to generate Autofill Assistant related histograms. // A class to generate Autofill Assistant related histograms.
...@@ -37,6 +39,76 @@ class Metrics { ...@@ -37,6 +39,76 @@ class Metrics {
}; };
static void RecordDropOut(DropOutReason reason); static void RecordDropOut(DropOutReason reason);
// Intended for debugging: writes string representation of |reason| to |out|.
friend std::ostream& operator<<(std::ostream& out,
const DropOutReason& reason) {
#ifdef NDEBUG
// Non-debugging builds write the enum number.
out << static_cast<int>(reason);
return out;
#else
// Debugging builds write a string representation of |reason|.
switch (reason) {
case AA_START:
out << "AA_START";
break;
case AUTOSTART_TIMEOUT:
out << "AUTOSTART_TIMEOUT";
break;
case NO_SCRIPTS:
out << "NO_SCRIPTS";
break;
case CUSTOM_TAB_CLOSED:
out << "CUSTOM_TAB_CLOSED";
break;
case DECLINED:
out << "DECLINED";
break;
case SHEET_CLOSED:
out << "SHEET_CLOSED";
break;
case SCRIPT_FAILED:
out << "SCRIPT_FAILED";
break;
case NAVIGATION:
out << "NAVIGATION";
break;
case OVERLAY_STOP:
out << "OVERLAY_STOP";
break;
case PR_FAILED:
out << "PR_FAILED";
break;
case CONTENT_DESTROYED:
out << "CONTENT_DESTROYED";
break;
case RENDER_PROCESS_GONE:
out << "RENDER_PROCESS_GONE";
break;
case INTERSTITIAL_PAGE:
out << "INTERSTITIAL_PAGE";
break;
case SCRIPT_SHUTDOWN:
out << "SCRIPT_SHUTDOWN";
break;
case SAFETY_NET_TERMINATE:
out << "SAFETY_NET_TERMINATE";
break;
case TAB_DETACHED:
out << "TAB_DETACHED";
break;
case TAB_CHANGED:
out << "TAB_CHANGED";
break;
case NUM_ENTRIES:
out << "NUM_ENTRIES";
// Intentionally no default case to make compilation fail if a new value
// was added to the enum but not to this list.
}
return out;
#endif // NDEBUG
}
}; };
} // namespace autofill_assistant } // namespace autofill_assistant
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "components/autofill_assistant/browser/selector.h" #include "components/autofill_assistant/browser/selector.h"
#include "base/strings/string_util.h"
namespace autofill_assistant { namespace autofill_assistant {
Selector::Selector() : pseudo_type(PseudoType::UNDEFINED) {} Selector::Selector() : pseudo_type(PseudoType::UNDEFINED) {}
...@@ -41,4 +43,14 @@ bool Selector::empty() const { ...@@ -41,4 +43,14 @@ bool Selector::empty() const {
return this->selectors.empty(); return this->selectors.empty();
} }
} // namespace autofill_assistant std::ostream& operator<<(std::ostream& out, const Selector& selector) {
\ No newline at end of file #ifdef NDEBUG
out << selector.selectors.size() << " element(s)";
return out;
#else
out << "elements=[" << base::JoinString(selector.selectors, ",") << "]";
return out;
#endif // NDEBUG
}
} // namespace autofill_assistant
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_SELECTOR_H_ #ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_SELECTOR_H_
#define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_SELECTOR_H_ #define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_SELECTOR_H_
#include <ostream>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -39,6 +40,10 @@ struct Selector { ...@@ -39,6 +40,10 @@ struct Selector {
bool operator<(const Selector& other) const; bool operator<(const Selector& other) const;
bool operator==(const Selector& other) const; bool operator==(const Selector& other) const;
// The output operator. The actual selectors are only available in debug
// builds.
friend std::ostream& operator<<(std::ostream& out, const Selector& selector);
// Checks whether this selector is empty. // Checks whether this selector is empty.
bool empty() const; bool empty() const;
}; };
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_ #ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_
#define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_ #define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_
#include <ostream>
namespace autofill_assistant { namespace autofill_assistant {
// High-level states the Autofill Assistant can be in. // High-level states the Autofill Assistant can be in.
...@@ -47,6 +49,43 @@ enum class AutofillAssistantState { ...@@ -47,6 +49,43 @@ enum class AutofillAssistantState {
STOPPED STOPPED
}; };
inline std::ostream& operator<<(std::ostream& out,
const AutofillAssistantState& state) {
#ifdef NDEBUG
// Non-debugging builds write the enum number.
out << static_cast<int>(state);
return out;
#else
// Debugging builds write a string representation of |state|.
switch (state) {
case AutofillAssistantState::INACTIVE:
out << "INACTIVE";
break;
case AutofillAssistantState::STARTING:
out << "STARTING";
break;
case AutofillAssistantState::RUNNING:
out << "RUNNING";
break;
case AutofillAssistantState::PROMPT:
out << "PROMPT";
break;
case AutofillAssistantState::AUTOSTART_FALLBACK_PROMPT:
out << "AUTOSTART_FALLBACK_PROMPT";
break;
case AutofillAssistantState::MODAL_DIALOG:
out << "MODAL_DIALOG";
break;
case AutofillAssistantState::STOPPED:
out << "STOPPED";
break;
// Intentionally no default case to make compilation fail if a new value
// was added to the enum but not to this list.
}
return out;
#endif // NDEBUG
}
} // namespace autofill_assistant } // namespace autofill_assistant
#endif // COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_ #endif // COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_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