summaryrefslogtreecommitdiff
path: root/chromium/components/password_manager/core/browser/password_reuse_detection_manager.h
blob: 135895096001af89d22bdb2886b9752f7b4642c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2016 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.

#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_REUSE_DETECTION_MANAGER_H_
#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_REUSE_DETECTION_MANAGER_H_

#include <string>

#include "base/containers/flat_set.h"
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/password_manager/core/browser/password_reuse_detector.h"
#include "components/password_manager/core/browser/password_reuse_detector_consumer.h"
#include "url/gurl.h"

namespace base {
class Clock;
}

namespace password_manager {

class PasswordManagerClient;

// Class for managing password reuse detection. Now it receives keystrokes and
// does nothing with them. TODO(crbug.com/657041): write other features of this
// class when they are implemented. This class is one per-tab.
class PasswordReuseDetectionManager : public PasswordReuseDetectorConsumer {
 public:
  explicit PasswordReuseDetectionManager(PasswordManagerClient* client);

  PasswordReuseDetectionManager(const PasswordReuseDetectionManager&) = delete;
  PasswordReuseDetectionManager& operator=(
      const PasswordReuseDetectionManager&) = delete;

  ~PasswordReuseDetectionManager() override;
  void DidNavigateMainFrame(const GURL& main_frame_url);
  void OnKeyPressedCommitted(const std::u16string& text);
#if defined(OS_ANDROID)
  void OnKeyPressedUncommitted(const std::u16string& text);
#endif
  void OnPaste(const std::u16string text);

  // PasswordReuseDetectorConsumer implementation
  void OnReuseCheckDone(
      bool is_reuse_found,
      size_t password_length,
      absl::optional<PasswordHashData> reused_protected_password_hash,
      const std::vector<MatchingReusedCredential>& matching_reused_credentials,
      int saved_passwords) override;

  void SetClockForTesting(base::Clock* clock);

 private:
  void OnKeyPressed(const std::u16string& text, const bool is_committed);
  // Determines the type of password being reused.
  metrics_util::PasswordType GetReusedPasswordType(
      absl::optional<PasswordHashData> reused_protected_password_hash,
      size_t match_domain_count);

  void CheckStoresForReuse(const std::u16string& input);

  raw_ptr<PasswordManagerClient> client_;
  std::u16string input_characters_;
  GURL main_frame_url_;
  base::Time last_keystroke_time_;
  // Used to retrieve the current time, in base::Time units.
  raw_ptr<base::Clock> clock_;
  bool reuse_on_this_page_was_found_ = false;
};

}  // namespace password_manager

#endif  // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_REUSE_DETECTION_MANAGER_H_