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