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/bind.h" | |
7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
9 #include "base/environment.h" | 10 #include "base/environment.h" |
10 #include "base/file_path.h" | 11 #include "base/file_path.h" |
11 #include "base/file_util.h" | 12 #include "base/file_util.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
14 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 #endif | 150 #endif |
150 | 151 |
151 enum ContextType { | 152 enum ContextType { |
152 kNormalContext, | 153 kNormalContext, |
153 kMediaContext | 154 kMediaContext |
154 }; | 155 }; |
155 | 156 |
156 typedef std::list<std::pair<FilePath::StringType, int> > | 157 typedef std::list<std::pair<FilePath::StringType, int> > |
157 ComponentExtensionList; | 158 ComponentExtensionList; |
158 | 159 |
160 // Helper method needed because PostTask cannot currently take a Callback | |
161 // function with non-void return type. | |
csilv
2011/10/28 22:28:53
If you expect to be unnecessary in the future, ple
James Hawkins
2011/10/28 23:03:41
Done.
| |
162 void CreateDirectory(const FilePath& path) { | |
163 file_util::CreateDirectory(path); | |
164 } | |
165 | |
159 #if defined(FILE_MANAGER_EXTENSION) | 166 #if defined(FILE_MANAGER_EXTENSION) |
160 void AddFileManagerExtension(ComponentExtensionList* component_extensions) { | 167 void AddFileManagerExtension(ComponentExtensionList* component_extensions) { |
161 #ifndef NDEBUG | 168 #ifndef NDEBUG |
162 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 169 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
163 if (command_line->HasSwitch(switches::kFileManagerExtensionPath)) { | 170 if (command_line->HasSwitch(switches::kFileManagerExtensionPath)) { |
164 FilePath filemgr_extension_path = | 171 FilePath filemgr_extension_path = |
165 command_line->GetSwitchValuePath(switches::kFileManagerExtensionPath); | 172 command_line->GetSwitchValuePath(switches::kFileManagerExtensionPath); |
166 component_extensions->push_back(std::make_pair( | 173 component_extensions->push_back(std::make_pair( |
167 filemgr_extension_path.value(), | 174 filemgr_extension_path.value(), |
168 IDR_FILEMANAGER_MANIFEST)); | 175 IDR_FILEMANAGER_MANIFEST)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 return NULL; | 237 return NULL; |
231 } | 238 } |
232 return new ProfileImpl(path, NULL); | 239 return new ProfileImpl(path, NULL); |
233 } | 240 } |
234 | 241 |
235 // static | 242 // static |
236 Profile* Profile::CreateProfileAsync(const FilePath& path, | 243 Profile* Profile::CreateProfileAsync(const FilePath& path, |
237 Profile::Delegate* delegate) { | 244 Profile::Delegate* delegate) { |
238 DCHECK(delegate); | 245 DCHECK(delegate); |
239 // This is safe while all file operations are done on the FILE thread. | 246 // This is safe while all file operations are done on the FILE thread. |
240 BrowserThread::PostTask(BrowserThread::FILE, | 247 BrowserThread::PostTask( |
241 FROM_HERE, | 248 BrowserThread::FILE, FROM_HERE, base::Bind(CreateDirectory, path)); |
242 NewRunnableFunction(&file_util::CreateDirectory, | |
243 path)); | |
244 // Async version. | 249 // Async version. |
245 return new ProfileImpl(path, delegate); | 250 return new ProfileImpl(path, delegate); |
246 } | 251 } |
247 | 252 |
248 // static | 253 // static |
249 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { | 254 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { |
250 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, | 255 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, |
251 false, | 256 false, |
252 PrefService::UNSYNCABLE_PREF); | 257 PrefService::UNSYNCABLE_PREF); |
253 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, | 258 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 // It would be nice to use PathService for fetching this directory, but | 334 // It would be nice to use PathService for fetching this directory, but |
330 // the cache directory depends on the profile directory, which isn't available | 335 // the cache directory depends on the profile directory, which isn't available |
331 // to PathService. | 336 // to PathService. |
332 chrome::GetUserCacheDirectory(path_, &base_cache_path_); | 337 chrome::GetUserCacheDirectory(path_, &base_cache_path_); |
333 if (!delegate_) { | 338 if (!delegate_) { |
334 if (!file_util::CreateDirectory(base_cache_path_)) | 339 if (!file_util::CreateDirectory(base_cache_path_)) |
335 LOG(FATAL) << "Failed to create " << base_cache_path_.value(); | 340 LOG(FATAL) << "Failed to create " << base_cache_path_.value(); |
336 } else { | 341 } else { |
337 // Async profile loading is used, so call this on the FILE thread instead. | 342 // Async profile loading is used, so call this on the FILE thread instead. |
338 // It is safe since all other file operations should also be done there. | 343 // It is safe since all other file operations should also be done there. |
339 BrowserThread::PostTask(BrowserThread::FILE, | 344 BrowserThread::PostTask( |
340 FROM_HERE, | 345 BrowserThread::FILE, FROM_HERE, |
341 NewRunnableFunction(&file_util::CreateDirectory, | 346 base::Bind(CreateDirectory, base_cache_path_)); |
342 base_cache_path_)); | |
343 } | 347 } |
344 | 348 |
345 #if !defined(OS_CHROMEOS) | 349 #if !defined(OS_CHROMEOS) |
346 // Listen for bookmark model load, to bootstrap the sync service. | 350 // Listen for bookmark model load, to bootstrap the sync service. |
347 // On CrOS sync service will be initialized after sign in. | 351 // On CrOS sync service will be initialized after sign in. |
348 registrar_.Add(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, | 352 registrar_.Add(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
349 content::Source<Profile>(this)); | 353 content::Source<Profile>(this)); |
350 #endif | 354 #endif |
351 | 355 |
352 PrefService* local_state = g_browser_process->local_state(); | 356 PrefService* local_state = g_browser_process->local_state(); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
632 | 636 |
633 ProfileImpl::~ProfileImpl() { | 637 ProfileImpl::~ProfileImpl() { |
634 content::NotificationService::current()->Notify( | 638 content::NotificationService::current()->Notify( |
635 chrome::NOTIFICATION_PROFILE_DESTROYED, | 639 chrome::NOTIFICATION_PROFILE_DESTROYED, |
636 content::Source<Profile>(this), | 640 content::Source<Profile>(this), |
637 content::NotificationService::NoDetails()); | 641 content::NotificationService::NoDetails()); |
638 | 642 |
639 if (appcache_service_ && clear_local_state_on_exit_) { | 643 if (appcache_service_ && clear_local_state_on_exit_) { |
640 BrowserThread::PostTask( | 644 BrowserThread::PostTask( |
641 BrowserThread::IO, FROM_HERE, | 645 BrowserThread::IO, FROM_HERE, |
642 NewRunnableMethod( | 646 base::Bind(&appcache::AppCacheService::set_clear_local_state_on_exit, |
643 appcache_service_.get(), | 647 appcache_service_.get(), true)); |
644 &appcache::AppCacheService::set_clear_local_state_on_exit, | |
645 true)); | |
646 } | 648 } |
647 | 649 |
648 if (webkit_context_.get()) | 650 if (webkit_context_.get()) |
649 webkit_context_->DeleteSessionOnlyData(); | 651 webkit_context_->DeleteSessionOnlyData(); |
650 | 652 |
651 StopCreateSessionServiceTimer(); | 653 StopCreateSessionServiceTimer(); |
652 | 654 |
653 // Remove pref observers | 655 // Remove pref observers |
654 pref_change_registrar_.RemoveAll(); | 656 pref_change_registrar_.RemoveAll(); |
655 | 657 |
656 // The sync service needs to be deleted before the services it calls. | 658 // The sync service needs to be deleted before the services it calls. |
657 // TODO(stevet): Make ProfileSyncService into a PKS and let the PDM take care | 659 // TODO(stevet): Make ProfileSyncService into a PKS and let the PDM take care |
658 // of the cleanup below. | 660 // of the cleanup below. |
659 sync_service_.reset(); | 661 sync_service_.reset(); |
660 | 662 |
661 ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext( | 663 ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext( |
662 &GetResourceContext()); | 664 &GetResourceContext()); |
663 | 665 |
664 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); | 666 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); |
665 | 667 |
666 if (db_tracker_) { | 668 if (db_tracker_) { |
667 BrowserThread::PostTask( | 669 BrowserThread::PostTask( |
668 BrowserThread::FILE, FROM_HERE, | 670 BrowserThread::FILE, FROM_HERE, |
669 NewRunnableMethod( | 671 base::Bind(&webkit_database::DatabaseTracker::Shutdown, |
670 db_tracker_.get(), | 672 db_tracker_.get())); |
671 &webkit_database::DatabaseTracker::Shutdown)); | |
672 } | 673 } |
673 | 674 |
674 // Password store uses WebDB, shut it down before the WebDB has been shutdown. | 675 // Password store uses WebDB, shut it down before the WebDB has been shutdown. |
675 if (password_store_.get()) | 676 if (password_store_.get()) |
676 password_store_->Shutdown(); | 677 password_store_->Shutdown(); |
677 | 678 |
678 // Both HistoryService and WebDataService maintain threads for background | 679 // Both HistoryService and WebDataService maintain threads for background |
679 // processing. Its possible each thread still has tasks on it that have | 680 // processing. Its possible each thread still has tasks on it that have |
680 // increased the ref count of the service. In such a situation, when we | 681 // increased the ref count of the service. In such a situation, when we |
681 // decrement the refcount, it won't be 0, and the threads/databases aren't | 682 // decrement the refcount, it won't be 0, and the threads/databases aren't |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
961 const Extension* extension) { | 962 const Extension* extension) { |
962 base::Time install_time; | 963 base::Time install_time; |
963 if (extension->location() != Extension::COMPONENT) { | 964 if (extension->location() != Extension::COMPONENT) { |
964 install_time = GetExtensionService()->extension_prefs()-> | 965 install_time = GetExtensionService()->extension_prefs()-> |
965 GetInstallTime(extension->id()); | 966 GetInstallTime(extension->id()); |
966 } | 967 } |
967 bool incognito_enabled = | 968 bool incognito_enabled = |
968 GetExtensionService()->IsIncognitoEnabled(extension->id()); | 969 GetExtensionService()->IsIncognitoEnabled(extension->id()); |
969 BrowserThread::PostTask( | 970 BrowserThread::PostTask( |
970 BrowserThread::IO, FROM_HERE, | 971 BrowserThread::IO, FROM_HERE, |
971 NewRunnableMethod(extension_info_map_.get(), | 972 base::Bind(&ExtensionInfoMap::AddExtension, extension_info_map_.get(), |
972 &ExtensionInfoMap::AddExtension, | 973 make_scoped_refptr(extension), install_time, |
973 make_scoped_refptr(extension), | 974 incognito_enabled)); |
974 install_time, incognito_enabled)); | |
975 } | 975 } |
976 | 976 |
977 void ProfileImpl::UnregisterExtensionWithRequestContexts( | 977 void ProfileImpl::UnregisterExtensionWithRequestContexts( |
978 const std::string& extension_id, | 978 const std::string& extension_id, |
979 const extension_misc::UnloadedExtensionReason reason) { | 979 const extension_misc::UnloadedExtensionReason reason) { |
980 BrowserThread::PostTask( | 980 BrowserThread::PostTask( |
981 BrowserThread::IO, FROM_HERE, | 981 BrowserThread::IO, FROM_HERE, |
982 NewRunnableMethod(extension_info_map_.get(), | 982 base::Bind(&ExtensionInfoMap::RemoveExtension, extension_info_map_.get(), |
983 &ExtensionInfoMap::RemoveExtension, | 983 extension_id, reason)); |
984 extension_id, | |
985 reason)); | |
986 } | 984 } |
987 | 985 |
988 net::SSLConfigService* ProfileImpl::GetSSLConfigService() { | 986 net::SSLConfigService* ProfileImpl::GetSSLConfigService() { |
989 return ssl_config_service_manager_->Get(); | 987 return ssl_config_service_manager_->Get(); |
990 } | 988 } |
991 | 989 |
992 HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() { | 990 HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() { |
993 if (!host_content_settings_map_.get()) { | 991 if (!host_content_settings_map_.get()) { |
994 host_content_settings_map_ = new HostContentSettingsMap( | 992 host_content_settings_map_ = new HostContentSettingsMap( |
995 GetPrefs(), GetExtensionService(), false); | 993 GetPrefs(), GetExtensionService(), false); |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1359 GetExtensionSpecialStoragePolicy(), | 1357 GetExtensionSpecialStoragePolicy(), |
1360 quota_manager_->proxy(), | 1358 quota_manager_->proxy(), |
1361 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | 1359 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
1362 webkit_context_ = new WebKitContext( | 1360 webkit_context_ = new WebKitContext( |
1363 IsOffTheRecord(), GetPath(), GetExtensionSpecialStoragePolicy(), | 1361 IsOffTheRecord(), GetPath(), GetExtensionSpecialStoragePolicy(), |
1364 clear_local_state_on_exit_, quota_manager_->proxy(), | 1362 clear_local_state_on_exit_, quota_manager_->proxy(), |
1365 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT)); | 1363 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT)); |
1366 appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy()); | 1364 appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy()); |
1367 BrowserThread::PostTask( | 1365 BrowserThread::PostTask( |
1368 BrowserThread::IO, FROM_HERE, | 1366 BrowserThread::IO, FROM_HERE, |
1369 NewRunnableMethod( | 1367 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, |
1370 appcache_service_.get(), | 1368 appcache_service_.get(), |
1371 &ChromeAppCacheService::InitializeOnIOThread, | 1369 IsOffTheRecord() |
1372 IsOffTheRecord() | 1370 ? FilePath() : GetPath().Append(chrome::kAppCacheDirname), |
1373 ? FilePath() : GetPath().Append(chrome::kAppCacheDirname), | 1371 &GetResourceContext(), |
1374 &GetResourceContext(), | 1372 make_scoped_refptr(GetExtensionSpecialStoragePolicy()))); |
1375 make_scoped_refptr(GetExtensionSpecialStoragePolicy()))); | |
1376 } | 1373 } |
1377 | 1374 |
1378 WebKitContext* ProfileImpl::GetWebKitContext() { | 1375 WebKitContext* ProfileImpl::GetWebKitContext() { |
1379 CreateQuotaManagerAndClients(); | 1376 CreateQuotaManagerAndClients(); |
1380 return webkit_context_.get(); | 1377 return webkit_context_.get(); |
1381 } | 1378 } |
1382 | 1379 |
1383 void ProfileImpl::MarkAsCleanShutdown() { | 1380 void ProfileImpl::MarkAsCleanShutdown() { |
1384 if (prefs_.get()) { | 1381 if (prefs_.get()) { |
1385 // The session cleanly exited, set kSessionExitedCleanly appropriately. | 1382 // The session cleanly exited, set kSessionExitedCleanly appropriately. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1521 profile_sync_factory_->CreateProfileSyncService(cros_user)); | 1518 profile_sync_factory_->CreateProfileSyncService(cros_user)); |
1522 profile_sync_factory_->RegisterDataTypes(sync_service_.get()); | 1519 profile_sync_factory_->RegisterDataTypes(sync_service_.get()); |
1523 sync_service_->Initialize(); | 1520 sync_service_->Initialize(); |
1524 } | 1521 } |
1525 | 1522 |
1526 ChromeBlobStorageContext* ProfileImpl::GetBlobStorageContext() { | 1523 ChromeBlobStorageContext* ProfileImpl::GetBlobStorageContext() { |
1527 if (!blob_storage_context_) { | 1524 if (!blob_storage_context_) { |
1528 blob_storage_context_ = new ChromeBlobStorageContext(); | 1525 blob_storage_context_ = new ChromeBlobStorageContext(); |
1529 BrowserThread::PostTask( | 1526 BrowserThread::PostTask( |
1530 BrowserThread::IO, FROM_HERE, | 1527 BrowserThread::IO, FROM_HERE, |
1531 NewRunnableMethod(blob_storage_context_.get(), | 1528 base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, |
1532 &ChromeBlobStorageContext::InitializeOnIOThread)); | 1529 blob_storage_context_.get())); |
1533 } | 1530 } |
1534 return blob_storage_context_; | 1531 return blob_storage_context_; |
1535 } | 1532 } |
1536 | 1533 |
1537 ExtensionInfoMap* ProfileImpl::GetExtensionInfoMap() { | 1534 ExtensionInfoMap* ProfileImpl::GetExtensionInfoMap() { |
1538 return extension_info_map_.get(); | 1535 return extension_info_map_.get(); |
1539 } | 1536 } |
1540 | 1537 |
1541 ChromeURLDataManager* ProfileImpl::GetChromeURLDataManager() { | 1538 ChromeURLDataManager* ProfileImpl::GetChromeURLDataManager() { |
1542 if (!chrome_url_data_manager_.get()) | 1539 if (!chrome_url_data_manager_.get()) |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1677 | 1674 |
1678 void ProfileImpl::ClearNetworkingHistorySince(base::Time time) { | 1675 void ProfileImpl::ClearNetworkingHistorySince(base::Time time) { |
1679 io_data_.ClearNetworkingHistorySince(time); | 1676 io_data_.ClearNetworkingHistorySince(time); |
1680 } | 1677 } |
1681 | 1678 |
1682 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() { | 1679 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() { |
1683 if (!spellcheck_profile_.get()) | 1680 if (!spellcheck_profile_.get()) |
1684 spellcheck_profile_.reset(new SpellCheckProfile(path_)); | 1681 spellcheck_profile_.reset(new SpellCheckProfile(path_)); |
1685 return spellcheck_profile_.get(); | 1682 return spellcheck_profile_.get(); |
1686 } | 1683 } |
OLD | NEW |