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

Side by Side Diff: chrome/browser/profiles/profile_impl.cc

Issue 9665007: Profile refactoring: Remove all PasswordStore code from the Profile interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win and Mac Created 8 years, 9 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 | Annotate | Revision Log
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/profiles/profile_impl.h" 5 #include "chrome/browser/profiles/profile_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "chrome/browser/history/shortcuts_backend.h" 49 #include "chrome/browser/history/shortcuts_backend.h"
50 #include "chrome/browser/history/top_sites.h" 50 #include "chrome/browser/history/top_sites.h"
51 #include "chrome/browser/instant/instant_controller.h" 51 #include "chrome/browser/instant/instant_controller.h"
52 #include "chrome/browser/metrics/metrics_service.h" 52 #include "chrome/browser/metrics/metrics_service.h"
53 #include "chrome/browser/net/chrome_url_request_context.h" 53 #include "chrome/browser/net/chrome_url_request_context.h"
54 #include "chrome/browser/net/net_pref_observer.h" 54 #include "chrome/browser/net/net_pref_observer.h"
55 #include "chrome/browser/net/predictor.h" 55 #include "chrome/browser/net/predictor.h"
56 #include "chrome/browser/net/proxy_service_factory.h" 56 #include "chrome/browser/net/proxy_service_factory.h"
57 #include "chrome/browser/net/ssl_config_service_manager.h" 57 #include "chrome/browser/net/ssl_config_service_manager.h"
58 #include "chrome/browser/net/url_fixer_upper.h" 58 #include "chrome/browser/net/url_fixer_upper.h"
59 #include "chrome/browser/password_manager/password_store_default.h"
60 #include "chrome/browser/plugin_prefs.h" 59 #include "chrome/browser/plugin_prefs.h"
61 #include "chrome/browser/policy/configuration_policy_pref_store.h" 60 #include "chrome/browser/policy/configuration_policy_pref_store.h"
62 #include "chrome/browser/prefs/browser_prefs.h" 61 #include "chrome/browser/prefs/browser_prefs.h"
63 #include "chrome/browser/prefs/pref_value_store.h" 62 #include "chrome/browser/prefs/pref_value_store.h"
64 #include "chrome/browser/prefs/scoped_user_pref_update.h" 63 #include "chrome/browser/prefs/scoped_user_pref_update.h"
65 #include "chrome/browser/prerender/prerender_manager_factory.h" 64 #include "chrome/browser/prerender/prerender_manager_factory.h"
66 #include "chrome/browser/profiles/gaia_info_update_service.h" 65 #include "chrome/browser/profiles/gaia_info_update_service.h"
67 #include "chrome/browser/profiles/profile_dependency_manager.h" 66 #include "chrome/browser/profiles/profile_dependency_manager.h"
68 #include "chrome/browser/profiles/profile_info_cache.h" 67 #include "chrome/browser/profiles/profile_info_cache.h"
69 #include "chrome/browser/profiles/profile_manager.h" 68 #include "chrome/browser/profiles/profile_manager.h"
(...skipping 25 matching lines...) Expand all
95 #include "content/public/browser/notification_service.h" 94 #include "content/public/browser/notification_service.h"
96 #include "content/public/browser/user_metrics.h" 95 #include "content/public/browser/user_metrics.h"
97 #include "grit/locale_settings.h" 96 #include "grit/locale_settings.h"
98 #include "net/base/transport_security_state.h" 97 #include "net/base/transport_security_state.h"
99 #include "net/http/http_server_properties.h" 98 #include "net/http/http_server_properties.h"
100 #include "webkit/appcache/appcache_service.h" 99 #include "webkit/appcache/appcache_service.h"
101 #include "webkit/database/database_tracker.h" 100 #include "webkit/database/database_tracker.h"
102 101
103 #if defined(OS_WIN) 102 #if defined(OS_WIN)
104 #include "chrome/browser/instant/promo_counter.h" 103 #include "chrome/browser/instant/promo_counter.h"
105 #include "chrome/browser/password_manager/password_store_win.h"
106 #include "chrome/installer/util/install_util.h" 104 #include "chrome/installer/util/install_util.h"
107 #elif defined(OS_MACOSX)
108 #include "chrome/browser/keychain_mac.h"
109 #include "chrome/browser/mock_keychain_mac.h"
110 #include "chrome/browser/password_manager/password_store_mac.h"
111 #elif defined(OS_CHROMEOS) 105 #elif defined(OS_CHROMEOS)
112 #include "chrome/browser/chromeos/enterprise_extension_observer.h" 106 #include "chrome/browser/chromeos/enterprise_extension_observer.h"
113 #elif defined(OS_POSIX)
114 #include "base/nix/xdg_util.h"
115 #if defined(USE_GNOME_KEYRING)
116 #include "chrome/browser/password_manager/native_backend_gnome_x.h"
117 #endif
118 #include "chrome/browser/password_manager/native_backend_kwallet_x.h"
119 #include "chrome/browser/password_manager/password_store_x.h"
120 #endif 107 #endif
121 108
122 #if defined(OS_CHROMEOS) 109 #if defined(OS_CHROMEOS)
123 #include "chrome/browser/chromeos/locale_change_guard.h" 110 #include "chrome/browser/chromeos/locale_change_guard.h"
124 #include "chrome/browser/chromeos/login/user_manager.h" 111 #include "chrome/browser/chromeos/login/user_manager.h"
125 #include "chrome/browser/chromeos/preferences.h" 112 #include "chrome/browser/chromeos/preferences.h"
126 #include "chrome/browser/chromeos/proxy_config_service_impl.h" 113 #include "chrome/browser/chromeos/proxy_config_service_impl.h"
127 #endif 114 #endif
128 115
129 using base::Time; 116 using base::Time;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 PrefService::UNSYNCABLE_PREF); 195 PrefService::UNSYNCABLE_PREF);
209 prefs->RegisterIntegerPref(prefs::kProfileAvatarIndex, 196 prefs->RegisterIntegerPref(prefs::kProfileAvatarIndex,
210 -1, 197 -1,
211 PrefService::SYNCABLE_PREF); 198 PrefService::SYNCABLE_PREF);
212 prefs->RegisterStringPref(prefs::kProfileName, 199 prefs->RegisterStringPref(prefs::kProfileName,
213 "", 200 "",
214 PrefService::SYNCABLE_PREF); 201 PrefService::SYNCABLE_PREF);
215 prefs->RegisterBooleanPref(prefs::kRestoreSessionStateDialogShown, 202 prefs->RegisterBooleanPref(prefs::kRestoreSessionStateDialogShown,
216 false, 203 false,
217 PrefService::SYNCABLE_PREF); 204 PrefService::SYNCABLE_PREF);
218 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
219 prefs->RegisterIntegerPref(prefs::kLocalProfileId,
220 kInvalidLocalProfileId,
221 PrefService::UNSYNCABLE_PREF);
222 // Notice that the preprocessor conditions above are exactly those that will
223 // result in using PasswordStoreX in CreatePasswordStore() below.
224 PasswordStoreX::RegisterUserPrefs(prefs);
225 #endif
226 } 205 }
227 206
228 ProfileImpl::ProfileImpl(const FilePath& path, 207 ProfileImpl::ProfileImpl(const FilePath& path,
229 Profile::Delegate* delegate) 208 Profile::Delegate* delegate)
230 : path_(path), 209 : path_(path),
231 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( 210 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_(
232 new VisitedLinkEventListener(this))), 211 new VisitedLinkEventListener(this))),
233 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), 212 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)),
234 extension_devtools_manager_(NULL), 213 extension_devtools_manager_(NULL),
235 host_content_settings_map_(NULL), 214 host_content_settings_map_(NULL),
236 history_service_created_(false), 215 history_service_created_(false),
237 favicon_service_created_(false), 216 favicon_service_created_(false),
238 created_web_data_service_(false), 217 created_web_data_service_(false),
239 created_password_store_(false),
240 start_time_(Time::Now()), 218 start_time_(Time::Now()),
241 #if defined(OS_WIN) 219 #if defined(OS_WIN)
242 checked_instant_promo_(false), 220 checked_instant_promo_(false),
243 #endif 221 #endif
244 delegate_(delegate), 222 delegate_(delegate),
245 predictor_(NULL), 223 predictor_(NULL),
246 session_restore_enabled_(false) { 224 session_restore_enabled_(false) {
247 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << 225 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
248 "profile files to the root directory!"; 226 "profile files to the root directory!";
249 227
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 if (io_data_.HasMainRequestContext() && 554 if (io_data_.HasMainRequestContext() &&
577 default_request_context_ == GetRequestContext()) { 555 default_request_context_ == GetRequestContext()) {
578 default_request_context_ = NULL; 556 default_request_context_ = NULL;
579 } 557 }
580 558
581 // Destroy OTR profile and its profile services first. 559 // Destroy OTR profile and its profile services first.
582 DestroyOffTheRecordProfile(); 560 DestroyOffTheRecordProfile();
583 561
584 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); 562 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this);
585 563
586 // Password store uses WebDB, shut it down before the WebDB has been shutdown.
587 if (password_store_.get())
588 password_store_->Shutdown();
589
590 // Both HistoryService and WebDataService maintain threads for background 564 // Both HistoryService and WebDataService maintain threads for background
591 // processing. Its possible each thread still has tasks on it that have 565 // processing. Its possible each thread still has tasks on it that have
592 // increased the ref count of the service. In such a situation, when we 566 // increased the ref count of the service. In such a situation, when we
593 // decrement the refcount, it won't be 0, and the threads/databases aren't 567 // decrement the refcount, it won't be 0, and the threads/databases aren't
594 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the 568 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
595 // databases are properly closed. 569 // databases are properly closed.
596 if (web_data_service_.get()) 570 if (web_data_service_.get())
597 web_data_service_->Shutdown(); 571 web_data_service_->Shutdown();
598 572
599 if (top_sites_.get()) 573 if (top_sites_.get())
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 947
974 void ProfileImpl::CreateWebDataService() { 948 void ProfileImpl::CreateWebDataService() {
975 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL); 949 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
976 created_web_data_service_ = true; 950 created_web_data_service_ = true;
977 scoped_refptr<WebDataService> wds(new WebDataService()); 951 scoped_refptr<WebDataService> wds(new WebDataService());
978 if (!wds->Init(GetPath())) 952 if (!wds->Init(GetPath()))
979 return; 953 return;
980 web_data_service_.swap(wds); 954 web_data_service_.swap(wds);
981 } 955 }
982 956
983 PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) {
984 if (!created_password_store_)
985 CreatePasswordStore();
986 return password_store_.get();
987 }
988
989 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
990 LocalProfileId ProfileImpl::GetLocalProfileId() {
991 PrefService* prefs = GetPrefs();
992 LocalProfileId id = prefs->GetInteger(prefs::kLocalProfileId);
993 if (id == kInvalidLocalProfileId) {
994 // Note that there are many more users than this. Thus, by design, this is
995 // not a unique id. However, it is large enough that it is very unlikely
996 // that it would be repeated twice on a single machine. It is still possible
997 // for that to occur though, so the potential results of it actually
998 // happening should be considered when using this value.
999 static const LocalProfileId kLocalProfileIdMask =
1000 static_cast<LocalProfileId>((1 << 24) - 1);
1001 do {
1002 id = rand() & kLocalProfileIdMask;
1003 // TODO(mdm): scan other profiles to make sure they are not using this id?
1004 } while (id == kInvalidLocalProfileId);
1005 prefs->SetInteger(prefs::kLocalProfileId, id);
1006 }
1007 return id;
1008 }
1009 #endif // !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
1010
1011 void ProfileImpl::CreatePasswordStore() {
1012 DCHECK(!created_password_store_ && password_store_.get() == NULL);
1013 created_password_store_ = true;
1014 scoped_refptr<PasswordStore> ps;
1015 FilePath login_db_file_path = GetPath();
1016 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
1017 LoginDatabase* login_db = new LoginDatabase();
1018 if (!login_db->Init(login_db_file_path)) {
1019 LOG(ERROR) << "Could not initialize login database.";
1020 delete login_db;
1021 return;
1022 }
1023 #if defined(OS_WIN)
1024 ps = new PasswordStoreWin(login_db, this,
1025 GetWebDataService(Profile::IMPLICIT_ACCESS));
1026 #elif defined(OS_MACOSX)
1027 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseMockKeychain)) {
1028 ps = new PasswordStoreMac(new MockKeychain(), login_db);
1029 } else {
1030 ps = new PasswordStoreMac(new MacKeychain(), login_db);
1031 }
1032 #elif defined(OS_CHROMEOS)
1033 // For now, we use PasswordStoreDefault. We might want to make a native
1034 // backend for PasswordStoreX (see below) in the future though.
1035 ps = new PasswordStoreDefault(login_db, this,
1036 GetWebDataService(Profile::IMPLICIT_ACCESS));
1037 #elif defined(OS_POSIX)
1038 // On POSIX systems, we try to use the "native" password management system of
1039 // the desktop environment currently running, allowing GNOME Keyring in XFCE.
1040 // (In all cases we fall back on the basic store in case of failure.)
1041 base::nix::DesktopEnvironment desktop_env;
1042 std::string store_type =
1043 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
1044 switches::kPasswordStore);
1045 if (store_type == "kwallet") {
1046 desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4;
1047 } else if (store_type == "gnome") {
1048 desktop_env = base::nix::DESKTOP_ENVIRONMENT_GNOME;
1049 } else if (store_type == "basic") {
1050 desktop_env = base::nix::DESKTOP_ENVIRONMENT_OTHER;
1051 } else {
1052 // Detect the store to use automatically.
1053 scoped_ptr<base::Environment> env(base::Environment::Create());
1054 desktop_env = base::nix::GetDesktopEnvironment(env.get());
1055 const char* name = base::nix::GetDesktopEnvironmentName(desktop_env);
1056 VLOG(1) << "Password storage detected desktop environment: "
1057 << (name ? name : "(unknown)");
1058 }
1059
1060 scoped_ptr<PasswordStoreX::NativeBackend> backend;
1061 if (desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE4) {
1062 // KDE3 didn't use DBus, which our KWallet store uses.
1063 VLOG(1) << "Trying KWallet for password storage.";
1064 backend.reset(new NativeBackendKWallet(GetLocalProfileId(), GetPrefs()));
1065 if (backend->Init())
1066 VLOG(1) << "Using KWallet for password storage.";
1067 else
1068 backend.reset();
1069 } else if (desktop_env == base::nix::DESKTOP_ENVIRONMENT_GNOME ||
1070 desktop_env == base::nix::DESKTOP_ENVIRONMENT_XFCE) {
1071 #if defined(USE_GNOME_KEYRING)
1072 VLOG(1) << "Trying GNOME keyring for password storage.";
1073 backend.reset(new NativeBackendGnome(GetLocalProfileId(), GetPrefs()));
1074 if (backend->Init())
1075 VLOG(1) << "Using GNOME keyring for password storage.";
1076 else
1077 backend.reset();
1078 #endif // defined(USE_GNOME_KEYRING)
1079 }
1080
1081 if (!backend.get()) {
1082 LOG(WARNING) << "Using basic (unencrypted) store for password storage. "
1083 "See http://code.google.com/p/chromium/wiki/LinuxPasswordStorage for "
1084 "more information about password storage options.";
1085 }
1086
1087 ps = new PasswordStoreX(login_db, this,
1088 GetWebDataService(Profile::IMPLICIT_ACCESS),
1089 backend.release());
1090 #else
1091 NOTIMPLEMENTED();
1092 #endif
1093 if (!ps)
1094 delete login_db;
1095
1096 if (!ps || !ps->Init()) {
1097 NOTREACHED() << "Could not initialize password manager.";
1098 return;
1099 }
1100 password_store_.swap(ps);
1101 }
1102
1103 DownloadManager* ProfileImpl::GetDownloadManager() { 957 DownloadManager* ProfileImpl::GetDownloadManager() {
1104 return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager(); 958 return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager();
1105 } 959 }
1106 960
1107 bool ProfileImpl::DidLastSessionExitCleanly() { 961 bool ProfileImpl::DidLastSessionExitCleanly() {
1108 // last_session_exited_cleanly_ is set when the preferences are loaded. Force 962 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
1109 // it to be set by asking for the prefs. 963 // it to be set by asking for the prefs.
1110 GetPrefs(); 964 GetPrefs();
1111 return last_session_exited_cleanly_; 965 return last_session_exited_cleanly_;
1112 } 966 }
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 FilePath* cache_path, 1309 FilePath* cache_path,
1456 int* max_size) { 1310 int* max_size) {
1457 DCHECK(cache_path); 1311 DCHECK(cache_path);
1458 DCHECK(max_size); 1312 DCHECK(max_size);
1459 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); 1313 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir));
1460 if (!path.empty()) 1314 if (!path.empty())
1461 *cache_path = path; 1315 *cache_path = path;
1462 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : 1316 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) :
1463 prefs_->GetInteger(prefs::kDiskCacheSize); 1317 prefs_->GetInteger(prefs::kDiskCacheSize);
1464 } 1318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698