| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 192 } |
| 193 | 193 |
| 194 // static | 194 // static |
| 195 int ProfileImpl::create_readme_delay_ms = 60000; | 195 int ProfileImpl::create_readme_delay_ms = 60000; |
| 196 | 196 |
| 197 // static | 197 // static |
| 198 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { | 198 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { |
| 199 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, | 199 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, |
| 200 false, | 200 false, |
| 201 PrefService::UNSYNCABLE_PREF); | 201 PrefService::UNSYNCABLE_PREF); |
| 202 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, | |
| 203 false, | |
| 204 PrefService::SYNCABLE_PREF); | |
| 205 prefs->RegisterBooleanPref(prefs::kProfileShortcutCreated, | 202 prefs->RegisterBooleanPref(prefs::kProfileShortcutCreated, |
| 206 false, | 203 false, |
| 207 PrefService::UNSYNCABLE_PREF); | 204 PrefService::UNSYNCABLE_PREF); |
| 208 prefs->RegisterIntegerPref(prefs::kProfileAvatarIndex, | 205 prefs->RegisterIntegerPref(prefs::kProfileAvatarIndex, |
| 209 -1, | 206 -1, |
| 210 PrefService::SYNCABLE_PREF); | 207 PrefService::SYNCABLE_PREF); |
| 211 prefs->RegisterStringPref(prefs::kProfileName, | 208 prefs->RegisterStringPref(prefs::kProfileName, |
| 212 "", | 209 "", |
| 213 PrefService::SYNCABLE_PREF); | 210 PrefService::SYNCABLE_PREF); |
| 214 prefs->RegisterBooleanPref(prefs::kRestoreSessionStateDialogShown, | 211 prefs->RegisterBooleanPref(prefs::kRestoreSessionStateDialogShown, |
| 215 false, | 212 false, |
| 216 PrefService::SYNCABLE_PREF); | 213 PrefService::SYNCABLE_PREF); |
| 214 |
| 215 // Deprecated. Kept around for migration. |
| 216 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, |
| 217 false, |
| 218 PrefService::SYNCABLE_PREF); |
| 217 } | 219 } |
| 218 | 220 |
| 219 ProfileImpl::ProfileImpl(const FilePath& path, | 221 ProfileImpl::ProfileImpl(const FilePath& path, |
| 220 Delegate* delegate, | 222 Delegate* delegate, |
| 221 CreateMode create_mode) | 223 CreateMode create_mode) |
| 222 : path_(path), | 224 : path_(path), |
| 223 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( | 225 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( |
| 224 new VisitedLinkEventListener(this))), | 226 new VisitedLinkEventListener(this))), |
| 225 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), | 227 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), |
| 226 host_content_settings_map_(NULL), | 228 host_content_settings_map_(NULL), |
| 227 history_service_created_(false), | 229 history_service_created_(false), |
| 228 favicon_service_created_(false), | 230 favicon_service_created_(false), |
| 229 clear_local_state_on_exit_(false), | |
| 230 start_time_(Time::Now()), | 231 start_time_(Time::Now()), |
| 231 delegate_(delegate), | 232 delegate_(delegate), |
| 232 predictor_(NULL), | 233 predictor_(NULL), |
| 233 session_restore_enabled_(false) { | 234 session_restore_enabled_(false) { |
| 234 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 235 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
| 235 "profile files to the root directory!"; | 236 "profile files to the root directory!"; |
| 236 | 237 |
| 237 #if defined(ENABLE_SESSION_SERVICE) | 238 #if defined(ENABLE_SESSION_SERVICE) |
| 238 create_session_service_timer_.Start(FROM_HERE, | 239 create_session_service_timer_.Start(FROM_HERE, |
| 239 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, | 240 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 269 OnPrefsLoaded(true); | 270 OnPrefsLoaded(true); |
| 270 } else { | 271 } else { |
| 271 NOTREACHED(); | 272 NOTREACHED(); |
| 272 } | 273 } |
| 273 } | 274 } |
| 274 | 275 |
| 275 void ProfileImpl::DoFinalInit(bool is_new_profile) { | 276 void ProfileImpl::DoFinalInit(bool is_new_profile) { |
| 276 PrefService* prefs = GetPrefs(); | 277 PrefService* prefs = GetPrefs(); |
| 277 pref_change_registrar_.Init(prefs); | 278 pref_change_registrar_.Init(prefs); |
| 278 pref_change_registrar_.Add(prefs::kSpeechRecognitionFilterProfanities, this); | 279 pref_change_registrar_.Add(prefs::kSpeechRecognitionFilterProfanities, this); |
| 279 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); | |
| 280 pref_change_registrar_.Add(prefs::kGoogleServicesUsername, this); | 280 pref_change_registrar_.Add(prefs::kGoogleServicesUsername, this); |
| 281 pref_change_registrar_.Add(prefs::kDefaultZoomLevel, this); | 281 pref_change_registrar_.Add(prefs::kDefaultZoomLevel, this); |
| 282 pref_change_registrar_.Add(prefs::kProfileAvatarIndex, this); | 282 pref_change_registrar_.Add(prefs::kProfileAvatarIndex, this); |
| 283 pref_change_registrar_.Add(prefs::kProfileName, this); | 283 pref_change_registrar_.Add(prefs::kProfileName, this); |
| 284 | 284 |
| 285 // It would be nice to use PathService for fetching this directory, but | 285 // It would be nice to use PathService for fetching this directory, but |
| 286 // the cache directory depends on the profile directory, which isn't available | 286 // the cache directory depends on the profile directory, which isn't available |
| 287 // to PathService. | 287 // to PathService. |
| 288 chrome::GetUserCacheDirectory(path_, &base_cache_path_); | 288 chrome::GetUserCacheDirectory(path_, &base_cache_path_); |
| 289 // Always create the cache directory asynchronously. | 289 // Always create the cache directory asynchronously. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 318 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepAliveForTest)) | 318 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepAliveForTest)) |
| 319 init_background_mode_manager = false; | 319 init_background_mode_manager = false; |
| 320 #endif | 320 #endif |
| 321 if (init_background_mode_manager) { | 321 if (init_background_mode_manager) { |
| 322 if (g_browser_process->background_mode_manager()) | 322 if (g_browser_process->background_mode_manager()) |
| 323 g_browser_process->background_mode_manager()->RegisterProfile(this); | 323 g_browser_process->background_mode_manager()->RegisterProfile(this); |
| 324 } | 324 } |
| 325 | 325 |
| 326 InitRegisteredProtocolHandlers(); | 326 InitRegisteredProtocolHandlers(); |
| 327 | 327 |
| 328 clear_local_state_on_exit_ = prefs->GetBoolean(prefs::kClearSiteDataOnExit); | |
| 329 if (clear_local_state_on_exit_) { | |
| 330 content::RecordAction( | |
| 331 UserMetricsAction("ClearSiteDataOnExitEnabled")); | |
| 332 } else { | |
| 333 content::RecordAction( | |
| 334 UserMetricsAction("ClearSiteDataOnExitDisabled")); | |
| 335 } | |
| 336 | |
| 337 InstantController::RecordMetrics(this); | 328 InstantController::RecordMetrics(this); |
| 338 | 329 |
| 339 FilePath cookie_path = GetPath(); | 330 FilePath cookie_path = GetPath(); |
| 340 cookie_path = cookie_path.Append(chrome::kCookieFilename); | 331 cookie_path = cookie_path.Append(chrome::kCookieFilename); |
| 341 FilePath server_bound_cert_path = GetPath(); | 332 FilePath server_bound_cert_path = GetPath(); |
| 342 server_bound_cert_path = | 333 server_bound_cert_path = |
| 343 server_bound_cert_path.Append(chrome::kOBCertFilename); | 334 server_bound_cert_path.Append(chrome::kOBCertFilename); |
| 344 FilePath cache_path = base_cache_path_; | 335 FilePath cache_path = base_cache_path_; |
| 345 int cache_max_size; | 336 int cache_max_size; |
| 346 GetCacheParameters(false, &cache_path, &cache_max_size); | 337 GetCacheParameters(false, &cache_path, &cache_max_size); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); | 464 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); |
| 474 } | 465 } |
| 475 | 466 |
| 476 ProfileImpl::~ProfileImpl() { | 467 ProfileImpl::~ProfileImpl() { |
| 477 content::NotificationService::current()->Notify( | 468 content::NotificationService::current()->Notify( |
| 478 chrome::NOTIFICATION_PROFILE_DESTROYED, | 469 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 479 content::Source<Profile>(this), | 470 content::Source<Profile>(this), |
| 480 content::NotificationService::NoDetails()); | 471 content::NotificationService::NoDetails()); |
| 481 bool prefs_loaded = prefs_->GetInitializationStatus() != | 472 bool prefs_loaded = prefs_->GetInitializationStatus() != |
| 482 PrefService::INITIALIZATION_STATUS_WAITING; | 473 PrefService::INITIALIZATION_STATUS_WAITING; |
| 483 // Honor the "clear local state" setting. | |
| 484 if (clear_local_state_on_exit_) | |
| 485 BrowserContext::ClearLocalOnDestruction(this); | |
| 486 | 474 |
| 487 #if defined(ENABLE_SESSION_SERVICE) | 475 #if defined(ENABLE_SESSION_SERVICE) |
| 488 StopCreateSessionServiceTimer(); | 476 StopCreateSessionServiceTimer(); |
| 489 #endif | 477 #endif |
| 490 | 478 |
| 491 // Remove pref observers | 479 // Remove pref observers |
| 492 pref_change_registrar_.RemoveAll(); | 480 pref_change_registrar_.RemoveAll(); |
| 493 | 481 |
| 494 ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext( | 482 ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext( |
| 495 io_data_.GetResourceContextNoInit()); | 483 io_data_.GetResourceContextNoInit()); |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 std::string* pref_name_in = content::Details<std::string>(details).ptr(); | 891 std::string* pref_name_in = content::Details<std::string>(details).ptr(); |
| 904 PrefService* prefs = content::Source<PrefService>(source).ptr(); | 892 PrefService* prefs = content::Source<PrefService>(source).ptr(); |
| 905 DCHECK(pref_name_in && prefs); | 893 DCHECK(pref_name_in && prefs); |
| 906 if (*pref_name_in == prefs::kSpeechRecognitionFilterProfanities) { | 894 if (*pref_name_in == prefs::kSpeechRecognitionFilterProfanities) { |
| 907 content::SpeechRecognitionPreferences* speech_prefs = | 895 content::SpeechRecognitionPreferences* speech_prefs = |
| 908 GetSpeechRecognitionPreferences(); | 896 GetSpeechRecognitionPreferences(); |
| 909 if (speech_prefs) { | 897 if (speech_prefs) { |
| 910 speech_prefs->SetFilterProfanities(prefs->GetBoolean( | 898 speech_prefs->SetFilterProfanities(prefs->GetBoolean( |
| 911 prefs::kSpeechRecognitionFilterProfanities)); | 899 prefs::kSpeechRecognitionFilterProfanities)); |
| 912 } | 900 } |
| 913 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { | |
| 914 clear_local_state_on_exit_ = | |
| 915 prefs->GetBoolean(prefs::kClearSiteDataOnExit); | |
| 916 } else if (*pref_name_in == prefs::kGoogleServicesUsername) { | 901 } else if (*pref_name_in == prefs::kGoogleServicesUsername) { |
| 917 UpdateProfileUserNameCache(); | 902 UpdateProfileUserNameCache(); |
| 918 } else if (*pref_name_in == prefs::kProfileAvatarIndex) { | 903 } else if (*pref_name_in == prefs::kProfileAvatarIndex) { |
| 919 UpdateProfileAvatarCache(); | 904 UpdateProfileAvatarCache(); |
| 920 } else if (*pref_name_in == prefs::kProfileName) { | 905 } else if (*pref_name_in == prefs::kProfileName) { |
| 921 UpdateProfileNameCache(); | 906 UpdateProfileNameCache(); |
| 922 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { | 907 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { |
| 923 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( | 908 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( |
| 924 prefs->GetDouble(prefs::kDefaultZoomLevel)); | 909 prefs->GetDouble(prefs::kDefaultZoomLevel)); |
| 925 } | 910 } |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 if (!path.empty()) | 1132 if (!path.empty()) |
| 1148 *cache_path = path; | 1133 *cache_path = path; |
| 1149 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1134 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
| 1150 prefs_->GetInteger(prefs::kDiskCacheSize); | 1135 prefs_->GetInteger(prefs::kDiskCacheSize); |
| 1151 } | 1136 } |
| 1152 | 1137 |
| 1153 base::Callback<ChromeURLDataManagerBackend*(void)> | 1138 base::Callback<ChromeURLDataManagerBackend*(void)> |
| 1154 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { | 1139 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { |
| 1155 return io_data_.GetChromeURLDataManagerBackendGetter(); | 1140 return io_data_.GetChromeURLDataManagerBackendGetter(); |
| 1156 } | 1141 } |
| OLD | NEW |