File: password_store_bridge.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (103 lines) | stat: -rw-r--r-- 4,120 bytes parent folder | download | duplicates (3)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_PASSWORD_MANAGER_ANDROID_PASSWORD_STORE_BRIDGE_H_
#define CHROME_BROWSER_PASSWORD_MANAGER_ANDROID_PASSWORD_STORE_BRIDGE_H_

#include <jni.h>

#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "base/scoped_observation.h"
#include "chrome/browser/affiliations/affiliation_service_factory.h"
#include "chrome/browser/password_manager/account_password_store_factory.h"
#include "chrome/browser/password_manager/profile_password_store_factory.h"
#include "components/password_manager/core/browser/password_store/password_store_interface.h"
#include "components/password_manager/core/browser/ui/saved_passwords_presenter.h"

class Profile;

class PasswordStoreBridge
    : public password_manager::SavedPasswordsPresenter::Observer {
 public:
  PasswordStoreBridge(const base::android::JavaParamRef<jobject>& java_bridge,
                      Profile* profile);
  ~PasswordStoreBridge() override;

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

  // Called by Java to store a new credential into the profile password store.
  void InsertPasswordCredentialInProfileStoreForTesting(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& credential);

  // Called by Java to store a new credential into the account password store.
  void InsertPasswordCredentialInAccountStoreForTesting(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& credential);

  void BlocklistForTesting(JNIEnv* env,
                           const base::android::JavaParamRef<jstring>& jurl);

  // Called by Java to edit a credential.
  bool EditPassword(JNIEnv* env,
                    const base::android::JavaParamRef<jobject>& credential,
                    const base::android::JavaParamRef<jstring>& new_password);

  // Called by Java to get the number of stored credentials for both profile and
  // account stores.
  jint GetPasswordStoreCredentialsCountForAllStores(JNIEnv* env) const;

  // Called by Java to get the number of stored credentials in the account
  // storage.
  jint GetPasswordStoreCredentialsCountForAccountStore(JNIEnv* env) const;

  // Called by Java to get the number of stored credentials in the local
  // storage.
  jint GetPasswordStoreCredentialsCountForProfileStore(JNIEnv* env) const;

  // Called by Java to get all stored credentials.
  void GetAllCredentials(
      JNIEnv* env,
      const base::android::JavaParamRef<jobjectArray>& java_credentials) const;

  // Called by Java to clear all stored passwords.
  void ClearAllPasswords(JNIEnv* env);

  // Called by Java to clear all passwords from profile store.
  void ClearAllPasswordsFromProfileStore(JNIEnv* env);

  // Called by Java to destroy `this`.
  void Destroy(JNIEnv* env);

 private:
  // SavedPasswordsPresenter::Observer:
  void OnSavedPasswordsChanged(
      const password_manager::PasswordStoreChangeList& changes) override;

  void OnEdited(const password_manager::CredentialUIEntry& form) override;

  // The corresponding java object.
  base::android::ScopedJavaGlobalRef<jobject> java_bridge_;

  raw_ptr<Profile> profile_;

  const scoped_refptr<password_manager::PasswordStoreInterface> profile_store_;
  const scoped_refptr<password_manager::PasswordStoreInterface> account_store_;

  // Used to fetch and edit passwords.
  // TODO(crbug.com/40267119): Use PasswordStore directly.
  password_manager::SavedPasswordsPresenter saved_passwords_presenter_;

  // A scoped observer for `saved_passwords_presenter_`.
  base::ScopedObservation<password_manager::SavedPasswordsPresenter,
                          password_manager::SavedPasswordsPresenter::Observer>
      observed_saved_password_presenter_{this};

  // `weak_factory_` is used for all callback uses.
  base::WeakPtrFactory<PasswordStoreBridge> weak_factory_{this};
};

#endif  // CHROME_BROWSER_PASSWORD_MANAGER_ANDROID_PASSWORD_STORE_BRIDGE_H_