| 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/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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 #include "chrome/browser/history/shortcuts_backend.h" | 50 #include "chrome/browser/history/shortcuts_backend.h" |
| 51 #include "chrome/browser/history/top_sites.h" | 51 #include "chrome/browser/history/top_sites.h" |
| 52 #include "chrome/browser/instant/instant_controller.h" | 52 #include "chrome/browser/instant/instant_controller.h" |
| 53 #include "chrome/browser/metrics/metrics_service.h" | 53 #include "chrome/browser/metrics/metrics_service.h" |
| 54 #include "chrome/browser/net/chrome_url_request_context.h" | 54 #include "chrome/browser/net/chrome_url_request_context.h" |
| 55 #include "chrome/browser/net/net_pref_observer.h" | 55 #include "chrome/browser/net/net_pref_observer.h" |
| 56 #include "chrome/browser/net/predictor.h" | 56 #include "chrome/browser/net/predictor.h" |
| 57 #include "chrome/browser/net/proxy_service_factory.h" | 57 #include "chrome/browser/net/proxy_service_factory.h" |
| 58 #include "chrome/browser/net/ssl_config_service_manager.h" | 58 #include "chrome/browser/net/ssl_config_service_manager.h" |
| 59 #include "chrome/browser/net/url_fixer_upper.h" | 59 #include "chrome/browser/net/url_fixer_upper.h" |
| 60 #include "chrome/browser/password_manager/password_store_default.h" | |
| 61 #include "chrome/browser/plugin_prefs.h" | 60 #include "chrome/browser/plugin_prefs.h" |
| 62 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 61 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 63 #include "chrome/browser/prefs/browser_prefs.h" | 62 #include "chrome/browser/prefs/browser_prefs.h" |
| 64 #include "chrome/browser/prefs/pref_value_store.h" | 63 #include "chrome/browser/prefs/pref_value_store.h" |
| 65 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 64 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 66 #include "chrome/browser/prerender/prerender_manager_factory.h" | 65 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 67 #include "chrome/browser/profiles/gaia_info_update_service.h" | 66 #include "chrome/browser/profiles/gaia_info_update_service.h" |
| 68 #include "chrome/browser/profiles/profile_dependency_manager.h" | 67 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 69 #include "chrome/browser/profiles/profile_info_cache.h" | 68 #include "chrome/browser/profiles/profile_info_cache.h" |
| 70 #include "chrome/browser/profiles/profile_manager.h" | 69 #include "chrome/browser/profiles/profile_manager.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 98 #include "grit/chromium_strings.h" | 97 #include "grit/chromium_strings.h" |
| 99 #include "grit/locale_settings.h" | 98 #include "grit/locale_settings.h" |
| 100 #include "net/base/transport_security_state.h" | 99 #include "net/base/transport_security_state.h" |
| 101 #include "net/http/http_server_properties.h" | 100 #include "net/http/http_server_properties.h" |
| 102 #include "webkit/appcache/appcache_service.h" | 101 #include "webkit/appcache/appcache_service.h" |
| 103 #include "webkit/database/database_tracker.h" | 102 #include "webkit/database/database_tracker.h" |
| 104 #include "ui/base/l10n/l10n_util.h" | 103 #include "ui/base/l10n/l10n_util.h" |
| 105 | 104 |
| 106 #if defined(OS_WIN) | 105 #if defined(OS_WIN) |
| 107 #include "chrome/browser/instant/promo_counter.h" | 106 #include "chrome/browser/instant/promo_counter.h" |
| 108 #include "chrome/browser/password_manager/password_store_win.h" | |
| 109 #include "chrome/installer/util/install_util.h" | 107 #include "chrome/installer/util/install_util.h" |
| 110 #elif defined(OS_MACOSX) | |
| 111 #include "chrome/browser/keychain_mac.h" | |
| 112 #include "chrome/browser/mock_keychain_mac.h" | |
| 113 #include "chrome/browser/password_manager/password_store_mac.h" | |
| 114 #elif defined(OS_CHROMEOS) | 108 #elif defined(OS_CHROMEOS) |
| 115 #include "chrome/browser/chromeos/enterprise_extension_observer.h" | 109 #include "chrome/browser/chromeos/enterprise_extension_observer.h" |
| 116 #elif defined(OS_POSIX) | |
| 117 #include "base/nix/xdg_util.h" | |
| 118 #if defined(USE_GNOME_KEYRING) | |
| 119 #include "chrome/browser/password_manager/native_backend_gnome_x.h" | |
| 120 #endif | |
| 121 #include "chrome/browser/password_manager/native_backend_kwallet_x.h" | |
| 122 #include "chrome/browser/password_manager/password_store_x.h" | |
| 123 #endif | 110 #endif |
| 124 | 111 |
| 125 #if defined(OS_CHROMEOS) | 112 #if defined(OS_CHROMEOS) |
| 126 #include "chrome/browser/chromeos/locale_change_guard.h" | 113 #include "chrome/browser/chromeos/locale_change_guard.h" |
| 127 #include "chrome/browser/chromeos/login/user_manager.h" | 114 #include "chrome/browser/chromeos/login/user_manager.h" |
| 128 #include "chrome/browser/chromeos/preferences.h" | 115 #include "chrome/browser/chromeos/preferences.h" |
| 129 #include "chrome/browser/chromeos/proxy_config_service_impl.h" | 116 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
| 130 #endif | 117 #endif |
| 131 | 118 |
| 132 using base::Time; | 119 using base::Time; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 PrefService::UNSYNCABLE_PREF); | 221 PrefService::UNSYNCABLE_PREF); |
| 235 prefs->RegisterIntegerPref(prefs::kProfileAvatarIndex, | 222 prefs->RegisterIntegerPref(prefs::kProfileAvatarIndex, |
| 236 -1, | 223 -1, |
| 237 PrefService::SYNCABLE_PREF); | 224 PrefService::SYNCABLE_PREF); |
| 238 prefs->RegisterStringPref(prefs::kProfileName, | 225 prefs->RegisterStringPref(prefs::kProfileName, |
| 239 "", | 226 "", |
| 240 PrefService::SYNCABLE_PREF); | 227 PrefService::SYNCABLE_PREF); |
| 241 prefs->RegisterBooleanPref(prefs::kRestoreSessionStateDialogShown, | 228 prefs->RegisterBooleanPref(prefs::kRestoreSessionStateDialogShown, |
| 242 false, | 229 false, |
| 243 PrefService::SYNCABLE_PREF); | 230 PrefService::SYNCABLE_PREF); |
| 244 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) | |
| 245 prefs->RegisterIntegerPref(prefs::kLocalProfileId, | |
| 246 kInvalidLocalProfileId, | |
| 247 PrefService::UNSYNCABLE_PREF); | |
| 248 // Notice that the preprocessor conditions above are exactly those that will | |
| 249 // result in using PasswordStoreX in CreatePasswordStore() below. | |
| 250 PasswordStoreX::RegisterUserPrefs(prefs); | |
| 251 #endif | |
| 252 } | 231 } |
| 253 | 232 |
| 254 ProfileImpl::ProfileImpl(const FilePath& path, | 233 ProfileImpl::ProfileImpl(const FilePath& path, |
| 255 Delegate* delegate, | 234 Delegate* delegate, |
| 256 CreateMode create_mode) | 235 CreateMode create_mode) |
| 257 : path_(path), | 236 : path_(path), |
| 258 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( | 237 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( |
| 259 new VisitedLinkEventListener(this))), | 238 new VisitedLinkEventListener(this))), |
| 260 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), | 239 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), |
| 261 extension_devtools_manager_(NULL), | 240 extension_devtools_manager_(NULL), |
| 262 host_content_settings_map_(NULL), | 241 host_content_settings_map_(NULL), |
| 263 history_service_created_(false), | 242 history_service_created_(false), |
| 264 favicon_service_created_(false), | 243 favicon_service_created_(false), |
| 265 created_web_data_service_(false), | 244 created_web_data_service_(false), |
| 266 created_password_store_(false), | |
| 267 start_time_(Time::Now()), | 245 start_time_(Time::Now()), |
| 268 #if defined(OS_WIN) | 246 #if defined(OS_WIN) |
| 269 checked_instant_promo_(false), | 247 checked_instant_promo_(false), |
| 270 #endif | 248 #endif |
| 271 delegate_(delegate), | 249 delegate_(delegate), |
| 272 predictor_(NULL), | 250 predictor_(NULL), |
| 273 session_restore_enabled_(false) { | 251 session_restore_enabled_(false) { |
| 274 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 252 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
| 275 "profile files to the root directory!"; | 253 "profile files to the root directory!"; |
| 276 | 254 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 if (io_data_.HasMainRequestContext() && | 583 if (io_data_.HasMainRequestContext() && |
| 606 default_request_context_ == GetRequestContext()) { | 584 default_request_context_ == GetRequestContext()) { |
| 607 default_request_context_ = NULL; | 585 default_request_context_ = NULL; |
| 608 } | 586 } |
| 609 | 587 |
| 610 // Destroy OTR profile and its profile services first. | 588 // Destroy OTR profile and its profile services first. |
| 611 DestroyOffTheRecordProfile(); | 589 DestroyOffTheRecordProfile(); |
| 612 | 590 |
| 613 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); | 591 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); |
| 614 | 592 |
| 615 // Password store uses WebDB, shut it down before the WebDB has been shutdown. | |
| 616 if (password_store_.get()) | |
| 617 password_store_->Shutdown(); | |
| 618 | |
| 619 // Both HistoryService and WebDataService maintain threads for background | 593 // Both HistoryService and WebDataService maintain threads for background |
| 620 // processing. Its possible each thread still has tasks on it that have | 594 // processing. Its possible each thread still has tasks on it that have |
| 621 // increased the ref count of the service. In such a situation, when we | 595 // increased the ref count of the service. In such a situation, when we |
| 622 // decrement the refcount, it won't be 0, and the threads/databases aren't | 596 // decrement the refcount, it won't be 0, and the threads/databases aren't |
| 623 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the | 597 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the |
| 624 // databases are properly closed. | 598 // databases are properly closed. |
| 625 if (web_data_service_.get()) | 599 if (web_data_service_.get()) |
| 626 web_data_service_->Shutdown(); | 600 web_data_service_->Shutdown(); |
| 627 | 601 |
| 628 if (top_sites_.get()) | 602 if (top_sites_.get()) |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 | 979 |
| 1006 void ProfileImpl::CreateWebDataService() { | 980 void ProfileImpl::CreateWebDataService() { |
| 1007 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL); | 981 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL); |
| 1008 created_web_data_service_ = true; | 982 created_web_data_service_ = true; |
| 1009 scoped_refptr<WebDataService> wds(new WebDataService()); | 983 scoped_refptr<WebDataService> wds(new WebDataService()); |
| 1010 if (!wds->Init(GetPath())) | 984 if (!wds->Init(GetPath())) |
| 1011 return; | 985 return; |
| 1012 web_data_service_.swap(wds); | 986 web_data_service_.swap(wds); |
| 1013 } | 987 } |
| 1014 | 988 |
| 1015 PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) { | |
| 1016 if (!created_password_store_) | |
| 1017 CreatePasswordStore(); | |
| 1018 return password_store_.get(); | |
| 1019 } | |
| 1020 | |
| 1021 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) | |
| 1022 LocalProfileId ProfileImpl::GetLocalProfileId() { | |
| 1023 PrefService* prefs = GetPrefs(); | |
| 1024 LocalProfileId id = prefs->GetInteger(prefs::kLocalProfileId); | |
| 1025 if (id == kInvalidLocalProfileId) { | |
| 1026 // Note that there are many more users than this. Thus, by design, this is | |
| 1027 // not a unique id. However, it is large enough that it is very unlikely | |
| 1028 // that it would be repeated twice on a single machine. It is still possible | |
| 1029 // for that to occur though, so the potential results of it actually | |
| 1030 // happening should be considered when using this value. | |
| 1031 static const LocalProfileId kLocalProfileIdMask = | |
| 1032 static_cast<LocalProfileId>((1 << 24) - 1); | |
| 1033 do { | |
| 1034 id = rand() & kLocalProfileIdMask; | |
| 1035 // TODO(mdm): scan other profiles to make sure they are not using this id? | |
| 1036 } while (id == kInvalidLocalProfileId); | |
| 1037 prefs->SetInteger(prefs::kLocalProfileId, id); | |
| 1038 } | |
| 1039 return id; | |
| 1040 } | |
| 1041 #endif // !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) | |
| 1042 | |
| 1043 void ProfileImpl::CreatePasswordStore() { | |
| 1044 DCHECK(!created_password_store_ && password_store_.get() == NULL); | |
| 1045 created_password_store_ = true; | |
| 1046 scoped_refptr<PasswordStore> ps; | |
| 1047 FilePath login_db_file_path = GetPath(); | |
| 1048 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName); | |
| 1049 LoginDatabase* login_db = new LoginDatabase(); | |
| 1050 if (!login_db->Init(login_db_file_path)) { | |
| 1051 LOG(ERROR) << "Could not initialize login database."; | |
| 1052 delete login_db; | |
| 1053 return; | |
| 1054 } | |
| 1055 #if defined(OS_WIN) | |
| 1056 ps = new PasswordStoreWin(login_db, this, | |
| 1057 GetWebDataService(Profile::IMPLICIT_ACCESS)); | |
| 1058 #elif defined(OS_MACOSX) | |
| 1059 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseMockKeychain)) { | |
| 1060 ps = new PasswordStoreMac(new MockKeychain(), login_db); | |
| 1061 } else { | |
| 1062 ps = new PasswordStoreMac(new MacKeychain(), login_db); | |
| 1063 } | |
| 1064 #elif defined(OS_CHROMEOS) | |
| 1065 // For now, we use PasswordStoreDefault. We might want to make a native | |
| 1066 // backend for PasswordStoreX (see below) in the future though. | |
| 1067 ps = new PasswordStoreDefault(login_db, this, | |
| 1068 GetWebDataService(Profile::IMPLICIT_ACCESS)); | |
| 1069 #elif defined(OS_POSIX) | |
| 1070 // On POSIX systems, we try to use the "native" password management system of | |
| 1071 // the desktop environment currently running, allowing GNOME Keyring in XFCE. | |
| 1072 // (In all cases we fall back on the basic store in case of failure.) | |
| 1073 base::nix::DesktopEnvironment desktop_env; | |
| 1074 std::string store_type = | |
| 1075 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 1076 switches::kPasswordStore); | |
| 1077 if (store_type == "kwallet") { | |
| 1078 desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; | |
| 1079 } else if (store_type == "gnome") { | |
| 1080 desktop_env = base::nix::DESKTOP_ENVIRONMENT_GNOME; | |
| 1081 } else if (store_type == "basic") { | |
| 1082 desktop_env = base::nix::DESKTOP_ENVIRONMENT_OTHER; | |
| 1083 } else { | |
| 1084 // Detect the store to use automatically. | |
| 1085 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
| 1086 desktop_env = base::nix::GetDesktopEnvironment(env.get()); | |
| 1087 const char* name = base::nix::GetDesktopEnvironmentName(desktop_env); | |
| 1088 VLOG(1) << "Password storage detected desktop environment: " | |
| 1089 << (name ? name : "(unknown)"); | |
| 1090 } | |
| 1091 | |
| 1092 scoped_ptr<PasswordStoreX::NativeBackend> backend; | |
| 1093 if (desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE4) { | |
| 1094 // KDE3 didn't use DBus, which our KWallet store uses. | |
| 1095 VLOG(1) << "Trying KWallet for password storage."; | |
| 1096 backend.reset(new NativeBackendKWallet(GetLocalProfileId(), GetPrefs())); | |
| 1097 if (backend->Init()) | |
| 1098 VLOG(1) << "Using KWallet for password storage."; | |
| 1099 else | |
| 1100 backend.reset(); | |
| 1101 } else if (desktop_env == base::nix::DESKTOP_ENVIRONMENT_GNOME || | |
| 1102 desktop_env == base::nix::DESKTOP_ENVIRONMENT_XFCE) { | |
| 1103 #if defined(USE_GNOME_KEYRING) | |
| 1104 VLOG(1) << "Trying GNOME keyring for password storage."; | |
| 1105 backend.reset(new NativeBackendGnome(GetLocalProfileId(), GetPrefs())); | |
| 1106 if (backend->Init()) | |
| 1107 VLOG(1) << "Using GNOME keyring for password storage."; | |
| 1108 else | |
| 1109 backend.reset(); | |
| 1110 #endif // defined(USE_GNOME_KEYRING) | |
| 1111 } | |
| 1112 | |
| 1113 if (!backend.get()) { | |
| 1114 LOG(WARNING) << "Using basic (unencrypted) store for password storage. " | |
| 1115 "See http://code.google.com/p/chromium/wiki/LinuxPasswordStorage for " | |
| 1116 "more information about password storage options."; | |
| 1117 } | |
| 1118 | |
| 1119 ps = new PasswordStoreX(login_db, this, | |
| 1120 GetWebDataService(Profile::IMPLICIT_ACCESS), | |
| 1121 backend.release()); | |
| 1122 #else | |
| 1123 NOTIMPLEMENTED(); | |
| 1124 #endif | |
| 1125 if (!ps) | |
| 1126 delete login_db; | |
| 1127 | |
| 1128 if (!ps || !ps->Init()) { | |
| 1129 NOTREACHED() << "Could not initialize password manager."; | |
| 1130 return; | |
| 1131 } | |
| 1132 password_store_.swap(ps); | |
| 1133 } | |
| 1134 | |
| 1135 DownloadManager* ProfileImpl::GetDownloadManager() { | 989 DownloadManager* ProfileImpl::GetDownloadManager() { |
| 1136 return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager(); | 990 return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager(); |
| 1137 } | 991 } |
| 1138 | 992 |
| 1139 bool ProfileImpl::DidLastSessionExitCleanly() { | 993 bool ProfileImpl::DidLastSessionExitCleanly() { |
| 1140 // last_session_exited_cleanly_ is set when the preferences are loaded. Force | 994 // last_session_exited_cleanly_ is set when the preferences are loaded. Force |
| 1141 // it to be set by asking for the prefs. | 995 // it to be set by asking for the prefs. |
| 1142 GetPrefs(); | 996 GetPrefs(); |
| 1143 return last_session_exited_cleanly_; | 997 return last_session_exited_cleanly_; |
| 1144 } | 998 } |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1487 FilePath* cache_path, | 1341 FilePath* cache_path, |
| 1488 int* max_size) { | 1342 int* max_size) { |
| 1489 DCHECK(cache_path); | 1343 DCHECK(cache_path); |
| 1490 DCHECK(max_size); | 1344 DCHECK(max_size); |
| 1491 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); | 1345 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); |
| 1492 if (!path.empty()) | 1346 if (!path.empty()) |
| 1493 *cache_path = path; | 1347 *cache_path = path; |
| 1494 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1348 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
| 1495 prefs_->GetInteger(prefs::kDiskCacheSize); | 1349 prefs_->GetInteger(prefs::kDiskCacheSize); |
| 1496 } | 1350 } |
| OLD | NEW |