Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: chrome/browser/profiles/profile_impl.cc

Issue 6894020: Adds async interface method to PersistentPrefStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 switches::kHstsHosts)); 796 switches::kHstsHosts));
792 transport_security_persister_ = 797 transport_security_persister_ =
793 new TransportSecurityPersister(false /* read-write */); 798 new TransportSecurityPersister(false /* read-write */);
794 transport_security_persister_->Initialize( 799 transport_security_persister_->Initialize(
795 transport_security_state_.get(), path_); 800 transport_security_state_.get(), path_);
796 } 801 }
797 802
798 return transport_security_state_.get(); 803 return transport_security_state_.get();
799 } 804 }
800 805
801 void ProfileImpl::OnPrefsLoaded(PrefService* prefs, bool success) { 806 void ProfileImpl::OnPrefsLoaded(bool success) {
802 DCHECK(prefs == prefs_.get());
803
804 if (!success) { 807 if (!success) {
805 DCHECK(delegate_); 808 DCHECK(delegate_);
806 delegate_->OnProfileCreated(this, false); 809 delegate_->OnProfileCreated(this, false);
807 return; 810 return;
808 } 811 }
809 812
810 // The Profile class and ProfileManager class may read some prefs so 813 // The Profile class and ProfileManager class may read some prefs so
811 // register known prefs as soon as possible. 814 // register known prefs as soon as possible.
812 Profile::RegisterUserPrefs(prefs_.get()); 815 Profile::RegisterUserPrefs(prefs_.get());
813 browser::RegisterUserPrefs(prefs_.get()); 816 browser::RegisterUserPrefs(prefs_.get());
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 1288
1286 // NOTE: If you change what thread this writes on, be sure and update 1289 // NOTE: If you change what thread this writes on, be sure and update
1287 // ChromeFrame::EndSession(). 1290 // ChromeFrame::EndSession().
1288 prefs_->SavePersistentPrefs(); 1291 prefs_->SavePersistentPrefs();
1289 } 1292 }
1290 } 1293 }
1291 1294
1292 void ProfileImpl::Observe(NotificationType type, 1295 void ProfileImpl::Observe(NotificationType type,
1293 const NotificationSource& source, 1296 const NotificationSource& source,
1294 const NotificationDetails& details) { 1297 const NotificationDetails& details) {
1295 if (NotificationType::PREF_CHANGED == type) { 1298 switch (type.value) {
1296 std::string* pref_name_in = Details<std::string>(details).ptr(); 1299 case NotificationType::PREF_INITIALIZATION_COMPLETED: {
1297 PrefService* prefs = Source<PrefService>(source).ptr(); 1300 bool succeeded = Details<PrefService>(details).ptr() != NULL;
1298 DCHECK(pref_name_in && prefs); 1301 PrefService *prefs = Source<PrefService>(source).ptr();
1299 if (*pref_name_in == prefs::kSpellCheckDictionary || 1302 DCHECK(prefs == prefs_.get());
1300 *pref_name_in == prefs::kEnableSpellCheck) { 1303 registrar_.Remove(this, NotificationType::PREF_INITIALIZATION_COMPLETED,
1301 ReinitializeSpellCheckHost(true); 1304 Source<PrefService>(prefs));
1302 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) { 1305 OnPrefsLoaded(succeeded);
1303 bool enabled = prefs->GetBoolean(prefs::kEnableAutoSpellCorrect); 1306 break;
1304 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); 1307 }
1305 !i.IsAtEnd(); i.Advance()) { 1308 case NotificationType::PREF_CHANGED: {
1306 RenderProcessHost* process = i.GetCurrentValue(); 1309 std::string* pref_name_in = Details<std::string>(details).ptr();
1307 process->Send(new SpellCheckMsg_EnableAutoSpellCorrect(enabled)); 1310 PrefService* prefs = Source<PrefService>(source).ptr();
1311 DCHECK(pref_name_in && prefs);
1312 if (*pref_name_in == prefs::kSpellCheckDictionary ||
1313 *pref_name_in == prefs::kEnableSpellCheck) {
1314 ReinitializeSpellCheckHost(true);
1315 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1316 bool enabled = prefs->GetBoolean(prefs::kEnableAutoSpellCorrect);
1317 for (RenderProcessHost::iterator
1318 i(RenderProcessHost::AllHostsIterator());
1319 !i.IsAtEnd(); i.Advance()) {
1320 RenderProcessHost* process = i.GetCurrentValue();
1321 process->Send(new SpellCheckMsg_EnableAutoSpellCorrect(enabled));
1322 }
1323 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) {
1324 clear_local_state_on_exit_ =
1325 prefs->GetBoolean(prefs::kClearSiteDataOnExit);
1326 if (webkit_context_) {
1327 webkit_context_->set_clear_local_state_on_exit(
1328 clear_local_state_on_exit_);
1329 }
1330 if (appcache_service_) {
1331 appcache_service_->SetClearLocalStateOnExit(
1332 clear_local_state_on_exit_);
1333 }
1334 } else if (*pref_name_in == prefs::kGoogleServicesUsername) {
1335 ProfileManager* profile_manager = g_browser_process->profile_manager();
1336 profile_manager->RegisterProfileName(this);
1308 } 1337 }
1309 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { 1338 break;
1310 clear_local_state_on_exit_ =
1311 prefs->GetBoolean(prefs::kClearSiteDataOnExit);
1312 if (webkit_context_) {
1313 webkit_context_->set_clear_local_state_on_exit(
1314 clear_local_state_on_exit_);
1315 }
1316 if (appcache_service_) {
1317 appcache_service_->SetClearLocalStateOnExit(
1318 clear_local_state_on_exit_);
1319 }
1320 } else if (*pref_name_in == prefs::kGoogleServicesUsername) {
1321 ProfileManager* profile_manager = g_browser_process->profile_manager();
1322 profile_manager->RegisterProfileName(this);
1323 } 1339 }
1324 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) { 1340 case NotificationType::BOOKMARK_MODEL_LOADED:
1325 GetProfileSyncService(); // Causes lazy-load if sync is enabled. 1341 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1326 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED, 1342 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1327 Source<Profile>(this)); 1343 Source<Profile>(this));
1344 break;
1345 default:
1346 NOTREACHED();
1328 } 1347 }
1329 } 1348 }
1330 1349
1331 void ProfileImpl::StopCreateSessionServiceTimer() { 1350 void ProfileImpl::StopCreateSessionServiceTimer() {
1332 create_session_service_timer_.Stop(); 1351 create_session_service_timer_.Stop();
1333 } 1352 }
1334 1353
1335 void ProfileImpl::EnsureSessionServiceCreated() { 1354 void ProfileImpl::EnsureSessionServiceCreated() {
1336 SessionServiceFactory::GetForProfile(this); 1355 SessionServiceFactory::GetForProfile(this);
1337 } 1356 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 return pref_proxy_config_tracker_; 1560 return pref_proxy_config_tracker_;
1542 } 1561 }
1543 1562
1544 prerender::PrerenderManager* ProfileImpl::GetPrerenderManager() { 1563 prerender::PrerenderManager* ProfileImpl::GetPrerenderManager() {
1545 if (!prerender::PrerenderManager::IsPrerenderingPossible()) 1564 if (!prerender::PrerenderManager::IsPrerenderingPossible())
1546 return NULL; 1565 return NULL;
1547 if (!prerender_manager_.get()) 1566 if (!prerender_manager_.get())
1548 prerender_manager_.reset(new prerender::PrerenderManager(this)); 1567 prerender_manager_.reset(new prerender::PrerenderManager(this));
1549 return prerender_manager_.get(); 1568 return prerender_manager_.get();
1550 } 1569 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698