OLD | NEW |
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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/environment.h" | 8 #include "base/environment.h" |
9 #include "chrome/browser/password_manager/login_database.h" | 9 #include "chrome/browser/password_manager/login_database.h" |
10 #include "chrome/browser/password_manager/password_store.h" | 10 #include "chrome/browser/password_manager/password_store.h" |
11 #include "chrome/browser/password_manager/password_store_default.h" | 11 #include "chrome/browser/password_manager/password_store_default.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/profiles/profile_dependency_manager.h" | 13 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 14 #include "chrome/browser/webdata/web_data_service.h" |
| 15 #include "chrome/browser/webdata/web_data_service_factory.h" |
14 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
15 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
17 | 19 |
18 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
19 #include "chrome/browser/password_manager/password_store_win.h" | 21 #include "chrome/browser/password_manager/password_store_win.h" |
20 #elif defined(OS_MACOSX) | 22 #elif defined(OS_MACOSX) |
21 #include "chrome/browser/password_manager/password_store_mac.h" | 23 #include "chrome/browser/password_manager/password_store_mac.h" |
22 #include "crypto/keychain_mac.h" | 24 #include "crypto/keychain_mac.h" |
23 #include "crypto/mock_keychain_mac.h" | 25 #include "crypto/mock_keychain_mac.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 58 |
57 // static | 59 // static |
58 PasswordStoreFactory* PasswordStoreFactory::GetInstance() { | 60 PasswordStoreFactory* PasswordStoreFactory::GetInstance() { |
59 return Singleton<PasswordStoreFactory>::get(); | 61 return Singleton<PasswordStoreFactory>::get(); |
60 } | 62 } |
61 | 63 |
62 PasswordStoreFactory::PasswordStoreFactory() | 64 PasswordStoreFactory::PasswordStoreFactory() |
63 : RefcountedProfileKeyedServiceFactory( | 65 : RefcountedProfileKeyedServiceFactory( |
64 "PasswordStore", | 66 "PasswordStore", |
65 ProfileDependencyManager::GetInstance()) { | 67 ProfileDependencyManager::GetInstance()) { |
66 // TODO(erg): We must always depend on WebDB; we don't want the dependency | 68 DependsOn(WebDataServiceFactory::GetInstance()); |
67 // graph to be different based on platform. | |
68 // | |
69 // DependsOn(WebDataServiceFactory::GetInstance()); | |
70 } | 69 } |
71 | 70 |
72 PasswordStoreFactory::~PasswordStoreFactory() {} | 71 PasswordStoreFactory::~PasswordStoreFactory() {} |
73 | 72 |
74 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && \ | 73 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && \ |
75 defined(OS_POSIX) | 74 defined(OS_POSIX) |
76 LocalProfileId PasswordStoreFactory::GetLocalProfileId( | 75 LocalProfileId PasswordStoreFactory::GetLocalProfileId( |
77 PrefService* prefs) const { | 76 PrefService* prefs) const { |
78 LocalProfileId id = prefs->GetInteger(prefs::kLocalProfileId); | 77 LocalProfileId id = prefs->GetInteger(prefs::kLocalProfileId); |
79 if (id == kInvalidLocalProfileId) { | 78 if (id == kInvalidLocalProfileId) { |
(...skipping 21 matching lines...) Expand all Loading... |
101 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName); | 100 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName); |
102 LoginDatabase* login_db = new LoginDatabase(); | 101 LoginDatabase* login_db = new LoginDatabase(); |
103 if (!login_db->Init(login_db_file_path)) { | 102 if (!login_db->Init(login_db_file_path)) { |
104 LOG(ERROR) << "Could not initialize login database."; | 103 LOG(ERROR) << "Could not initialize login database."; |
105 delete login_db; | 104 delete login_db; |
106 return NULL; | 105 return NULL; |
107 } | 106 } |
108 #if defined(OS_WIN) | 107 #if defined(OS_WIN) |
109 ps = new PasswordStoreWin( | 108 ps = new PasswordStoreWin( |
110 login_db, profile, | 109 login_db, profile, |
111 profile->GetWebDataService(Profile::IMPLICIT_ACCESS)); | 110 WebDataServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS)); |
112 #elif defined(OS_MACOSX) | 111 #elif defined(OS_MACOSX) |
113 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseMockKeychain)) { | 112 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseMockKeychain)) { |
114 ps = new PasswordStoreMac(new crypto::MockKeychain(), login_db); | 113 ps = new PasswordStoreMac(new crypto::MockKeychain(), login_db); |
115 } else { | 114 } else { |
116 ps = new PasswordStoreMac(new crypto::MacKeychain(), login_db); | 115 ps = new PasswordStoreMac(new crypto::MacKeychain(), login_db); |
117 } | 116 } |
118 #elif defined(OS_CHROMEOS) || defined(OS_ANDROID) | 117 #elif defined(OS_CHROMEOS) || defined(OS_ANDROID) |
119 // For now, we use PasswordStoreDefault. We might want to make a native | 118 // For now, we use PasswordStoreDefault. We might want to make a native |
120 // backend for PasswordStoreX (see below) in the future though. | 119 // backend for PasswordStoreX (see below) in the future though. |
121 ps = new PasswordStoreDefault( | 120 ps = new PasswordStoreDefault(login_db, profile, |
122 login_db, profile, profile->GetWebDataService(Profile::IMPLICIT_ACCESS)); | 121 WebDataServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS)); |
123 #elif defined(OS_POSIX) | 122 #elif defined(OS_POSIX) |
124 // On POSIX systems, we try to use the "native" password management system of | 123 // On POSIX systems, we try to use the "native" password management system of |
125 // the desktop environment currently running, allowing GNOME Keyring in XFCE. | 124 // the desktop environment currently running, allowing GNOME Keyring in XFCE. |
126 // (In all cases we fall back on the basic store in case of failure.) | 125 // (In all cases we fall back on the basic store in case of failure.) |
127 base::nix::DesktopEnvironment desktop_env; | 126 base::nix::DesktopEnvironment desktop_env; |
128 std::string store_type = | 127 std::string store_type = |
129 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 128 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
130 switches::kPasswordStore); | 129 switches::kPasswordStore); |
131 if (store_type == "kwallet") { | 130 if (store_type == "kwallet") { |
132 desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; | 131 desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 #endif // defined(USE_GNOME_KEYRING) | 166 #endif // defined(USE_GNOME_KEYRING) |
168 } | 167 } |
169 | 168 |
170 if (!backend.get()) { | 169 if (!backend.get()) { |
171 LOG(WARNING) << "Using basic (unencrypted) store for password storage. " | 170 LOG(WARNING) << "Using basic (unencrypted) store for password storage. " |
172 "See http://code.google.com/p/chromium/wiki/LinuxPasswordStorage for " | 171 "See http://code.google.com/p/chromium/wiki/LinuxPasswordStorage for " |
173 "more information about password storage options."; | 172 "more information about password storage options."; |
174 } | 173 } |
175 | 174 |
176 ps = new PasswordStoreX(login_db, profile, | 175 ps = new PasswordStoreX(login_db, profile, |
177 profile->GetWebDataService(Profile::IMPLICIT_ACCESS), | 176 WebDataServiceFactory::GetForProfile(profile, |
| 177 Profile::IMPLICIT_ACCESS), |
178 backend.release()); | 178 backend.release()); |
179 #else | 179 #else |
180 NOTIMPLEMENTED(); | 180 NOTIMPLEMENTED(); |
181 #endif | 181 #endif |
182 if (!ps) | 182 if (!ps) |
183 delete login_db; | 183 delete login_db; |
184 | 184 |
185 if (!ps || !ps->Init()) { | 185 if (!ps || !ps->Init()) { |
186 NOTREACHED() << "Could not initialize password manager."; | 186 NOTREACHED() << "Could not initialize password manager."; |
187 return NULL; | 187 return NULL; |
(...skipping 15 matching lines...) Expand all Loading... |
203 #endif | 203 #endif |
204 } | 204 } |
205 | 205 |
206 bool PasswordStoreFactory::ServiceRedirectedInIncognito() { | 206 bool PasswordStoreFactory::ServiceRedirectedInIncognito() { |
207 return true; | 207 return true; |
208 } | 208 } |
209 | 209 |
210 bool PasswordStoreFactory::ServiceIsNULLWhileTesting() { | 210 bool PasswordStoreFactory::ServiceIsNULLWhileTesting() { |
211 return true; | 211 return true; |
212 } | 212 } |
OLD | NEW |