save_password_progress_logger.h revision a02191e04bc25c4935f804f2c080ae28663d096d
1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_AUTOFILL_CORE_COMMON_SAVE_PASSWORD_PROGRESS_LOGGER_H_
6#define COMPONENTS_AUTOFILL_CORE_COMMON_SAVE_PASSWORD_PROGRESS_LOGGER_H_
7
8#include <string>
9
10#include "url/gurl.h"
11
12namespace base {
13class Value;
14}
15
16namespace autofill {
17
18struct PasswordForm;
19
20// When logging decisions made by password management code about whether to
21// offer user-entered credentials for saving or not, do use this class. It
22// offers a suite of convenience methods to format and scrub logs. The methods
23// have built-in privacy protections (never include a password, scrub URLs), so
24// that the result is appropriate for display on the internals page.
25//
26// To use this class, the method SendLog needs to be overriden to send the logs
27// for display as appropriate.
28//
29// TODO(vabr): Logically, this class belongs to the password_manager component.
30// But the PasswordAutofillAgent needs to use it, so until that agent is in a
31// third component, shared by autofill and password_manager, this helper needs
32// to stay in autofill as well.
33class SavePasswordProgressLogger {
34 public:
35  // All three possible decisions about saving a password. Call LogFinalDecision
36  // as soon as one is taken by the password management code.
37  enum Decision { DECISION_SAVE, DECISION_ASK, DECISION_DROP };
38
39  SavePasswordProgressLogger();
40  virtual ~SavePasswordProgressLogger();
41
42  // Logging: specialized methods (for logging forms, URLs, etc.) take care of
43  // proper removing of sensitive data where appropriate.
44  void LogPasswordForm(const std::string& message,
45                       const autofill::PasswordForm& form);
46  void LogHTMLForm(const std::string& message,
47                   const std::string& name_or_id,
48                   const std::string& method,
49                   const GURL& action);
50  void LogURL(const std::string& message, const GURL& url);
51  void LogBoolean(const std::string& message, bool value);
52  void LogNumber(const std::string& message, int value);
53  void LogNumber(const std::string& message, size_t value);
54  void LogFinalDecision(Decision decision);
55  // Do not use LogMessage when there is an appropriate specialized method
56  // above. LogMessage performs no scrubbing of sensitive data.
57  void LogMessage(const std::string& message);
58
59 protected:
60  // Sends |log| immediately for display.
61  virtual void SendLog(const std::string& log) = 0;
62
63 private:
64  // Takes a structured |log|, converts it to a string suitable for plain text
65  // output, adds the |name| as a caption, and sends out via SendLog.
66  void LogValue(const std::string& name, const base::Value& log);
67
68  DISALLOW_COPY_AND_ASSIGN(SavePasswordProgressLogger);
69};
70
71}  // namespace autofill
72
73#endif  // COMPONENTS_AUTOFILL_CORE_COMMON_SAVE_PASSWORD_PROGRESS_LOGGER_H_
74