Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: chrome/browser/password_manager/password_store_factory.cc

Issue 2256633002: Add two more options for the --password-store switch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/password_manager/password_store_factory.h" 5 #include "chrome/browser/password_manager/password_store_factory.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/environment.h" 11 #include "base/environment.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "base/rand_util.h" 13 #include "base/rand_util.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "chrome/browser/profiles/incognito_helpers.h" 16 #include "chrome/browser/profiles/incognito_helpers.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/sync/glue/sync_start_util.h" 18 #include "chrome/browser/sync/glue/sync_start_util.h"
19 #include "chrome/browser/sync/profile_sync_service_factory.h" 19 #include "chrome/browser/sync/profile_sync_service_factory.h"
20 #include "chrome/browser/web_data_service_factory.h" 20 #include "chrome/browser/web_data_service_factory.h"
21 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
22 #include "components/browser_sync/browser/profile_sync_service.h" 22 #include "components/browser_sync/browser/profile_sync_service.h"
23 #include "components/keyed_service/content/browser_context_dependency_manager.h" 23 #include "components/keyed_service/content/browser_context_dependency_manager.h"
24 #include "components/os_crypt/key_storage_util_linux.h"
24 #include "components/os_crypt/os_crypt_switches.h" 25 #include "components/os_crypt/os_crypt_switches.h"
25 #include "components/password_manager/core/browser/login_database.h" 26 #include "components/password_manager/core/browser/login_database.h"
26 #include "components/password_manager/core/browser/password_store.h" 27 #include "components/password_manager/core/browser/password_store.h"
27 #include "components/password_manager/core/browser/password_store_default.h" 28 #include "components/password_manager/core/browser/password_store_default.h"
28 #include "components/password_manager/core/browser/password_store_factory_util.h " 29 #include "components/password_manager/core/browser/password_store_factory_util.h "
29 #include "components/password_manager/core/common/password_manager_pref_names.h" 30 #include "components/password_manager/core/common/password_manager_pref_names.h"
30 #include "components/pref_registry/pref_registry_syncable.h" 31 #include "components/pref_registry/pref_registry_syncable.h"
31 #include "components/prefs/pref_service.h" 32 #include "components/prefs/pref_service.h"
32 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
33 34
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 #elif defined(OS_CHROMEOS) || defined(OS_ANDROID) 177 #elif defined(OS_CHROMEOS) || defined(OS_ANDROID)
177 // For now, we use PasswordStoreDefault. We might want to make a native 178 // For now, we use PasswordStoreDefault. We might want to make a native
178 // backend for PasswordStoreX (see below) in the future though. 179 // backend for PasswordStoreX (see below) in the future though.
179 ps = new password_manager::PasswordStoreDefault( 180 ps = new password_manager::PasswordStoreDefault(
180 main_thread_runner, db_thread_runner, std::move(login_db)); 181 main_thread_runner, db_thread_runner, std::move(login_db));
181 #elif defined(USE_X11) 182 #elif defined(USE_X11)
182 // On POSIX systems, we try to use the "native" password management system of 183 // On POSIX systems, we try to use the "native" password management system of
183 // the desktop environment currently running, allowing GNOME Keyring in XFCE. 184 // the desktop environment currently running, allowing GNOME Keyring in XFCE.
184 // (In all cases we fall back on the basic store in case of failure.) 185 // (In all cases we fall back on the basic store in case of failure.)
185 base::nix::DesktopEnvironment desktop_env = GetDesktopEnvironment(); 186 base::nix::DesktopEnvironment desktop_env = GetDesktopEnvironment();
186 base::nix::DesktopEnvironment used_desktop_env;
187 std::string store_type = 187 std::string store_type =
188 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 188 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
189 switches::kPasswordStore); 189 switches::kPasswordStore);
190 LinuxBackendUsed used_backend = PLAINTEXT; 190 LinuxBackendUsed used_backend = PLAINTEXT;
191 if (store_type == "kwallet") {
192 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4;
193 } else if (store_type == "kwallet5") {
194 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE5;
195 } else if (store_type == "gnome") {
196 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_GNOME;
197 } else if (store_type == "basic") {
198 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_OTHER;
199 } else {
200 // Detect the store to use automatically.
201 used_desktop_env = desktop_env;
202 const char* name = base::nix::GetDesktopEnvironmentName(desktop_env);
203 VLOG(1) << "Password storage detected desktop environment: "
204 << (name ? name : "(unknown)");
205 }
206 191
207 PrefService* prefs = profile->GetPrefs(); 192 PrefService* prefs = profile->GetPrefs();
208 LocalProfileId id = GetLocalProfileId(prefs); 193 LocalProfileId id = GetLocalProfileId(prefs);
209 194
195 SelectedLinuxBackend selected_backend =
196 SelectBackend(store_type, desktop_env);
197
210 std::unique_ptr<PasswordStoreX::NativeBackend> backend; 198 std::unique_ptr<PasswordStoreX::NativeBackend> backend;
211 if (used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE4 || 199 if (selected_backend == SelectedLinuxBackend::KWALLET ||
212 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE5) { 200 selected_backend == SelectedLinuxBackend::KWALLET5) {
213 // KDE3 didn't use DBus, which our KWallet store uses.
214 VLOG(1) << "Trying KWallet for password storage."; 201 VLOG(1) << "Trying KWallet for password storage.";
202 base::nix::DesktopEnvironment used_desktop_env =
203 selected_backend == SelectedLinuxBackend::KWALLET
204 ? base::nix::DESKTOP_ENVIRONMENT_KDE4
205 : base::nix::DESKTOP_ENVIRONMENT_KDE5;
215 backend.reset(new NativeBackendKWallet(id, used_desktop_env)); 206 backend.reset(new NativeBackendKWallet(id, used_desktop_env));
216 if (backend->Init()) { 207 if (backend->Init()) {
217 VLOG(1) << "Using KWallet for password storage."; 208 VLOG(1) << "Using KWallet for password storage.";
218 used_backend = KWALLET; 209 used_backend = KWALLET;
219 } else { 210 } else {
220 backend.reset(); 211 backend.reset();
221 } 212 }
222 } else if (used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_GNOME || 213 } else if (selected_backend == SelectedLinuxBackend::GNOME_ANY ||
223 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_UNITY || 214 selected_backend == SelectedLinuxBackend::GNOME_KEYRING ||
224 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_XFCE) { 215 selected_backend == SelectedLinuxBackend::GNOME_LIBSECRET) {
225 #if defined(USE_LIBSECRET) 216 #if defined(USE_LIBSECRET)
226 VLOG(1) << "Trying libsecret for password storage."; 217 if (selected_backend == SelectedLinuxBackend::GNOME_ANY ||
227 backend.reset(new NativeBackendLibsecret(id)); 218 selected_backend == SelectedLinuxBackend::GNOME_LIBSECRET) {
228 if (backend->Init()) { 219 VLOG(1) << "Trying libsecret for password storage.";
229 VLOG(1) << "Using libsecret keyring for password storage."; 220 backend.reset(new NativeBackendLibsecret(id));
230 used_backend = LIBSECRET; 221 if (backend->Init()) {
231 } else { 222 VLOG(1) << "Using libsecret keyring for password storage.";
232 backend.reset(); 223 used_backend = LIBSECRET;
224 } else {
225 backend.reset();
226 }
233 } 227 }
234 #endif // defined(USE_LIBSECRET) 228 #endif // defined(USE_LIBSECRET)
235 if (!backend.get()) {
236 #if defined(USE_GNOME_KEYRING) 229 #if defined(USE_GNOME_KEYRING)
230 if (!backend.get() &&
231 (selected_backend == SelectedLinuxBackend::GNOME_ANY ||
232 selected_backend == SelectedLinuxBackend::GNOME_KEYRING)) {
237 VLOG(1) << "Trying GNOME keyring for password storage."; 233 VLOG(1) << "Trying GNOME keyring for password storage.";
238 backend.reset(new NativeBackendGnome(id)); 234 backend.reset(new NativeBackendGnome(id));
239 if (backend->Init()) { 235 if (backend->Init()) {
240 VLOG(1) << "Using GNOME keyring for password storage."; 236 VLOG(1) << "Using GNOME keyring for password storage.";
241 used_backend = GNOME_KEYRING; 237 used_backend = GNOME_KEYRING;
242 } else { 238 } else {
243 backend.reset(); 239 backend.reset();
244 } 240 }
241 }
245 #endif // defined(USE_GNOME_KEYRING) 242 #endif // defined(USE_GNOME_KEYRING)
246 }
247 } 243 }
248 244
249 if (!backend.get()) { 245 if (!backend.get()) {
250 LOG(WARNING) << "Using basic (unencrypted) store for password storage. " 246 LOG(WARNING) << "Using basic (unencrypted) store for password storage. "
251 "See " 247 "See "
252 "https://chromium.googlesource.com/chromium/src/+/master/docs/linux_pass word_storage.md" 248 "https://chromium.googlesource.com/chromium/src/+/master/docs/linux_pass word_storage.md"
253 " for more information about password storage options."; 249 " for more information about password storage options.";
254 } 250 }
255 251
256 ps = new PasswordStoreX(main_thread_runner, db_thread_runner, 252 ps = new PasswordStoreX(main_thread_runner, db_thread_runner,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 break; 348 break;
353 case LIBSECRET: 349 case LIBSECRET:
354 usage = OTHER_LIBSECRET; 350 usage = OTHER_LIBSECRET;
355 break; 351 break;
356 } 352 }
357 } 353 }
358 UMA_HISTOGRAM_ENUMERATION("PasswordManager.LinuxBackendStatistics", usage, 354 UMA_HISTOGRAM_ENUMERATION("PasswordManager.LinuxBackendStatistics", usage,
359 MAX_BACKEND_USAGE_VALUE); 355 MAX_BACKEND_USAGE_VALUE);
360 } 356 }
361 #endif 357 #endif
OLDNEW
« no previous file with comments | « no previous file | chrome/common/chrome_switches.cc » ('j') | components/os_crypt/key_storage_util_linux.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698