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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 switches::kHstsHosts)); | 804 switches::kHstsHosts)); |
800 transport_security_persister_ = | 805 transport_security_persister_ = |
801 new TransportSecurityPersister(false /* read-write */); | 806 new TransportSecurityPersister(false /* read-write */); |
802 transport_security_persister_->Initialize( | 807 transport_security_persister_->Initialize( |
803 transport_security_state_.get(), path_); | 808 transport_security_state_.get(), path_); |
804 } | 809 } |
805 | 810 |
806 return transport_security_state_.get(); | 811 return transport_security_state_.get(); |
807 } | 812 } |
808 | 813 |
809 void ProfileImpl::OnPrefsLoaded(PrefService* prefs, bool success) { | 814 void ProfileImpl::OnPrefsLoaded(bool success) { |
810 DCHECK(prefs == prefs_.get()); | |
811 | |
812 if (!success) { | 815 if (!success) { |
813 DCHECK(delegate_); | 816 DCHECK(delegate_); |
814 delegate_->OnProfileCreated(this, false); | 817 delegate_->OnProfileCreated(this, false); |
815 return; | 818 return; |
816 } | 819 } |
817 | 820 |
818 // The Profile class and ProfileManager class may read some prefs so | 821 // The Profile class and ProfileManager class may read some prefs so |
819 // register known prefs as soon as possible. | 822 // register known prefs as soon as possible. |
820 Profile::RegisterUserPrefs(prefs_.get()); | 823 Profile::RegisterUserPrefs(prefs_.get()); |
821 browser::RegisterUserPrefs(prefs_.get()); | 824 browser::RegisterUserPrefs(prefs_.get()); |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 | 1313 |
1311 // NOTE: If you change what thread this writes on, be sure and update | 1314 // NOTE: If you change what thread this writes on, be sure and update |
1312 // ChromeFrame::EndSession(). | 1315 // ChromeFrame::EndSession(). |
1313 prefs_->SavePersistentPrefs(); | 1316 prefs_->SavePersistentPrefs(); |
1314 } | 1317 } |
1315 } | 1318 } |
1316 | 1319 |
1317 void ProfileImpl::Observe(NotificationType type, | 1320 void ProfileImpl::Observe(NotificationType type, |
1318 const NotificationSource& source, | 1321 const NotificationSource& source, |
1319 const NotificationDetails& details) { | 1322 const NotificationDetails& details) { |
1320 if (NotificationType::PREF_CHANGED == type) { | 1323 switch (type.value) { |
1321 std::string* pref_name_in = Details<std::string>(details).ptr(); | 1324 case NotificationType::PREF_INITIALIZATION_COMPLETED: { |
1322 PrefService* prefs = Source<PrefService>(source).ptr(); | 1325 bool* succeeded = Details<bool>(details).ptr(); |
1323 DCHECK(pref_name_in && prefs); | 1326 PrefService *prefs = Source<PrefService>(source).ptr(); |
1324 if (*pref_name_in == prefs::kSpellCheckDictionary || | 1327 DCHECK(prefs == prefs_.get()); |
1325 *pref_name_in == prefs::kEnableSpellCheck) { | 1328 registrar_.Remove(this, NotificationType::PREF_INITIALIZATION_COMPLETED, |
1326 ReinitializeSpellCheckHost(true); | 1329 Source<PrefService>(prefs)); |
1327 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) { | 1330 OnPrefsLoaded(*succeeded); |
1328 bool enabled = prefs->GetBoolean(prefs::kEnableAutoSpellCorrect); | 1331 break; |
1329 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 1332 } |
1330 !i.IsAtEnd(); i.Advance()) { | 1333 case NotificationType::PREF_CHANGED: { |
1331 RenderProcessHost* process = i.GetCurrentValue(); | 1334 std::string* pref_name_in = Details<std::string>(details).ptr(); |
1332 process->Send(new SpellCheckMsg_EnableAutoSpellCorrect(enabled)); | 1335 PrefService* prefs = Source<PrefService>(source).ptr(); |
| 1336 DCHECK(pref_name_in && prefs); |
| 1337 if (*pref_name_in == prefs::kSpellCheckDictionary || |
| 1338 *pref_name_in == prefs::kEnableSpellCheck) { |
| 1339 ReinitializeSpellCheckHost(true); |
| 1340 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) { |
| 1341 bool enabled = prefs->GetBoolean(prefs::kEnableAutoSpellCorrect); |
| 1342 for (RenderProcessHost::iterator |
| 1343 i(RenderProcessHost::AllHostsIterator()); |
| 1344 !i.IsAtEnd(); i.Advance()) { |
| 1345 RenderProcessHost* process = i.GetCurrentValue(); |
| 1346 process->Send(new SpellCheckMsg_EnableAutoSpellCorrect(enabled)); |
| 1347 } |
| 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 } |
| 1359 } else if (*pref_name_in == prefs::kGoogleServicesUsername) { |
| 1360 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1361 profile_manager->RegisterProfileName(this); |
1333 } | 1362 } |
1334 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { | 1363 break; |
1335 clear_local_state_on_exit_ = | |
1336 prefs->GetBoolean(prefs::kClearSiteDataOnExit); | |
1337 if (webkit_context_) { | |
1338 webkit_context_->set_clear_local_state_on_exit( | |
1339 clear_local_state_on_exit_); | |
1340 } | |
1341 if (appcache_service_) { | |
1342 appcache_service_->SetClearLocalStateOnExit( | |
1343 clear_local_state_on_exit_); | |
1344 } | |
1345 } else if (*pref_name_in == prefs::kGoogleServicesUsername) { | |
1346 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
1347 profile_manager->RegisterProfileName(this); | |
1348 } | 1364 } |
1349 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) { | 1365 case NotificationType::BOOKMARK_MODEL_LOADED: |
1350 GetProfileSyncService(); // Causes lazy-load if sync is enabled. | 1366 GetProfileSyncService(); // Causes lazy-load if sync is enabled. |
1351 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED, | 1367 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED, |
1352 Source<Profile>(this)); | 1368 Source<Profile>(this)); |
| 1369 break; |
| 1370 default: |
| 1371 NOTREACHED(); |
1353 } | 1372 } |
1354 } | 1373 } |
1355 | 1374 |
1356 void ProfileImpl::StopCreateSessionServiceTimer() { | 1375 void ProfileImpl::StopCreateSessionServiceTimer() { |
1357 create_session_service_timer_.Stop(); | 1376 create_session_service_timer_.Stop(); |
1358 } | 1377 } |
1359 | 1378 |
1360 void ProfileImpl::EnsureSessionServiceCreated() { | 1379 void ProfileImpl::EnsureSessionServiceCreated() { |
1361 SessionServiceFactory::GetForProfile(this); | 1380 SessionServiceFactory::GetForProfile(this); |
1362 } | 1381 } |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 return pref_proxy_config_tracker_; | 1585 return pref_proxy_config_tracker_; |
1567 } | 1586 } |
1568 | 1587 |
1569 prerender::PrerenderManager* ProfileImpl::GetPrerenderManager() { | 1588 prerender::PrerenderManager* ProfileImpl::GetPrerenderManager() { |
1570 if (!prerender::PrerenderManager::IsPrerenderingPossible()) | 1589 if (!prerender::PrerenderManager::IsPrerenderingPossible()) |
1571 return NULL; | 1590 return NULL; |
1572 if (!prerender_manager_.get()) | 1591 if (!prerender_manager_.get()) |
1573 prerender_manager_.reset(new prerender::PrerenderManager(this)); | 1592 prerender_manager_.reset(new prerender::PrerenderManager(this)); |
1574 return prerender_manager_.get(); | 1593 return prerender_manager_.get(); |
1575 } | 1594 } |
OLD | NEW |