password_manager_client.h revision 010d83a9304c5a91596085d917d248abff47903a
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_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_MANAGER_CLIENT_H_
6#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_MANAGER_CLIENT_H_
7
8#include "base/metrics/field_trial.h"
9#include "components/autofill/core/common/password_form.h"
10#include "components/autofill/core/common/password_form_fill_data.h"
11
12class PrefService;
13
14namespace password_manager {
15
16class PasswordFormManager;
17class PasswordManagerDriver;
18class PasswordStore;
19class PasswordManagerLogger;
20
21// An abstraction of operations that depend on the embedders (e.g. Chrome)
22// environment.
23class PasswordManagerClient {
24 public:
25  PasswordManagerClient() {}
26  virtual ~PasswordManagerClient() {}
27
28  // For automated testing, the save password prompt should sometimes not be
29  // shown, and password immediately saved instead. That can be enforced by
30  // a command-line flag. If auto-saving is enforced, this method returns true.
31  // The default return value is false.
32  virtual bool IsAutomaticPasswordSavingEnabled() const;
33
34  // Informs the embedder of a password form that can be saved if the user
35  // allows it. The embedder is not required to prompt the user if it decides
36  // that this form doesn't need to be saved.
37  virtual void PromptUserToSavePassword(PasswordFormManager* form_to_save) = 0;
38
39  // Called when a password is autofilled. |best_matches| contains the
40  // PasswordForm into which a password was filled: the client may choose to
41  // save this to the PasswordStore, for example. Default implementation is a
42  // noop.
43  virtual void PasswordWasAutofilled(
44      const autofill::PasswordFormMap& best_matches) const {}
45
46  // Called when password autofill is blocked by the blacklist. |best_matches|
47  // contains the PasswordForm that flags the current site as being on the
48  // blacklist. The client may choose to remove this from the PasswordStore in
49  // order to unblacklist a site, for example. Default implementation is a noop.
50  virtual void PasswordAutofillWasBlocked(
51      const autofill::PasswordFormMap& best_matches) const {}
52
53  // Called to authenticate the autofill password data.  If authentication is
54  // successful, this should continue filling the form.
55  virtual void AuthenticateAutofillAndFillForm(
56      scoped_ptr<autofill::PasswordFormFillData> fill_data) = 0;
57
58  // Gets prefs associated with this embedder.
59  virtual PrefService* GetPrefs() = 0;
60
61  // Returns the PasswordStore associated with this instance.
62  virtual PasswordStore* GetPasswordStore() = 0;
63
64  // Returns the PasswordManagerDriver instance associated with this instance.
65  virtual PasswordManagerDriver* GetDriver() = 0;
66
67  // Returns the probability that the experiment identified by |experiment_name|
68  // should be enabled. The default implementation returns 0.
69  virtual base::FieldTrial::Probability GetProbabilityForExperiment(
70      const std::string& experiment_name);
71
72  // Returns true if password sync is enabled in the embedder. The default
73  // implementation returns false.
74  virtual bool IsPasswordSyncEnabled();
75
76  // Attach or detach (setting NULL) a logger for this client.
77  virtual void SetLogger(PasswordManagerLogger* logger);
78
79  // Send |text| to the logger.
80  virtual void LogSavePasswordProgress(const std::string& text);
81
82  // Returns true if logs recorded via LogSavePasswordProgress will be
83  // displayed, and false otherwise.
84  virtual bool IsLoggingActive() const;
85
86 private:
87  DISALLOW_COPY_AND_ASSIGN(PasswordManagerClient);
88};
89
90}  // namespace password_manager
91
92#endif  // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_MANAGER_CLIENT_H_
93