| Index: components/os_crypt/key_storage_util_linux.cc
|
| diff --git a/components/os_crypt/key_storage_util_linux.cc b/components/os_crypt/key_storage_util_linux.cc
|
| index 5be4252e58c11fb257763ecf4ef164d95c77fc64..2daf7b0b95d7412b59df942a0d45193500df16f7 100644
|
| --- a/components/os_crypt/key_storage_util_linux.cc
|
| +++ b/components/os_crypt/key_storage_util_linux.cc
|
| @@ -4,12 +4,33 @@
|
|
|
| #include "components/os_crypt/key_storage_util_linux.h"
|
|
|
| +#include "base/files/file_path.h"
|
| +#include "base/files/file_util.h"
|
| #include "base/logging.h"
|
|
|
| +namespace {
|
| +
|
| +// OSCrypt has a setting that determines whether a backend will be used.
|
| +// The presense of this file in the file system means that the backend
|
| +// should be ignored. It's absence means we should use the backend.
|
| +constexpr const char kPreferenceFileName[] = "Disable Local Encryption";
|
| +
|
| +bool ReadBackendUse(const base::FilePath& user_data_dir, bool* use) {
|
| + if (user_data_dir.empty())
|
| + return false;
|
| + base::FilePath pref_path = user_data_dir.Append(kPreferenceFileName);
|
| + *use = !base::PathExists(pref_path);
|
| + return true;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| namespace os_crypt {
|
|
|
| SelectedLinuxBackend SelectBackend(const std::string& type,
|
| + bool use_backend,
|
| base::nix::DesktopEnvironment desktop_env) {
|
| + // Explicitly requesting a store overrides other production logic.
|
| if (type == "kwallet")
|
| return SelectedLinuxBackend::KWALLET;
|
| if (type == "kwallet5")
|
| @@ -23,11 +44,14 @@ SelectedLinuxBackend SelectBackend(const std::string& type,
|
| if (type == "basic")
|
| return SelectedLinuxBackend::BASIC_TEXT;
|
|
|
| + // Ignore the backends if requested to.
|
| + if (!use_backend)
|
| + return SelectedLinuxBackend::BASIC_TEXT;
|
| +
|
| + // Detect the store to use automatically.
|
| const char* name = base::nix::GetDesktopEnvironmentName(desktop_env);
|
| VLOG(1) << "Password storage detected desktop environment: "
|
| << (name ? name : "(unknown)");
|
| -
|
| - // Detect the store to use automatically.
|
| switch (desktop_env) {
|
| case base::nix::DESKTOP_ENVIRONMENT_KDE4:
|
| return SelectedLinuxBackend::KWALLET;
|
| @@ -47,4 +71,21 @@ SelectedLinuxBackend SelectBackend(const std::string& type,
|
| return SelectedLinuxBackend::BASIC_TEXT;
|
| }
|
|
|
| +bool WriteBackendUse(const base::FilePath& user_data_dir, bool use) {
|
| + if (user_data_dir.empty())
|
| + return false;
|
| + base::FilePath pref_path = user_data_dir.Append(kPreferenceFileName);
|
| + if (use)
|
| + return base::DeleteFile(pref_path, false);
|
| + FILE* f = base::OpenFile(pref_path, "w");
|
| + return f != nullptr && base::CloseFile(f);
|
| +}
|
| +
|
| +bool GetBackendUse(const base::FilePath& user_data_dir) {
|
| + bool setting;
|
| + if (ReadBackendUse(user_data_dir, &setting))
|
| + return setting;
|
| + return true;
|
| +}
|
| +
|
| } // namespace os_crypt
|
|
|