| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 ProfileImpl::ProfileImpl(const FilePath& path, | 220 ProfileImpl::ProfileImpl(const FilePath& path, |
| 221 Delegate* delegate, | 221 Delegate* delegate, |
| 222 CreateMode create_mode) | 222 CreateMode create_mode) |
| 223 : path_(path), | 223 : path_(path), |
| 224 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( | 224 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( |
| 225 new VisitedLinkEventListener(this))), | 225 new VisitedLinkEventListener(this))), |
| 226 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), | 226 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), |
| 227 host_content_settings_map_(NULL), | 227 host_content_settings_map_(NULL), |
| 228 history_service_created_(false), | 228 history_service_created_(false), |
| 229 favicon_service_created_(false), | 229 favicon_service_created_(false), |
| 230 created_web_data_service_(false), | |
| 231 start_time_(Time::Now()), | 230 start_time_(Time::Now()), |
| 232 delegate_(delegate), | 231 delegate_(delegate), |
| 233 predictor_(NULL), | 232 predictor_(NULL), |
| 234 session_restore_enabled_(false) { | 233 session_restore_enabled_(false) { |
| 235 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 234 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
| 236 "profile files to the root directory!"; | 235 "profile files to the root directory!"; |
| 237 | 236 |
| 238 #if defined(ENABLE_SESSION_SERVICE) | 237 #if defined(ENABLE_SESSION_SERVICE) |
| 239 create_session_service_timer_.Start(FROM_HERE, | 238 create_session_service_timer_.Start(FROM_HERE, |
| 240 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, | 239 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 if (io_data_.HasMainRequestContext() && | 479 if (io_data_.HasMainRequestContext() && |
| 481 default_request_context_ == GetRequestContext()) { | 480 default_request_context_ == GetRequestContext()) { |
| 482 default_request_context_ = NULL; | 481 default_request_context_ = NULL; |
| 483 } | 482 } |
| 484 | 483 |
| 485 // Destroy OTR profile and its profile services first. | 484 // Destroy OTR profile and its profile services first. |
| 486 DestroyOffTheRecordProfile(); | 485 DestroyOffTheRecordProfile(); |
| 487 | 486 |
| 488 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); | 487 ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); |
| 489 | 488 |
| 490 // Both HistoryService and WebDataService maintain threads for background | 489 // The HistoryService maintains threads for background processing. Its |
| 491 // processing. Its possible each thread still has tasks on it that have | 490 // possible each thread still has tasks on it that have increased the ref |
| 492 // increased the ref count of the service. In such a situation, when we | 491 // count of the service. In such a situation, when we decrement the refcount, |
| 493 // decrement the refcount, it won't be 0, and the threads/databases aren't | 492 // it won't be 0, and the threads/databases aren't properly shut down. By |
| 494 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the | 493 // explicitly calling Cleanup/Shutdown we ensure the databases are properly |
| 495 // databases are properly closed. | 494 // closed. |
| 496 if (web_data_service_.get()) | |
| 497 web_data_service_->Shutdown(); | |
| 498 | 495 |
| 499 if (top_sites_.get()) | 496 if (top_sites_.get()) |
| 500 top_sites_->Shutdown(); | 497 top_sites_->Shutdown(); |
| 501 | 498 |
| 502 if (bookmark_bar_model_.get()) { | 499 if (bookmark_bar_model_.get()) { |
| 503 // It's possible that bookmarks haven't loaded and history is waiting for | 500 // It's possible that bookmarks haven't loaded and history is waiting for |
| 504 // bookmarks to complete loading. In such a situation history can't shutdown | 501 // bookmarks to complete loading. In such a situation history can't shutdown |
| 505 // (meaning if we invoked history_service_->Cleanup now, we would | 502 // (meaning if we invoked history_service_->Cleanup now, we would |
| 506 // deadlock). To break the deadlock we tell BookmarkModel it's about to be | 503 // deadlock). To break the deadlock we tell BookmarkModel it's about to be |
| 507 // deleted so that it can release the signal history is waiting on, allowing | 504 // deleted so that it can release the signal history is waiting on, allowing |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 history::ShortcutsBackend* ProfileImpl::GetShortcutsBackend() { | 802 history::ShortcutsBackend* ProfileImpl::GetShortcutsBackend() { |
| 806 // This is called on one thread only - UI, so no magic is needed to protect | 803 // This is called on one thread only - UI, so no magic is needed to protect |
| 807 // against the multiple concurrent calls. | 804 // against the multiple concurrent calls. |
| 808 if (!shortcuts_backend_.get()) { | 805 if (!shortcuts_backend_.get()) { |
| 809 shortcuts_backend_ = new history::ShortcutsBackend(GetPath(), this); | 806 shortcuts_backend_ = new history::ShortcutsBackend(GetPath(), this); |
| 810 CHECK(shortcuts_backend_->Init()); | 807 CHECK(shortcuts_backend_->Init()); |
| 811 } | 808 } |
| 812 return shortcuts_backend_.get(); | 809 return shortcuts_backend_.get(); |
| 813 } | 810 } |
| 814 | 811 |
| 815 WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) { | |
| 816 if (!created_web_data_service_) | |
| 817 CreateWebDataService(); | |
| 818 return web_data_service_.get(); | |
| 819 } | |
| 820 | |
| 821 WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() { | |
| 822 return web_data_service_.get(); | |
| 823 } | |
| 824 | |
| 825 void ProfileImpl::CreateWebDataService() { | |
| 826 DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL); | |
| 827 created_web_data_service_ = true; | |
| 828 scoped_refptr<WebDataService> wds(new WebDataService()); | |
| 829 if (!wds->Init(GetPath())) | |
| 830 return; | |
| 831 web_data_service_.swap(wds); | |
| 832 } | |
| 833 | |
| 834 DownloadManager* ProfileImpl::GetDownloadManager() { | 812 DownloadManager* ProfileImpl::GetDownloadManager() { |
| 835 return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager(); | 813 return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager(); |
| 836 } | 814 } |
| 837 | 815 |
| 838 bool ProfileImpl::DidLastSessionExitCleanly() { | 816 bool ProfileImpl::DidLastSessionExitCleanly() { |
| 839 // last_session_exited_cleanly_ is set when the preferences are loaded. Force | 817 // last_session_exited_cleanly_ is set when the preferences are loaded. Force |
| 840 // it to be set by asking for the prefs. | 818 // it to be set by asking for the prefs. |
| 841 GetPrefs(); | 819 GetPrefs(); |
| 842 return last_session_exited_cleanly_; | 820 return last_session_exited_cleanly_; |
| 843 } | 821 } |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 FilePath* cache_path, | 1134 FilePath* cache_path, |
| 1157 int* max_size) { | 1135 int* max_size) { |
| 1158 DCHECK(cache_path); | 1136 DCHECK(cache_path); |
| 1159 DCHECK(max_size); | 1137 DCHECK(max_size); |
| 1160 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); | 1138 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); |
| 1161 if (!path.empty()) | 1139 if (!path.empty()) |
| 1162 *cache_path = path; | 1140 *cache_path = path; |
| 1163 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1141 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
| 1164 prefs_->GetInteger(prefs::kDiskCacheSize); | 1142 prefs_->GetInteger(prefs::kDiskCacheSize); |
| 1165 } | 1143 } |
| OLD | NEW |