| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/profile.h" | 5 #include "chrome/browser/profile.h" |
| 6 | 6 |
| 7 #include "app/theme_provider.h" | 7 #include "app/theme_provider.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "chrome/browser/bookmarks/bookmark_model.h" | 14 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 15 #include "chrome/browser/browser_list.h" | 15 #include "chrome/browser/browser_list.h" |
| 16 #include "chrome/browser/browser_process.h" | |
| 17 #include "chrome/browser/browser_theme_provider.h" | 16 #include "chrome/browser/browser_theme_provider.h" |
| 17 #include "chrome/browser/chrome_thread.h" |
| 18 #include "chrome/browser/download/download_manager.h" | 18 #include "chrome/browser/download/download_manager.h" |
| 19 #include "chrome/browser/extensions/extension_devtools_manager.h" | 19 #include "chrome/browser/extensions/extension_devtools_manager.h" |
| 20 #include "chrome/browser/extensions/extension_message_service.h" | 20 #include "chrome/browser/extensions/extension_message_service.h" |
| 21 #include "chrome/browser/extensions/extension_process_manager.h" | 21 #include "chrome/browser/extensions/extension_process_manager.h" |
| 22 #include "chrome/browser/extensions/extensions_service.h" | 22 #include "chrome/browser/extensions/extensions_service.h" |
| 23 #include "chrome/browser/extensions/user_script_master.h" | 23 #include "chrome/browser/extensions/user_script_master.h" |
| 24 #include "chrome/browser/favicon_service.h" | 24 #include "chrome/browser/favicon_service.h" |
| 25 #include "chrome/browser/strict_transport_security_persister.h" | 25 #include "chrome/browser/strict_transport_security_persister.h" |
| 26 #include "chrome/browser/history/history.h" | 26 #include "chrome/browser/history/history.h" |
| 27 #include "chrome/browser/in_process_webkit/webkit_context.h" | 27 #include "chrome/browser/in_process_webkit/webkit_context.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 125 |
| 126 // A pointer to the request context for the default profile. See comments on | 126 // A pointer to the request context for the default profile. See comments on |
| 127 // Profile::GetDefaultRequestContext. | 127 // Profile::GetDefaultRequestContext. |
| 128 URLRequestContextGetter* Profile::default_request_context_; | 128 URLRequestContextGetter* Profile::default_request_context_; |
| 129 | 129 |
| 130 static void CleanupRequestContext(ChromeURLRequestContextGetter* context) { | 130 static void CleanupRequestContext(ChromeURLRequestContextGetter* context) { |
| 131 if (context) { | 131 if (context) { |
| 132 context->CleanupOnUIThread(); | 132 context->CleanupOnUIThread(); |
| 133 | 133 |
| 134 // Clean up request context on IO thread. | 134 // Clean up request context on IO thread. |
| 135 g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE, | 135 ChromeThread::ReleaseSoon(ChromeThread::IO, FROM_HERE, context); |
| 136 context); | |
| 137 } | 136 } |
| 138 } | 137 } |
| 139 | 138 |
| 140 // static | 139 // static |
| 141 const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0); | 140 const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0); |
| 142 | 141 |
| 143 // static | 142 // static |
| 144 void Profile::RegisterUserPrefs(PrefService* prefs) { | 143 void Profile::RegisterUserPrefs(PrefService* prefs) { |
| 145 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true); | 144 prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true); |
| 146 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true); | 145 prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true); |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 // Tell UserScriptMaser to watch this extension's directory for changes so | 687 // Tell UserScriptMaser to watch this extension's directory for changes so |
| 689 // you can live edit content scripts during development. | 688 // you can live edit content scripts during development. |
| 690 user_script_master_->AddWatchedPath(path); | 689 user_script_master_->AddWatchedPath(path); |
| 691 } | 690 } |
| 692 } | 691 } |
| 693 | 692 |
| 694 void ProfileImpl::InitWebResources() { | 693 void ProfileImpl::InitWebResources() { |
| 695 if (web_resource_service_) | 694 if (web_resource_service_) |
| 696 return; // Already initialized. | 695 return; // Already initialized. |
| 697 | 696 |
| 698 web_resource_service_ = new WebResourceService( | 697 web_resource_service_ = new WebResourceService(this); |
| 699 this, | |
| 700 g_browser_process->file_thread()->message_loop()); | |
| 701 | |
| 702 web_resource_service_->StartAfterDelay(); | 698 web_resource_service_->StartAfterDelay(); |
| 703 } | 699 } |
| 704 | 700 |
| 705 ProfileImpl::~ProfileImpl() { | 701 ProfileImpl::~ProfileImpl() { |
| 706 tab_restore_service_ = NULL; | 702 tab_restore_service_ = NULL; |
| 707 | 703 |
| 708 StopCreateSessionServiceTimer(); | 704 StopCreateSessionServiceTimer(); |
| 709 // TemplateURLModel schedules a task on the WebDataService from its | 705 // TemplateURLModel schedules a task on the WebDataService from its |
| 710 // destructor. Delete it first to ensure the task gets scheduled before we | 706 // destructor. Delete it first to ensure the task gets scheduled before we |
| 711 // shut down the database. | 707 // shut down the database. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 off_the_record_profile_.reset(); | 803 off_the_record_profile_.reset(); |
| 808 } | 804 } |
| 809 | 805 |
| 810 Profile* ProfileImpl::GetOriginalProfile() { | 806 Profile* ProfileImpl::GetOriginalProfile() { |
| 811 return this; | 807 return this; |
| 812 } | 808 } |
| 813 | 809 |
| 814 VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() { | 810 VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() { |
| 815 if (!visited_link_master_.get()) { | 811 if (!visited_link_master_.get()) { |
| 816 scoped_ptr<VisitedLinkMaster> visited_links( | 812 scoped_ptr<VisitedLinkMaster> visited_links( |
| 817 new VisitedLinkMaster(g_browser_process->file_thread(), | 813 new VisitedLinkMaster(visited_link_event_listener_.get(), this)); |
| 818 visited_link_event_listener_.get(), this)); | |
| 819 if (!visited_links->Init()) | 814 if (!visited_links->Init()) |
| 820 return NULL; | 815 return NULL; |
| 821 visited_link_master_.swap(visited_links); | 816 visited_link_master_.swap(visited_links); |
| 822 } | 817 } |
| 823 | 818 |
| 824 return visited_link_master_.get(); | 819 return visited_link_master_.get(); |
| 825 } | 820 } |
| 826 | 821 |
| 827 ExtensionsService* ProfileImpl::GetExtensionsService() { | 822 ExtensionsService* ProfileImpl::GetExtensionsService() { |
| 828 return extensions_service_.get(); | 823 return extensions_service_.get(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 850 | 845 |
| 851 DCHECK(ssl_host_state_->CalledOnValidThread()); | 846 DCHECK(ssl_host_state_->CalledOnValidThread()); |
| 852 return ssl_host_state_.get(); | 847 return ssl_host_state_.get(); |
| 853 } | 848 } |
| 854 | 849 |
| 855 net::StrictTransportSecurityState* | 850 net::StrictTransportSecurityState* |
| 856 ProfileImpl::GetStrictTransportSecurityState() { | 851 ProfileImpl::GetStrictTransportSecurityState() { |
| 857 if (!strict_transport_security_state_.get()) { | 852 if (!strict_transport_security_state_.get()) { |
| 858 strict_transport_security_state_ = new net::StrictTransportSecurityState(); | 853 strict_transport_security_state_ = new net::StrictTransportSecurityState(); |
| 859 strict_transport_security_persister_ = new StrictTransportSecurityPersister( | 854 strict_transport_security_persister_ = new StrictTransportSecurityPersister( |
| 860 strict_transport_security_state_.get(), | 855 strict_transport_security_state_.get(), path_); |
| 861 g_browser_process->file_thread(), path_); | |
| 862 } | 856 } |
| 863 | 857 |
| 864 return strict_transport_security_state_.get(); | 858 return strict_transport_security_state_.get(); |
| 865 } | 859 } |
| 866 | 860 |
| 867 PrefService* ProfileImpl::GetPrefs() { | 861 PrefService* ProfileImpl::GetPrefs() { |
| 868 if (!prefs_.get()) { | 862 if (!prefs_.get()) { |
| 869 prefs_.reset(new PrefService(GetPrefFilePath(), | 863 prefs_.reset(new PrefService(GetPrefFilePath())); |
| 870 g_browser_process->file_thread())); | |
| 871 | 864 |
| 872 // The Profile class and ProfileManager class may read some prefs so | 865 // The Profile class and ProfileManager class may read some prefs so |
| 873 // register known prefs as soon as possible. | 866 // register known prefs as soon as possible. |
| 874 Profile::RegisterUserPrefs(prefs_.get()); | 867 Profile::RegisterUserPrefs(prefs_.get()); |
| 875 ProfileManager::RegisterUserPrefs(prefs_.get()); | 868 ProfileManager::RegisterUserPrefs(prefs_.get()); |
| 876 #if defined(OS_CHROMEOS) | 869 #if defined(OS_CHROMEOS) |
| 877 // Register Touchpad prefs here instead of in browser_prefs because these | 870 // Register Touchpad prefs here instead of in browser_prefs because these |
| 878 // prefs are used in the constructor of ProfileImpl which happens before | 871 // prefs are used in the constructor of ProfileImpl which happens before |
| 879 // browser_prefs' RegisterAllPrefs is called. | 872 // browser_prefs' RegisterAllPrefs is called. |
| 880 chromeos::Preferences::RegisterUserPrefs(prefs_.get()); | 873 chromeos::Preferences::RegisterUserPrefs(prefs_.get()); |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 spellchecker_->EnableAutoSpellCorrect( | 1254 spellchecker_->EnableAutoSpellCorrect( |
| 1262 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect)); | 1255 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect)); |
| 1263 | 1256 |
| 1264 NotifySpellCheckerChanged(); | 1257 NotifySpellCheckerChanged(); |
| 1265 } else { | 1258 } else { |
| 1266 DeleteSpellCheckerImpl(true); | 1259 DeleteSpellCheckerImpl(true); |
| 1267 } | 1260 } |
| 1268 } | 1261 } |
| 1269 | 1262 |
| 1270 void ProfileImpl::NotifySpellCheckerChanged() { | 1263 void ProfileImpl::NotifySpellCheckerChanged() { |
| 1271 // The I/O thread may be NULL during testing. | 1264 SpellcheckerReinitializedDetails scoped_spellchecker; |
| 1272 base::Thread* io_thread = g_browser_process->io_thread(); | 1265 scoped_spellchecker.spellchecker = spellchecker_; |
| 1273 if (io_thread) { // Notify resource message filters. | 1266 ChromeThread::PostTask( |
| 1274 SpellcheckerReinitializedDetails scoped_spellchecker; | 1267 ChromeThread::IO, FROM_HERE, |
| 1275 scoped_spellchecker.spellchecker = spellchecker_; | 1268 new NotifySpellcheckerChangeTask(this, scoped_spellchecker)); |
| 1276 io_thread->message_loop()->PostTask(FROM_HERE, | |
| 1277 new NotifySpellcheckerChangeTask(this, scoped_spellchecker)); | |
| 1278 } | |
| 1279 } | 1269 } |
| 1280 | 1270 |
| 1281 void ProfileImpl::DeleteSpellCheckerImpl(bool notify) { | 1271 void ProfileImpl::DeleteSpellCheckerImpl(bool notify) { |
| 1282 if (spellchecker_) { | 1272 if (!spellchecker_) |
| 1283 // The spellchecker must be deleted on the I/O thread. | 1273 return; |
| 1284 // The I/O thread may be NULL during testing. | |
| 1285 base::Thread* io_thread = g_browser_process->io_thread(); | |
| 1286 if (io_thread) | |
| 1287 io_thread->message_loop()->ReleaseSoon(FROM_HERE, spellchecker_); | |
| 1288 else // during testing, we don't have an I/O thread | |
| 1289 spellchecker_->Release(); | |
| 1290 | 1274 |
| 1291 spellchecker_ = NULL; | 1275 // The spellchecker must be deleted on the I/O thread. |
| 1276 ChromeThread::ReleaseSoon(ChromeThread::IO, FROM_HERE, spellchecker_); |
| 1277 spellchecker_ = NULL; |
| 1292 | 1278 |
| 1293 if (notify) | 1279 if (notify) |
| 1294 NotifySpellCheckerChanged(); | 1280 NotifySpellCheckerChanged(); |
| 1295 } | |
| 1296 } | 1281 } |
| 1297 | 1282 |
| 1298 SpellChecker* ProfileImpl::GetSpellChecker() { | 1283 SpellChecker* ProfileImpl::GetSpellChecker() { |
| 1299 if (!spellchecker_) { | 1284 if (!spellchecker_) { |
| 1300 // This is where spellchecker gets initialized. Note that this is being | 1285 // This is where spellchecker gets initialized. Note that this is being |
| 1301 // initialized in the ui_thread. However, this is not a problem as long as | 1286 // initialized in the ui_thread. However, this is not a problem as long as |
| 1302 // it is *used* in the io thread. | 1287 // it is *used* in the io thread. |
| 1303 // TODO(sidchat): One day, change everything so that spellchecker gets | 1288 // TODO(sidchat): One day, change everything so that spellchecker gets |
| 1304 // initialized in the IO thread itself. | 1289 // initialized in the IO thread itself. |
| 1305 ReinitializeSpellChecker(); | 1290 ReinitializeSpellChecker(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 return sync_service_.get(); | 1354 return sync_service_.get(); |
| 1370 } | 1355 } |
| 1371 #endif | 1356 #endif |
| 1372 return NULL; | 1357 return NULL; |
| 1373 } | 1358 } |
| 1374 | 1359 |
| 1375 void ProfileImpl::InitSyncService() { | 1360 void ProfileImpl::InitSyncService() { |
| 1376 sync_service_.reset(new ProfileSyncService(this)); | 1361 sync_service_.reset(new ProfileSyncService(this)); |
| 1377 sync_service_->Initialize(); | 1362 sync_service_->Initialize(); |
| 1378 } | 1363 } |
| OLD | NEW |