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