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

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

Issue 8399028: base::Bind: Convert chrome/browser/profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More win fox. Created 9 years, 1 month 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/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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 #endif 153 #endif
153 154
154 enum ContextType { 155 enum ContextType {
155 kNormalContext, 156 kNormalContext,
156 kMediaContext 157 kMediaContext
157 }; 158 };
158 159
159 typedef std::list<std::pair<FilePath::StringType, int> > 160 typedef std::list<std::pair<FilePath::StringType, int> >
160 ComponentExtensionList; 161 ComponentExtensionList;
161 162
163 // Helper method needed because PostTask cannot currently take a Callback
164 // function with non-void return type.
165 // TODO(jhawkins): Remove once IgnoreReturn is fixed.
166 void CreateDirectoryNoResult(const FilePath& path) {
167 file_util::CreateDirectory(path);
168 }
169
162 #if defined(FILE_MANAGER_EXTENSION) 170 #if defined(FILE_MANAGER_EXTENSION)
163 void AddFileManagerExtension(ComponentExtensionList* component_extensions) { 171 void AddFileManagerExtension(ComponentExtensionList* component_extensions) {
164 #ifndef NDEBUG 172 #ifndef NDEBUG
165 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 173 const CommandLine* command_line = CommandLine::ForCurrentProcess();
166 if (command_line->HasSwitch(switches::kFileManagerExtensionPath)) { 174 if (command_line->HasSwitch(switches::kFileManagerExtensionPath)) {
167 FilePath filemgr_extension_path = 175 FilePath filemgr_extension_path =
168 command_line->GetSwitchValuePath(switches::kFileManagerExtensionPath); 176 command_line->GetSwitchValuePath(switches::kFileManagerExtensionPath);
169 component_extensions->push_back(std::make_pair( 177 component_extensions->push_back(std::make_pair(
170 filemgr_extension_path.value(), 178 filemgr_extension_path.value(),
171 IDR_FILEMANAGER_MANIFEST)); 179 IDR_FILEMANAGER_MANIFEST));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 return NULL; 241 return NULL;
234 } 242 }
235 return new ProfileImpl(path, NULL); 243 return new ProfileImpl(path, NULL);
236 } 244 }
237 245
238 // static 246 // static
239 Profile* Profile::CreateProfileAsync(const FilePath& path, 247 Profile* Profile::CreateProfileAsync(const FilePath& path,
240 Profile::Delegate* delegate) { 248 Profile::Delegate* delegate) {
241 DCHECK(delegate); 249 DCHECK(delegate);
242 // This is safe while all file operations are done on the FILE thread. 250 // This is safe while all file operations are done on the FILE thread.
243 BrowserThread::PostTask(BrowserThread::FILE, 251 BrowserThread::PostTask(
244 FROM_HERE, 252 BrowserThread::FILE, FROM_HERE,
245 NewRunnableFunction(&file_util::CreateDirectory, 253 base::Bind(&CreateDirectoryNoResult, path));
246 path));
247 // Async version. 254 // Async version.
248 return new ProfileImpl(path, delegate); 255 return new ProfileImpl(path, delegate);
249 } 256 }
250 257
251 // static 258 // static
252 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { 259 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) {
253 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, 260 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled,
254 false, 261 false,
255 PrefService::UNSYNCABLE_PREF); 262 PrefService::UNSYNCABLE_PREF);
256 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, 263 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // It would be nice to use PathService for fetching this directory, but 339 // It would be nice to use PathService for fetching this directory, but
333 // the cache directory depends on the profile directory, which isn't available 340 // the cache directory depends on the profile directory, which isn't available
334 // to PathService. 341 // to PathService.
335 chrome::GetUserCacheDirectory(path_, &base_cache_path_); 342 chrome::GetUserCacheDirectory(path_, &base_cache_path_);
336 if (!delegate_) { 343 if (!delegate_) {
337 if (!file_util::CreateDirectory(base_cache_path_)) 344 if (!file_util::CreateDirectory(base_cache_path_))
338 LOG(FATAL) << "Failed to create " << base_cache_path_.value(); 345 LOG(FATAL) << "Failed to create " << base_cache_path_.value();
339 } else { 346 } else {
340 // Async profile loading is used, so call this on the FILE thread instead. 347 // Async profile loading is used, so call this on the FILE thread instead.
341 // It is safe since all other file operations should also be done there. 348 // It is safe since all other file operations should also be done there.
342 BrowserThread::PostTask(BrowserThread::FILE, 349 BrowserThread::PostTask(
343 FROM_HERE, 350 BrowserThread::FILE, FROM_HERE,
344 NewRunnableFunction(&file_util::CreateDirectory, 351 base::Bind(&CreateDirectoryNoResult, base_cache_path_));
345 base_cache_path_));
346 } 352 }
347 353
348 #if !defined(OS_CHROMEOS) 354 #if !defined(OS_CHROMEOS)
349 // Listen for bookmark model load, to bootstrap the sync service. 355 // Listen for bookmark model load, to bootstrap the sync service.
350 // On CrOS sync service will be initialized after sign in. 356 // On CrOS sync service will be initialized after sign in.
351 registrar_.Add(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, 357 registrar_.Add(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED,
352 content::Source<Profile>(this)); 358 content::Source<Profile>(this));
353 #endif 359 #endif
354 360
355 PrefService* local_state = g_browser_process->local_state(); 361 PrefService* local_state = g_browser_process->local_state();
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 641
636 ProfileImpl::~ProfileImpl() { 642 ProfileImpl::~ProfileImpl() {
637 content::NotificationService::current()->Notify( 643 content::NotificationService::current()->Notify(
638 chrome::NOTIFICATION_PROFILE_DESTROYED, 644 chrome::NOTIFICATION_PROFILE_DESTROYED,
639 content::Source<Profile>(this), 645 content::Source<Profile>(this),
640 content::NotificationService::NoDetails()); 646 content::NotificationService::NoDetails());
641 647
642 if (appcache_service_ && clear_local_state_on_exit_) { 648 if (appcache_service_ && clear_local_state_on_exit_) {
643 BrowserThread::PostTask( 649 BrowserThread::PostTask(
644 BrowserThread::IO, FROM_HERE, 650 BrowserThread::IO, FROM_HERE,
645 NewRunnableMethod( 651 base::Bind(&appcache::AppCacheService::set_clear_local_state_on_exit,
646 appcache_service_.get(), 652 appcache_service_.get(), true));
647 &appcache::AppCacheService::set_clear_local_state_on_exit,
648 true));
649 } 653 }
650 654
651 if (webkit_context_.get()) 655 if (webkit_context_.get())
652 webkit_context_->DeleteSessionOnlyData(); 656 webkit_context_->DeleteSessionOnlyData();
653 657
654 StopCreateSessionServiceTimer(); 658 StopCreateSessionServiceTimer();
655 659
656 // Remove pref observers 660 // Remove pref observers
657 pref_change_registrar_.RemoveAll(); 661 pref_change_registrar_.RemoveAll();
658 662
659 // The sync service needs to be deleted before the services it calls. 663 // The sync service needs to be deleted before the services it calls.
660 // TODO(stevet): Make ProfileSyncService into a PKS and let the PDM take care 664 // TODO(stevet): Make ProfileSyncService into a PKS and let the PDM take care
661 // of the cleanup below. 665 // of the cleanup below.
662 sync_service_.reset(); 666 sync_service_.reset();
663 667
664 ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext( 668 ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext(
665 &GetResourceContext()); 669 &GetResourceContext());
666 670
667 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); 671 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this);
668 672
669 if (db_tracker_) { 673 if (db_tracker_) {
670 BrowserThread::PostTask( 674 BrowserThread::PostTask(
671 BrowserThread::FILE, FROM_HERE, 675 BrowserThread::FILE, FROM_HERE,
672 NewRunnableMethod( 676 base::Bind(&webkit_database::DatabaseTracker::Shutdown,
673 db_tracker_.get(), 677 db_tracker_.get()));
674 &webkit_database::DatabaseTracker::Shutdown));
675 } 678 }
676 679
677 // Password store uses WebDB, shut it down before the WebDB has been shutdown. 680 // Password store uses WebDB, shut it down before the WebDB has been shutdown.
678 if (password_store_.get()) 681 if (password_store_.get())
679 password_store_->Shutdown(); 682 password_store_->Shutdown();
680 683
681 // Both HistoryService and WebDataService maintain threads for background 684 // Both HistoryService and WebDataService maintain threads for background
682 // processing. Its possible each thread still has tasks on it that have 685 // processing. Its possible each thread still has tasks on it that have
683 // increased the ref count of the service. In such a situation, when we 686 // increased the ref count of the service. In such a situation, when we
684 // decrement the refcount, it won't be 0, and the threads/databases aren't 687 // 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
964 const Extension* extension) { 967 const Extension* extension) {
965 base::Time install_time; 968 base::Time install_time;
966 if (extension->location() != Extension::COMPONENT) { 969 if (extension->location() != Extension::COMPONENT) {
967 install_time = GetExtensionService()->extension_prefs()-> 970 install_time = GetExtensionService()->extension_prefs()->
968 GetInstallTime(extension->id()); 971 GetInstallTime(extension->id());
969 } 972 }
970 bool incognito_enabled = 973 bool incognito_enabled =
971 GetExtensionService()->IsIncognitoEnabled(extension->id()); 974 GetExtensionService()->IsIncognitoEnabled(extension->id());
972 BrowserThread::PostTask( 975 BrowserThread::PostTask(
973 BrowserThread::IO, FROM_HERE, 976 BrowserThread::IO, FROM_HERE,
974 NewRunnableMethod(extension_info_map_.get(), 977 base::Bind(&ExtensionInfoMap::AddExtension, extension_info_map_.get(),
975 &ExtensionInfoMap::AddExtension, 978 make_scoped_refptr(extension), install_time,
976 make_scoped_refptr(extension), 979 incognito_enabled));
977 install_time, incognito_enabled));
978 } 980 }
979 981
980 void ProfileImpl::UnregisterExtensionWithRequestContexts( 982 void ProfileImpl::UnregisterExtensionWithRequestContexts(
981 const std::string& extension_id, 983 const std::string& extension_id,
982 const extension_misc::UnloadedExtensionReason reason) { 984 const extension_misc::UnloadedExtensionReason reason) {
983 BrowserThread::PostTask( 985 BrowserThread::PostTask(
984 BrowserThread::IO, FROM_HERE, 986 BrowserThread::IO, FROM_HERE,
985 NewRunnableMethod(extension_info_map_.get(), 987 base::Bind(&ExtensionInfoMap::RemoveExtension, extension_info_map_.get(),
986 &ExtensionInfoMap::RemoveExtension, 988 extension_id, reason));
987 extension_id,
988 reason));
989 } 989 }
990 990
991 net::SSLConfigService* ProfileImpl::GetSSLConfigService() { 991 net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
992 return ssl_config_service_manager_->Get(); 992 return ssl_config_service_manager_->Get();
993 } 993 }
994 994
995 HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() { 995 HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
996 if (!host_content_settings_map_.get()) { 996 if (!host_content_settings_map_.get()) {
997 host_content_settings_map_ = new HostContentSettingsMap( 997 host_content_settings_map_ = new HostContentSettingsMap(
998 GetPrefs(), GetExtensionService(), false); 998 GetPrefs(), GetExtensionService(), false);
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 GetExtensionSpecialStoragePolicy(), 1362 GetExtensionSpecialStoragePolicy(),
1363 quota_manager_->proxy(), 1363 quota_manager_->proxy(),
1364 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); 1364 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
1365 webkit_context_ = new WebKitContext( 1365 webkit_context_ = new WebKitContext(
1366 IsOffTheRecord(), GetPath(), GetExtensionSpecialStoragePolicy(), 1366 IsOffTheRecord(), GetPath(), GetExtensionSpecialStoragePolicy(),
1367 clear_local_state_on_exit_, quota_manager_->proxy(), 1367 clear_local_state_on_exit_, quota_manager_->proxy(),
1368 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT)); 1368 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT));
1369 appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy()); 1369 appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy());
1370 BrowserThread::PostTask( 1370 BrowserThread::PostTask(
1371 BrowserThread::IO, FROM_HERE, 1371 BrowserThread::IO, FROM_HERE,
1372 NewRunnableMethod( 1372 base::Bind(&ChromeAppCacheService::InitializeOnIOThread,
1373 appcache_service_.get(), 1373 appcache_service_.get(),
1374 &ChromeAppCacheService::InitializeOnIOThread, 1374 IsOffTheRecord()
1375 IsOffTheRecord() 1375 ? FilePath() : GetPath().Append(chrome::kAppCacheDirname),
1376 ? FilePath() : GetPath().Append(chrome::kAppCacheDirname), 1376 &GetResourceContext(),
1377 &GetResourceContext(), 1377 make_scoped_refptr(GetExtensionSpecialStoragePolicy())));
1378 make_scoped_refptr(GetExtensionSpecialStoragePolicy())));
1379 } 1378 }
1380 1379
1381 WebKitContext* ProfileImpl::GetWebKitContext() { 1380 WebKitContext* ProfileImpl::GetWebKitContext() {
1382 CreateQuotaManagerAndClients(); 1381 CreateQuotaManagerAndClients();
1383 return webkit_context_.get(); 1382 return webkit_context_.get();
1384 } 1383 }
1385 1384
1386 void ProfileImpl::MarkAsCleanShutdown() { 1385 void ProfileImpl::MarkAsCleanShutdown() {
1387 if (prefs_.get()) { 1386 if (prefs_.get()) {
1388 // The session cleanly exited, set kSessionExitedCleanly appropriately. 1387 // The session cleanly exited, set kSessionExitedCleanly appropriately.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 profile_sync_factory_->CreateProfileSyncService(cros_user)); 1523 profile_sync_factory_->CreateProfileSyncService(cros_user));
1525 profile_sync_factory_->RegisterDataTypes(sync_service_.get()); 1524 profile_sync_factory_->RegisterDataTypes(sync_service_.get());
1526 sync_service_->Initialize(); 1525 sync_service_->Initialize();
1527 } 1526 }
1528 1527
1529 ChromeBlobStorageContext* ProfileImpl::GetBlobStorageContext() { 1528 ChromeBlobStorageContext* ProfileImpl::GetBlobStorageContext() {
1530 if (!blob_storage_context_) { 1529 if (!blob_storage_context_) {
1531 blob_storage_context_ = new ChromeBlobStorageContext(); 1530 blob_storage_context_ = new ChromeBlobStorageContext();
1532 BrowserThread::PostTask( 1531 BrowserThread::PostTask(
1533 BrowserThread::IO, FROM_HERE, 1532 BrowserThread::IO, FROM_HERE,
1534 NewRunnableMethod(blob_storage_context_.get(), 1533 base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread,
1535 &ChromeBlobStorageContext::InitializeOnIOThread)); 1534 blob_storage_context_.get()));
1536 } 1535 }
1537 return blob_storage_context_; 1536 return blob_storage_context_;
1538 } 1537 }
1539 1538
1540 ExtensionInfoMap* ProfileImpl::GetExtensionInfoMap() { 1539 ExtensionInfoMap* ProfileImpl::GetExtensionInfoMap() {
1541 return extension_info_map_.get(); 1540 return extension_info_map_.get();
1542 } 1541 }
1543 1542
1544 ChromeURLDataManager* ProfileImpl::GetChromeURLDataManager() { 1543 ChromeURLDataManager* ProfileImpl::GetChromeURLDataManager() {
1545 if (!chrome_url_data_manager_.get()) 1544 if (!chrome_url_data_manager_.get())
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1707 if (!home_page.is_valid()) 1706 if (!home_page.is_valid())
1708 return GURL(chrome::kChromeUINewTabURL); 1707 return GURL(chrome::kChromeUINewTabURL);
1709 return home_page; 1708 return home_page;
1710 } 1709 }
1711 1710
1712 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() { 1711 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() {
1713 if (!spellcheck_profile_.get()) 1712 if (!spellcheck_profile_.get())
1714 spellcheck_profile_.reset(new SpellCheckProfile(path_)); 1713 spellcheck_profile_.reset(new SpellCheckProfile(path_));
1715 return spellcheck_profile_.get(); 1714 return spellcheck_profile_.get();
1716 } 1715 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/off_the_record_profile_impl.cc ('k') | chrome/browser/profiles/profile_io_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698