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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 #endif | 280 #endif |
281 shutdown_session_service_(false), | 281 shutdown_session_service_(false), |
282 delegate_(delegate) { | 282 delegate_(delegate) { |
283 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 283 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
284 "profile files to the root directory!"; | 284 "profile files to the root directory!"; |
285 create_session_service_timer_.Start( | 285 create_session_service_timer_.Start( |
286 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, | 286 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, |
287 &ProfileImpl::EnsureSessionServiceCreated); | 287 &ProfileImpl::EnsureSessionServiceCreated); |
288 | 288 |
289 if (delegate_) { | 289 if (delegate_) { |
290 prefs_.reset(PrefService::CreatePrefServiceAsync( | 290 // Wait for the notifcation that prefs has been loaded (successfully or |
| 291 // not). |
| 292 registrar_.Add(this, NotificationType::PREF_INITIALIZATION_COMPLETED, |
| 293 Source<Profile>(this)); |
| 294 registrar_.Add(this, NotificationType::PREF_INITIALIZATION_FAILED, |
| 295 Source<Profile>(this)); |
| 296 prefs_.reset(PrefService::CreatePrefService( |
291 GetPrefFilePath(), | 297 GetPrefFilePath(), |
292 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), | 298 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), |
293 GetOriginalProfile(), | 299 GetOriginalProfile(), |
294 this)); // Ask to notify us in the end. | 300 true)); |
295 } else { | 301 } else { |
296 // Load prefs synchronously. | 302 // Load prefs synchronously. |
297 prefs_.reset(PrefService::CreatePrefService( | 303 prefs_.reset(PrefService::CreatePrefService( |
298 GetPrefFilePath(), | 304 GetPrefFilePath(), |
299 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), | 305 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), |
300 GetOriginalProfile())); | 306 GetOriginalProfile(), |
301 OnPrefsLoaded(prefs_.get(), true); | 307 false)); |
| 308 OnPrefsLoaded(true); |
302 } | 309 } |
303 } | 310 } |
304 | 311 |
305 void ProfileImpl::DoFinalInit() { | 312 void ProfileImpl::DoFinalInit() { |
306 PrefService* prefs = GetPrefs(); | 313 PrefService* prefs = GetPrefs(); |
307 pref_change_registrar_.Init(prefs); | 314 pref_change_registrar_.Init(prefs); |
308 pref_change_registrar_.Add(prefs::kSpellCheckDictionary, this); | 315 pref_change_registrar_.Add(prefs::kSpellCheckDictionary, this); |
309 pref_change_registrar_.Add(prefs::kEnableSpellCheck, this); | 316 pref_change_registrar_.Add(prefs::kEnableSpellCheck, this); |
310 pref_change_registrar_.Add(prefs::kEnableAutoSpellCorrect, this); | 317 pref_change_registrar_.Add(prefs::kEnableAutoSpellCorrect, this); |
311 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); | 318 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 transport_security_state_ = new net::TransportSecurityState(); | 797 transport_security_state_ = new net::TransportSecurityState(); |
791 transport_security_persister_ = | 798 transport_security_persister_ = |
792 new TransportSecurityPersister(false /* read-write */); | 799 new TransportSecurityPersister(false /* read-write */); |
793 transport_security_persister_->Initialize( | 800 transport_security_persister_->Initialize( |
794 transport_security_state_.get(), path_); | 801 transport_security_state_.get(), path_); |
795 } | 802 } |
796 | 803 |
797 return transport_security_state_.get(); | 804 return transport_security_state_.get(); |
798 } | 805 } |
799 | 806 |
800 void ProfileImpl::OnPrefsLoaded(PrefService* prefs, bool success) { | 807 void ProfileImpl::OnPrefsLoaded(bool success) { |
801 DCHECK(prefs == prefs_.get()); | |
802 | |
803 if (!success) { | 808 if (!success) { |
804 DCHECK(delegate_); | 809 DCHECK(delegate_); |
805 delegate_->OnProfileCreated(this, false); | 810 delegate_->OnProfileCreated(this, false); |
806 return; | 811 return; |
807 } | 812 } |
808 | 813 |
809 // The Profile class and ProfileManager class may read some prefs so | 814 // The Profile class and ProfileManager class may read some prefs so |
810 // register known prefs as soon as possible. | 815 // register known prefs as soon as possible. |
811 Profile::RegisterUserPrefs(prefs_.get()); | 816 Profile::RegisterUserPrefs(prefs_.get()); |
812 browser::RegisterUserPrefs(prefs_.get()); | 817 browser::RegisterUserPrefs(prefs_.get()); |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 | 1315 |
1311 // NOTE: If you change what thread this writes on, be sure and update | 1316 // NOTE: If you change what thread this writes on, be sure and update |
1312 // ChromeFrame::EndSession(). | 1317 // ChromeFrame::EndSession(). |
1313 prefs_->SavePersistentPrefs(); | 1318 prefs_->SavePersistentPrefs(); |
1314 } | 1319 } |
1315 } | 1320 } |
1316 | 1321 |
1317 void ProfileImpl::Observe(NotificationType type, | 1322 void ProfileImpl::Observe(NotificationType type, |
1318 const NotificationSource& source, | 1323 const NotificationSource& source, |
1319 const NotificationDetails& details) { | 1324 const NotificationDetails& details) { |
1320 if (NotificationType::PREF_CHANGED == type) { | 1325 bool initialization_succeeded = true; |
1321 std::string* pref_name_in = Details<std::string>(details).ptr(); | 1326 switch (type.value) { |
1322 PrefService* prefs = Source<PrefService>(source).ptr(); | 1327 case NotificationType::PREF_INITIALIZATION_FAILED: |
1323 DCHECK(pref_name_in && prefs); | 1328 initialization_succeeded = false; |
1324 if (*pref_name_in == prefs::kSpellCheckDictionary || | 1329 // Fall through. |
1325 *pref_name_in == prefs::kEnableSpellCheck) { | 1330 case NotificationType::PREF_INITIALIZATION_COMPLETED: |
1326 ReinitializeSpellCheckHost(true); | 1331 registrar_.Remove(this, NotificationType::PREF_INITIALIZATION_COMPLETED, |
1327 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) { | 1332 Source<Profile>(this)); |
1328 NotificationService::current()->Notify( | 1333 registrar_.Remove(this, NotificationType::PREF_INITIALIZATION_FAILED, |
1329 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED, | 1334 Source<Profile>(this)); |
1330 Source<Profile>(this), NotificationService::NoDetails()); | 1335 OnPrefsLoaded(initialization_succeeded); |
1331 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { | 1336 break; |
1332 clear_local_state_on_exit_ = | 1337 case NotificationType::PREF_CHANGED: { |
1333 prefs->GetBoolean(prefs::kClearSiteDataOnExit); | 1338 std::string* pref_name_in = Details<std::string>(details).ptr(); |
1334 if (webkit_context_) { | 1339 PrefService* prefs = Source<PrefService>(source).ptr(); |
1335 webkit_context_->set_clear_local_state_on_exit( | 1340 DCHECK(pref_name_in && prefs); |
1336 clear_local_state_on_exit_); | 1341 if (*pref_name_in == prefs::kSpellCheckDictionary || |
| 1342 *pref_name_in == prefs::kEnableSpellCheck) { |
| 1343 ReinitializeSpellCheckHost(true); |
| 1344 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) { |
| 1345 NotificationService::current()->Notify( |
| 1346 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED, |
| 1347 Source<Profile>(this), NotificationService::NoDetails()); |
| 1348 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { |
| 1349 clear_local_state_on_exit_ = |
| 1350 prefs->GetBoolean(prefs::kClearSiteDataOnExit); |
| 1351 if (webkit_context_) { |
| 1352 webkit_context_->set_clear_local_state_on_exit( |
| 1353 clear_local_state_on_exit_); |
| 1354 } |
| 1355 if (appcache_service_) { |
| 1356 appcache_service_->SetClearLocalStateOnExit( |
| 1357 clear_local_state_on_exit_); |
| 1358 } |
1337 } | 1359 } |
1338 if (appcache_service_) { | 1360 break; |
1339 appcache_service_->SetClearLocalStateOnExit( | |
1340 clear_local_state_on_exit_); | |
1341 } | |
1342 } | 1361 } |
1343 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) { | 1362 case NotificationType::BOOKMARK_MODEL_LOADED: |
1344 GetProfileSyncService(); // Causes lazy-load if sync is enabled. | 1363 GetProfileSyncService(); // Causes lazy-load if sync is enabled. |
1345 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED, | 1364 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED, |
1346 Source<Profile>(this)); | 1365 Source<Profile>(this)); |
| 1366 break; |
| 1367 default: |
| 1368 NOTREACHED(); |
1347 } | 1369 } |
1348 } | 1370 } |
1349 | 1371 |
1350 void ProfileImpl::StopCreateSessionServiceTimer() { | 1372 void ProfileImpl::StopCreateSessionServiceTimer() { |
1351 create_session_service_timer_.Stop(); | 1373 create_session_service_timer_.Stop(); |
1352 } | 1374 } |
1353 | 1375 |
1354 TokenService* ProfileImpl::GetTokenService() { | 1376 TokenService* ProfileImpl::GetTokenService() { |
1355 if (!token_service_.get()) { | 1377 if (!token_service_.get()) { |
1356 token_service_.reset(new TokenService()); | 1378 token_service_.reset(new TokenService()); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1563 return pref_proxy_config_tracker_; | 1585 return pref_proxy_config_tracker_; |
1564 } | 1586 } |
1565 | 1587 |
1566 prerender::PrerenderManager* ProfileImpl::GetPrerenderManager() { | 1588 prerender::PrerenderManager* ProfileImpl::GetPrerenderManager() { |
1567 if (!prerender::PrerenderManager::IsPrerenderingPossible()) | 1589 if (!prerender::PrerenderManager::IsPrerenderingPossible()) |
1568 return NULL; | 1590 return NULL; |
1569 if (!prerender_manager_.get()) | 1591 if (!prerender_manager_.get()) |
1570 prerender_manager_.reset(new prerender::PrerenderManager(this)); | 1592 prerender_manager_.reset(new prerender::PrerenderManager(this)); |
1571 return prerender_manager_.get(); | 1593 return prerender_manager_.get(); |
1572 } | 1594 } |
OLD | NEW |