| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/environment.h" | 9 #include "base/environment.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 checked_instant_promo_(false), | 281 checked_instant_promo_(false), |
| 282 #endif | 282 #endif |
| 283 delegate_(delegate) { | 283 delegate_(delegate) { |
| 284 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 284 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
| 285 "profile files to the root directory!"; | 285 "profile files to the root directory!"; |
| 286 create_session_service_timer_.Start( | 286 create_session_service_timer_.Start( |
| 287 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, | 287 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, |
| 288 &ProfileImpl::EnsureSessionServiceCreated); | 288 &ProfileImpl::EnsureSessionServiceCreated); |
| 289 | 289 |
| 290 if (delegate_) { | 290 if (delegate_) { |
| 291 prefs_.reset(PrefService::CreatePrefServiceAsync( | 291 prefs_.reset(PrefService::CreatePrefService( |
| 292 GetPrefFilePath(), | 292 GetPrefFilePath(), |
| 293 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), | 293 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), |
| 294 GetOriginalProfile(), | 294 GetOriginalProfile(), |
| 295 this)); // Ask to notify us in the end. | 295 true)); |
| 296 // Wait for the notifcation that prefs has been loaded (successfully or |
| 297 // not). |
| 298 registrar_.Add(this, NotificationType::PREF_INITIALIZATION_COMPLETED, |
| 299 Source<PrefService>(prefs_.get())); |
| 296 } else { | 300 } else { |
| 297 // Load prefs synchronously. | 301 // Load prefs synchronously. |
| 298 prefs_.reset(PrefService::CreatePrefService( | 302 prefs_.reset(PrefService::CreatePrefService( |
| 299 GetPrefFilePath(), | 303 GetPrefFilePath(), |
| 300 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), | 304 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), |
| 301 GetOriginalProfile())); | 305 GetOriginalProfile(), |
| 302 OnPrefsLoaded(prefs_.get(), true); | 306 false)); |
| 307 OnPrefsLoaded(true); |
| 303 } | 308 } |
| 304 } | 309 } |
| 305 | 310 |
| 306 void ProfileImpl::DoFinalInit() { | 311 void ProfileImpl::DoFinalInit() { |
| 307 PrefService* prefs = GetPrefs(); | 312 PrefService* prefs = GetPrefs(); |
| 308 pref_change_registrar_.Init(prefs); | 313 pref_change_registrar_.Init(prefs); |
| 309 pref_change_registrar_.Add(prefs::kSpellCheckDictionary, this); | 314 pref_change_registrar_.Add(prefs::kSpellCheckDictionary, this); |
| 310 pref_change_registrar_.Add(prefs::kEnableSpellCheck, this); | 315 pref_change_registrar_.Add(prefs::kEnableSpellCheck, this); |
| 311 pref_change_registrar_.Add(prefs::kEnableAutoSpellCorrect, this); | 316 pref_change_registrar_.Add(prefs::kEnableAutoSpellCorrect, this); |
| 312 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); | 317 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 switches::kHstsHosts)); | 800 switches::kHstsHosts)); |
| 796 transport_security_persister_ = | 801 transport_security_persister_ = |
| 797 new TransportSecurityPersister(false /* read-write */); | 802 new TransportSecurityPersister(false /* read-write */); |
| 798 transport_security_persister_->Initialize( | 803 transport_security_persister_->Initialize( |
| 799 transport_security_state_.get(), path_); | 804 transport_security_state_.get(), path_); |
| 800 } | 805 } |
| 801 | 806 |
| 802 return transport_security_state_.get(); | 807 return transport_security_state_.get(); |
| 803 } | 808 } |
| 804 | 809 |
| 805 void ProfileImpl::OnPrefsLoaded(PrefService* prefs, bool success) { | 810 void ProfileImpl::OnPrefsLoaded(bool success) { |
| 806 DCHECK(prefs == prefs_.get()); | |
| 807 | |
| 808 if (!success) { | 811 if (!success) { |
| 809 DCHECK(delegate_); | 812 DCHECK(delegate_); |
| 810 delegate_->OnProfileCreated(this, false); | 813 delegate_->OnProfileCreated(this, false); |
| 811 return; | 814 return; |
| 812 } | 815 } |
| 813 | 816 |
| 814 // The Profile class and ProfileManager class may read some prefs so | 817 // The Profile class and ProfileManager class may read some prefs so |
| 815 // register known prefs as soon as possible. | 818 // register known prefs as soon as possible. |
| 816 Profile::RegisterUserPrefs(prefs_.get()); | 819 Profile::RegisterUserPrefs(prefs_.get()); |
| 817 browser::RegisterUserPrefs(prefs_.get()); | 820 browser::RegisterUserPrefs(prefs_.get()); |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 | 1294 |
| 1292 // NOTE: If you change what thread this writes on, be sure and update | 1295 // NOTE: If you change what thread this writes on, be sure and update |
| 1293 // ChromeFrame::EndSession(). | 1296 // ChromeFrame::EndSession(). |
| 1294 prefs_->SavePersistentPrefs(); | 1297 prefs_->SavePersistentPrefs(); |
| 1295 } | 1298 } |
| 1296 } | 1299 } |
| 1297 | 1300 |
| 1298 void ProfileImpl::Observe(NotificationType type, | 1301 void ProfileImpl::Observe(NotificationType type, |
| 1299 const NotificationSource& source, | 1302 const NotificationSource& source, |
| 1300 const NotificationDetails& details) { | 1303 const NotificationDetails& details) { |
| 1301 if (NotificationType::PREF_CHANGED == type) { | 1304 switch (type.value) { |
| 1302 std::string* pref_name_in = Details<std::string>(details).ptr(); | 1305 case NotificationType::PREF_INITIALIZATION_COMPLETED: { |
| 1303 PrefService* prefs = Source<PrefService>(source).ptr(); | 1306 bool* succeeded = Details<bool>(details).ptr(); |
| 1304 DCHECK(pref_name_in && prefs); | 1307 PrefService *prefs = Source<PrefService>(source).ptr(); |
| 1305 if (*pref_name_in == prefs::kSpellCheckDictionary || | 1308 DCHECK(prefs == prefs_.get()); |
| 1306 *pref_name_in == prefs::kEnableSpellCheck) { | 1309 registrar_.Remove(this, NotificationType::PREF_INITIALIZATION_COMPLETED, |
| 1307 ReinitializeSpellCheckHost(true); | 1310 Source<PrefService>(prefs)); |
| 1308 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) { | 1311 OnPrefsLoaded(*succeeded); |
| 1309 bool enabled = prefs->GetBoolean(prefs::kEnableAutoSpellCorrect); | 1312 break; |
| 1310 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 1313 } |
| 1311 !i.IsAtEnd(); i.Advance()) { | 1314 case NotificationType::PREF_CHANGED: { |
| 1312 RenderProcessHost* process = i.GetCurrentValue(); | 1315 std::string* pref_name_in = Details<std::string>(details).ptr(); |
| 1313 process->Send(new SpellCheckMsg_EnableAutoSpellCorrect(enabled)); | 1316 PrefService* prefs = Source<PrefService>(source).ptr(); |
| 1317 DCHECK(pref_name_in && prefs); |
| 1318 if (*pref_name_in == prefs::kSpellCheckDictionary || |
| 1319 *pref_name_in == prefs::kEnableSpellCheck) { |
| 1320 ReinitializeSpellCheckHost(true); |
| 1321 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) { |
| 1322 bool enabled = prefs->GetBoolean(prefs::kEnableAutoSpellCorrect); |
| 1323 for (RenderProcessHost::iterator |
| 1324 i(RenderProcessHost::AllHostsIterator()); |
| 1325 !i.IsAtEnd(); i.Advance()) { |
| 1326 RenderProcessHost* process = i.GetCurrentValue(); |
| 1327 process->Send(new SpellCheckMsg_EnableAutoSpellCorrect(enabled)); |
| 1328 } |
| 1329 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { |
| 1330 clear_local_state_on_exit_ = |
| 1331 prefs->GetBoolean(prefs::kClearSiteDataOnExit); |
| 1332 if (webkit_context_) { |
| 1333 webkit_context_->set_clear_local_state_on_exit( |
| 1334 clear_local_state_on_exit_); |
| 1335 } |
| 1336 if (appcache_service_) { |
| 1337 appcache_service_->SetClearLocalStateOnExit( |
| 1338 clear_local_state_on_exit_); |
| 1339 } |
| 1340 } else if (*pref_name_in == prefs::kGoogleServicesUsername) { |
| 1341 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1342 profile_manager->RegisterProfileName(this); |
| 1314 } | 1343 } |
| 1315 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { | 1344 break; |
| 1316 clear_local_state_on_exit_ = | |
| 1317 prefs->GetBoolean(prefs::kClearSiteDataOnExit); | |
| 1318 if (webkit_context_) { | |
| 1319 webkit_context_->set_clear_local_state_on_exit( | |
| 1320 clear_local_state_on_exit_); | |
| 1321 } | |
| 1322 if (appcache_service_) { | |
| 1323 appcache_service_->SetClearLocalStateOnExit( | |
| 1324 clear_local_state_on_exit_); | |
| 1325 } | |
| 1326 } else if (*pref_name_in == prefs::kGoogleServicesUsername) { | |
| 1327 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 1328 profile_manager->RegisterProfileName(this); | |
| 1329 } | 1345 } |
| 1330 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) { | 1346 case NotificationType::BOOKMARK_MODEL_LOADED: |
| 1331 GetProfileSyncService(); // Causes lazy-load if sync is enabled. | 1347 GetProfileSyncService(); // Causes lazy-load if sync is enabled. |
| 1332 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED, | 1348 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED, |
| 1333 Source<Profile>(this)); | 1349 Source<Profile>(this)); |
| 1350 break; |
| 1351 default: |
| 1352 NOTREACHED(); |
| 1334 } | 1353 } |
| 1335 } | 1354 } |
| 1336 | 1355 |
| 1337 void ProfileImpl::StopCreateSessionServiceTimer() { | 1356 void ProfileImpl::StopCreateSessionServiceTimer() { |
| 1338 create_session_service_timer_.Stop(); | 1357 create_session_service_timer_.Stop(); |
| 1339 } | 1358 } |
| 1340 | 1359 |
| 1341 void ProfileImpl::EnsureSessionServiceCreated() { | 1360 void ProfileImpl::EnsureSessionServiceCreated() { |
| 1342 SessionServiceFactory::GetForProfile(this); | 1361 SessionServiceFactory::GetForProfile(this); |
| 1343 } | 1362 } |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1547 return pref_proxy_config_tracker_; | 1566 return pref_proxy_config_tracker_; |
| 1548 } | 1567 } |
| 1549 | 1568 |
| 1550 prerender::PrerenderManager* ProfileImpl::GetPrerenderManager() { | 1569 prerender::PrerenderManager* ProfileImpl::GetPrerenderManager() { |
| 1551 if (!prerender::PrerenderManager::IsPrerenderingPossible()) | 1570 if (!prerender::PrerenderManager::IsPrerenderingPossible()) |
| 1552 return NULL; | 1571 return NULL; |
| 1553 if (!prerender_manager_.get()) | 1572 if (!prerender_manager_.get()) |
| 1554 prerender_manager_.reset(new prerender::PrerenderManager(this)); | 1573 prerender_manager_.reset(new prerender::PrerenderManager(this)); |
| 1555 return prerender_manager_.get(); | 1574 return prerender_manager_.get(); |
| 1556 } | 1575 } |
| OLD | NEW |