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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 checked_instant_promo_(false), | 285 checked_instant_promo_(false), |
286 #endif | 286 #endif |
287 delegate_(delegate) { | 287 delegate_(delegate) { |
288 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 288 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
289 "profile files to the root directory!"; | 289 "profile files to the root directory!"; |
290 create_session_service_timer_.Start( | 290 create_session_service_timer_.Start( |
291 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, | 291 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, |
292 &ProfileImpl::EnsureSessionServiceCreated); | 292 &ProfileImpl::EnsureSessionServiceCreated); |
293 | 293 |
294 if (delegate_) { | 294 if (delegate_) { |
295 prefs_.reset(PrefService::CreatePrefServiceAsync( | 295 prefs_.reset(PrefService::CreatePrefService( |
296 GetPrefFilePath(), | 296 GetPrefFilePath(), |
297 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), | 297 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), |
298 GetOriginalProfile(), | 298 GetOriginalProfile(), |
299 this)); // Ask to notify us in the end. | 299 true)); |
| 300 // Wait for the notifcation that prefs has been loaded (successfully or |
| 301 // not). |
| 302 registrar_.Add(this, NotificationType::PREF_INITIALIZATION_COMPLETED, |
| 303 Source<PrefService>(prefs_.get())); |
300 } else { | 304 } else { |
301 // Load prefs synchronously. | 305 // Load prefs synchronously. |
302 prefs_.reset(PrefService::CreatePrefService( | 306 prefs_.reset(PrefService::CreatePrefService( |
303 GetPrefFilePath(), | 307 GetPrefFilePath(), |
304 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), | 308 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), |
305 GetOriginalProfile())); | 309 GetOriginalProfile(), |
306 OnPrefsLoaded(prefs_.get(), true); | 310 false)); |
| 311 OnPrefsLoaded(true); |
307 } | 312 } |
308 } | 313 } |
309 | 314 |
310 void ProfileImpl::DoFinalInit() { | 315 void ProfileImpl::DoFinalInit() { |
311 PrefService* prefs = GetPrefs(); | 316 PrefService* prefs = GetPrefs(); |
312 pref_change_registrar_.Init(prefs); | 317 pref_change_registrar_.Init(prefs); |
313 pref_change_registrar_.Add(prefs::kSpellCheckDictionary, this); | 318 pref_change_registrar_.Add(prefs::kSpellCheckDictionary, this); |
314 pref_change_registrar_.Add(prefs::kEnableSpellCheck, this); | 319 pref_change_registrar_.Add(prefs::kEnableSpellCheck, this); |
315 pref_change_registrar_.Add(prefs::kEnableAutoSpellCorrect, this); | 320 pref_change_registrar_.Add(prefs::kEnableAutoSpellCorrect, this); |
316 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); | 321 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 switches::kHstsHosts)); | 801 switches::kHstsHosts)); |
797 transport_security_persister_ = | 802 transport_security_persister_ = |
798 new TransportSecurityPersister(false /* read-write */); | 803 new TransportSecurityPersister(false /* read-write */); |
799 transport_security_persister_->Initialize( | 804 transport_security_persister_->Initialize( |
800 transport_security_state_.get(), path_); | 805 transport_security_state_.get(), path_); |
801 } | 806 } |
802 | 807 |
803 return transport_security_state_.get(); | 808 return transport_security_state_.get(); |
804 } | 809 } |
805 | 810 |
806 void ProfileImpl::OnPrefsLoaded(PrefService* prefs, bool success) { | 811 void ProfileImpl::OnPrefsLoaded(bool success) { |
807 DCHECK(prefs == prefs_.get()); | |
808 | |
809 if (!success) { | 812 if (!success) { |
810 DCHECK(delegate_); | 813 DCHECK(delegate_); |
811 delegate_->OnProfileCreated(this, false); | 814 delegate_->OnProfileCreated(this, false); |
812 return; | 815 return; |
813 } | 816 } |
814 | 817 |
815 // The Profile class and ProfileManager class may read some prefs so | 818 // The Profile class and ProfileManager class may read some prefs so |
816 // register known prefs as soon as possible. | 819 // register known prefs as soon as possible. |
817 Profile::RegisterUserPrefs(prefs_.get()); | 820 Profile::RegisterUserPrefs(prefs_.get()); |
818 browser::RegisterUserPrefs(prefs_.get()); | 821 browser::RegisterUserPrefs(prefs_.get()); |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 | 1315 |
1313 // 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 |
1314 // ChromeFrame::EndSession(). | 1317 // ChromeFrame::EndSession(). |
1315 prefs_->SavePersistentPrefs(); | 1318 prefs_->SavePersistentPrefs(); |
1316 } | 1319 } |
1317 } | 1320 } |
1318 | 1321 |
1319 void ProfileImpl::Observe(NotificationType type, | 1322 void ProfileImpl::Observe(NotificationType type, |
1320 const NotificationSource& source, | 1323 const NotificationSource& source, |
1321 const NotificationDetails& details) { | 1324 const NotificationDetails& details) { |
1322 if (NotificationType::PREF_CHANGED == type) { | 1325 switch (type.value) { |
1323 std::string* pref_name_in = Details<std::string>(details).ptr(); | 1326 case NotificationType::PREF_INITIALIZATION_COMPLETED: { |
1324 PrefService* prefs = Source<PrefService>(source).ptr(); | 1327 bool* succeeded = Details<bool>(details).ptr(); |
1325 DCHECK(pref_name_in && prefs); | 1328 PrefService *prefs = Source<PrefService>(source).ptr(); |
1326 if (*pref_name_in == prefs::kSpellCheckDictionary || | 1329 DCHECK(prefs == prefs_.get()); |
1327 *pref_name_in == prefs::kEnableSpellCheck) { | 1330 registrar_.Remove(this, NotificationType::PREF_INITIALIZATION_COMPLETED, |
1328 ReinitializeSpellCheckHost(true); | 1331 Source<PrefService>(prefs)); |
1329 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) { | 1332 OnPrefsLoaded(*succeeded); |
1330 bool enabled = prefs->GetBoolean(prefs::kEnableAutoSpellCorrect); | 1333 break; |
1331 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 1334 } |
1332 !i.IsAtEnd(); i.Advance()) { | 1335 case NotificationType::PREF_CHANGED: { |
1333 RenderProcessHost* process = i.GetCurrentValue(); | 1336 std::string* pref_name_in = Details<std::string>(details).ptr(); |
1334 process->Send(new SpellCheckMsg_EnableAutoSpellCorrect(enabled)); | 1337 PrefService* prefs = Source<PrefService>(source).ptr(); |
| 1338 DCHECK(pref_name_in && prefs); |
| 1339 if (*pref_name_in == prefs::kSpellCheckDictionary || |
| 1340 *pref_name_in == prefs::kEnableSpellCheck) { |
| 1341 ReinitializeSpellCheckHost(true); |
| 1342 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) { |
| 1343 bool enabled = prefs->GetBoolean(prefs::kEnableAutoSpellCorrect); |
| 1344 for (RenderProcessHost::iterator |
| 1345 i(RenderProcessHost::AllHostsIterator()); |
| 1346 !i.IsAtEnd(); i.Advance()) { |
| 1347 RenderProcessHost* process = i.GetCurrentValue(); |
| 1348 process->Send(new SpellCheckMsg_EnableAutoSpellCorrect(enabled)); |
| 1349 } |
| 1350 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { |
| 1351 clear_local_state_on_exit_ = |
| 1352 prefs->GetBoolean(prefs::kClearSiteDataOnExit); |
| 1353 if (webkit_context_) { |
| 1354 webkit_context_->set_clear_local_state_on_exit( |
| 1355 clear_local_state_on_exit_); |
| 1356 } |
| 1357 if (appcache_service_) { |
| 1358 appcache_service_->SetClearLocalStateOnExit( |
| 1359 clear_local_state_on_exit_); |
| 1360 } |
| 1361 } else if (*pref_name_in == prefs::kGoogleServicesUsername) { |
| 1362 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1363 profile_manager->RegisterProfileName(this); |
1335 } | 1364 } |
1336 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { | 1365 break; |
1337 clear_local_state_on_exit_ = | |
1338 prefs->GetBoolean(prefs::kClearSiteDataOnExit); | |
1339 if (webkit_context_) { | |
1340 webkit_context_->set_clear_local_state_on_exit( | |
1341 clear_local_state_on_exit_); | |
1342 } | |
1343 if (appcache_service_) { | |
1344 appcache_service_->SetClearLocalStateOnExit( | |
1345 clear_local_state_on_exit_); | |
1346 } | |
1347 } else if (*pref_name_in == prefs::kGoogleServicesUsername) { | |
1348 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
1349 profile_manager->RegisterProfileName(this); | |
1350 } | 1366 } |
1351 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) { | 1367 case NotificationType::BOOKMARK_MODEL_LOADED: |
1352 GetProfileSyncService(); // Causes lazy-load if sync is enabled. | 1368 GetProfileSyncService(); // Causes lazy-load if sync is enabled. |
1353 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED, | 1369 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED, |
1354 Source<Profile>(this)); | 1370 Source<Profile>(this)); |
| 1371 break; |
| 1372 default: |
| 1373 NOTREACHED(); |
1355 } | 1374 } |
1356 } | 1375 } |
1357 | 1376 |
1358 void ProfileImpl::StopCreateSessionServiceTimer() { | 1377 void ProfileImpl::StopCreateSessionServiceTimer() { |
1359 create_session_service_timer_.Stop(); | 1378 create_session_service_timer_.Stop(); |
1360 } | 1379 } |
1361 | 1380 |
1362 void ProfileImpl::EnsureSessionServiceCreated() { | 1381 void ProfileImpl::EnsureSessionServiceCreated() { |
1363 SessionServiceFactory::GetForProfile(this); | 1382 SessionServiceFactory::GetForProfile(this); |
1364 } | 1383 } |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 return pref_proxy_config_tracker_; | 1587 return pref_proxy_config_tracker_; |
1569 } | 1588 } |
1570 | 1589 |
1571 prerender::PrerenderManager* ProfileImpl::GetPrerenderManager() { | 1590 prerender::PrerenderManager* ProfileImpl::GetPrerenderManager() { |
1572 if (!prerender::PrerenderManager::IsPrerenderingPossible()) | 1591 if (!prerender::PrerenderManager::IsPrerenderingPossible()) |
1573 return NULL; | 1592 return NULL; |
1574 if (!prerender_manager_.get()) | 1593 if (!prerender_manager_.get()) |
1575 prerender_manager_.reset(new prerender::PrerenderManager(this)); | 1594 prerender_manager_.reset(new prerender::PrerenderManager(this)); |
1576 return prerender_manager_.get(); | 1595 return prerender_manager_.get(); |
1577 } | 1596 } |
OLD | NEW |